Merge "Do not rename rbd based volume after migration"

This commit is contained in:
Zuul 2020-03-27 00:53:18 +00:00 committed by Gerrit Code Review
commit 3ccc33f766
2 changed files with 27 additions and 1 deletions

View File

@ -1836,6 +1836,24 @@ class RBDTestCase(test.TestCase):
self.assertEqual({'_name_id': None, self.assertEqual({'_name_id': None,
'provider_location': None}, model_update) 'provider_location': None}, model_update)
@common_mocks
def test_update_migrated_volume_in_use(self):
client = self.mock_client.return_value
client.__enter__.return_value = client
with mock.patch.object(self.driver.rbd.RBD(), 'rename') as mock_rename:
context = {}
mock_rename.return_value = 0
model_update = self.driver.update_migrated_volume(context,
self.volume_a,
self.volume_b,
'in-use')
mock_rename.assert_not_called()
self.assertEqual({'_name_id': self.volume_b.id,
'provider_location':
self.volume_b['provider_location']},
model_update)
@common_mocks @common_mocks
def test_update_migrated_volume_image_exists(self): def test_update_migrated_volume_image_exists(self):
client = self.mock_client.return_value client = self.mock_client.return_value

View File

@ -1768,6 +1768,13 @@ class RBDDriver(driver.CloneableImageVD, driver.MigrateVD,
name_id = None name_id = None
provider_location = None provider_location = None
if original_volume_status == 'in-use':
# The back-end will not be renamed.
name_id = new_volume['_name_id'] or new_volume['id']
provider_location = new_volume['provider_location']
return {'_name_id': name_id,
'provider_location': provider_location}
existing_name = CONF.volume_name_template % new_volume.id existing_name = CONF.volume_name_template % new_volume.id
wanted_name = CONF.volume_name_template % volume.id wanted_name = CONF.volume_name_template % volume.id
with RADOSClient(self) as client: with RADOSClient(self) as client:
@ -1783,7 +1790,8 @@ class RBDDriver(driver.CloneableImageVD, driver.MigrateVD,
# one from the new volume as well. # one from the new volume as well.
name_id = new_volume._name_id or new_volume.id name_id = new_volume._name_id or new_volume.id
provider_location = new_volume['provider_location'] provider_location = new_volume['provider_location']
return {'_name_id': name_id, 'provider_location': provider_location} return {'_name_id': name_id,
'provider_location': provider_location}
def migrate_volume(self, context, volume, host): def migrate_volume(self, context, volume, host):