Fix a migration issue of Huawei driver

While migrating volume crossing backends by the host-based way,
after data copying is done, Huawei driver's update_migrated_volume
method doesn't return the provider_location property, which
results old and new volumes' provider_locations aren't swapped as
expected, afterwards, while deleting the old volume, new volume's
provider_location will be used and the if-volume-exist-check fails
because it verifies the new volume's LUN ID actually on the old
backend, which certainly doesn't exist.

This patch fixes this issue.

Change-Id: Iee27c0368522c90525a4b8ad757f9fb89dc293a0
This commit is contained in:
zengyingzhe 2017-09-14 15:33:20 +08:00
parent 853e76f423
commit 011daa9b46
2 changed files with 17 additions and 12 deletions

View File

@ -4948,11 +4948,11 @@ class HuaweiFCDriverTestCase(HuaweiTestBase):
@mock.patch.object(rest_client.RestClient, 'rename_lun')
def test_update_migrated_volume_success(self, mock_rename_lun):
model_update = self.driver.update_migrated_volume(None,
self.original_volume,
self.current_volume,
'available')
self.assertEqual({'_name_id': None}, model_update)
model_update = self.driver.update_migrated_volume(
None, self.original_volume, self.current_volume, 'available')
self.assertIsNone(model_update['_name_id'])
self.assertDictEqual(json.loads(PROVIDER_LOCATION),
json.loads(model_update['provider_location']))
@mock.patch.object(rest_client.RestClient, 'rename_lun')
def test_update_migrated_volume_fail(self, mock_rename_lun):
@ -4964,6 +4964,8 @@ class HuaweiFCDriverTestCase(HuaweiTestBase):
'available')
self.assertEqual(self.current_volume.name_id,
model_update['_name_id'])
self.assertDictEqual(json.loads(PROVIDER_LOCATION),
json.loads(model_update['provider_location']))
@mock.patch.object(rest_client.RestClient, 'add_lun_to_partition')
def test_retype_volume_success(self, mock_add_lun_to_partition):

View File

@ -590,18 +590,21 @@ class HuaweiBaseDriver(driver.VolumeDriver):
orig_lun_name = huawei_utils.encode_name(volume.id)
new_lun_id, lun_wwn = huawei_utils.get_volume_lun_id(
self.client, new_volume)
new_metadata = huawei_utils.get_lun_metadata(new_volume)
model_update = {
'provider_location': huawei_utils.to_string(**new_metadata),
}
try:
self.client.rename_lun(new_lun_id, orig_lun_name)
except exception.VolumeBackendAPIException:
LOG.error('Unable to rename lun %s on array.', new_lun_id)
return {'_name_id': new_volume.name_id}
LOG.debug("Renamed lun %(id)s to %(name)s successfully.",
{'id': new_lun_id,
'name': orig_lun_name})
model_update = {'_name_id': None}
model_update['_name_id'] = new_volume.name_id
else:
LOG.debug("Renamed lun %(id)s to %(name)s successfully.",
{'id': new_lun_id,
'name': orig_lun_name})
model_update['_name_id'] = None
return model_update