From 685c16041c7e84fb0861b9b1833fc6c3cc372d05 Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Tue, 29 Aug 2017 12:58:46 -0400 Subject: [PATCH] Refactor LiveMigrationTask._find_destination This method was getting too large and complicated, so this change pulls out the part that deals with building a RequestSpec to send to select_destinations(). Change-Id: I5cb183cefe5d30abef48f292c73fc8779110b841 --- nova/conductor/tasks/live_migrate.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/nova/conductor/tasks/live_migrate.py b/nova/conductor/tasks/live_migrate.py index 0fb8bc527c..eb02355535 100644 --- a/nova/conductor/tasks/live_migrate.py +++ b/nova/conductor/tasks/live_migrate.py @@ -286,9 +286,16 @@ class LiveMigrationTask(base.TaskBase): reason=(_('Unable to determine in which cell ' 'destination host %s lives.') % self.destination)) - def _find_destination(self): - # TODO(johngarbutt) this retry loop should be shared - attempted_hosts = [self.source] + def _get_request_spec_for_select_destinations(self, attempted_hosts=None): + """Builds a RequestSpec that can be passed to select_destinations + + Used when calling the scheduler to pick a destination host for live + migrating the instance. + + :param attempted_hosts: List of host names to ignore in the scheduler. + This is generally at least seeded with the source host. + :returns: nova.objects.RequestSpec object + """ image = utils.get_image_from_system_metadata( self.instance.system_metadata) filter_properties = {'ignore_hosts': attempted_hosts} @@ -324,6 +331,14 @@ class LiveMigrationTask(base.TaskBase): request_spec.requested_destination = objects.Destination( cell=cell_mapping) + return request_spec + + def _find_destination(self): + # TODO(johngarbutt) this retry loop should be shared + attempted_hosts = [self.source] + request_spec = self._get_request_spec_for_select_destinations( + attempted_hosts) + host = None while host is None: self._check_not_over_max_retries(attempted_hosts)