resize: Add bw min service level check of source compute

During resize the RequestSpec goes from the dest compute to the
source compute and then back to the dest. The previous patch [1] added
service level check for the dest compute. However the source compute also
needs to be new enough so the RequestSpec is passed through it.

Please note that the functional coverage for this api change is in a
later patch [2].

[1] https://review.opendev.org/#/c/680394
[2] https://review.opendev.org/#/c/679019

blueprint: support-move-ops-with-qos-ports
Change-Id: Ib1a73f5e20b6f9a325d8b24d9253a18f2a46db1f
This commit is contained in:
Balazs Gibizer 2019-09-04 12:34:19 +02:00
parent a061b0ea2e
commit d19b8badbc
2 changed files with 43 additions and 8 deletions

View File

@ -85,6 +85,8 @@ INVALID_FLAVOR_IMAGE_EXCEPTIONS = (
exception.RealtimeMaskNotFoundOrInvalid,
)
MIN_COMPUTE_MOVE_BANDWIDTH = 39
class ServersController(wsgi.Controller):
"""The Server API base controller class for the OpenStack API."""
@ -940,14 +942,25 @@ class ServersController(wsgi.Controller):
# We could potentially move this check to conductor and avoid the
# extra API call to neutron when we support move operations with ports
# having resource requests.
if (common.instance_has_port_with_resource_request(
context, instance_id, self.network_api) and not
common.supports_port_resource_request_during_move(req)):
msg = _("The resize action on a server with ports having "
"resource requests, like a port with a QoS minimum "
"bandwidth policy, is not supported with this "
"microversion")
raise exc.HTTPBadRequest(explanation=msg)
if common.instance_has_port_with_resource_request(
context, instance_id, self.network_api):
if not common.supports_port_resource_request_during_move(req):
msg = _("The resize action on a server with ports having "
"resource requests, like a port with a QoS minimum "
"bandwidth policy, is not supported with this "
"microversion")
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:
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.controller._action_create_image,
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')