summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorUnmesh Gurjar <unmesh.gurjar@nttdata.com>2012-12-11 03:30:31 -0800
committerUnmesh Gurjar <unmesh.gurjar@nttdata.com>2012-12-14 06:03:03 -0800
commit921eec91abee56ea69e1b8b2bff59379b68bff87 (patch)
tree4918cd80c54d28ab08e4b89be9432acc1d43ab67 /nova
parent0597c1ccd31e7264395bcb451b8b6d38d5bfa92f (diff)
downloadnova-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')
-rw-r--r--nova/tests/test_cinder.py9
-rw-r--r--nova/volume/cinder.py21
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)