From 6e34c4719582bcd83c671af262107de511523891 Mon Sep 17 00:00:00 2001 From: ushen Date: Mon, 9 Mar 2020 19:34:24 +0800 Subject: [PATCH] Do not rename rbd based volume after migration After rbd based volume migrated (retyped), it will be renamed to the original name unless name collision or some errors happen. But the problem is this information seems not reflect on connection info, especially this volume is already in-use. This patch mimics behavior of lvm driver by not renaming in-used volume after migration(retype) Close-Bug: #1866935 Change-Id: I4db0dc978d55d4704dd60e2eb8738b38ddefbbbd (cherry picked from commit 662677280beedeb88a8161ddd3f08cfb95a9e5b6) (cherry picked from commit 7c1118febca2a0a0da9454372e4ae03705d8007f) --- cinder/tests/unit/volume/drivers/test_rbd.py | 18 ++++++++++++++++++ cinder/volume/drivers/rbd.py | 10 +++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/cinder/tests/unit/volume/drivers/test_rbd.py b/cinder/tests/unit/volume/drivers/test_rbd.py index 964ee697ed4..0071b707a22 100644 --- a/cinder/tests/unit/volume/drivers/test_rbd.py +++ b/cinder/tests/unit/volume/drivers/test_rbd.py @@ -1809,6 +1809,24 @@ class RBDTestCase(test.TestCase): self.assertEqual({'_name_id': None, '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 def test_update_migrated_volume_image_exists(self): client = self.mock_client.return_value diff --git a/cinder/volume/drivers/rbd.py b/cinder/volume/drivers/rbd.py index 3a8f5b1e4d4..5839774cfd1 100644 --- a/cinder/volume/drivers/rbd.py +++ b/cinder/volume/drivers/rbd.py @@ -1746,6 +1746,13 @@ class RBDDriver(driver.CloneableImageVD, driver.MigrateVD, name_id = 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 wanted_name = CONF.volume_name_template % volume.id with RADOSClient(self) as client: @@ -1761,7 +1768,8 @@ class RBDDriver(driver.CloneableImageVD, driver.MigrateVD, # one from the new volume as well. 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} + return {'_name_id': name_id, + 'provider_location': provider_location} def migrate_volume(self, context, volume, host):