handle AutoDiskConfigDisabledByImage at API layer
nova compute api layer might raise AutoDiskConfigDisabledByImage, so API layer need to catch them and report correct info. Also, create api handle lots of exceptions which inherit from Invalid, this patch combined them and catch Invalid only. Change-Id: Id0c89e96637d2f82b5bd204eba2c6291b9a5dd38
This commit is contained in:
@@ -983,23 +983,18 @@ class Controller(wsgi.Controller):
|
||||
except (exception.ImageNotActive,
|
||||
exception.FlavorDiskTooSmall,
|
||||
exception.FlavorMemoryTooSmall,
|
||||
exception.InvalidMetadata,
|
||||
exception.InvalidRequest,
|
||||
exception.MultiplePortsNotApplicable,
|
||||
exception.InvalidFixedIpAndMaxCountRequest,
|
||||
exception.NetworkNotFound,
|
||||
exception.PortNotFound,
|
||||
exception.FixedIpAlreadyInUse,
|
||||
exception.SecurityGroupNotFound,
|
||||
exception.InvalidBDM,
|
||||
exception.PortRequiresFixedIP,
|
||||
exception.NetworkRequiresSubnet,
|
||||
exception.InstanceUserDataTooLarge,
|
||||
exception.InstanceUserDataMalformed) as error:
|
||||
raise exc.HTTPBadRequest(explanation=error.format_message())
|
||||
except (exception.PortInUse,
|
||||
exception.NoUniqueMatch) as error:
|
||||
raise exc.HTTPConflict(explanation=error.format_message())
|
||||
except exception.Invalid as error:
|
||||
raise exc.HTTPBadRequest(explanation=error.format_message())
|
||||
|
||||
# If the caller wanted a reservation_id, return it
|
||||
if ret_resv_id:
|
||||
@@ -1189,7 +1184,8 @@ class Controller(wsgi.Controller):
|
||||
except exception.Invalid:
|
||||
msg = _("Invalid instance image.")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
except exception.NoValidHost as e:
|
||||
except (exception.NoValidHost,
|
||||
exception.AutoDiskConfigDisabledByImage) as e:
|
||||
raise exc.HTTPBadRequest(explanation=e.format_message())
|
||||
|
||||
return webob.Response(status_int=202)
|
||||
@@ -1396,7 +1392,8 @@ class Controller(wsgi.Controller):
|
||||
except (exception.ImageNotActive,
|
||||
exception.FlavorDiskTooSmall,
|
||||
exception.FlavorMemoryTooSmall,
|
||||
exception.InvalidMetadata) as error:
|
||||
exception.InvalidMetadata,
|
||||
exception.AutoDiskConfigDisabledByImage) as error:
|
||||
raise exc.HTTPBadRequest(explanation=error.format_message())
|
||||
|
||||
instance = self._get_server(context, req, id)
|
||||
|
||||
@@ -763,6 +763,22 @@ class ServerActionsControllerTest(test.TestCase):
|
||||
self.assertEqual(instance_meta['kernel_id'], '1')
|
||||
self.assertEqual(instance_meta['ramdisk_id'], '2')
|
||||
|
||||
@mock.patch.object(compute_api.API, 'rebuild')
|
||||
def test_rebuild_instance_raise_auto_disk_config_exc(self, mock_rebuild):
|
||||
body = {
|
||||
"rebuild": {
|
||||
"imageRef": self._image_href,
|
||||
},
|
||||
}
|
||||
|
||||
req = fakes.HTTPRequest.blank(self.url)
|
||||
mock_rebuild.side_effect = exception.AutoDiskConfigDisabledByImage(
|
||||
image='dummy')
|
||||
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.controller._action_rebuild,
|
||||
req, FAKE_UUID, body)
|
||||
|
||||
def test_resize_server(self):
|
||||
|
||||
body = dict(resize=dict(flavorRef="http://localhost/3"))
|
||||
@@ -871,6 +887,18 @@ class ServerActionsControllerTest(test.TestCase):
|
||||
self.controller._action_resize,
|
||||
req, FAKE_UUID, body)
|
||||
|
||||
@mock.patch.object(compute_api.API, 'resize')
|
||||
def test_resize_instance_raise_auto_disk_config_exc(self, mock_resize):
|
||||
mock_resize.side_effect = exception.AutoDiskConfigDisabledByImage(
|
||||
image='dummy')
|
||||
|
||||
body = dict(resize=dict(flavorRef="http://localhost/3"))
|
||||
|
||||
req = fakes.HTTPRequest.blank(self.url)
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.controller._action_resize,
|
||||
req, FAKE_UUID, body)
|
||||
|
||||
def test_confirm_resize_server(self):
|
||||
body = dict(confirmResize=None)
|
||||
|
||||
|
||||
@@ -2166,6 +2166,15 @@ class ServersControllerCreateTest(test.TestCase):
|
||||
self.controller.create,
|
||||
self.req, self.body)
|
||||
|
||||
@mock.patch.object(compute_api.API, 'create')
|
||||
def test_create_instance_raise_auto_disk_config_exc(self, mock_create):
|
||||
mock_create.side_effect = exception.AutoDiskConfigDisabledByImage(
|
||||
image='dummy')
|
||||
|
||||
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'
|
||||
|
||||
Reference in New Issue
Block a user