diff --git a/cinder/tests/unit/test_volume_utils.py b/cinder/tests/unit/test_volume_utils.py index c2ba899b4..d97ce9961 100644 --- a/cinder/tests/unit/test_volume_utils.py +++ b/cinder/tests/unit/test_volume_utils.py @@ -674,3 +674,14 @@ class VolumeUtilsTestCase(test.TestCase): expected = None self.assertEqual(expected, volume_utils.append_host(host, pool)) + + def test_compare_hosts(self): + host_1 = 'fake_host@backend1' + host_2 = 'fake_host@backend1#pool1' + self.assertTrue(volume_utils.hosts_are_equivalent(host_1, host_2)) + + host_2 = 'fake_host@backend1' + self.assertTrue(volume_utils.hosts_are_equivalent(host_1, host_2)) + + host_2 = 'fake_host2@backend1' + self.assertFalse(volume_utils.hosts_are_equivalent(host_1, host_2)) diff --git a/cinder/volume/manager.py b/cinder/volume/manager.py index 63034a670..8f563a82d 100644 --- a/cinder/volume/manager.py +++ b/cinder/volume/manager.py @@ -1665,7 +1665,17 @@ class VolumeManager(manager.SchedulerDependentManager): # Call driver to try and change the type retype_model_update = None - if not retyped: + + # NOTE(jdg): Check to see if the destination host is the same + # as the current. If it's not don't call the driver.retype + # method, otherwise drivers that implement retype may report + # success, but it's invalid in the case of a migrate. + + # We assume that those that support pools do this internally + # so we strip off the pools designation + if (not retyped and + vol_utils.hosts_are_equivalent(self.driver.host, + host['host'])): try: new_type = volume_types.get_volume_type(context, new_type_id) ret = self.driver.retype(context, diff --git a/cinder/volume/utils.py b/cinder/volume/utils.py index c43f9d697..6e71f0d33 100644 --- a/cinder/volume/utils.py +++ b/cinder/volume/utils.py @@ -507,3 +507,7 @@ def matching_backend_name(src_volume_type, volume_type): volume_type.get('volume_backend_name') else: return False + + +def hosts_are_equivalent(host_1, host_2): + return extract_host(host_1) == extract_host(host_2)