Merge "resize: Add bw min service level check of source compute"

This commit is contained in:
Zuul 2019-09-09 19:20:58 +00:00 committed by Gerrit Code Review
commit 56873d1258
2 changed files with 43 additions and 8 deletions

View File

@ -86,6 +86,8 @@ INVALID_FLAVOR_IMAGE_EXCEPTIONS = (
exception.RealtimeMaskNotFoundOrInvalid, exception.RealtimeMaskNotFoundOrInvalid,
) )
MIN_COMPUTE_MOVE_BANDWIDTH = 39
class ServersController(wsgi.Controller): class ServersController(wsgi.Controller):
"""The Server API base controller class for the OpenStack API.""" """The Server API base controller class for the OpenStack API."""
@ -941,14 +943,25 @@ class ServersController(wsgi.Controller):
# We could potentially move this check to conductor and avoid the # We could potentially move this check to conductor and avoid the
# extra API call to neutron when we support move operations with ports # extra API call to neutron when we support move operations with ports
# having resource requests. # having resource requests.
if (common.instance_has_port_with_resource_request( if common.instance_has_port_with_resource_request(
context, instance_id, self.network_api) and not context, instance_id, self.network_api):
common.supports_port_resource_request_during_move(req)): if not common.supports_port_resource_request_during_move(req):
msg = _("The resize action on a server with ports having " msg = _("The resize action on a server with ports having "
"resource requests, like a port with a QoS minimum " "resource requests, like a port with a QoS minimum "
"bandwidth policy, is not supported with this " "bandwidth policy, is not supported with this "
"microversion") "microversion")
raise exc.HTTPBadRequest(explanation=msg) raise exc.HTTPBadRequest(explanation=msg)
# TODO(gibi): Remove when nova only supports compute newer than
# Train
source_service = objects.Service.get_by_host_and_binary(
context, instance.host, 'nova-compute')
if source_service.version < MIN_COMPUTE_MOVE_BANDWIDTH:
msg = _("The resize action on a server with ports having "
"resource requests, like a port with a QoS "
"minimum bandwidth policy, is not yet supported "
"on the source compute")
raise exc.HTTPConflict(explanation=msg)
try: try:
self.compute_api.resize(context, instance, flavor_id, **kwargs) self.compute_api.resize(context, instance, flavor_id, **kwargs)

View File

@ -1222,3 +1222,25 @@ class ServerActionsControllerTestV21(test.TestCase):
self.assertRaises(webob.exc.HTTPConflict, self.assertRaises(webob.exc.HTTPConflict,
self.controller._action_create_image, self.controller._action_create_image,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
@mock.patch('nova.api.openstack.common.'
'supports_port_resource_request_during_move',
return_value=True)
@mock.patch('nova.objects.Service.get_by_host_and_binary')
@mock.patch('nova.api.openstack.common.'
'instance_has_port_with_resource_request', return_value=True)
def test_resize_with_bandwidth_from_old_compute_not_supported(
self, mock_has_res_req, mock_get_service, mock_support):
body = dict(resize=dict(flavorRef="http://localhost/3"))
mock_get_service.return_value = objects.Service()
mock_get_service.return_value.version = 38
self.assertRaises(webob.exc.HTTPConflict,
self.controller._action_resize,
self.req, FAKE_UUID, body=body)
mock_has_res_req.assert_called_once_with(
self.req.environ['nova.context'], FAKE_UUID,
self.controller.network_api)
mock_get_service.assert_called_once_with(
self.req.environ['nova.context'], 'fake_host', 'nova-compute')