Browse Source

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

changes/72/671072/18
Zuul 1 week ago
parent
commit
56873d1258

+ 21
- 8
nova/api/openstack/compute/servers.py View File

@@ -86,6 +86,8 @@ INVALID_FLAVOR_IMAGE_EXCEPTIONS = (
86 86
     exception.RealtimeMaskNotFoundOrInvalid,
87 87
 )
88 88
 
89
+MIN_COMPUTE_MOVE_BANDWIDTH = 39
90
+
89 91
 
90 92
 class ServersController(wsgi.Controller):
91 93
     """The Server API base controller class for the OpenStack API."""
@@ -941,14 +943,25 @@ class ServersController(wsgi.Controller):
941 943
         # We could potentially move this check to conductor and avoid the
942 944
         # extra API call to neutron when we support move operations with ports
943 945
         # having resource requests.
944
-        if (common.instance_has_port_with_resource_request(
945
-                    context, instance_id, self.network_api) and not
946
-                common.supports_port_resource_request_during_move(req)):
947
-            msg = _("The resize action on a server with ports having "
948
-                    "resource requests, like a port with a QoS minimum "
949
-                    "bandwidth policy, is not supported with this "
950
-                    "microversion")
951
-            raise exc.HTTPBadRequest(explanation=msg)
946
+        if common.instance_has_port_with_resource_request(
947
+                context, instance_id, self.network_api):
948
+            if not common.supports_port_resource_request_during_move(req):
949
+                msg = _("The resize action on a server with ports having "
950
+                        "resource requests, like a port with a QoS minimum "
951
+                        "bandwidth policy, is not supported with this "
952
+                        "microversion")
953
+                raise exc.HTTPBadRequest(explanation=msg)
954
+
955
+            # TODO(gibi): Remove when nova only supports compute newer than
956
+            # Train
957
+            source_service = objects.Service.get_by_host_and_binary(
958
+                context, instance.host, 'nova-compute')
959
+            if source_service.version < MIN_COMPUTE_MOVE_BANDWIDTH:
960
+                msg = _("The resize action on a server with ports having "
961
+                        "resource requests, like a port with a QoS "
962
+                        "minimum bandwidth policy, is not yet supported "
963
+                        "on the source compute")
964
+                raise exc.HTTPConflict(explanation=msg)
952 965
 
953 966
         try:
954 967
             self.compute_api.resize(context, instance, flavor_id, **kwargs)

+ 22
- 0
nova/tests/unit/api/openstack/compute/test_server_actions.py View File

@@ -1222,3 +1222,25 @@ class ServerActionsControllerTestV21(test.TestCase):
1222 1222
         self.assertRaises(webob.exc.HTTPConflict,
1223 1223
                           self.controller._action_create_image,
1224 1224
                           self.req, FAKE_UUID, body=body)
1225
+
1226
+    @mock.patch('nova.api.openstack.common.'
1227
+                'supports_port_resource_request_during_move',
1228
+                return_value=True)
1229
+    @mock.patch('nova.objects.Service.get_by_host_and_binary')
1230
+    @mock.patch('nova.api.openstack.common.'
1231
+                'instance_has_port_with_resource_request', return_value=True)
1232
+    def test_resize_with_bandwidth_from_old_compute_not_supported(
1233
+            self, mock_has_res_req, mock_get_service, mock_support):
1234
+        body = dict(resize=dict(flavorRef="http://localhost/3"))
1235
+        mock_get_service.return_value = objects.Service()
1236
+        mock_get_service.return_value.version = 38
1237
+
1238
+        self.assertRaises(webob.exc.HTTPConflict,
1239
+                          self.controller._action_resize,
1240
+                          self.req, FAKE_UUID, body=body)
1241
+
1242
+        mock_has_res_req.assert_called_once_with(
1243
+            self.req.environ['nova.context'], FAKE_UUID,
1244
+            self.controller.network_api)
1245
+        mock_get_service.assert_called_once_with(
1246
+            self.req.environ['nova.context'], 'fake_host', 'nova-compute')

Loading…
Cancel
Save