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 <chris.friesen@windriver.com>
This commit is contained in:
Chris Friesen 2019-03-05 09:53:37 -06:00
parent c43c1d3fb9
commit cb5ad6d3c1
2 changed files with 13 additions and 2 deletions

View File

@ -726,6 +726,7 @@ class ServersController(wsgi.Controller):
exception.MemoryPageSizeInvalid,
exception.MemoryPageSizeForbidden,
exception.PciRequestAliasNotDefined,
exception.PciInvalidAlias,
exception.RealtimeConfigurationInvalid,
exception.RealtimeMaskNotFoundOrInvalid,
exception.SnapshotNotFound,

View File

@ -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")