From e32aaf82a37ac09c3180dbe7476287db24237452 Mon Sep 17 00:00:00 2001 From: peter_wang Date: Tue, 17 Nov 2015 02:44:58 -0500 Subject: [PATCH] VNX: Fix metadata get overriden issue Cinder is using 'metadata' or 'volume_metadata' to return volume metadata since versionedobjects is not fully merged, so VNX could not get the correct existing metadata, only append VNX specific metadata so existing metadata get overridden. In this fix, VNX will first try 'volume_metadata' if not exists, try 'metadata' when getting metadata. Change-Id: I1215883a6076e9b15b1ced19aa40aae43c66a00c Closes-bug: 1516903 --- cinder/tests/unit/test_emc_vnxdirect.py | 9 ++++----- cinder/volume/drivers/emc/emc_vnx_cli.py | 6 +++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cinder/tests/unit/test_emc_vnxdirect.py b/cinder/tests/unit/test_emc_vnxdirect.py index 9e9a6caa2..b2cd2b84a 100644 --- a/cinder/tests/unit/test_emc_vnxdirect.py +++ b/cinder/tests/unit/test_emc_vnxdirect.py @@ -130,7 +130,7 @@ class EMCVNXCLIDriverTestData(object): 'display_description': 'test volume', 'volume_type_id': None, 'provider_location': 'system^FNM11111|type^lun|id^1|version^05.03.00', - 'volume_metadata': [{'key': 'lun_type', 'value': 'lun'}]} + 'metadata': {'key': 'lun_type', 'value': 'lun'}} volume_in_cg = { 'name': 'vol2', @@ -279,7 +279,7 @@ class EMCVNXCLIDriverTestData(object): 'volume_attachment': [], 'provider_location': 'system^FNM11111|type^lun|id^1|version^05.03.00', - '_name_id': None, 'volume_metadata': []} + '_name_id': None, 'metadata': {}} test_new_type = {'name': 'voltype0', 'qos_specs_id': None, 'deleted': False, @@ -312,7 +312,7 @@ class EMCVNXCLIDriverTestData(object): 'volume_attachment': [], 'attach_status': 'detached', 'volume_type': [], - '_name_id': None, 'volume_metadata': []} + '_name_id': None, 'metadata': {}} test_volume5 = {'migration_status': None, 'availability_zone': 'nova', 'id': '1181d1b2-cea3-4f55-8fa8-3360d026ce25', @@ -330,7 +330,7 @@ class EMCVNXCLIDriverTestData(object): 'volume_attachment': [], 'attach_status': 'detached', 'volume_type': [], - '_name_id': None, 'volume_metadata': []} + '_name_id': None, 'metadata': {}} test_new_type2 = {'name': 'voltype0', 'qos_specs_id': None, 'deleted': False, @@ -3182,7 +3182,6 @@ Time Remaining: 0 second(s) '-FAST'] emc_vnx_cli.CommandLineHelper.get_array_serial = mock.Mock( return_value={'array_serial': "FNM00124500890"}) - self.driver.retype(None, self.testData.test_volume3, new_type_data, diff_data, diff --git a/cinder/volume/drivers/emc/emc_vnx_cli.py b/cinder/volume/drivers/emc/emc_vnx_cli.py index b3b7ffd83..8d71cc66f 100644 --- a/cinder/volume/drivers/emc/emc_vnx_cli.py +++ b/cinder/volume/drivers/emc/emc_vnx_cli.py @@ -2967,11 +2967,15 @@ class EMCVnxCliBase(object): return model_update def _get_volume_metadata(self, volume): + # Since versionedobjects is partially merged, metadata + # may come from 'volume_metadata' or 'metadata', here + # we need to take care both of them. volume_metadata = {} if 'volume_metadata' in volume: for metadata in volume['volume_metadata']: volume_metadata[metadata['key']] = metadata['value'] - return volume_metadata + return volume_metadata + return volume['metadata'] if 'metadata' in volume else {} def dumps_provider_location(self, pl_dict): return '|'.join([k + '^' + pl_dict[k] for k in pl_dict])