From 673f3118b6b558f8c23a669ad6aae1cf8df6632e Mon Sep 17 00:00:00 2001 From: Chris Yeoh Date: Wed, 17 Apr 2013 10:02:33 +0930 Subject: Translate cinder NotFound exception When we attempt to get information about a snapshot which doesn't exist we get a cinder NotFound exception. However, this is not caught and causes a stacktrace in the logs. This occurs on every tempest run in the test EC2VolumesTest.test_create_volume_from_snapshot. The fix is to translate the exception to SnapshotNotFound which is handled correctly further up the call chain. Fixes bug 1169777 Part of blueprint no-stacktraces-in-logs Change-Id: If893b5083b93894e671c978bd23bd89d3d017531 --- nova/tests/volume/test_cinder.py | 8 ++++++++ nova/volume/cinder.py | 17 ++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/nova/tests/volume/test_cinder.py b/nova/tests/volume/test_cinder.py index 78d2602cc..420fa2373 100644 --- a/nova/tests/volume/test_cinder.py +++ b/nova/tests/volume/test_cinder.py @@ -229,6 +229,14 @@ class CinderApiTestCase(test.TestCase): self.api.get_snapshot(self.ctx, snapshot_id) + def test_get_snapshot_failed(self): + snapshot_id = 'snapshot_id' + cinder.cinderclient(self.ctx).AndRaise(cinder_exception.NotFound('')) + self.mox.ReplayAll() + + self.assertRaises(exception.SnapshotNotFound, + self.api.get_snapshot, self.ctx, snapshot_id) + def test_get_all_snapshots(self): cinder.cinderclient(self.ctx).AndReturn(self.cinderclient) cinder._untranslate_snapshot_summary_view(self.ctx, diff --git a/nova/volume/cinder.py b/nova/volume/cinder.py index 98e548332..0d2666038 100644 --- a/nova/volume/cinder.py +++ b/nova/volume/cinder.py @@ -185,6 +185,18 @@ class API(base.Base): return exception.InvalidInput(reason=exc_value.message) return exc_value + def _reraise_translated_snapshot_exception(self, snapshot_id=None): + """Transform the exception for the snapshot but keep its traceback + intact.""" + exc_type, exc_value, exc_trace = sys.exc_info() + new_exc = self._translate_snapshot_exception(snapshot_id, exc_value) + raise new_exc, None, exc_trace + + def _translate_snapshot_exception(self, snapshot_id, exc_value): + if isinstance(exc_value, cinder_exception.NotFound): + return exception.SnapshotNotFound(snapshot_id=snapshot_id) + return exc_value + def get(self, context, volume_id): try: item = cinderclient(context).volumes.get(volume_id) @@ -280,7 +292,10 @@ class API(base.Base): raise NotImplementedError() def get_snapshot(self, context, snapshot_id): - item = cinderclient(context).volume_snapshots.get(snapshot_id) + try: + item = cinderclient(context).volume_snapshots.get(snapshot_id) + except Exception: + self._reraise_translated_snapshot_exception(snapshot_id) return _untranslate_snapshot_summary_view(context, item) def get_all_snapshots(self, context): -- cgit