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
(cherry picked from commit 921eec91ab
)
This commit is contained in:
parent
2fcd06c3c2
commit
43e35a1ddc
|
@ -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):
|
||||
|
||||
|
@ -149,3 +154,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')
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -140,9 +142,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)
|
||||
|
|
Loading…
Reference in New Issue