Skip to content

Commit 7404689

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Disable limit if affinity(anti)/same(different)host is requested" into stable/rocky
2 parents 98a335c + aa19788 commit 7404689

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

nova/scheduler/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,12 @@ def resources_from_request_spec(spec_obj):
465465
if 'force_nodes' in spec_obj and spec_obj.force_nodes:
466466
res_req._limit = None
467467

468+
# Don't limit allocation candidates when using affinity/anti-affinity.
469+
if ('scheduler_hints' in spec_obj and any(
470+
key in ['group', 'same_host', 'different_host']
471+
for key in spec_obj.scheduler_hints)):
472+
res_req._limit = None
473+
468474
return res_req
469475

470476

nova/tests/unit/scheduler/test_utils.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
1212

13+
import ddt
1314
import mock
1415

1516
from nova.api.openstack.placement import lib as plib
@@ -23,6 +24,7 @@
2324
from nova.tests import uuidsentinel as uuids
2425

2526

27+
@ddt.ddt
2628
class TestUtils(test.NoDBTestCase):
2729

2830
def setUp(self):
@@ -462,6 +464,42 @@ def test_process_use_force_hosts(self):
462464
)
463465
self.assertEqual(expected_querystring, resources.to_querystring())
464466

467+
@ddt.data(
468+
# Test single hint that we are checking for.
469+
{'group': [uuids.fake]},
470+
# Test hint we care about and some other random hint.
471+
{'same_host': [uuids.fake], 'fake-hint': ['fake-value']},
472+
# Test multiple hints we are checking for.
473+
{'same_host': [uuids.server1], 'different_host': [uuids.server2]})
474+
def test_resources_from_request_spec_no_limit_based_on_hint(self, hints):
475+
"""Tests that there is no limit applied to the
476+
GET /allocation_candidates query string if a given scheduler hint
477+
is in the request spec.
478+
"""
479+
flavor = objects.Flavor(vcpus=1,
480+
memory_mb=1024,
481+
root_gb=15,
482+
ephemeral_gb=0,
483+
swap=0)
484+
fake_spec = objects.RequestSpec(
485+
flavor=flavor, scheduler_hints=hints)
486+
expected = utils.ResourceRequest()
487+
expected._rg_by_id[None] = plib.RequestGroup(
488+
use_same_provider=False,
489+
resources={
490+
'VCPU': 1,
491+
'MEMORY_MB': 1024,
492+
'DISK_GB': 15,
493+
},
494+
)
495+
expected._limit = None
496+
resources = utils.resources_from_request_spec(fake_spec)
497+
self.assertResourceRequestsEqual(expected, resources)
498+
expected_querystring = (
499+
'resources=DISK_GB%3A15%2CMEMORY_MB%3A1024%2CVCPU%3A1'
500+
)
501+
self.assertEqual(expected_querystring, resources.to_querystring())
502+
465503
@mock.patch('nova.compute.utils.is_volume_backed_instance',
466504
return_value=False)
467505
def test_resources_from_flavor_no_bfv(self, mock_is_bfv):

0 commit comments

Comments
 (0)