V2.1 cleanup: Use concrete NotFound exception instead of generic
V2.1 API use decorator expected_error protect we haven't any unexpected exception raise out. So we should use concrete exception instead of generic exception. This patch uses concrete NotFound exception instead of the generic exception NotFound. Change-Id: I13a04bdc78b92de69b81333eeb529cadc4d3c856
This commit is contained in:
parent
afeb8a7b0e
commit
83c9d3e55e
|
@ -73,7 +73,7 @@ class InterfaceAttachmentController(wsgi.Controller):
|
|||
|
||||
try:
|
||||
port_info = self.network_api.show_port(context, port_id)
|
||||
except exception.NotFound as e:
|
||||
except exception.PortNotFound as e:
|
||||
raise exc.HTTPNotFound(explanation=e.format_message())
|
||||
except exception.Forbidden as e:
|
||||
raise exc.HTTPForbidden(explanation=e.format_message())
|
||||
|
|
|
@ -74,7 +74,7 @@ class EvacuateController(wsgi.Controller):
|
|||
if host is not None:
|
||||
try:
|
||||
self.host_api.service_get_by_compute_host(context, host)
|
||||
except exception.NotFound:
|
||||
except exception.ComputeHostNotFound:
|
||||
msg = _("Compute host %s not found.") % host
|
||||
raise exc.HTTPNotFound(explanation=msg)
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ class ImagesController(wsgi.Controller):
|
|||
|
||||
try:
|
||||
image = self._image_api.get(context, id)
|
||||
except (exception.NotFound, exception.InvalidImageRef):
|
||||
except (exception.ImageNotFound, exception.InvalidImageRef):
|
||||
explanation = _("Image not found.")
|
||||
raise webob.exc.HTTPNotFound(explanation=explanation)
|
||||
|
||||
|
|
|
@ -728,7 +728,7 @@ class ServersController(wsgi.Controller):
|
|||
instance.update(update_dict)
|
||||
instance.save()
|
||||
return self._view_builder.show(req, instance)
|
||||
except exception.NotFound:
|
||||
except exception.InstanceNotFound:
|
||||
msg = _("Instance could not be found")
|
||||
raise exc.HTTPNotFound(explanation=msg)
|
||||
|
||||
|
@ -836,7 +836,7 @@ class ServersController(wsgi.Controller):
|
|||
"""Destroys a server."""
|
||||
try:
|
||||
self._delete(req.environ['nova.context'], req, id)
|
||||
except exception.NotFound:
|
||||
except exception.InstanceNotFound:
|
||||
msg = _("Instance could not be found")
|
||||
raise exc.HTTPNotFound(explanation=msg)
|
||||
except exception.InstanceIsLocked as e:
|
||||
|
|
|
@ -95,7 +95,7 @@ class VolumeController(wsgi.Controller):
|
|||
|
||||
try:
|
||||
vol = self.volume_api.get(context, id)
|
||||
except exception.NotFound as e:
|
||||
except exception.VolumeNotFound as e:
|
||||
raise exc.HTTPNotFound(explanation=e.format_message())
|
||||
|
||||
return {'volume': _translate_volume_detail_view(context, vol)}
|
||||
|
@ -109,7 +109,7 @@ class VolumeController(wsgi.Controller):
|
|||
|
||||
try:
|
||||
self.volume_api.delete(context, id)
|
||||
except exception.NotFound as e:
|
||||
except exception.VolumeNotFound as e:
|
||||
raise exc.HTTPNotFound(explanation=e.format_message())
|
||||
|
||||
@extensions.expected_errors(())
|
||||
|
@ -471,7 +471,7 @@ class SnapshotController(wsgi.Controller):
|
|||
|
||||
try:
|
||||
vol = self.volume_api.get_snapshot(context, id)
|
||||
except exception.NotFound as e:
|
||||
except exception.SnapshotNotFound as e:
|
||||
raise exc.HTTPNotFound(explanation=e.format_message())
|
||||
|
||||
return {'snapshot': _translate_snapshot_detail_view(context, vol)}
|
||||
|
@ -485,7 +485,7 @@ class SnapshotController(wsgi.Controller):
|
|||
|
||||
try:
|
||||
self.volume_api.delete_snapshot(context, id)
|
||||
except exception.NotFound as e:
|
||||
except exception.SnapshotNotFound as e:
|
||||
raise exc.HTTPNotFound(explanation=e.format_message())
|
||||
|
||||
@extensions.expected_errors(())
|
||||
|
|
|
@ -175,7 +175,7 @@ class InterfaceAttachTestsV21(test.NoDBTestCase):
|
|||
result = self.attachments.show(self.req, FAKE_UUID1, FAKE_PORT_ID1)
|
||||
self.assertEqual(self.expected_show, result)
|
||||
|
||||
def test_show_invalid(self):
|
||||
def test_show_with_port_not_found(self):
|
||||
self.assertRaises(exc.HTTPNotFound,
|
||||
self.attachments.show, self.req, FAKE_UUID2,
|
||||
FAKE_PORT_ID1)
|
||||
|
|
|
@ -14,6 +14,9 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
import webob
|
||||
|
||||
from nova.api.openstack.compute.contrib import fping
|
||||
from nova.api.openstack.compute.plugins.v3 import fping as fping_v21
|
||||
from nova import exception
|
||||
|
@ -98,6 +101,15 @@ class FpingTestV21(test.TestCase):
|
|||
for key in "project_id", "id", "alive":
|
||||
self.assertIn(key, srv)
|
||||
|
||||
@mock.patch('nova.db.instance_get_by_uuid')
|
||||
def test_fping_show_with_not_found(self, mock_get_instance):
|
||||
mock_get_instance.side_effect = exception.InstanceNotFound(
|
||||
instance_id='')
|
||||
req = fakes.HTTPRequest.blank(self._get_url() +
|
||||
"os-fping/%s" % FAKE_UUID)
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.controller.show, req, FAKE_UUID)
|
||||
|
||||
|
||||
class FpingTestV2(FpingTestV21):
|
||||
controller_cls = fping.FpingController
|
||||
|
|
|
@ -174,7 +174,8 @@ class ImagesControllerTestV21(test.NoDBTestCase):
|
|||
|
||||
self.assertThat(actual_image, matchers.DictMatches(expected_image))
|
||||
|
||||
@mock.patch('nova.image.api.API.get', side_effect=exception.NotFound)
|
||||
@mock.patch('nova.image.api.API.get',
|
||||
side_effect=exception.ImageNotFound(image_id=''))
|
||||
def test_get_image_404(self, _get_mocked):
|
||||
fake_req = self.http_request.blank(self.url_base + 'images/unknown')
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
|
|
|
@ -649,7 +649,7 @@ def stub_compute_volume_snapshot_create(self, context, volume_id, create_info):
|
|||
|
||||
def stub_snapshot_delete(self, context, snapshot_id):
|
||||
if snapshot_id == '-1':
|
||||
raise exc.NotFound
|
||||
raise exc.SnapshotNotFound(snapshot_id=snapshot_id)
|
||||
|
||||
|
||||
def stub_compute_volume_snapshot_delete(self, context, volume_id, snapshot_id,
|
||||
|
@ -659,7 +659,7 @@ def stub_compute_volume_snapshot_delete(self, context, volume_id, snapshot_id,
|
|||
|
||||
def stub_snapshot_get(self, context, snapshot_id):
|
||||
if snapshot_id == '-1':
|
||||
raise exc.NotFound
|
||||
raise exc.SnapshotNotFound(snapshot_id=snapshot_id)
|
||||
return stub_snapshot(snapshot_id)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue