Browse Source

Merge "Disable limit if affinity(anti)/same(different)host is requested" into stable/queens

tags/17.0.12
Zuul 1 month ago
parent
commit
c5b2242483
2 changed files with 41 additions and 0 deletions
  1. 6
    0
      nova/scheduler/utils.py
  2. 35
    0
      nova/tests/unit/scheduler/test_utils.py

+ 6
- 0
nova/scheduler/utils.py View File

@@ -343,6 +343,12 @@ def resources_from_request_spec(spec_obj):
343 343
     if 'force_nodes' in spec_obj and spec_obj.force_nodes:
344 344
         res_req._limit = None
345 345
 
346
+    # Don't limit allocation candidates when using affinity/anti-affinity.
347
+    if ('scheduler_hints' in spec_obj and any(
348
+        key in ['group', 'same_host', 'different_host']
349
+        for key in spec_obj.scheduler_hints)):
350
+        res_req._limit = None
351
+
346 352
     return res_req
347 353
 
348 354
 

+ 35
- 0
nova/tests/unit/scheduler/test_utils.py View File

@@ -10,6 +10,7 @@
10 10
 #    License for the specific language governing permissions and limitations
11 11
 #    under the License.
12 12
 
13
+import ddt
13 14
 import mock
14 15
 
15 16
 from nova.api.openstack.placement import lib as plib
@@ -23,6 +24,7 @@ from nova.tests.unit import fake_instance
23 24
 from nova.tests import uuidsentinel as uuids
24 25
 
25 26
 
27
+@ddt.ddt
26 28
 class TestUtils(test.NoDBTestCase):
27 29
 
28 30
     def setUp(self):
@@ -35,6 +37,7 @@ class TestUtils(test.NoDBTestCase):
35 37
         self.assertEqual(set(ex_by_id), set(ob_by_id))
36 38
         for ident in ex_by_id:
37 39
             self.assertEqual(vars(ex_by_id[ident]), vars(ob_by_id[ident]))
40
+        self.assertEqual(expected._limit, observed._limit)
38 41
 
39 42
     def _test_resources_from_request_spec(self, flavor, expected):
40 43
         fake_spec = objects.RequestSpec(flavor=flavor)
@@ -299,6 +302,38 @@ class TestUtils(test.NoDBTestCase):
299 302
         resources = utils.resources_from_request_spec(fake_spec)
300 303
         self.assertEqual(expected._limit, resources._limit)
301 304
 
305
+    @ddt.data(
306
+        # Test single hint that we are checking for.
307
+        {'group': [uuids.fake]},
308
+        # Test hint we care about and some other random hint.
309
+        {'same_host': [uuids.fake], 'fake-hint': ['fake-value']},
310
+        # Test multiple hints we are checking for.
311
+        {'same_host': [uuids.server1], 'different_host': [uuids.server2]})
312
+    def test_resources_from_request_spec_no_limit_based_on_hint(self, hints):
313
+        """Tests that there is no limit applied to the
314
+        GET /allocation_candidates query string if a given scheduler hint
315
+        is in the request spec.
316
+        """
317
+        flavor = objects.Flavor(vcpus=1,
318
+                                memory_mb=1024,
319
+                                root_gb=15,
320
+                                ephemeral_gb=0,
321
+                                swap=0)
322
+        fake_spec = objects.RequestSpec(
323
+            flavor=flavor, scheduler_hints=hints)
324
+        expected = utils.ResourceRequest()
325
+        expected._rg_by_id[None] = plib.RequestGroup(
326
+            use_same_provider=False,
327
+            resources={
328
+                'VCPU': 1,
329
+                'MEMORY_MB': 1024,
330
+                'DISK_GB': 15,
331
+            },
332
+        )
333
+        expected._limit = None
334
+        resources = utils.resources_from_request_spec(fake_spec)
335
+        self.assertResourceRequestsEqual(expected, resources)
336
+
302 337
     @mock.patch('nova.compute.utils.is_volume_backed_instance',
303 338
                 return_value=False)
304 339
     def test_resources_from_flavor_no_bfv(self, mock_is_bfv):

Loading…
Cancel
Save