From cb5ad6d3c14caccfc2b222dc5d2f1f6c5e05da9c Mon Sep 17 00:00:00 2001 From: Chris Friesen Date: Tue, 5 Mar 2019 09:53:37 -0600 Subject: [PATCH] Handle missing exception in instance creation code In the instance creation code path it's possible for the PciInvalidAlias exception to be raised if the flavor extra-specs have an invalid PCI alias. This should be converted to HTTPBadRequest along with the other exceptions stemming from invalid extra-specs. Without this, it gets reported as an HTTP 500 error. Change-Id: Ia6921b5cd9253f65ff6904bdbce942759633de95 Closes-Bug: #1818701 Signed-off-by: Chris Friesen --- nova/api/openstack/compute/servers.py | 1 + .../unit/api/openstack/compute/test_serversV21.py | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index ed44746924..02d2fcdb58 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -726,6 +726,7 @@ class ServersController(wsgi.Controller): exception.MemoryPageSizeInvalid, exception.MemoryPageSizeForbidden, exception.PciRequestAliasNotDefined, + exception.PciInvalidAlias, exception.RealtimeConfigurationInvalid, exception.RealtimeMaskNotFoundOrInvalid, exception.SnapshotNotFound, diff --git a/nova/tests/unit/api/openstack/compute/test_serversV21.py b/nova/tests/unit/api/openstack/compute/test_serversV21.py index 170a54c7ba..93fb95dfa0 100644 --- a/nova/tests/unit/api/openstack/compute/test_serversV21.py +++ b/nova/tests/unit/api/openstack/compute/test_serversV21.py @@ -6068,8 +6068,18 @@ class ServersControllerCreateTest(test.TestCase): 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, {}) + ex = self.assertRaises(webob.exc.HTTPBadRequest, + self._test_create_extra, {}) + self.assertIn('PCI alias fake_name is not defined', six.text_type(ex)) + + @mock.patch.object(compute_api.API, 'create', + side_effect=exception.PciInvalidAlias( + reason='just because')) + def test_create_instance_pci_invalid_alias(self, mock_create): + # Tests that PciInvalidAlias is translated to a 400 error. + ex = self.assertRaises(webob.exc.HTTPBadRequest, + self._test_create_extra, {}) + self.assertIn('Invalid PCI alias definition', six.text_type(ex)) def test_create_instance_with_user_data(self): value = base64.encode_as_text("A random string")