Handle InstanceUserDataTooLarge at api layer

compute layer might raise InstanceUserDataTooLarge exception,
this patch catches the exception at API layer and handle it.

Closes-Bug: #1338473

Change-Id: I881e526eaa51ab28316f643430d904f620123d56
This commit is contained in:
jichenjc
2014-07-03 09:37:09 +08:00
parent 825c9eae08
commit fa7da67af1
4 changed files with 20 additions and 0 deletions

View File

@@ -517,6 +517,7 @@ class ServersController(wsgi.Controller):
exception.InvalidRequest,
exception.MultiplePortsNotApplicable,
exception.InstanceUserDataMalformed,
exception.InstanceUserDataTooLarge,
exception.PortNotFound,
exception.FixedIpAlreadyInUse,
exception.SecurityGroupNotFound,

View File

@@ -993,6 +993,7 @@ class Controller(wsgi.Controller):
exception.InvalidBDM,
exception.PortRequiresFixedIP,
exception.NetworkRequiresSubnet,
exception.InstanceUserDataTooLarge,
exception.InstanceUserDataMalformed) as error:
raise exc.HTTPBadRequest(explanation=error.format_message())
except (exception.PortInUse,

View File

@@ -2094,6 +2094,15 @@ class ServersControllerCreateTest(test.TestCase):
self.assertRaises(webob.exc.HTTPBadRequest,
self._test_create_extra, params)
@mock.patch.object(compute_api.API, 'create')
def test_create_instance_raise_user_data_too_large(self, mock_create):
mock_create.side_effect = exception.InstanceUserDataTooLarge(
maxsize=1, length=2)
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.create,
self.req, self.body)
def test_create_instance_with_network_with_no_subnet(self):
network = 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee'
requested_networks = [{'uuid': network}]

View File

@@ -2157,6 +2157,15 @@ class ServersControllerCreateTest(test.TestCase):
self.assertRaises(webob.exc.HTTPBadRequest,
self._test_create_extra, params)
@mock.patch.object(compute_api.API, 'create')
def test_create_instance_raise_user_data_too_large(self, mock_create):
mock_create.side_effect = exception.InstanceUserDataTooLarge(
maxsize=1, length=2)
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.create,
self.req, self.body)
def test_create_instance_with_network_with_no_subnet(self):
self.flags(network_api_class='nova.network.neutronv2.api.API')
network = 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee'