diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index 4d0acd538c72..97d4b96df2bd 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -712,7 +712,8 @@ class ServersController(wsgi.Controller): exception.ImageNUMATopologyCPUDuplicates, exception.ImageNUMATopologyCPUsUnassigned, exception.ImageNUMATopologyMemoryOutOfRange, - exception.InstanceGroupNotFound) as error: + exception.InstanceGroupNotFound, + exception.PciRequestAliasNotDefined) as error: raise exc.HTTPBadRequest(explanation=error.format_message()) except (exception.PortInUse, exception.InstanceExists, @@ -943,7 +944,8 @@ class ServersController(wsgi.Controller): exception.CannotResizeDisk, exception.CannotResizeToSameFlavor, exception.FlavorNotFound, - exception.NoValidHost) as e: + exception.NoValidHost, + exception.PciRequestAliasNotDefined) as e: raise exc.HTTPBadRequest(explanation=e.format_message()) except exception.Invalid: msg = _("Invalid instance image.") diff --git a/nova/tests/unit/api/openstack/compute/test_server_actions.py b/nova/tests/unit/api/openstack/compute/test_server_actions.py index b6af65ca6a5b..aacf455034ee 100644 --- a/nova/tests/unit/api/openstack/compute/test_server_actions.py +++ b/nova/tests/unit/api/openstack/compute/test_server_actions.py @@ -800,6 +800,16 @@ class ServerActionsControllerTestV21(test.TestCase): self.controller._action_resize, self.req, FAKE_UUID, body=body) + @mock.patch('nova.compute.api.API.resize', + side_effect=exception.PciRequestAliasNotDefined( + alias='fake_name')) + def test_resize_pci_alias_not_defined(self, mock_resize): + # Tests that PciRequestAliasNotDefined is translated to a 400 error. + body = dict(resize=dict(flavorRef="http://localhost/3")) + self.assertRaises(webob.exc.HTTPBadRequest, + self.controller._action_resize, + self.req, FAKE_UUID, body=body) + def test_confirm_resize_server(self): body = dict(confirmResize=None) diff --git a/nova/tests/unit/api/openstack/compute/test_serversV21.py b/nova/tests/unit/api/openstack/compute/test_serversV21.py index fe0b47d2e92f..5a1ed2162e3f 100644 --- a/nova/tests/unit/api/openstack/compute/test_serversV21.py +++ b/nova/tests/unit/api/openstack/compute/test_serversV21.py @@ -3377,6 +3377,14 @@ class ServersControllerCreateTest(test.TestCase): self.controller.create, self.req, body=self.body) + @mock.patch.object(compute_api.API, 'create', + side_effect=exception.PciRequestAliasNotDefined( + alias='fake_name')) + def test_create_instance_pci_alias_not_defined(self, mock_create): + # Tests that PciRequestAliasNotDefined is translated to a 400 error. + self.assertRaises(webob.exc.HTTPBadRequest, + self._test_create_extra, {}) + class ServersControllerCreateTestV219(ServersControllerCreateTest): def _create_instance_req(self, set_desc, desc=None):