Merge "Fix bug of renaming volume with same name"
This commit is contained in:
commit
461d0bbed0
|
@ -1688,6 +1688,26 @@ class RBDTestCase(test.TestCase):
|
|||
self.assertEqual({'_name_id': None,
|
||||
'provider_location': None}, model_update)
|
||||
|
||||
@common_mocks
|
||||
def test_update_migrated_volume_image_exists(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 = 1
|
||||
mock_rename.side_effect = MockImageExistsException
|
||||
|
||||
model_update = self.driver.update_migrated_volume(context,
|
||||
self.volume_a,
|
||||
self.volume_b,
|
||||
'available')
|
||||
mock_rename.assert_called_with(client.ioctx,
|
||||
'volume-%s' % self.volume_b.id,
|
||||
'volume-%s' % self.volume_a.id)
|
||||
self.assertEqual({'_name_id': self.volume_b.id,
|
||||
'provider_location': None}, model_update)
|
||||
|
||||
def test_rbd_volume_proxy_init(self):
|
||||
mock_driver = mock.Mock(name='driver')
|
||||
mock_driver._connect_to_rados.return_value = (None, None)
|
||||
|
|
|
@ -1623,7 +1623,7 @@ class RBDDriver(driver.CloneableImageVD, driver.MigrateVD,
|
|||
self.RBDProxy().rename(client.ioctx,
|
||||
utils.convert_str(existing_name),
|
||||
utils.convert_str(wanted_name))
|
||||
except self.rbd.ImageNotFound:
|
||||
except (self.rbd.ImageNotFound, self.rbd.ImageExists):
|
||||
LOG.error('Unable to rename the logical volume '
|
||||
'for volume %s.', volume.id)
|
||||
# If the rename fails, _name_id should be set to the new
|
||||
|
|
Loading…
Reference in New Issue