diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-12-19 12:27:40 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-12-19 12:27:40 +0000 |
| commit | b3540b094a3aff072dd497ec49fa4c8fae110d82 (patch) | |
| tree | 31a25a6fec217e5569985dcd223c519ac72b4dec | |
| parent | 1d864329c6c5320bde0cd30e3b39f2f93bbe9196 (diff) | |
| parent | 921eec91abee56ea69e1b8b2bff59379b68bff87 (diff) | |
| download | nova-b3540b094a3aff072dd497ec49fa4c8fae110d82.tar.gz nova-b3540b094a3aff072dd497ec49fa4c8fae110d82.tar.xz nova-b3540b094a3aff072dd497ec49fa4c8fae110d82.zip | |
Merge "Fixed deleting instance booted from invalid vol"
| -rw-r--r-- | nova/tests/test_cinder.py | 9 | ||||
| -rw-r--r-- | nova/volume/cinder.py | 21 |
2 files changed, 28 insertions, 2 deletions
diff --git a/nova/tests/test_cinder.py b/nova/tests/test_cinder.py index 3302aedb8..11d29a3ff 100644 --- a/nova/tests/test_cinder.py +++ b/nova/tests/test_cinder.py @@ -17,7 +17,9 @@ import httplib2 import urlparse +from cinderclient import exceptions as cinder_exception from nova import context +from nova import exception from nova.volume import cinder from nova import test @@ -77,6 +79,9 @@ class FakeHTTPClient(cinder.cinder_client.client.HTTPClient): volume = {'volume': _stub_volume(id='1234')} return (200, volume) + def get_volumes_nonexisting(self, **kw): + raise cinder_exception.NotFound(code=404, message='Resource not found') + class FakeCinderClient(cinder.cinder_client.Client): @@ -146,3 +151,7 @@ class CinderTestCase(test.TestCase): self.assertEquals( self.fake_client_factory.client.client.management_url, 'http://other_host:8776/v1/project_id') + + def test_get_non_existing_volume(self): + self.assertRaises(exception.VolumeNotFound, self.api.get, self.context, + 'nonexisting') diff --git a/nova/volume/cinder.py b/nova/volume/cinder.py index ae7b76e26..1b8305505 100644 --- a/nova/volume/cinder.py +++ b/nova/volume/cinder.py @@ -20,7 +20,9 @@ Handles all requests relating to volumes + cinder. """ +import sys +from cinderclient import exceptions as cinder_exception from cinderclient import service_catalog from cinderclient.v1 import client as cinder_client @@ -139,9 +141,24 @@ def _untranslate_snapshot_summary_view(context, snapshot): class API(base.Base): """API for interacting with the volume manager.""" + def _reraise_translated_volume_exception(self, volume_id): + """Transform the exception for the volume but keep its traceback + intact.""" + exc_type, exc_value, exc_trace = sys.exc_info() + new_exc = self._translate_volume_exception(volume_id, exc_value) + raise new_exc, None, exc_trace + + def _translate_volume_exception(self, volume_id, exc_value): + if isinstance(exc_value, cinder_exception.NotFound): + return exception.VolumeNotFound(volume_id=volume_id) + return exc_value + def get(self, context, volume_id): - item = cinderclient(context).volumes.get(volume_id) - return _untranslate_volume_summary_view(context, item) + try: + item = cinderclient(context).volumes.get(volume_id) + return _untranslate_volume_summary_view(context, item) + except Exception: + self._reraise_translated_volume_exception(volume_id) def get_all(self, context, search_opts={}): items = cinderclient(context).volumes.list(detailed=True) |
