Browse Source

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

changes/72/671072/18
Zuul 1 week ago
parent
commit
e01b628581

+ 22
- 8
nova/api/openstack/compute/migrate_server.py View File

@@ -27,10 +27,13 @@ from nova.compute import api as compute
27 27
 from nova import exception
28 28
 from nova.i18n import _
29 29
 from nova import network
30
+from nova import objects
30 31
 from nova.policies import migrate_server as ms_policies
31 32
 
32 33
 LOG = logging.getLogger(__name__)
33 34
 
35
+MIN_COMPUTE_MOVE_BANDWIDTH = 39
36
+
34 37
 
35 38
 class MigrateServerController(wsgi.Controller):
36 39
     def __init__(self):
@@ -58,14 +61,25 @@ class MigrateServerController(wsgi.Controller):
58 61
         # We could potentially move this check to conductor and avoid the
59 62
         # extra API call to neutron when we support move operations with ports
60 63
         # having resource requests.
61
-        if (common.instance_has_port_with_resource_request(
62
-                    context, instance.uuid, self.network_api) and not
63
-                common.supports_port_resource_request_during_move(req)):
64
-            msg = _("The migrate action on a server with ports having "
65
-                    "resource requests, like a port with a QoS minimum "
66
-                    "bandwidth policy, is not supported with this "
67
-                    "microversion")
68
-            raise exc.HTTPBadRequest(explanation=msg)
64
+        if common.instance_has_port_with_resource_request(
65
+                context, instance.uuid, self.network_api):
66
+            if not common.supports_port_resource_request_during_move(req):
67
+                msg = _("The migrate action on a server with ports having "
68
+                        "resource requests, like a port with a QoS minimum "
69
+                        "bandwidth policy, is not supported with this "
70
+                        "microversion")
71
+                raise exc.HTTPBadRequest(explanation=msg)
72
+
73
+            # TODO(gibi): Remove when nova only supports compute newer than
74
+            # Train
75
+            source_service = objects.Service.get_by_host_and_binary(
76
+                context, instance.host, 'nova-compute')
77
+            if source_service.version < MIN_COMPUTE_MOVE_BANDWIDTH:
78
+                msg = _("The migrate action on a server with ports having "
79
+                        "resource requests, like a port with a QoS "
80
+                        "minimum bandwidth policy, is not yet supported "
81
+                        "on the source compute")
82
+                raise exc.HTTPConflict(explanation=msg)
69 83
 
70 84
         try:
71 85
             self.compute_api.resize(req.environ['nova.context'], instance,

+ 23
- 0
nova/tests/unit/api/openstack/compute/test_migrate_server.py View File

@@ -296,6 +296,29 @@ class MigrateServerTestsV21(admin_only_action_common.CommonTests):
296 296
             expected_exc=webob.exc.HTTPInternalServerError,
297 297
             check_response=False)
298 298
 
299
+    @mock.patch('nova.api.openstack.common.'
300
+                'supports_port_resource_request_during_move',
301
+                return_value=True)
302
+    @mock.patch('nova.objects.Service.get_by_host_and_binary')
303
+    @mock.patch('nova.api.openstack.common.'
304
+                'instance_has_port_with_resource_request', return_value=True)
305
+    def test_migrate_with_bandwidth_from_old_compute_not_supported(
306
+            self, mock_has_res_req, mock_get_service, mock_support):
307
+        instance = self._stub_instance_get()
308
+
309
+        mock_get_service.return_value = objects.Service(host=instance['host'])
310
+        mock_get_service.return_value.version = 38
311
+
312
+        self.assertRaises(
313
+            webob.exc.HTTPConflict, self.controller._migrate, self.req,
314
+            instance['uuid'], body={'migrate': None})
315
+
316
+        mock_has_res_req.assert_called_once_with(
317
+            self.req.environ['nova.context'], instance['uuid'],
318
+            self.controller.network_api)
319
+        mock_get_service.assert_called_once_with(
320
+            self.req.environ['nova.context'], instance['host'], 'nova-compute')
321
+
299 322
 
300 323
 class MigrateServerTestsV225(MigrateServerTestsV21):
301 324
 

Loading…
Cancel
Save