From 9b224641295af3763d011816d6399565ac7b98de Mon Sep 17 00:00:00 2001 From: "zhangchunlong1@huawei.com" Date: Wed, 3 Sep 2014 19:12:16 +0800 Subject: [PATCH] remove the CONF.allow_migrate_to_same_host When running the "migrate" operation and the CONF.allow_resize_to_same_host is set as "false", the CONF.allow_migrate_to_same_host doesn't work in the function 'resize' from nova/compute/api.py. At the same time, there is no checking the CONF.allow_migrate_to_same_host in the function _prep_resize from nova/compute/manager.py DocImpact: remove the CONF.allow_migrate_to_same_host Change-Id: I4c54c7c6e0e5e37cc46c52350ba4ce2047325ef9 Closes-Bug: #1364851 --- nova/compute/api.py | 8 -------- nova/compute/manager.py | 8 +++++++- nova/tests/unit/compute/test_compute_api.py | 6 +----- nova/tests/unit/virt/vmwareapi/test_driver_api.py | 2 ++ nova/virt/driver.py | 3 ++- nova/virt/fake.py | 1 + nova/virt/ironic/driver.py | 3 ++- nova/virt/libvirt/driver.py | 4 ++-- nova/virt/vmwareapi/driver.py | 3 ++- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/nova/compute/api.py b/nova/compute/api.py index b0f73838e4fb..7615b7473b4e 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -88,10 +88,6 @@ compute_opts = [ default=False, help='Allow destination machine to match source for resize. ' 'Useful when testing in single-host environments.'), - cfg.BoolOpt('allow_migrate_to_same_host', - default=False, - help='Allow migrate machine to the same host. ' - 'Useful when testing in single-host environments.'), cfg.StrOpt('default_schedule_zone', help='Availability zone to use when user doesn\'t specify one'), cfg.ListOpt('non_inheritable_image_properties', @@ -2661,10 +2657,6 @@ class API(base.Base): if not CONF.allow_resize_to_same_host: filter_properties['ignore_hosts'].append(instance.host) - # Here when flavor_id is None, the process is considered as migrate. - if (not flavor_id and not CONF.allow_migrate_to_same_host): - filter_properties['ignore_hosts'].append(instance.host) - if self.cell_type == 'api': # Commit reservations early and create migration record. self._resize_cells_support(context, quotas, instance, diff --git a/nova/compute/manager.py b/nova/compute/manager.py index d62a732cffc2..db3c757b3fa2 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -3685,7 +3685,13 @@ class ComputeManager(manager.Manager): raise exception.MigrationError(reason=msg) same_host = instance.host == self.host - if same_host and not CONF.allow_resize_to_same_host: + # if the flavor IDs match, it's migrate; otherwise resize + if same_host and instance_type['id'] == instance['instance_type_id']: + # check driver whether support migrate to same host + if not self.driver.capabilities['supports_migrate_to_same_host']: + raise exception.UnableToMigrateToSelf( + instance_id=instance.uuid, host=self.host) + elif same_host and not CONF.allow_resize_to_same_host: self._set_instance_error_state(context, instance) msg = _('destination same as source!') raise exception.MigrationError(reason=msg) diff --git a/nova/tests/unit/compute/test_compute_api.py b/nova/tests/unit/compute/test_compute_api.py index c0b7b314922f..448aa9efab35 100644 --- a/nova/tests/unit/compute/test_compute_api.py +++ b/nova/tests/unit/compute/test_compute_api.py @@ -1375,7 +1375,6 @@ class _ComputeAPIUnitTestMixIn(object): def _test_resize(self, flavor_id_passed=True, same_host=False, allow_same_host=False, - allow_mig_same_host=False, project_id=None, extra_kwargs=None, same_flavor=False, @@ -1383,8 +1382,7 @@ class _ComputeAPIUnitTestMixIn(object): if extra_kwargs is None: extra_kwargs = {} - self.flags(allow_resize_to_same_host=allow_same_host, - allow_migrate_to_same_host=allow_mig_same_host) + self.flags(allow_resize_to_same_host=allow_same_host) params = {} if project_id is not None: @@ -1441,8 +1439,6 @@ class _ComputeAPIUnitTestMixIn(object): else: filter_properties = {'ignore_hosts': [fake_inst['host']]} - if not flavor_id_passed and not allow_mig_same_host: - filter_properties['ignore_hosts'].append(fake_inst['host']) if flavor_id_passed: expected_reservations = fake_quotas.reservations else: diff --git a/nova/tests/unit/virt/vmwareapi/test_driver_api.py b/nova/tests/unit/virt/vmwareapi/test_driver_api.py index 39cdf084162c..bee90a680aa8 100644 --- a/nova/tests/unit/virt/vmwareapi/test_driver_api.py +++ b/nova/tests/unit/virt/vmwareapi/test_driver_api.py @@ -307,6 +307,8 @@ class VMwareAPIVMTestCase(test.NoDBTestCase): def test_driver_capabilities(self): self.assertTrue(self.conn.capabilities['has_imagecache']) self.assertFalse(self.conn.capabilities['supports_recreate']) + self.assertTrue( + self.conn.capabilities['supports_migrate_to_same_host']) def test_configuration_linked_clone(self): self.flags(use_linked_clone=None, group='vmware') diff --git a/nova/virt/driver.py b/nova/virt/driver.py index 4e794f91d213..e59df0df9860 100644 --- a/nova/virt/driver.py +++ b/nova/virt/driver.py @@ -136,7 +136,8 @@ class ComputeDriver(object): capabilities = { "has_imagecache": False, "supports_recreate": False, - } + "supports_migrate_to_same_host": False + } def __init__(self, virtapi): self.virtapi = virtapi diff --git a/nova/virt/fake.py b/nova/virt/fake.py index ad6c8bcc0d04..4e84829e19da 100644 --- a/nova/virt/fake.py +++ b/nova/virt/fake.py @@ -90,6 +90,7 @@ class FakeDriver(driver.ComputeDriver): capabilities = { "has_imagecache": True, "supports_recreate": True, + "supports_migrate_to_same_host": True } # Since we don't have a real hypervisor, pretend we have lots of diff --git a/nova/virt/ironic/driver.py b/nova/virt/ironic/driver.py index 86b265ee35e9..ddb919aa2208 100644 --- a/nova/virt/ironic/driver.py +++ b/nova/virt/ironic/driver.py @@ -159,7 +159,8 @@ class IronicDriver(virt_driver.ComputeDriver): """Hypervisor driver for Ironic - bare metal provisioning.""" capabilities = {"has_imagecache": False, - "supports_recreate": False} + "supports_recreate": False, + "supports_migrate_to_same_host": False} def __init__(self, virtapi, read_only=False): super(IronicDriver, self).__init__(virtapi) diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 6097fbf9b44f..aa014a150b9b 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -382,11 +382,11 @@ MIN_LIBVIRT_PARALLELS_VERSION = (1, 2, 12) class LibvirtDriver(driver.ComputeDriver): - capabilities = { "has_imagecache": True, "supports_recreate": True, - } + "supports_migrate_to_same_host": False + } def __init__(self, virtapi, read_only=False): super(LibvirtDriver, self).__init__(virtapi) diff --git a/nova/virt/vmwareapi/driver.py b/nova/virt/vmwareapi/driver.py index cc92ad665c24..61ab6f09d70b 100644 --- a/nova/virt/vmwareapi/driver.py +++ b/nova/virt/vmwareapi/driver.py @@ -109,7 +109,8 @@ class VMwareVCDriver(driver.ComputeDriver): capabilities = { "has_imagecache": True, "supports_recreate": False, - } + "supports_migrate_to_same_host": True + } # The vCenter driver includes API that acts on ESX hosts or groups # of ESX hosts in clusters or non-cluster logical-groupings.