diff --git a/nova/api/openstack/compute/plugins/v3/attach_interfaces.py b/nova/api/openstack/compute/plugins/v3/attach_interfaces.py index d33595cae0c9..fdb671f6dfbb 100644 --- a/nova/api/openstack/compute/plugins/v3/attach_interfaces.py +++ b/nova/api/openstack/compute/plugins/v3/attach_interfaces.py @@ -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()) diff --git a/nova/api/openstack/compute/plugins/v3/evacuate.py b/nova/api/openstack/compute/plugins/v3/evacuate.py index 2f709c5b8482..a859cdf79dd1 100644 --- a/nova/api/openstack/compute/plugins/v3/evacuate.py +++ b/nova/api/openstack/compute/plugins/v3/evacuate.py @@ -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) diff --git a/nova/api/openstack/compute/plugins/v3/images.py b/nova/api/openstack/compute/plugins/v3/images.py index a85c2c4866e9..692cfa41ef11 100644 --- a/nova/api/openstack/compute/plugins/v3/images.py +++ b/nova/api/openstack/compute/plugins/v3/images.py @@ -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) diff --git a/nova/api/openstack/compute/plugins/v3/servers.py b/nova/api/openstack/compute/plugins/v3/servers.py index aa3c05055313..640890e700c4 100644 --- a/nova/api/openstack/compute/plugins/v3/servers.py +++ b/nova/api/openstack/compute/plugins/v3/servers.py @@ -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: diff --git a/nova/api/openstack/compute/plugins/v3/volumes.py b/nova/api/openstack/compute/plugins/v3/volumes.py index 82226b937bce..0db84d87a93f 100644 --- a/nova/api/openstack/compute/plugins/v3/volumes.py +++ b/nova/api/openstack/compute/plugins/v3/volumes.py @@ -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(()) diff --git a/nova/tests/unit/api/openstack/compute/contrib/test_attach_interfaces.py b/nova/tests/unit/api/openstack/compute/contrib/test_attach_interfaces.py index 09cd9487dc9c..d1c3d6a44d24 100644 --- a/nova/tests/unit/api/openstack/compute/contrib/test_attach_interfaces.py +++ b/nova/tests/unit/api/openstack/compute/contrib/test_attach_interfaces.py @@ -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) diff --git a/nova/tests/unit/api/openstack/compute/contrib/test_fping.py b/nova/tests/unit/api/openstack/compute/contrib/test_fping.py index a6364d6ee7f7..428cf8247736 100644 --- a/nova/tests/unit/api/openstack/compute/contrib/test_fping.py +++ b/nova/tests/unit/api/openstack/compute/contrib/test_fping.py @@ -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 diff --git a/nova/tests/unit/api/openstack/compute/test_images.py b/nova/tests/unit/api/openstack/compute/test_images.py index f3c172d940c5..b34a9ad03155 100644 --- a/nova/tests/unit/api/openstack/compute/test_images.py +++ b/nova/tests/unit/api/openstack/compute/test_images.py @@ -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, diff --git a/nova/tests/unit/api/openstack/fakes.py b/nova/tests/unit/api/openstack/fakes.py index e628a2a24ae5..2819e1f1ef7c 100644 --- a/nova/tests/unit/api/openstack/fakes.py +++ b/nova/tests/unit/api/openstack/fakes.py @@ -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)