diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-04-23 16:21:17 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-04-23 16:21:17 +0000 |
| commit | 98efba2dff8f67220595447728f69330089a3ebd (patch) | |
| tree | de63c78b389f9dad6cd06c1828dfa92ca4f058ae | |
| parent | 28cfcd5020e6168f9de38978558683b528055be5 (diff) | |
| parent | 673f3118b6b558f8c23a669ad6aae1cf8df6632e (diff) | |
| download | nova-98efba2dff8f67220595447728f69330089a3ebd.tar.gz nova-98efba2dff8f67220595447728f69330089a3ebd.tar.xz nova-98efba2dff8f67220595447728f69330089a3ebd.zip | |
Merge "Translate cinder NotFound exception"
| -rw-r--r-- | nova/tests/volume/test_cinder.py | 8 | ||||
| -rw-r--r-- | nova/volume/cinder.py | 17 |
2 files changed, 24 insertions, 1 deletions
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): |
