Skip to content

Commit

Permalink
Distinguish resize from offline migrate in scheduler
Browse files Browse the repository at this point in the history
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
  • Loading branch information
joker-at-work committed Oct 27, 2023
1 parent 7cb4383 commit b00d74f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
5 changes: 4 additions & 1 deletion nova/compute/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
13 changes: 13 additions & 0 deletions nova/scheduler/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions nova/tests/unit/compute/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit b00d74f

Please sign in to comment.