From f7f8f89433de62190b967410d2b33387934e5d71 Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Mon, 17 Dec 2018 14:02:22 -0500 Subject: [PATCH] Remove legacy RequestSpec compat code from live migrate task Change I34ffaf285718059b55f90e812b57f1e11d566c6f made the RequestSpec lookup required in the API, so we should not get to conductor during a live migration without a request spec. This change removes the old compat code from the conductor live migration task. Related to blueprint request-spec-use-by-compute Change-Id: I88e175ed4e6d509029aef256d69686d1876374bb --- nova/conductor/tasks/live_migrate.py | 25 +++-------- .../unit/conductor/tasks/test_live_migrate.py | 42 ------------------- 2 files changed, 5 insertions(+), 62 deletions(-) diff --git a/nova/conductor/tasks/live_migrate.py b/nova/conductor/tasks/live_migrate.py index 3ed3f279f1fa..8def16ac6d97 100644 --- a/nova/conductor/tasks/live_migrate.py +++ b/nova/conductor/tasks/live_migrate.py @@ -24,7 +24,6 @@ from nova.i18n import _ from nova import network from nova import objects from nova.scheduler import utils as scheduler_utils -from nova import utils LOG = logging.getLogger(__name__) CONF = nova.conf.CONF @@ -314,25 +313,11 @@ class LiveMigrationTask(base.TaskBase): This is generally at least seeded with the source host. :returns: nova.objects.RequestSpec object """ - if not self.request_spec: - # NOTE(sbauza): We were unable to find an original RequestSpec - # object - probably because the instance is old. - # We need to mock that the old way - image = utils.get_image_from_system_metadata( - self.instance.system_metadata) - filter_properties = {'ignore_hosts': attempted_hosts} - request_spec = objects.RequestSpec.from_components( - self.context, self.instance.uuid, image, - self.instance.flavor, self.instance.numa_topology, - self.instance.pci_requests, - filter_properties, None, self.instance.availability_zone - ) - else: - request_spec = self.request_spec - # NOTE(sbauza): Force_hosts/nodes needs to be reset - # if we want to make sure that the next destination - # is not forced to be the original host - request_spec.reset_forced_destinations() + request_spec = self.request_spec + # NOTE(sbauza): Force_hosts/nodes needs to be reset + # if we want to make sure that the next destination + # is not forced to be the original host + request_spec.reset_forced_destinations() scheduler_utils.setup_instance_group(self.context, request_spec) # We currently only support live migrating to hosts in the same diff --git a/nova/tests/unit/conductor/tasks/test_live_migrate.py b/nova/tests/unit/conductor/tasks/test_live_migrate.py index b50845696ba7..0f0d13f664d2 100644 --- a/nova/tests/unit/conductor/tasks/test_live_migrate.py +++ b/nova/tests/unit/conductor/tasks/test_live_migrate.py @@ -27,7 +27,6 @@ from nova.scheduler import utils as scheduler_utils from nova import servicegroup from nova import test from nova.tests.unit import fake_instance -from nova import utils fake_selection1 = objects.Selection(service_host="host1", nodename="node1", @@ -358,47 +357,6 @@ class LiveMigrationTaskTestCase(test.NoDBTestCase): mock_check.assert_called_once_with('host1') mock_call.assert_called_once_with('host1') - def test_find_destination_works_with_no_request_spec(self): - task = live_migrate.LiveMigrationTask( - self.context, self.instance, self.destination, - self.block_migration, self.disk_over_commit, self.migration, - compute_rpcapi.ComputeAPI(), servicegroup.API(), - scheduler_client.SchedulerClient(), request_spec=None) - another_spec = objects.RequestSpec() - self.instance.flavor = objects.Flavor() - self.instance.numa_topology = None - self.instance.pci_requests = None - - @mock.patch.object(task, '_call_livem_checks_on_host') - @mock.patch.object(task, '_check_compatible_with_source_hypervisor') - @mock.patch.object(task.scheduler_client, 'select_destinations') - @mock.patch.object(objects.RequestSpec, 'from_components') - @mock.patch.object(scheduler_utils, 'setup_instance_group') - @mock.patch.object(utils, 'get_image_from_system_metadata') - def do_test(get_image, setup_ig, from_components, select_dest, - check_compat, call_livem_checks): - get_image.return_value = "image" - from_components.return_value = another_spec - select_dest.return_value = [[fake_selection1]] - - self.assertEqual(("host1", "node1"), task._find_destination()) - - get_image.assert_called_once_with(self.instance.system_metadata) - setup_ig.assert_called_once_with(self.context, another_spec) - self.ensure_network_metadata_mock.assert_called_once_with( - self.instance) - self.heal_reqspec_is_bfv_mock.assert_called_once_with( - self.context, another_spec, self.instance) - select_dest.assert_called_once_with(self.context, another_spec, - [self.instance.uuid], return_objects=True, - return_alternates=False) - # Make sure the request_spec was updated to include the cell - # mapping. - self.assertIsNotNone(another_spec.requested_destination.cell) - check_compat.assert_called_once_with("host1") - call_livem_checks.assert_called_once_with("host1") - do_test() - @mock.patch.object(live_migrate.LiveMigrationTask, '_call_livem_checks_on_host') @mock.patch.object(live_migrate.LiveMigrationTask,