diff options
author | Unmesh Gurjar <unmesh.gurjar@nttdata.com> | 2012-12-11 03:30:31 -0800 |
---|---|---|
committer | Unmesh Gurjar <unmesh.gurjar@nttdata.com> | 2012-12-14 06:03:03 -0800 |
commit | 921eec91abee56ea69e1b8b2bff59379b68bff87 (patch) | |
tree | 4918cd80c54d28ab08e4b89be9432acc1d43ab67 /nova/volume | |
parent | 0597c1ccd31e7264395bcb451b8b6d38d5bfa92f (diff) | |
download | nova-921eec91abee56ea69e1b8b2bff59379b68bff87.tar.gz nova-921eec91abee56ea69e1b8b2bff59379b68bff87.tar.xz nova-921eec91abee56ea69e1b8b2bff59379b68bff87.zip |
Fixed deleting instance booted from invalid vol
1. Translated the exception (NotFound) raised from Cinder client to
Nova's native exception (VolumeNotFound).
2. Added unit test coverage.
Fixes LP: #1087214.
Change-Id: I3cee31a9fd068b65a4097f3f3054aebb69d9ba61
Diffstat (limited to 'nova/volume')
-rw-r--r-- | nova/volume/cinder.py | 21 |
1 files changed, 19 insertions, 2 deletions
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) |