From b00d74fae6fce55f7865ee0c6dd36c81595590ee Mon Sep 17 00:00:00 2001 From: Johannes Kulik Date: Fri, 27 Oct 2023 13:46:07 +0200 Subject: [PATCH] Distinguish resize from offline migrate in scheduler The scheduler reacts to the scheduler-hint `_nova_check_type`. To be able to have specific filters/weighers for resize, we set this scheduler-hint to "resize" already. Since resizes and offline migrations take the same code path and only differ in having a flavor change or not, we used to set "resize" also for offline migrations. In the future, we want to be able to distinguish between offline migrations and resizes, because one is triggered by customers and the other can only be triggered by admins. Therefore, we introduce another `_nova_check_type` "migrate". There's also already another `_nova_check_type` "live_migrate", so "migrate" does not clash there. To help in finding an offline migration scheduling request in the scheduler, we add the helper function `request_is_migrate()` in the same spirit as the already existing functions for "resize" and "live_migrate". Change-Id: Id8915a2eb52025e31604af8dde53343ab980ca3e --- nova/compute/api.py | 5 ++++- nova/scheduler/utils.py | 13 +++++++++++++ nova/tests/unit/compute/test_api.py | 8 ++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/nova/compute/api.py b/nova/compute/api.py index ef169323bb3..4b4341cf4b2 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -4143,7 +4143,10 @@ def resize(self, context, instance, flavor_id=None, clean_shutdown=True, validate_pci=True) # Not to be confused with scheduler_hint (singular) - scheduler_hints = {'_nova_check_type': ['resize']} + if same_flavor: + scheduler_hints = {'_nova_check_type': ['migrate']} + else: + scheduler_hints = {'_nova_check_type': ['resize']} filter_properties = {'ignore_hosts': [], 'scheduler_hints': scheduler_hints} diff --git a/nova/scheduler/utils.py b/nova/scheduler/utils.py index e984f136ec2..5cb92e9894a 100644 --- a/nova/scheduler/utils.py +++ b/nova/scheduler/utils.py @@ -1239,6 +1239,19 @@ def request_is_live_migrate(spec_obj): return check_type == 'live_migrate' +def request_is_migrate(spec_obj): + """Returns True if request is for an offline migration + + :param spec_obj: An objects.RequestSpec to examine (or None). + """ + if not spec_obj: + return False + if 'scheduler_hints' not in spec_obj: + return False + check_type = spec_obj.get_scheduler_hint('_nova_check_type') + return check_type == 'migrate' + + def claim_resources(ctx, client, spec_obj, instance_uuid, alloc_req, allocation_request_version=None): """Given an instance UUID (representing the consumer of resources) and the diff --git a/nova/tests/unit/compute/test_api.py b/nova/tests/unit/compute/test_api.py index f640251e1bd..c850f27a148 100644 --- a/nova/tests/unit/compute/test_api.py +++ b/nova/tests/unit/compute/test_api.py @@ -2066,8 +2066,12 @@ def _check_state(expected_task_state=None): else: filter_properties = {'ignore_hosts': [fake_inst['host']]} - filter_properties['scheduler_hints'] = { - '_nova_check_type': ['resize']} + if flavor_id_passed: + filter_properties['scheduler_hints'] = { + '_nova_check_type': ['resize']} + else: + filter_properties['scheduler_hints'] = { + '_nova_check_type': ['migrate']} if request_spec: fake_spec = objects.RequestSpec()