From 15ed23df114bf3f434cc3da5f3c04ba6f78d0d4d Mon Sep 17 00:00:00 2001 From: Wilson Liu Date: Tue, 28 Jun 2016 21:24:38 +0800 Subject: [PATCH] Huawei: Use versionedObject Since the core code has been changed to use versionedObject, Huawei drivers now changes to use versionedObject too. Implements: blueprint huawei-use-versionedobject Change-Id: I4d0e7ac804a9d42754e7f7ce70cdd8af132e173a --- cinder/tests/unit/test_huawei_drivers.py | 687 +++++++----------- cinder/volume/drivers/huawei/huawei_driver.py | 165 +++-- cinder/volume/drivers/huawei/huawei_utils.py | 10 +- cinder/volume/drivers/huawei/hypermetro.py | 24 +- cinder/volume/drivers/huawei/replication.py | 22 +- cinder/volume/drivers/huawei/rest_client.py | 4 +- 6 files changed, 378 insertions(+), 534 deletions(-) diff --git a/cinder/tests/unit/test_huawei_drivers.py b/cinder/tests/unit/test_huawei_drivers.py index 051a6070306..ec96f12b77f 100644 --- a/cinder/tests/unit/test_huawei_drivers.py +++ b/cinder/tests/unit/test_huawei_drivers.py @@ -25,6 +25,10 @@ from xml.dom import minidom from cinder import context from cinder import exception from cinder import test +from cinder.tests.unit.consistencygroup import fake_cgsnapshot +from cinder.tests.unit.consistencygroup import fake_consistencygroup +from cinder.tests.unit import fake_snapshot +from cinder.tests.unit import fake_volume from cinder.tests.unit import utils from cinder.volume import configuration as conf from cinder.volume.drivers.huawei import constants @@ -38,6 +42,16 @@ from cinder.volume.drivers.huawei import rest_client from cinder.volume.drivers.huawei import smartx from cinder.volume import volume_types +admin_contex = context.get_admin_context() + +PROVIDER_LOCATION = '11' +HOST = 'ubuntu001@backend001#OpenStack_Pool' +ID = '21ec7341-9256-497b-97d9-ef48edcf0635' +ADMIN_METADATA = {'huawei_lun_wwn': '6643e8c1004c5f6723e9f454003'} +TEST_PAIR_ID = "3400a30d844d0004" +REPLICA_DRIVER_DATA = '{"pair_id": "%s", "rmt_lun_id": "1"}' % TEST_PAIR_ID +VOL_METADATA = [{'key': 'hypermetro_id', 'value': '11'}, + {'key': 'remote_lun_id', 'value': '1'}] hypermetro_devices = """{ "remote_device": { @@ -51,23 +65,6 @@ hypermetro_devices = """{ } """ -test_volume = { - 'name': 'volume-21ec7341-9256-497b-97d9-ef48edcf0635', - 'size': 2, - 'volume_name': 'vol1', - 'id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'volume_id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'provider_auth': None, - 'project_id': 'project', - 'display_name': 'vol1', - 'display_description': 'test volume', - 'volume_type_id': None, - 'host': 'ubuntu001@backend001#OpenStack_Pool', - 'provider_location': '11', - 'status': 'available', - 'admin_metadata': {'huawei_lun_wwn': '6643e8c1004c5f6723e9f454003'}, -} - fake_smartx_value = {'smarttier': 'true', 'smartcache': 'true', 'smartpartition': 'true', @@ -86,76 +83,15 @@ fake_hypermetro_opts = {'hypermetro': 'true', 'thick_provisioning_support': False, } -hyper_volume = {'name': 'volume-21ec7341-9256-497b-97d9-ef48edcf0635', - 'size': 2, - 'volume_name': 'vol1', - 'id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'volume_id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'provider_auth': None, - 'project_id': 'project', - 'display_name': 'vol1', - 'display_description': 'test volume', - 'volume_type_id': None, - 'host': 'ubuntu@huawei#OpenStack_Pool', - 'provider_location': '11', - 'volume_metadata': [{'key': 'hypermetro_id', - 'value': '1'}, - {'key': 'remote_lun_id', - 'value': '11'}], - 'admin_metadata': {}, - } - sync_replica_specs = {'replication_enabled': ' True', 'replication_type': ' sync'} + async_replica_specs = {'replication_enabled': ' True', 'replication_type': ' async'} -TEST_PAIR_ID = "3400a30d844d0004" replica_hypermetro_specs = {'hypermetro': ' True', 'replication_enabled': ' True'} -replication_volume = { - 'name': 'volume-21ec7341-9256-497b-97d9-ef48edcf0635', - 'size': 2, - 'volume_name': 'vol1', - 'id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'volume_id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'provider_auth': None, - 'project_id': 'project', - 'display_name': 'vol1', - 'display_description': 'test volume', - 'volume_type_id': None, - 'host': 'ubuntu@huawei#OpenStack_Pool', - 'provider_location': '11', - 'admin_metadata': {'huawei_lun_wwn': '6643e8c1004c5f6723e9f454003'}, - 'replication_status': 'disabled', - 'replication_driver_data': - '{"pair_id": "%s", "rmt_lun_id": "1"}' % TEST_PAIR_ID, -} - -test_snap = { - 'name': 'volume-21ec7341-9256-497b-97d9-ef48edcf0635', - 'size': 1, - 'volume_name': 'vol1', - 'id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'volume_id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'provider_auth': None, - 'project_id': 'project', - 'display_name': 'vol1', - 'display_description': 'test volume', - 'volume_type_id': None, - 'provider_location': '11', - 'volume': {'provider_location': '12', - 'id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'admin_metadata': { - 'huawei_lun_wwn': '6643e8c1004c5f6723e9f454003'}}, -} - -test_cgsnapshot = {'id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'consistencygroup_id': '21ec7341-9256-497b-' - '97d9-ef48edcf0635', - 'status': 'available'} - test_host = {'host': 'ubuntu001@backend001#OpenStack_Pool', 'capabilities': {'smartcache': True, 'location_info': '210235G7J20000000000', @@ -242,9 +178,6 @@ hypermetro_devices = """ } """ -CONSISTGROUP = {'id': "21ec7341-9256-497b-97d9-ef48edcf0635", - 'status': "available", } - FAKE_FIND_POOL_RESPONSE = {'CAPACITY': '985661440', 'ID': '0', 'TOTALCAPACITY': '985661440'} @@ -1107,7 +1040,7 @@ FAKE_CONNECT_FC_RESPONSE = { "data": { "target_wwn": ["10000090fa0d6754"], "target_lun": "1", - "volume_id": "21ec7341-9256-497b-97d9-ef48edcf0635" + "volume_id": ID } } @@ -1166,7 +1099,7 @@ FAKE_GET_METROROUP_RESPONSE = { "HEALTHSTATUS": "1", "ID": "11", "ISEMPTY": "true", - "NAME": huawei_utils.encode_name(test_volume['id']), + "NAME": huawei_utils.encode_name(ID), "PRIORITYSTATIONTYPE": "0", "RECOVERYPOLICY": "1", "RESOURCETYPE": "11", @@ -1584,7 +1517,7 @@ MAP_COMMAND_TO_FAKE_RESPONSE['/hyperMetro/associate/pair/DELETE'] = ( MAP_COMMAND_TO_FAKE_RESPONSE['/HyperMetroPair/11/DELETE'] = ( FAKE_COMMON_SUCCESS_RESPONSE) -MAP_COMMAND_TO_FAKE_RESPONSE['/HyperMetroPair/1/GET'] = ( +MAP_COMMAND_TO_FAKE_RESPONSE['/HyperMetroPair/11/GET'] = ( FAKE_HYPERMETRO_RESPONSE) MAP_COMMAND_TO_FAKE_RESPONSE['/HyperMetroPair?range=[0-4095]/GET'] = ( @@ -2163,8 +2096,49 @@ class FakeFCStorage(huawei_driver.HuaweiFCDriver): self.configuration) +class HuaweiTestBase(test.TestCase): + """Base class for Huawei test cases. + + Implement common setup operations or test cases in this class. + """ + + def setUp(self): + super(HuaweiTestBase, self).setUp() + + self.volume = fake_volume.fake_volume_obj( + admin_contex, host=HOST, provider_location=PROVIDER_LOCATION, + admin_metadata=ADMIN_METADATA, id=ID) + + self.snapshot = fake_snapshot.fake_snapshot_obj( + admin_contex, provider_location=PROVIDER_LOCATION, id=ID) + + self.snapshot.volume = self.volume + + self.replica_volume = fake_volume.fake_volume_obj( + admin_contex, host=HOST, provider_location=PROVIDER_LOCATION, + admin_metadata=ADMIN_METADATA, replication_status='disabled', + replication_driver_data=REPLICA_DRIVER_DATA, id=ID) + + self.hyper_volume = fake_volume.fake_volume_obj( + admin_contex, host=HOST, provider_location=PROVIDER_LOCATION, + volume_metadata=VOL_METADATA, id=ID) + + self.original_volume = fake_volume.fake_volume_obj(admin_contex, + id=ID) + + self.current_volume = fake_volume.fake_volume_obj( + admin_contex, id=ID, provider_location=PROVIDER_LOCATION, + name_id=ID) + + self.cgsnapshot = fake_cgsnapshot.fake_cgsnapshot_obj( + admin_contex, id=ID, consistencygroup_id=ID, status='available') + + self.cg = fake_consistencygroup.fake_consistencyobject_obj( + admin_contex, id=ID, status='available') + + @ddt.ddt -class HuaweiISCSIDriverTestCase(test.TestCase): +class HuaweiISCSIDriverTestCase(HuaweiTestBase): def setUp(self): super(HuaweiISCSIDriverTestCase, self).setUp() @@ -2209,78 +2183,38 @@ class HuaweiISCSIDriverTestCase(test.TestCase): self.assertEqual('210235G7J20000000000', device_id) def test_check_volume_exist_on_array(self): - test_volume = {'name': 'volume-21ec7341-9256-497b-97d9-ef48edcf0635', - 'size': 2, - 'volume_name': 'vol1', - 'id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'volume_id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'provider_auth': None, - 'project_id': 'project', - 'display_name': 'vol1', - 'display_description': 'test volume', - 'volume_type_id': None, - 'host': 'ubuntu001@backend001#OpenStack_Pool', - 'provider_location': None, - } self.mock_object(rest_client.RestClient, 'get_lun_id_by_name', mock.Mock(return_value=None)) self.driver._check_volume_exist_on_array( - test_volume, constants.VOLUME_NOT_EXISTS_WARN) + self.volume, constants.VOLUME_NOT_EXISTS_WARN) def test_create_volume_success(self): # Have pool info in the volume. - test_volume = {'name': 'volume-21ec7341-9256-497b-97d9-ef48edcf0635', - 'size': 2, - 'volume_name': 'vol1', - 'id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'volume_id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'provider_auth': None, - 'project_id': 'project', - 'display_name': 'vol1', - 'display_description': 'test volume', - 'volume_type_id': None, - 'host': 'ubuntu001@backend001#OpenStack_Pool', - 'provider_location': '11', - 'admin_metadata': {}, - } - lun_info = self.driver.create_volume(test_volume) + self.volume.host = 'ubuntu001@backend001#OpenStack_Pool' + + lun_info = self.driver.create_volume(self.volume) self.assertEqual('1', lun_info['provider_location']) # No pool info in the volume. - test_volume = {'name': 'volume-21ec7341-9256-497b-97d9-ef48edcf0635', - 'size': 2, - 'volume_name': 'vol1', - 'id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'volume_id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'provider_auth': None, - 'project_id': 'project', - 'display_name': 'vol1', - 'display_description': 'test volume', - 'volume_type_id': None, - 'host': 'ubuntu001@backend001', - 'provider_location': '11', - 'admin_metadata': {}, - } - lun_info = self.driver.create_volume(test_volume) + self.volume.host = 'ubuntu001@backend001' + lun_info = self.driver.create_volume(self.volume) self.assertEqual('1', lun_info['provider_location']) def test_delete_volume_success(self): - self.driver.delete_volume(test_volume) + self.driver.delete_volume(self.volume) def test_create_snapshot_success(self): - lun_info = self.driver.create_snapshot(test_snap) + lun_info = self.driver.create_snapshot(self.snapshot) self.assertEqual(11, lun_info['provider_location']) - test_snap['volume']['provider_location'] = '' - lun_info = self.driver.create_snapshot(test_snap) - self.assertEqual(11, lun_info['provider_location']) - - test_snap['volume']['provider_location'] = None - lun_info = self.driver.create_snapshot(test_snap) + tmp_volume = fake_volume.fake_volume_obj(admin_contex) + self.snapshot.volume_id = ID + self.snapshot.volume = tmp_volume + lun_info = self.driver.create_snapshot(self.snapshot) self.assertEqual(11, lun_info['provider_location']) def test_delete_snapshot_success(self): - self.driver.delete_snapshot(test_snap) + self.driver.delete_snapshot(self.snapshot) def test_create_volume_from_snapsuccess(self): self.mock_object( @@ -2288,8 +2222,8 @@ class HuaweiISCSIDriverTestCase(test.TestCase): '_get_volume_type', mock.Mock(return_value={'extra_specs': sync_replica_specs})) self.mock_object(replication.ReplicaCommonDriver, 'sync') - model_update = self.driver.create_volume_from_snapshot(test_volume, - test_volume) + model_update = self.driver.create_volume_from_snapshot(self.volume, + self.volume) self.assertEqual('1', model_update['provider_location']) driver_data = {'pair_id': TEST_PAIR_ID, @@ -2303,7 +2237,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): temp_connector['multipath'] = True self.mock_object(rest_client.RestClient, 'get_tgt_port_group', mock.Mock(return_value = '11')) - iscsi_properties = self.driver.initialize_connection(test_volume, + iscsi_properties = self.driver.initialize_connection(self.volume, temp_connector) self.assertEqual([1, 1], iscsi_properties['data']['target_luns']) @@ -2316,7 +2250,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): mock.Mock(return_value = [])) self.assertRaises(exception.VolumeBackendAPIException, self.driver.initialize_connection, - test_volume, temp_connector) + self.volume, temp_connector) def test_initialize_connection_success_multipath_targetip(self): iscsi_info = [{'Name': 'iqn.1993-08.debian:01:ec2bff7ac3a3', @@ -2333,7 +2267,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): driver.client.iscsi_info = iscsi_info temp_connector = copy.deepcopy(FakeConnector) temp_connector['multipath'] = True - iscsi_properties = driver.initialize_connection(test_volume, + iscsi_properties = driver.initialize_connection(self.volume, temp_connector) self.assertEqual([1], iscsi_properties['data']['target_luns']) @@ -2354,7 +2288,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): temp_connector['multipath'] = True self.assertRaises(exception.VolumeBackendAPIException, driver.initialize_connection, - test_volume, temp_connector) + self.volume, temp_connector) def test_initialize_connection_success_multipath_defaultip(self): iscsi_info = [{'Name': 'iqn.1993-08.debian:01:ec2bff7ac3a3', @@ -2372,7 +2306,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): driver.client.iscsi_default_target_ip = default_target_ip temp_connector = copy.deepcopy(FakeConnector) temp_connector['multipath'] = True - iscsi_properties = driver.initialize_connection(test_volume, + iscsi_properties = driver.initialize_connection(self.volume, temp_connector) self.assertEqual([1], iscsi_properties['data']['target_luns']) @@ -2395,7 +2329,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): temp_connector['multipath'] = True self.assertRaises(exception.VolumeBackendAPIException, driver.initialize_connection, - test_volume, temp_connector) + self.volume, temp_connector) def test_initialize_connection_fail_no_port_in_portgroup(self): temp_connector = copy.deepcopy(FakeConnector) @@ -2406,7 +2340,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): mock.Mock(return_value = [])) self.assertRaises(exception.VolumeBackendAPIException, self.driver.initialize_connection, - test_volume, temp_connector) + self.volume, temp_connector) def test_initialize_connection_fail_multipath_no_ip(self): iscsi_info = [{'Name': 'iqn.1993-08.debian:01:ec2bff7ac3a3', @@ -2425,10 +2359,10 @@ class HuaweiISCSIDriverTestCase(test.TestCase): temp_connector['multipath'] = True self.assertRaises(exception.VolumeBackendAPIException, driver.initialize_connection, - test_volume, temp_connector) + self.volume, temp_connector) def test_terminate_connection_success(self): - self.driver.terminate_connection(test_volume, FakeConnector) + self.driver.terminate_connection(self.volume, FakeConnector) def test_get_volume_status(self): data = self.driver.get_volume_stats() @@ -2438,44 +2372,43 @@ class HuaweiISCSIDriverTestCase(test.TestCase): return_value={"CAPACITY": 6291456}) @mock.patch.object(rest_client.RestClient, 'extend_lun') def test_extend_volume_size_equal(self, mock_extend, mock_lun_info): - self.driver.extend_volume(test_volume, 3) + self.driver.extend_volume(self.volume, 3) self.assertEqual(0, mock_extend.call_count) @mock.patch.object(rest_client.RestClient, 'get_lun_info', return_value={"CAPACITY": 5291456}) @mock.patch.object(rest_client.RestClient, 'extend_lun') def test_extend_volume_success(self, mock_extend, mock_lun_info): - self.driver.extend_volume(test_volume, 3) + self.driver.extend_volume(self.volume, 3) self.assertEqual(1, mock_extend.call_count) @mock.patch.object(rest_client.RestClient, 'get_lun_info', return_value={"CAPACITY": 7291456}) def test_extend_volume_fail(self, mock_lun_info): self.assertRaises(exception.VolumeBackendAPIException, - self.driver.extend_volume, test_volume, 3) + self.driver.extend_volume, self.volume, 3) def test_extend_nonexistent_volume(self): - test_volume = { - 'name': 'volume-21ec7341-9256-497b-97d9-ef48edcf0635', - 'size': 2, - 'volume_name': 'vol1', - 'id': '21ec7341-9256-497b-97d9-ef48edcf0635' - } + self.volume = fake_volume.fake_volume_obj(admin_contex) self.mock_object(rest_client.RestClient, 'get_lun_id_by_name', mock.Mock(return_value=None)) self.assertRaises(exception.VolumeBackendAPIException, self.driver.extend_volume, - test_volume, 3) + self.volume, 3) - @ddt.data({'admin_metadata': {'huawei_lun_wwn': '1'}, - 'id': '21ec7341-9256-497b-97d9-ef48edcf0635'}, - {'volume_admin_metadata': [{'key': 'huawei_lun_wwn', - 'value': '1'}], - 'id': '21ec7341-9256-497b-97d9-ef48edcf0635'}) - def test_get_admin_metadata(self, volume_data): + def test_get_admin_metadata(self): + metadata = [{'key': 'huawei_lun_wwn', 'value': '1'}] + tmp_volume = fake_volume.fake_volume_obj( + admin_contex, volume_admin_metadata=metadata) expected_value = {'huawei_lun_wwn': '1'} - admin_metadata = huawei_utils.get_admin_metadata(volume_data) + admin_metadata = huawei_utils.get_admin_metadata(tmp_volume) + self.assertEqual(expected_value, admin_metadata) + + metadata = {'huawei_lun_wwn': '1'} + tmp_volume = fake_volume.fake_volume_obj(admin_contex) + tmp_volume.admin_metadata = metadata + admin_metadata = huawei_utils.get_admin_metadata(tmp_volume) self.assertEqual(expected_value, admin_metadata) def test_login_fail(self): @@ -2486,42 +2419,31 @@ class HuaweiISCSIDriverTestCase(test.TestCase): def test_create_snapshot_fail(self): self.driver.client.test_fail = True self.assertRaises(exception.VolumeBackendAPIException, - self.driver.create_snapshot, test_snap) + self.driver.create_snapshot, self.snapshot) def test_create_volume_fail(self): self.driver.client.test_fail = True self.assertRaises(exception.VolumeBackendAPIException, - self.driver.create_volume, test_volume) + self.driver.create_volume, self.volume) def test_delete_volume_fail(self): self.driver.client.test_fail = True - self.driver.delete_volume(test_volume) + self.driver.delete_volume(self.volume) def test_delete_snapshot_fail(self): self.driver.client.test_fail = True - self.driver.delete_snapshot(test_snap) + self.driver.delete_snapshot(self.snapshot) def test_delete_snapshot_with_snapshot_nonexistent(self): - fake_snap = { - 'name': 'volume-21ec7341-9256-497b-97d9-ef48edcf0635', - 'size': 1, - 'volume_name': 'vol1', - 'id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'volume_id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'provider_auth': None, - 'project_id': 'project', - 'display_name': 'vol1', - 'display_description': 'test volume', - 'volume_type_id': None, - 'provider_location': None, } - self.driver.delete_snapshot(fake_snap) + self.snapshot.provider_location = None + self.driver.delete_snapshot(self.snapshot) def test_initialize_connection_fail(self): self.driver.client.test_fail = True self.assertRaises(exception.VolumeBackendAPIException, self.driver.initialize_connection, - test_volume, FakeConnector) + self.volume, FakeConnector) def test_lun_is_associated_to_lungroup(self): self.driver.client.associate_lun_to_lungroup('11', '11') @@ -2609,7 +2531,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): 'IOType': '2'}) def test_create_smartqos(self, mock_qos_value): - lun_info = self.driver.create_volume(test_volume) + lun_info = self.driver.create_volume(self.volume) self.assertEqual('1', lun_info['provider_location']) @mock.patch.object(rest_client.RestClient, 'add_lun_to_partition') @@ -2623,7 +2545,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): 'cachename': 'cache-test', 'partitionname': 'partition-test'}) def test_create_smartx(self, mock_volume_types, mock_add_lun_to_partition): - lun_info = self.driver.create_volume(test_volume) + lun_info = self.driver.create_volume(self.volume) self.assertEqual('1', lun_info['provider_location']) def test_find_available_qos(self): @@ -2695,7 +2617,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): mock_login_return): metadata = {"hypermetro_id": '11', "remote_lun_id": '1'} - lun_info = self.driver.create_volume(hyper_volume) + lun_info = self.driver.create_volume(self.hyper_volume) self.assertEqual(metadata, lun_info['metadata']) @mock.patch.object(huawei_driver.HuaweiBaseDriver, '_get_volume_params', @@ -2723,7 +2645,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): mock_hyper_pair_info.side_effect = exception.VolumeBackendAPIException( data='Create hypermetro error.') self.assertRaises(exception.VolumeBackendAPIException, - self.driver.create_volume, hyper_volume) + self.driver.create_volume, self.hyper_volume) mock_delete_lun.assert_called_with('1') @mock.patch.object(rest_client.RestClient, 'get_all_pools', @@ -2775,7 +2697,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): def test_hypermetro_none_map_info_fail(self, mock_metadata): self.assertRaises(exception.VolumeBackendAPIException, self.driver.metro.connect_volume_fc, - test_volume, + self.volume, FakeConnector) @mock.patch.object(rest_client.RestClient, 'check_lun_exist', @@ -2791,7 +2713,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): mock_delete_hypermetro, mock_check_hyermetro, mock_lun_exit): - self.driver.delete_volume(hyper_volume) + self.driver.delete_volume(self.hyper_volume) @mock.patch.object(rest_client.RestClient, 'check_lun_exist', return_value=True) @@ -2813,7 +2735,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): exception.VolumeBackendAPIException(data='Delete hypermetro ' 'error.')) self.assertRaises(exception.VolumeBackendAPIException, - self.driver.delete_volume, hyper_volume) + self.driver.delete_volume, self.hyper_volume) mock_delete_lun.assert_called_with('11') def test_manage_existing_get_size_invalid_reference(self): @@ -2823,7 +2745,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): return_value=None): ex = self.assertRaises(exception.ManageExistingInvalidReference, self.driver.manage_existing_get_size, - test_volume, external_ref) + self.volume, external_ref) self.assertIsNotNone(re.search('please check the source-name ' 'or source-id', ex.msg)) @@ -2834,7 +2756,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): data='Error') self.assertRaises(exception.VolumeBackendAPIException, self.driver.manage_existing_get_size, - test_volume, external_ref) + self.volume, external_ref) self.assertIsNotNone(re.search('please check the source-name ' 'or source-id', ex.msg)) @@ -2847,14 +2769,14 @@ class HuaweiISCSIDriverTestCase(test.TestCase): def test_manage_existing_get_size_success(self, mock_get_lun_id_by_name, mock_get_lun_info, external_ref): - size = self.driver.manage_existing_get_size(test_volume, + size = self.driver.manage_existing_get_size(self.volume, external_ref) self.assertEqual(2, size) @mock.patch.object(rest_client.RestClient, 'get_lun_info', return_value={'CAPACITY': 2097152, 'ID': 'ID1', - 'PARENTNAME': 'StoragePool001'}) + 'PARENTNAME': 'OpenStack_Pool'}) @mock.patch.object(rest_client.RestClient, 'get_lun_id_by_name', return_value='ID1') def test_manage_existing_pool_mismatch(self, mock_get_by_name, @@ -2862,37 +2784,33 @@ class HuaweiISCSIDriverTestCase(test.TestCase): # LUN does not belong to the specified pool. with mock.patch.object(huawei_driver.HuaweiBaseDriver, '_get_lun_info_by_ref', - return_value={'PARENTNAME': 'StoragePool001'}): - test_volume = {'host': 'ubuntu-204@v3r3#StoragePool002', - 'name': 'volume-21ec7341-9256-497b-97d9-ef48edcf'} + return_value={'PARENTNAME': 'StoragePool'}): external_ref = {'source-name': 'LUN1'} ex = self.assertRaises(exception.ManageExistingInvalidReference, self.driver.manage_existing, - test_volume, external_ref) + self.volume, external_ref) self.assertIsNotNone(re.search('The specified LUN does not belong' ' to the given pool', ex.msg)) @mock.patch.object(rest_client.RestClient, 'get_lun_info', return_value={'CAPACITY': 2097152, 'ID': 'ID1', - 'PARENTNAME': 'StoragePool001'}) + 'PARENTNAME': 'OpenStack_Pool'}) @mock.patch.object(rest_client.RestClient, 'get_lun_id_by_name', return_value='ID1') def test_manage_existing_lun_abnormal(self, mock_get_by_name, mock_get_info): # Status is not normal. - ret = {'PARENTNAME': "StoragePool001", + ret = {'PARENTNAME': "OpenStack_Pool", 'HEALTHSTATUS': '2'} with mock.patch.object(huawei_driver.HuaweiBaseDriver, '_get_lun_info_by_ref', return_value=ret): - test_volume = {'host': 'ubuntu-204@v3r3#StoragePool001', - 'name': 'volume-21ec7341-9256-497b-97d9-ef48edcf'} external_ref = {'source-name': 'LUN1'} ex = self.assertRaises(exception.ManageExistingInvalidReference, self.driver.manage_existing, - test_volume, external_ref) + self.volume, external_ref) self.assertIsNotNone(re.search('LUN status is not normal', ex.msg)) @mock.patch.object(rest_client.RestClient, 'get_hypermetro_pairs', @@ -2900,15 +2818,13 @@ class HuaweiISCSIDriverTestCase(test.TestCase): @mock.patch.object(rest_client.RestClient, 'get_lun_info', return_value={'CAPACITY': 2097152, 'ID': 'ID1', - 'PARENTNAME': 'StoragePool001', + 'PARENTNAME': 'OpenStack_Pool', 'HEALTHSTATUS': constants.STATUS_HEALTH}) @mock.patch.object(rest_client.RestClient, 'get_lun_id_by_name', return_value='ID1') def test_manage_existing_with_hypermetro(self, mock_get_by_name, mock_get_info, mock_get_hyper_pairs): - test_volume = {'host': 'ubuntu-204@v3r3#StoragePool001', - 'name': 'volume-21ec7341-9256-497b-97d9-ef48edcf'} # Exists in a HyperMetroPair. with mock.patch.object(rest_client.RestClient, 'get_hypermetro_pairs', @@ -2916,7 +2832,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): external_ref = {'source-name': 'LUN1'} ex = self.assertRaises(exception.ManageExistingInvalidReference, self.driver.manage_existing, - test_volume, external_ref) + self.volume, external_ref) self.assertIsNotNone(re.search('HyperMetroPair', ex.msg)) @mock.patch.object(rest_client.RestClient, 'get_hypermetro_pairs') @@ -2924,7 +2840,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): @mock.patch.object(rest_client.RestClient, 'get_lun_info', return_value={'CAPACITY': 2097152, 'ID': 'ID1', - 'PARENTNAME': 'StoragePool001', + 'PARENTNAME': 'OpenStack_Pool', 'HEALTHSTATUS': constants.STATUS_HEALTH, 'WWN': '6643e8c1004c5f6723e9f454003'}) @mock.patch.object(rest_client.RestClient, 'get_lun_id_by_name', @@ -2932,15 +2848,10 @@ class HuaweiISCSIDriverTestCase(test.TestCase): def test_manage_existing_with_lower_version(self, mock_get_by_name, mock_get_info, mock_rename, mock_get_hyper_pairs): - test_volume = {'host': 'ubuntu-204@v3r3#StoragePool001', - 'id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'name': 'volume-21ec7341-9256-497b-97d9-ef48edcf', - 'admin_metadata': { - 'huawei_lun_wwn': '6643e8c1004c5f6723e9f454003'}} mock_get_hyper_pairs.side_effect = ( exception.VolumeBackendAPIException(data='err')) external_ref = {'source-name': 'LUN1'} - model_update = self.driver.manage_existing(test_volume, + model_update = self.driver.manage_existing(self.volume, external_ref) expected_val = { 'admin_metadata': { @@ -2954,15 +2865,12 @@ class HuaweiISCSIDriverTestCase(test.TestCase): @mock.patch.object(rest_client.RestClient, 'get_lun_info', return_value={'CAPACITY': 2097152, 'ID': 'ID1', - 'PARENTNAME': 'StoragePool001', + 'PARENTNAME': 'OpenStack_Pool', 'HEALTHSTATUS': constants.STATUS_HEALTH}) @mock.patch.object(rest_client.RestClient, 'get_lun_id_by_name', return_value='ID1') def test_manage_existing_with_splitmirror(self, ddt_data, mock_get_by_name, mock_get_info): - test_volume = {'host': 'ubuntu-204@v3r3#StoragePool001', - 'name': 'volume-21ec7341-9256-497b-97d9-ef48edcf', - 'id': '21ec7341-9256-497b-97d9-ef48edcf'} # Exists in a SplitMirror. with mock.patch.object(rest_client.RestClient, 'get_split_mirrors', return_value=ddt_data[0]), \ @@ -2971,35 +2879,33 @@ class HuaweiISCSIDriverTestCase(test.TestCase): external_ref = {'source-name': 'LUN1'} ex = self.assertRaises(exception.ManageExistingInvalidReference, self.driver.manage_existing, - test_volume, external_ref) + self.volume, external_ref) + self.assertIsNotNone(re.search('SplitMirror', ex.msg)) @ddt.data([{'PARENTID': 'ID1'}], [{'TARGETLUNID': 'ID1'}]) @mock.patch.object(rest_client.RestClient, 'get_lun_info', return_value={'CAPACITY': 2097152, 'ID': 'ID1', - 'PARENTNAME': 'StoragePool001', + 'PARENTNAME': 'OpenStack_Pool', 'HEALTHSTATUS': constants.STATUS_HEALTH}) @mock.patch.object(rest_client.RestClient, 'get_lun_id_by_name', return_value='ID1') def test_manage_existing_under_migration(self, ddt_data, mock_get_by_name, mock_get_info): - test_volume = {'host': 'ubuntu-204@v3r3#StoragePool001', - 'name': 'volume-21ec7341-9256-497b-97d9-ef48edcf', - 'id': '21ec7341-9256-497b-97d9-ef48edcf'} # Exists in a migration task. with mock.patch.object(rest_client.RestClient, 'get_migration_task', return_value=ddt_data): external_ref = {'source-name': 'LUN1'} ex = self.assertRaises(exception.ManageExistingInvalidReference, self.driver.manage_existing, - test_volume, external_ref) + self.volume, external_ref) self.assertIsNotNone(re.search('migration', ex.msg)) @mock.patch.object(rest_client.RestClient, 'get_lun_info', return_value={'CAPACITY': 2097152, 'ID': 'ID1', - 'PARENTNAME': 'StoragePool001', + 'PARENTNAME': 'OpenStack_Pool', 'SNAPSHOTIDS': [], 'ISADD2LUNGROUP': 'true', 'HEALTHSTATUS': constants.STATUS_HEALTH}) @@ -3008,12 +2914,11 @@ class HuaweiISCSIDriverTestCase(test.TestCase): def test_manage_existing_with_lungroup(self, mock_get_by_name, mock_get_info): # Already in LUN group. - test_volume = {'host': 'ubuntu-204@v3r3#StoragePool001', - 'name': 'volume-21ec7341-9256-497b-97d9-ef48edcf'} + external_ref = {'source-name': 'LUN1'} ex = self.assertRaises(exception.ManageExistingInvalidReference, self.driver.manage_existing, - test_volume, external_ref) + self.volume, external_ref) self.assertIsNotNone(re.search('Already exists in a LUN group', ex.msg)) @@ -3021,7 +2926,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): @mock.patch.object(rest_client.RestClient, 'rename_lun') @mock.patch.object(huawei_driver.HuaweiBaseDriver, '_get_lun_info_by_ref', - return_value={'PARENTNAME': 'StoragePool001', + return_value={'PARENTNAME': 'OpenStack_Pool', 'SNAPSHOTIDS': [], 'ID': 'ID1', 'HEALTHSTATUS': constants.STATUS_HEALTH, @@ -3034,15 +2939,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): def test_manage_existing_success(self, mock_get_by_name, mock_get_info, mock_check_lun, mock_rename, external_ref): - test_volume = { - 'host': 'ubuntu-204@v3r3#StoragePool001', - 'id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'name': 'volume-21ec7341-9256-497b-97d9-ef48edcf', - 'admin_metadata': { - 'huawei_lun_wwn': '6643e8c1004c5f6723e9f454003' - } - } - model_update = self.driver.manage_existing(test_volume, + model_update = self.driver.manage_existing(self.volume, external_ref) expected_val = { 'admin_metadata': { @@ -3054,35 +2951,21 @@ class HuaweiISCSIDriverTestCase(test.TestCase): @ddt.data([None, 0], ['ID1', 1]) @mock.patch.object(rest_client.RestClient, 'rename_lun') def test_unmanage(self, ddt_data, mock_rename): - test_volume = {'host': 'ubuntu-204@v3r3#StoragePool001', - 'id': '21ec7341-9256-497b-97d9-ef48edcf0635'} with mock.patch.object(huawei_driver.HuaweiBaseDriver, '_check_volume_exist_on_array', return_value=ddt_data[0]): - self.driver.unmanage(test_volume) + self.driver.unmanage(self.volume) self.assertEqual(ddt_data[1], mock_rename.call_count) - @mock.patch.object(rest_client.RestClient, 'get_snapshot_info', - return_value={'ID': 'ID1', - 'NAME': 'test1', - 'PARENTID': '12', - 'USERCAPACITY': 2097152, - 'HEALTHSTATUS': '2'}) - @mock.patch.object(rest_client.RestClient, 'get_snapshot_id_by_name', - return_value='ID1') - def test_manage_existing_snapshot_abnormal(self, mock_get_by_name, - mock_get_info): + def test_manage_existing_snapshot_abnormal(self): with mock.patch.object(huawei_driver.HuaweiBaseDriver, '_get_snapshot_info_by_ref', return_value={'HEALTHSTATUS': '2', - 'PARENTID': '12'}): - test_snapshot = {'volume_id': '21ec7341-9256-497b-97d9-ef48edcf', - 'id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'volume': {'provider_location': '12'}} + 'PARENTID': '11'}): external_ref = {'source-name': 'test1'} ex = self.assertRaises(exception.ManageExistingInvalidReference, self.driver.manage_existing_snapshot, - test_snapshot, external_ref) + self.snapshot, external_ref) self.assertIsNotNone(re.search('Snapshot status is not normal', ex.msg)) @@ -3090,7 +2973,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): return_value={'ID': 'ID1', 'EXPOSEDTOINITIATOR': 'true', 'NAME': 'test1', - 'PARENTID': '12', + 'PARENTID': '11', 'USERCAPACITY': 2097152, 'HEALTHSTATUS': constants.STATUS_HEALTH}) @mock.patch.object(rest_client.RestClient, 'get_snapshot_id_by_name', @@ -3098,13 +2981,10 @@ class HuaweiISCSIDriverTestCase(test.TestCase): def test_manage_existing_snapshot_with_lungroup(self, mock_get_by_name, mock_get_info): # Already in LUN group. - test_snapshot = {'volume_id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'volume': {'provider_location': '12'}} external_ref = {'source-name': 'test1'} ex = self.assertRaises(exception.ManageExistingInvalidReference, self.driver.manage_existing_snapshot, - test_snapshot, external_ref) + self.snapshot, external_ref) self.assertIsNotNone(re.search('Snapshot is exposed to initiator', ex.msg)) @@ -3114,56 +2994,36 @@ class HuaweiISCSIDriverTestCase(test.TestCase): return_value={'ID': 'ID1', 'EXPOSEDTOINITIATOR': 'false', 'NAME': 'test1', - 'PARENTID': '12', - 'USERCAPACITY': 2097152, - 'HEALTHSTATUS': constants.STATUS_HEALTH}) - @mock.patch.object(rest_client.RestClient, 'get_snapshot_info', - return_value={'ID': 'ID1', - 'EXPOSEDTOINITIATOR': 'false', - 'NAME': 'test1', - 'PARENTID': '12', - 'USERCAPACITY': 2097152, - 'HEALTHSTATUS': constants.STATUS_HEALTH}) - @mock.patch.object(rest_client.RestClient, 'get_snapshot_id_by_name', - return_value='ID1') - def test_manage_existing_snapshot_success(self, mock_get_by_name, - mock_get_info, - mock_check_snapshot, - mock_rename): - test_snapshot = {'volume_id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'volume': {'provider_location': '12'}} - external_ref = {'source-name': 'test1'} - model_update = self.driver.manage_existing_snapshot(test_snapshot, - external_ref) - self.assertEqual({'provider_location': 'ID1'}, model_update) - - test_snapshot = {'volume_id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'volume': {'provider_location': '12'}} - external_ref = {'source-id': 'ID1'} - model_update = self.driver.manage_existing_snapshot(test_snapshot, - external_ref) - self.assertEqual({'provider_location': 'ID1'}, model_update) - - @mock.patch.object(rest_client.RestClient, 'get_snapshot_info', - return_value={'ID': 'ID1', - 'EXPOSEDTOINITIATOR': 'false', - 'NAME': 'test1', - 'USERCAPACITY': 2097152, 'PARENTID': '11', + 'USERCAPACITY': 2097152, + 'HEALTHSTATUS': constants.STATUS_HEALTH}) + def test_manage_existing_snapshot_success(self, mock_get_info, + mock_rename): + external_ref = {'source-name': 'test1'} + model_update = self.driver.manage_existing_snapshot(self.snapshot, + external_ref) + self.assertEqual({'provider_location': 'ID1'}, model_update) + + external_ref = {'source-id': 'ID1'} + model_update = self.driver.manage_existing_snapshot(self.snapshot, + external_ref) + self.assertEqual({'provider_location': 'ID1'}, model_update) + + @mock.patch.object(rest_client.RestClient, 'get_snapshot_info', + return_value={'ID': 'ID1', + 'EXPOSEDTOINITIATOR': 'false', + 'NAME': 'test1', + 'USERCAPACITY': 2097152, + 'PARENTID': '12', 'HEALTHSTATUS': constants.STATUS_HEALTH}) @mock.patch.object(rest_client.RestClient, 'get_snapshot_id_by_name', return_value='ID1') def test_manage_existing_snapshot_mismatch_lun(self, mock_get_by_name, mock_get_info): external_ref = {'source-name': 'test1'} - test_snapshot = {'volume_id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'volume': {'provider_location': '12'}} ex = self.assertRaises(exception.ManageExistingInvalidReference, self.driver.manage_existing_snapshot, - test_snapshot, external_ref) + self.snapshot, external_ref) self.assertIsNotNone(re.search("Snapshot doesn't belong to volume", ex.msg)) @@ -3176,43 +3036,32 @@ class HuaweiISCSIDriverTestCase(test.TestCase): mock_get_info): external_ref = {'source-name': 'test1', 'source-id': 'ID1'} - test_snapshot = {'volume_id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'volume': {'provider_location': '12'}} - size = self.driver.manage_existing_snapshot_get_size(test_snapshot, + size = self.driver.manage_existing_snapshot_get_size(self.snapshot, external_ref) self.assertEqual(1, size) external_ref = {'source-name': 'test1'} - test_snapshot = {'volume_id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'volume': {'provider_location': '12'}} - size = self.driver.manage_existing_snapshot_get_size(test_snapshot, + size = self.driver.manage_existing_snapshot_get_size(self.snapshot, external_ref) self.assertEqual(1, size) external_ref = {'source-id': 'ID1'} - test_snapshot = {'volume_id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'volume': {'provider_location': '12'}} - size = self.driver.manage_existing_snapshot_get_size(test_snapshot, + size = self.driver.manage_existing_snapshot_get_size(self.snapshot, external_ref) self.assertEqual(1, size) @mock.patch.object(rest_client.RestClient, 'rename_snapshot') def test_unmanage_snapshot(self, mock_rename): - test_snapshot = {'volume_id': '21ec7341-9256-497b-97d9-ef48edcf0635', - 'id': '21ec7341-9256-497b-97d9-ef48edcf0635'} with mock.patch.object(rest_client.RestClient, 'get_snapshot_id_by_name', return_value=None): - self.driver.unmanage_snapshot(test_snapshot) + self.driver.unmanage_snapshot(self.snapshot) self.assertEqual(0, mock_rename.call_count) with mock.patch.object(rest_client.RestClient, 'get_snapshot_id_by_name', return_value='ID1'): - self.driver.unmanage_snapshot(test_snapshot) + self.driver.unmanage_snapshot(self.snapshot) self.assertEqual(1, mock_rename.call_count) @ddt.data(sync_replica_specs, async_replica_specs) @@ -3223,7 +3072,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): '_get_volume_type', mock.Mock(return_value={'extra_specs': mock_type})) - model_update = self.driver.create_volume(replication_volume) + model_update = self.driver.create_volume(self.replica_volume) driver_data = {'pair_id': TEST_PAIR_ID, 'rmt_lun_id': '1'} driver_data = replication.to_string(driver_data) @@ -3278,7 +3127,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): self.mock_object(mock_module, mock_func, mock_value) self.assertRaises( exception.VolumeBackendAPIException, - self.driver.create_volume, replication_volume) + self.driver.create_volume, self.replica_volume) def test_delete_replication_success(self): self.mock_object(replication.ReplicaCommonDriver, 'split') @@ -3286,11 +3135,11 @@ class HuaweiISCSIDriverTestCase(test.TestCase): huawei_driver.HuaweiBaseDriver, '_get_volume_type', mock.Mock(return_value={'extra_specs': sync_replica_specs})) - self.driver.delete_volume(replication_volume) + self.driver.delete_volume(self.replica_volume) self.mock_object(rest_client.RestClient, 'check_lun_exist', mock.Mock(return_value=False)) - self.driver.delete_volume(replication_volume) + self.driver.delete_volume(self.replica_volume) def test_wait_volume_online(self): replica = FakeReplicaPairManager(self.driver.client, @@ -3366,7 +3215,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): old_replica_client = driver.replica_client old_replica = driver.replica secondary_id, volumes_update = driver.failover_host( - None, [test_volume], 'default') + None, [self.volume], 'default') self.assertIn(driver.active_backend_id, ('', None)) self.assertEqual(old_client, driver.client) self.assertEqual(old_replica_client, driver.replica_client) @@ -3381,7 +3230,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): old_replica_client = driver.replica_client old_replica = driver.replica secondary_id, volumes_update = driver.failover_host( - None, [test_volume], REPLICA_BACKEND_ID) + None, [self.volume], REPLICA_BACKEND_ID) self.assertEqual(REPLICA_BACKEND_ID, driver.active_backend_id) self.assertEqual(old_client, driver.replica_client) self.assertEqual(old_replica_client, driver.client) @@ -3390,9 +3239,9 @@ class HuaweiISCSIDriverTestCase(test.TestCase): self.assertEqual(1, len(volumes_update)) v_id = volumes_update[0]['volume_id'] v_update = volumes_update[0]['updates'] - self.assertEqual(test_volume['id'], v_id) + self.assertEqual(self.volume.id, v_id) self.assertEqual('error', v_update['status']) - self.assertEqual(test_volume['status'], + self.assertEqual(self.volume['status'], v_update['metadata']['old_status']) def test_failback_to_current(self): @@ -3403,7 +3252,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): old_replica_client = driver.replica_client old_replica = driver.replica secondary_id, volumes_update = driver.failover_host( - None, [test_volume], REPLICA_BACKEND_ID) + None, [self.volume], REPLICA_BACKEND_ID) self.assertEqual(REPLICA_BACKEND_ID, driver.active_backend_id) self.assertEqual(old_client, driver.client) self.assertEqual(old_replica_client, driver.replica_client) @@ -3412,9 +3261,8 @@ class HuaweiISCSIDriverTestCase(test.TestCase): self.assertEqual(0, len(volumes_update)) def test_failback_normal_volumes(self): - volume = copy.deepcopy(test_volume) - volume['status'] = 'error' - volume['metadata'] = {'old_status', 'available'} + self.volume.status = 'error' + self.volume.metadata = {'old_status': 'available'} driver = FakeISCSIStorage(configuration=self.configuration) driver.active_backend_id = REPLICA_BACKEND_ID @@ -3423,7 +3271,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): old_replica_client = driver.replica_client old_replica = driver.replica secondary_id, volumes_update = driver.failover_host( - None, [volume], 'default') + None, [self.volume], 'default') self.assertIn(driver.active_backend_id, ('', None)) self.assertEqual(old_client, driver.replica_client) self.assertEqual(old_replica_client, driver.client) @@ -3432,7 +3280,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): self.assertEqual(1, len(volumes_update)) v_id = volumes_update[0]['volume_id'] v_update = volumes_update[0]['updates'] - self.assertEqual(volume['id'], v_id) + self.assertEqual(self.volume.id, v_id) self.assertEqual('available', v_update['status']) self.assertNotIn('old_status', v_update['metadata']) @@ -3447,7 +3295,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): mock.Mock( return_value={'replication_enabled': 'true'})) secondary_id, volumes_update = driver.failover_host( - None, [replication_volume], REPLICA_BACKEND_ID) + None, [self.replica_volume], REPLICA_BACKEND_ID) self.assertEqual(REPLICA_BACKEND_ID, driver.active_backend_id) self.assertEqual(old_client, driver.replica_client) self.assertEqual(old_replica_client, driver.client) @@ -3456,17 +3304,17 @@ class HuaweiISCSIDriverTestCase(test.TestCase): self.assertEqual(1, len(volumes_update)) v_id = volumes_update[0]['volume_id'] v_update = volumes_update[0]['updates'] - self.assertEqual(replication_volume['id'], v_id) + self.assertEqual(self.replica_volume.id, v_id) self.assertEqual('1', v_update['provider_location']) self.assertEqual('failed-over', v_update['replication_status']) new_drv_data = {'pair_id': TEST_PAIR_ID, - 'rmt_lun_id': replication_volume['provider_location']} + 'rmt_lun_id': self.replica_volume.provider_location} new_drv_data = replication.to_string(new_drv_data) self.assertEqual(new_drv_data, v_update['replication_driver_data']) @ddt.data({}, {'pair_id': TEST_PAIR_ID}) def test_failover_replica_volumes_invalid_drv_data(self, mock_drv_data): - volume = copy.deepcopy(replication_volume) + volume = self.replica_volume volume['replication_driver_data'] = replication.to_string( mock_drv_data) driver = FakeISCSIStorage(configuration=self.configuration) @@ -3487,7 +3335,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): self.assertEqual(1, len(volumes_update)) v_id = volumes_update[0]['volume_id'] v_update = volumes_update[0]['updates'] - self.assertEqual(volume['id'], v_id) + self.assertEqual(volume.id, v_id) self.assertEqual('error', v_update['replication_status']) def test_failback_replica_volumes(self): @@ -3498,7 +3346,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): mock.Mock( return_value={'replication_enabled': 'true'})) - volume = copy.deepcopy(replication_volume) + volume = self.replica_volume driver = FakeISCSIStorage(configuration=self.configuration) driver.active_backend_id = REPLICA_BACKEND_ID @@ -3516,11 +3364,11 @@ class HuaweiISCSIDriverTestCase(test.TestCase): self.assertEqual(1, len(volumes_update)) v_id = volumes_update[0]['volume_id'] v_update = volumes_update[0]['updates'] - self.assertEqual(replication_volume['id'], v_id) + self.assertEqual(self.replica_volume.id, v_id) self.assertEqual('1', v_update['provider_location']) self.assertEqual('available', v_update['replication_status']) new_drv_data = {'pair_id': TEST_PAIR_ID, - 'rmt_lun_id': replication_volume['provider_location']} + 'rmt_lun_id': self.replica_volume.provider_location} new_drv_data = replication.to_string(new_drv_data) self.assertEqual(new_drv_data, v_update['replication_driver_data']) @@ -3530,7 +3378,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): mock.Mock( return_value={'replication_enabled': 'true'})) - volume = copy.deepcopy(replication_volume) + volume = self.replica_volume volume['replication_driver_data'] = replication.to_string( mock_drv_data) @@ -3550,7 +3398,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): self.assertEqual(1, len(volumes_update)) v_id = volumes_update[0]['volume_id'] v_update = volumes_update[0]['updates'] - self.assertEqual(replication_volume['id'], v_id) + self.assertEqual(self.replica_volume.id, v_id) self.assertEqual('error', v_update['replication_status']) @mock.patch.object(replication.PairOp, 'is_primary', @@ -3709,10 +3557,10 @@ class HuaweiISCSIDriverTestCase(test.TestCase): self.assertIsNone(iqn) def test_create_cgsnapshot(self): - test_snapshots = [test_snap] + test_snapshots = [self.snapshot] ctxt = context.get_admin_context() model, snapshots = self.driver.create_cgsnapshot(ctxt, - test_cgsnapshot, + self.cgsnapshot, test_snapshots) snapshots_model_update = [{'id': '21ec7341-9256-497b-97d9' '-ef48edcf0635', @@ -3722,7 +3570,7 @@ class HuaweiISCSIDriverTestCase(test.TestCase): self.assertEqual('available', model['status']) def test_create_cgsnapshot_create_snapshot_fail(self): - test_snapshots = [test_snap] + test_snapshots = [self.snapshot] ctxt = context.get_admin_context() self.mock_object(rest_client.RestClient, 'create_snapshot', mock.Mock(side_effect=( @@ -3730,11 +3578,11 @@ class HuaweiISCSIDriverTestCase(test.TestCase): self.assertRaises(exception.VolumeBackendAPIException, self.driver.create_cgsnapshot, ctxt, - test_cgsnapshot, + self.cgsnapshot, test_snapshots) def test_create_cgsnapshot_active_snapshot_fail(self): - test_snapshots = [test_snap] + test_snapshots = [self.snapshot] ctxt = context.get_admin_context() self.mock_object(rest_client.RestClient, 'activate_snapshot', mock.Mock(side_effect=( @@ -3742,14 +3590,14 @@ class HuaweiISCSIDriverTestCase(test.TestCase): self.assertRaises(exception.VolumeBackendAPIException, self.driver.create_cgsnapshot, ctxt, - test_cgsnapshot, + self.cgsnapshot, test_snapshots) def test_delete_cgsnapshot(self): - test_snapshots = [test_snap] + test_snapshots = [self.snapshot] ctxt = context.get_admin_context() self.driver.delete_cgsnapshot(ctxt, - test_cgsnapshot, + self.cgsnapshot, test_snapshots) @@ -3761,7 +3609,7 @@ class FCSanLookupService(object): @ddt.ddt -class HuaweiFCDriverTestCase(test.TestCase): +class HuaweiFCDriverTestCase(HuaweiTestBase): def setUp(self): super(HuaweiFCDriverTestCase, self).setUp() @@ -3779,34 +3627,31 @@ class HuaweiFCDriverTestCase(test.TestCase): self.assertEqual('210235G7J20000000000', device_id) def test_create_volume_success(self): - lun_info = self.driver.create_volume(test_volume) + lun_info = self.driver.create_volume(self.volume) self.assertEqual('1', lun_info['provider_location']) def test_delete_volume_success(self): - self.driver.delete_volume(test_volume) + self.driver.delete_volume(self.volume) def test_create_snapshot_success(self): - lun_info = self.driver.create_snapshot(test_snap) + lun_info = self.driver.create_snapshot(self.snapshot) self.assertEqual(11, lun_info['provider_location']) - test_snap['volume']['provider_location'] = '' - lun_info = self.driver.create_snapshot(test_snap) - self.assertEqual(11, lun_info['provider_location']) - - test_snap['volume']['provider_location'] = None - lun_info = self.driver.create_snapshot(test_snap) + self.snapshot.volume.provider_location = None + self.snapshot.volume_id = ID + lun_info = self.driver.create_snapshot(self.snapshot) self.assertEqual(11, lun_info['provider_location']) def test_delete_snapshot_success(self): - self.driver.delete_snapshot(test_snap) + self.driver.delete_snapshot(self.snapshot) def test_create_volume_from_snapsuccess(self): - lun_info = self.driver.create_volume_from_snapshot(test_volume, - test_volume) + lun_info = self.driver.create_volume_from_snapshot(self.volume, + self.volume) self.assertEqual('1', lun_info['provider_location']) def test_initialize_connection_success(self): - iscsi_properties = self.driver.initialize_connection(test_volume, + iscsi_properties = self.driver.initialize_connection(self.volume, FakeConnector) self.assertEqual(1, iscsi_properties['data']['target_lun']) @@ -3815,7 +3660,7 @@ class HuaweiFCDriverTestCase(test.TestCase): mock.Mock(return_value=[])) self.assertRaises(exception.VolumeBackendAPIException, self.driver.initialize_connection, - test_volume, FakeConnector) + self.volume, FakeConnector) def test_initialize_connection_no_local_ini_tgt_map(self): self.mock_object(rest_client.RestClient, 'get_init_targ_map', @@ -3829,18 +3674,18 @@ class HuaweiFCDriverTestCase(test.TestCase): 'view_id': '1', 'aval_luns': '[1]'})) - self.driver.initialize_connection(hyper_volume, FakeConnector) + self.driver.initialize_connection(self.hyper_volume, FakeConnector) def test_hypermetro_connection_success(self): self.mock_object(rest_client.RestClient, 'find_array_version', mock.Mock(return_value='V300R003C00')) - fc_properties = self.driver.initialize_connection(hyper_volume, + fc_properties = self.driver.initialize_connection(self.hyper_volume, FakeConnector) self.assertEqual(1, fc_properties['data']['target_lun']) def test_terminate_connection_success(self): self.driver.client.terminateFlag = True - self.driver.terminate_connection(test_volume, FakeConnector) + self.driver.terminate_connection(self.volume, FakeConnector) self.assertTrue(self.driver.client.terminateFlag) def test_terminate_connection_portgroup_associated(self): @@ -3850,16 +3695,16 @@ class HuaweiFCDriverTestCase(test.TestCase): self.mock_object(huawei_driver.HuaweiFCDriver, '_delete_zone_and_remove_fc_initiators', mock.Mock(return_value=({}, 1))) - self.driver.terminate_connection(test_volume, FakeConnector) + self.driver.terminate_connection(self.volume, FakeConnector) def test_terminate_connection_fc_initiators_exist_in_host(self): self.mock_object(rest_client.RestClient, 'check_fc_initiators_exist_in_host', mock.Mock(return_value=True)) - self.driver.terminate_connection(test_volume, FakeConnector) + self.driver.terminate_connection(self.volume, FakeConnector) def test_terminate_connection_hypermetro_in_metadata(self): - self.driver.terminate_connection(hyper_volume, FakeConnector) + self.driver.terminate_connection(self.hyper_volume, FakeConnector) def test_get_volume_status(self): remote_device_info = {"ARRAYTYPE": "1", @@ -3891,7 +3736,7 @@ class HuaweiFCDriverTestCase(test.TestCase): self.assertNotIn('replication_enabled', data['pools'][0]) def test_extend_volume(self): - self.driver.extend_volume(test_volume, 3) + self.driver.extend_volume(self.volume, 3) def test_login_fail(self): self.driver.client.test_fail = True @@ -3901,26 +3746,26 @@ class HuaweiFCDriverTestCase(test.TestCase): def test_create_snapshot_fail(self): self.driver.client.test_fail = True self.assertRaises(exception.VolumeBackendAPIException, - self.driver.create_snapshot, test_snap) + self.driver.create_snapshot, self.snapshot) def test_create_volume_fail(self): self.driver.client.test_fail = True self.assertRaises(exception.VolumeBackendAPIException, - self.driver.create_volume, test_volume) + self.driver.create_volume, self.volume) def test_delete_volume_fail(self): self.driver.client.test_fail = True - self.driver.delete_volume(test_volume) + self.driver.delete_volume(self.volume) def test_delete_snapshot_fail(self): self.driver.client.test_fail = True - self.driver.delete_snapshot(test_snap) + self.driver.delete_snapshot(self.snapshot) def test_initialize_connection_fail(self): self.driver.client.test_fail = True self.assertRaises(exception.VolumeBackendAPIException, self.driver.initialize_connection, - test_volume, FakeConnector) + self.volume, FakeConnector) def test_lun_is_associated_to_lungroup(self): self.driver.client.associate_lun_to_lungroup('11', '11') @@ -3940,7 +3785,7 @@ class HuaweiFCDriverTestCase(test.TestCase): # Migrate volume without new type. empty_dict = {} moved, model_update = self.driver.migrate_volume(None, - test_volume, + self.volume, test_host, None) self.assertTrue(moved) @@ -3958,7 +3803,7 @@ class HuaweiFCDriverTestCase(test.TestCase): 'smartcache:cachename': 'cache-test', 'smartpartition:partitionname': 'partition-test'}} moved, model_update = self.driver.migrate_volume(None, - test_volume, + self.volume, test_host, new_type) self.assertTrue(moved) @@ -3970,7 +3815,7 @@ class HuaweiFCDriverTestCase(test.TestCase): # Migrate volume without new type. self.assertRaises(exception.VolumeBackendAPIException, self.driver.migrate_volume, None, - test_volume, test_host, None) + self.volume, test_host, None) # Migrate volume with new type. new_type = {'extra_specs': @@ -3984,11 +3829,11 @@ class HuaweiFCDriverTestCase(test.TestCase): self.driver.client.test_fail = True self.assertRaises(exception.VolumeBackendAPIException, self.driver.migrate_volume, None, - test_volume, test_host, new_type) + self.volume, test_host, new_type) def test_check_migration_valid(self): is_valid = self.driver._check_migration_valid(test_host, - test_volume) + self.volume) self.assertTrue(is_valid) # No pool_name in capabilities. invalid_host1 = {'host': 'ubuntu001@backend002#OpenStack_Pool', @@ -3998,7 +3843,7 @@ class HuaweiFCDriverTestCase(test.TestCase): 'volume_backend_name': 'HuaweiFCDriver', 'storage_protocol': 'FC'}} is_valid = self.driver._check_migration_valid(invalid_host1, - test_volume) + self.volume) self.assertFalse(is_valid) # location_info in capabilities is not matched. invalid_host2 = {'host': 'ubuntu001@backend002#OpenStack_Pool', @@ -4009,14 +3854,14 @@ class HuaweiFCDriverTestCase(test.TestCase): 'volume_backend_name': 'HuaweiFCDriver', 'storage_protocol': 'FC'}} is_valid = self.driver._check_migration_valid(invalid_host2, - test_volume) + self.volume) self.assertFalse(is_valid) # storage_protocol is not match current protocol and volume status is # 'in-use'. volume_in_use = {'name': 'volume-21ec7341-9256-497b-97d9-ef48edcf0635', 'size': 2, 'volume_name': 'vol1', - 'id': '21ec7341-9256-497b-97d9-ef48edcf0635', + 'id': ID, 'volume_id': '21ec7341-9256-497b-97d9-ef48edcf0635', 'volume_attachment': 'in-use', 'provider_location': '11'} @@ -4039,16 +3884,14 @@ class HuaweiFCDriverTestCase(test.TestCase): 'volume_backend_name': 'HuaweiFCDriver', 'storage_protocol': 'iSCSI'}} is_valid = self.driver._check_migration_valid(invalid_host3, - test_volume) + self.volume) self.assertFalse(is_valid) @mock.patch.object(rest_client.RestClient, 'rename_lun') def test_update_migrated_volume_success(self, mock_rename_lun): - original_volume = {'id': '21ec7341-9256-497b-97d9-ef48edcf0635'} - current_volume = {'id': '21ec7341-9256-497b-97d9-ef48edcf0636'} model_update = self.driver.update_migrated_volume(None, - original_volume, - current_volume, + self.original_volume, + self.current_volume, 'available') self.assertEqual({'_name_id': None}, model_update) @@ -4056,19 +3899,16 @@ class HuaweiFCDriverTestCase(test.TestCase): def test_update_migrated_volume_fail(self, mock_rename_lun): mock_rename_lun.side_effect = exception.VolumeBackendAPIException( data='Error occurred.') - original_volume = {'id': '21ec7341-9256-497b-97d9-ef48edcf0635'} - current_volume = {'id': '21ec7341-9256-497b-97d9-ef48edcf0636', - '_name_id': '21ec7341-9256-497b-97d9-ef48edcf0637'} model_update = self.driver.update_migrated_volume(None, - original_volume, - current_volume, + self.original_volume, + self.current_volume, 'available') - self.assertEqual({'_name_id': '21ec7341-9256-497b-97d9-ef48edcf0637'}, - model_update) + self.assertEqual(self.current_volume.name_id, + model_update['_name_id']) @mock.patch.object(rest_client.RestClient, 'add_lun_to_partition') def test_retype_volume_success(self, mock_add_lun_to_partition): - retype = self.driver.retype(None, test_volume, + retype = self.driver.retype(None, self.volume, test_new_type, None, test_host) self.assertTrue(retype) @@ -4079,7 +3919,7 @@ class HuaweiFCDriverTestCase(test.TestCase): return_value={'extra_specs': sync_replica_specs}) def test_retype_replication_volume_success(self, mock_get_type, mock_add_lun_to_partition): - retype = self.driver.retype(None, test_volume, + retype = self.driver.retype(None, self.volume, test_new_replication_type, None, test_host) self.assertTrue(retype) @@ -4088,21 +3928,21 @@ class HuaweiFCDriverTestCase(test.TestCase): self.assertRaises(exception.VolumeBackendAPIException, self.driver.retype, None, - test_volume, test_new_type, None, test_host) + self.volume, test_new_type, None, test_host) def test_retype_volume_partition_fail(self): self.driver.client.partition_not_exist = True self.assertRaises(exception.VolumeBackendAPIException, self.driver.retype, None, - test_volume, test_new_type, None, test_host) + self.volume, test_new_type, None, test_host) @mock.patch.object(rest_client.RestClient, 'add_lun_to_partition') def test_retype_volume_fail(self, mock_add_lun_to_partition): mock_add_lun_to_partition.side_effect = ( exception.VolumeBackendAPIException(data='Error occurred.')) - retype = self.driver.retype(None, test_volume, + retype = self.driver.retype(None, self.volume, test_new_type, None, test_host) self.assertFalse(retype) @@ -4206,7 +4046,7 @@ class HuaweiFCDriverTestCase(test.TestCase): def test_multi_resturls_success(self): self.driver.client.test_multi_url_flag = True - lun_info = self.driver.create_volume(test_volume) + lun_info = self.driver.create_volume(self.volume) self.assertEqual('1', lun_info['provider_location']) def test_get_id_from_result(self): @@ -4273,7 +4113,7 @@ class HuaweiFCDriverTestCase(test.TestCase): metadata = {"hypermetro_id": '11', "remote_lun_id": '1'} - lun_info = self.driver.create_volume(hyper_volume) + lun_info = self.driver.create_volume(self.hyper_volume) self.assertEqual(metadata, lun_info['metadata']) @mock.patch.object(huawei_driver.HuaweiBaseDriver, '_get_volume_params', @@ -4308,7 +4148,7 @@ class HuaweiFCDriverTestCase(test.TestCase): 'view_id': '1', 'aval_luns': '[1]'}) def test_hypermetro_connection_success_2(self, mock_map, mock_metadata): - fc_properties = self.driver.metro.connect_volume_fc(test_volume, + fc_properties = self.driver.metro.connect_volume_fc(self.volume, FakeConnector) self.assertEqual(1, fc_properties['data']['target_lun']) @@ -4316,7 +4156,7 @@ class HuaweiFCDriverTestCase(test.TestCase): return_value={'hypermetro_id': '3400a30d844d0007', 'remote_lun_id': '1'}) def test_terminate_hypermetro_connection_success(self, mock_metradata): - self.driver.metro.disconnect_volume_fc(test_volume, FakeConnector) + self.driver.metro.disconnect_volume_fc(self.volume, FakeConnector) @mock.patch.object(huawei_driver.huawei_utils, 'get_volume_metadata', return_value={'hypermetro_id': '3400a30d844d0007', @@ -4326,7 +4166,7 @@ class HuaweiFCDriverTestCase(test.TestCase): def test_hypermetroid_none_fail(self, mock_metadata, moke_metro_name): self.assertRaises(exception.VolumeBackendAPIException, self.driver.metro.connect_volume_fc, - test_volume, + self.volume, FakeConnector) def test_wait_volume_ready_success(self): @@ -4345,7 +4185,7 @@ class HuaweiFCDriverTestCase(test.TestCase): mock_host_initiators): self.assertRaises(exception.VolumeBackendAPIException, self.driver.metro.connect_volume_fc, - test_volume, + self.volume, FakeConnector) def test_create_snapshot_fail_hypermetro(self): @@ -4355,16 +4195,15 @@ class HuaweiFCDriverTestCase(test.TestCase): mock.Mock(return_value={'extra_specs': replica_hypermetro_specs})) self.assertRaises(exception.VolumeBackendAPIException, self.driver.create_volume_from_snapshot, - test_volume, test_snap) + self.volume, self.snapshot) def test_create_snapshot_fail_no_snapshot_id(self): - temp_snap = copy.deepcopy(test_snap) - temp_snap.pop('provider_location') + self.snapshot.provider_location = None self.mock_object(rest_client.RestClient, 'get_snapshot_id_by_name', mock.Mock(return_value=None)) self.assertRaises(exception.VolumeBackendAPIException, self.driver.create_volume_from_snapshot, - test_volume, temp_snap) + self.volume, self.snapshot) @mock.patch.object(rest_client.RestClient, 'call', return_value={"data": [{"RUNNINGSTATUS": "27", @@ -4412,7 +4251,7 @@ class HuaweiFCDriverTestCase(test.TestCase): """Test that create_consistencygroup return successfully.""" ctxt = context.get_admin_context() # Create consistency group - model_update = self.driver.create_consistencygroup(ctxt, CONSISTGROUP) + model_update = self.driver.create_consistencygroup(ctxt, self.cg) self.assertEqual('available', model_update['status'], @@ -4426,7 +4265,7 @@ class HuaweiFCDriverTestCase(test.TestCase): """Test that create_consistencygroup return successfully.""" ctxt = context.get_admin_context() # Create consistency group - model_update = self.driver.create_consistencygroup(ctxt, CONSISTGROUP) + model_update = self.driver.create_consistencygroup(ctxt, self.cg) self.assertEqual('available', model_update['status'], @@ -4437,11 +4276,11 @@ class HuaweiFCDriverTestCase(test.TestCase): return_value={"hypermetro": "true"}) def test_delete_hypermetro_consistencygroup_success(self, mock_grouptype): """Test that create_consistencygroup return successfully.""" - test_volumes = [test_volume] + test_volumes = [self.volume] ctxt = context.get_admin_context() # Create consistency group model, volumes = self.driver.delete_consistencygroup(ctxt, - CONSISTGROUP, + self.cg, test_volumes) self.assertEqual('available', model['status'], @@ -4449,13 +4288,13 @@ class HuaweiFCDriverTestCase(test.TestCase): def test_delete_normal_consistencygroup_success(self): ctxt = context.get_admin_context() - test_volumes = [test_volume] + test_volumes = [self.volume] self.mock_object(huawei_driver.HuaweiBaseDriver, '_get_consistencygroup_type', mock.Mock(return_value={"hypermetro": "false"})) model, volumes = self.driver.delete_consistencygroup(ctxt, - CONSISTGROUP, + self.cg, test_volumes) self.assertEqual('available', model['status'], @@ -4472,11 +4311,11 @@ class HuaweiFCDriverTestCase(test.TestCase): mock_metadata): """Test that create_consistencygroup return successfully.""" ctxt = context.get_admin_context() - add_volumes = [test_volume] - remove_volumes = [test_volume] + add_volumes = [self.volume] + remove_volumes = [self.volume] # Create consistency group model_update = self.driver.update_consistencygroup(ctxt, - CONSISTGROUP, + self.cg, add_volumes, remove_volumes) self.assertEqual('available', @@ -4486,7 +4325,7 @@ class HuaweiFCDriverTestCase(test.TestCase): def test_create_hypermetro_consistencygroup_success_2(self): ctxt = context.get_admin_context() # Create consistency group - temp_cg = copy.deepcopy(CONSISTGROUP) + temp_cg = copy.deepcopy(self.cg) temp_cg['volume_type_id'] = '550c089b-bfdd-4f7f-86e1-3ba88125555c,' self.mock_object(volume_types, 'get_volume_type', mock.Mock(return_value=test_hypermetro_type)) diff --git a/cinder/volume/drivers/huawei/huawei_driver.py b/cinder/volume/drivers/huawei/huawei_driver.py index 505525791e8..89933acc46a 100644 --- a/cinder/volume/drivers/huawei/huawei_driver.py +++ b/cinder/volume/drivers/huawei/huawei_driver.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +import collections import json import math import re @@ -71,6 +72,9 @@ huawei_opts = [ CONF = cfg.CONF CONF.register_opts(huawei_opts) +snap_attrs = ('id', 'volume_id', 'volume', 'provider_location') +Snapshot = collections.namedtuple('Snapshot', snap_attrs) + class HuaweiBaseDriver(driver.VolumeDriver): @@ -176,7 +180,7 @@ class HuaweiBaseDriver(driver.VolumeDriver): def _get_volume_type(self, volume): volume_type = None - type_id = volume['volume_type_id'] + type_id = volume.volume_type_id if type_id: ctxt = context.get_admin_context() volume_type = volume_types.get_volume_type(ctxt, type_id) @@ -195,7 +199,7 @@ class HuaweiBaseDriver(driver.VolumeDriver): def _get_consistencygroup_type(self, group): specs = {} opts = {} - type_id = group['volume_type_id'].split(",") + type_id = group.volume_type_id.split(",") if type_id[0] and len(type_id) == 2: ctxt = context.get_admin_context() volume_type = volume_types.get_volume_type(ctxt, type_id[0]) @@ -279,13 +283,13 @@ class HuaweiBaseDriver(driver.VolumeDriver): return opts def _get_lun_params(self, volume, opts): - pool_name = volume_utils.extract_host(volume['host'], level='pool') + pool_name = volume_utils.extract_host(volume.host, level='pool') params = { 'TYPE': '11', - 'NAME': huawei_utils.encode_name(volume['id']), + 'NAME': huawei_utils.encode_name(volume.id), 'PARENTTYPE': '216', 'PARENTID': self.client.get_pool_id(pool_name), - 'DESCRIPTION': volume['name'], + 'DESCRIPTION': volume.name, 'ALLOCTYPE': opts.get('LUNType', self.configuration.lun_type), 'CAPACITY': huawei_utils.get_volume_size(volume), 'WRITEPOLICY': self.configuration.lun_write_type, @@ -298,7 +302,7 @@ class HuaweiBaseDriver(driver.VolumeDriver): 'WRITECACHEPOLICY': self.configuration.lun_write_cache_policy, } LOG.info(_LI('volume: %(volume)s, lun params: %(params)s.'), - {'volume': volume['id'], 'params': params}) + {'volume': volume.id, 'params': params}) return params def _create_volume(self, volume, lun_params): @@ -393,7 +397,7 @@ class HuaweiBaseDriver(driver.VolumeDriver): return model_update def _delete_volume(self, volume): - lun_id = volume.get('provider_location') + lun_id = volume.provider_location if not lun_id: return @@ -436,7 +440,7 @@ class HuaweiBaseDriver(driver.VolumeDriver): raise # Delete a replication volume - replica_data = volume.get('replication_driver_data') + replica_data = volume.replication_driver_data if replica_data: try: self.replica.delete_replica(volume) @@ -533,19 +537,19 @@ class HuaweiBaseDriver(driver.VolumeDriver): wait_interval * 10) def _get_original_status(self, volume): - return 'in-use' if volume.get('volume_attachment') else 'available' + return 'in-use' if volume.volume_attachment else 'available' def update_migrated_volume(self, ctxt, volume, new_volume, original_volume_status=None): - original_name = huawei_utils.encode_name(volume['id']) - current_name = huawei_utils.encode_name(new_volume['id']) + original_name = huawei_utils.encode_name(volume.id) + current_name = huawei_utils.encode_name(new_volume.id) lun_id = self.client.get_lun_id_by_name(current_name) try: self.client.rename_lun(lun_id, original_name) except exception.VolumeBackendAPIException: LOG.error(_LE('Unable to rename lun %s on array.'), current_name) - return {'_name_id': new_volume['_name_id'] or new_volume['id']} + return {'_name_id': new_volume.name_id} LOG.debug("Rename lun from %(current_name)s to %(original_name)s " "successfully.", @@ -597,7 +601,7 @@ class HuaweiBaseDriver(driver.VolumeDriver): if not self._check_migration_valid(host, volume): return (False, None) - type_id = volume['volume_type_id'] + type_id = volume.volume_type_id volume_type = None if type_id: @@ -606,9 +610,9 @@ class HuaweiBaseDriver(driver.VolumeDriver): pool_name = host['capabilities']['pool_name'] pools = self.client.get_all_pools() pool_info = self.client.get_pool_info(pool_name, pools) - src_volume_name = huawei_utils.encode_name(volume['id']) + src_volume_name = huawei_utils.encode_name(volume.id) dst_volume_name = six.text_type(hash(src_volume_name)) - src_id = volume.get('provider_location') + src_id = volume.provider_location opts = None qos = None @@ -680,8 +684,8 @@ class HuaweiBaseDriver(driver.VolumeDriver): LOG.error(err_msg) raise exception.VolumeBackendAPIException(data=err_msg) - snapshotname = huawei_utils.encode_name(snapshot['id']) - snapshot_id = snapshot.get('provider_location') + snapshotname = huawei_utils.encode_name(snapshot.id) + snapshot_id = snapshot.provider_location if snapshot_id is None: snapshot_id = self.client.get_snapshot_id_by_name(snapshotname) if snapshot_id is None: @@ -696,7 +700,7 @@ class HuaweiBaseDriver(driver.VolumeDriver): self._create_base_type_volume(opts, volume, volume_type)) tgt_lun_id = model_update['provider_location'] - luncopy_name = huawei_utils.encode_name(volume['id']) + luncopy_name = huawei_utils.encode_name(volume.id) LOG.info(_LI( 'create_volume_from_snapshot: src_lun_id: %(src_lun_id)s, ' 'tgt_lun_id: %(tgt_lun_id)s, copy_name: %(copy_name)s.'), @@ -733,9 +737,10 @@ class HuaweiBaseDriver(driver.VolumeDriver): constants.VOLUME_NOT_EXISTS_RAISE) # Form the snapshot structure. - snapshot = {'id': uuid.uuid4().__str__(), - 'volume_id': src_vref['id'], - 'volume': src_vref} + snapshot = Snapshot(id=uuid.uuid4().__str__(), + volume_id=src_vref.id, + volume=src_vref, + provider_location=None) # Create snapshot. self.create_snapshot(snapshot) @@ -751,8 +756,8 @@ class HuaweiBaseDriver(driver.VolumeDriver): LOG.warning(_LW( 'Failure deleting the snapshot %(snapshot_id)s ' 'of volume %(volume_id)s.'), - {'snapshot_id': snapshot['id'], - 'volume_id': src_vref['id']},) + {'snapshot_id': snapshot.id, + 'volume_id': src_vref.id},) return model_update @@ -762,15 +767,15 @@ class HuaweiBaseDriver(driver.VolumeDriver): If the volume exists on the array, return the LUN ID. If not exists, raise or log warning. """ - # Firstly, try to find LUN ID by volume['provider_location']. - lun_id = volume.get('provider_location') + # Firstly, try to find LUN ID by volume.provider_location. + lun_id = volume.provider_location # If LUN ID not recorded, find LUN ID by LUN NAME. if not lun_id: - volume_name = huawei_utils.encode_name(volume['id']) + volume_name = huawei_utils.encode_name(volume.id) lun_id = self.client.get_lun_id_by_name(volume_name) if not lun_id: msg = (_("Volume %s does not exist on the array.") - % volume['id']) + % volume.id) if action == constants.VOLUME_NOT_EXISTS_WARN: LOG.warning(msg) if action == constants.VOLUME_NOT_EXISTS_RAISE: @@ -780,11 +785,11 @@ class HuaweiBaseDriver(driver.VolumeDriver): metadata = huawei_utils.get_admin_metadata(volume) lun_wwn = metadata.get('huawei_lun_wwn') if metadata else None if not lun_wwn: - LOG.debug("No LUN WWN recorded for volume %s.", volume['id']) + LOG.debug("No LUN WWN recorded for volume %s.", volume.id) if not self.client.check_lun_exist(lun_id, lun_wwn): msg = (_("Volume %s does not exist on the array.") - % volume['id']) + % volume.id) if action == constants.VOLUME_NOT_EXISTS_WARN: LOG.warning(msg) if action == constants.VOLUME_NOT_EXISTS_RAISE: @@ -801,7 +806,7 @@ class HuaweiBaseDriver(driver.VolumeDriver): opts = self._get_volume_params(volume_type) if opts.get('replication_enabled') == 'true': msg = (_("Can't extend replication volume, volume: %(id)s") % - {"id": volume['id']}) + {"id": volume.id}) LOG.error(msg) raise exception.VolumeBackendAPIException(data=msg) @@ -825,7 +830,7 @@ class HuaweiBaseDriver(driver.VolumeDriver): 'newsize': new_size}) LOG.error(msg) raise exception.VolumeBackendAPIException(data=msg) - volume_name = huawei_utils.encode_name(volume['id']) + volume_name = huawei_utils.encode_name(volume.id) LOG.info(_LI( 'Extend volume: %(volumename)s, ' @@ -837,17 +842,17 @@ class HuaweiBaseDriver(driver.VolumeDriver): self.client.extend_lun(lun_id, new_size) def create_snapshot(self, snapshot): - volume = snapshot.get('volume') + volume = snapshot.volume if not volume: msg = (_("Can't get volume id from snapshot, snapshot: %(id)s") - % {"id": snapshot['id']}) + % {"id": snapshot.id}) LOG.error(msg) raise exception.VolumeBackendAPIException(data=msg) - volume_name = huawei_utils.encode_name(snapshot['volume_id']) + volume_name = huawei_utils.encode_name(snapshot.volume_id) lun_id = self.client.get_lun_id(volume, volume_name) - snapshot_name = huawei_utils.encode_name(snapshot['id']) - snapshot_description = snapshot['id'] + snapshot_name = huawei_utils.encode_name(snapshot.id) + snapshot_description = snapshot.id snapshot_info = self.client.create_snapshot(lun_id, snapshot_name, snapshot_description) @@ -858,8 +863,8 @@ class HuaweiBaseDriver(driver.VolumeDriver): 'lun_info': snapshot_info} def delete_snapshot(self, snapshot): - snapshotname = huawei_utils.encode_name(snapshot['id']) - volume_name = huawei_utils.encode_name(snapshot['volume_id']) + snapshotname = huawei_utils.encode_name(snapshot.id) + volume_name = huawei_utils.encode_name(snapshot.volume_id) LOG.info(_LI( 'stop_snapshot: snapshot name: %(snapshot)s, ' @@ -867,7 +872,7 @@ class HuaweiBaseDriver(driver.VolumeDriver): {'snapshot': snapshotname, 'volume': volume_name},) - snapshot_id = snapshot.get('provider_location') + snapshot_id = snapshot.provider_location if snapshot_id is None: snapshot_id = self.client.get_snapshot_id_by_name(snapshotname) @@ -880,7 +885,7 @@ class HuaweiBaseDriver(driver.VolumeDriver): def retype(self, ctxt, volume, new_type, diff, host): """Convert the volume to be of the new type.""" LOG.debug("Enter retype: id=%(id)s, new_type=%(new_type)s, " - "diff=%(diff)s, host=%(host)s.", {'id': volume['id'], + "diff=%(diff)s, host=%(host)s.", {'id': volume.id, 'new_type': new_type, 'diff': diff, 'host': host}) @@ -1089,7 +1094,7 @@ class HuaweiBaseDriver(driver.VolumeDriver): 'replication_type': None, } - lun_id = volume.get('provider_location') + lun_id = volume.provider_location old_opts = self.get_lun_specs(lun_id) new_specs = new_type['extra_specs'] @@ -1098,9 +1103,9 @@ class HuaweiBaseDriver(driver.VolumeDriver): if 'LUNType' not in new_opts: new_opts['LUNType'] = self.configuration.lun_type - if volume['host'] != host['host']: + if volume.host != host['host']: migration = True - change_opts['host'] = (volume['host'], host['host']) + change_opts['host'] = (volume.host, host['host']) if old_opts['LUNType'] != new_opts['LUNType']: migration = True change_opts['LUNType'] = (old_opts['LUNType'], new_opts['LUNType']) @@ -1299,14 +1304,14 @@ class HuaweiBaseDriver(driver.VolumeDriver): def manage_existing(self, volume, external_ref): """Manage an existing volume on the backend storage.""" # Check whether the LUN is belonged to the specified pool. - pool = volume_utils.extract_host(volume['host'], 'pool') + pool = volume_utils.extract_host(volume.host, 'pool') LOG.debug("Pool specified is: %s.", pool) lun_info = self._get_lun_info_by_ref(external_ref) lun_id = lun_info.get('ID') description = lun_info.get('DESCRIPTION', '') if len(description) <= ( - constants.MAX_VOL_DESCRIPTION - len(volume['name']) - 1): - description = volume['name'] + ' ' + description + constants.MAX_VOL_DESCRIPTION - len(volume.name) - 1): + description = volume.name + ' ' + description lun_pool = lun_info.get('PARENTNAME') LOG.debug("Storage pool of existing LUN %(lun)s is %(pool)s.", @@ -1319,7 +1324,7 @@ class HuaweiBaseDriver(driver.VolumeDriver): # Check other stuffs to determine whether this LUN can be imported. self._check_lun_valid_for_manage(lun_info, external_ref) - type_id = volume.get('volume_type_id') + type_id = volume.volume_type_id new_opts = None if type_id: # Handle volume type if specified. @@ -1341,7 +1346,7 @@ class HuaweiBaseDriver(driver.VolumeDriver): self.modify_lun(lun_id, change_opts) # Rename the LUN to make it manageable for Cinder. - new_name = huawei_utils.encode_name(volume['id']) + new_name = huawei_utils.encode_name(volume.id) LOG.debug("Rename LUN %(old_name)s to %(new_name)s.", {'old_name': lun_info.get('NAME'), 'new_name': new_name}) @@ -1387,14 +1392,14 @@ class HuaweiBaseDriver(driver.VolumeDriver): def unmanage(self, volume): """Export Huawei volume from Cinder.""" - LOG.debug("Unmanage volume: %s.", volume['id']) + LOG.debug("Unmanage volume: %s.", volume.id) lun_id = self._check_volume_exist_on_array( volume, constants.VOLUME_NOT_EXISTS_WARN) if not lun_id: return - lun_name = huawei_utils.encode_name(volume['id']) + lun_name = huawei_utils.encode_name(volume.id) new_name = 'unmged_' + lun_name LOG.debug("Rename LUN %(lun_name)s to %(new_name)s.", {'lun_name': lun_name, @@ -1404,7 +1409,7 @@ class HuaweiBaseDriver(driver.VolumeDriver): except Exception: LOG.warning(_LW("Rename lun %(lun_id)s fails when " "unmanaging volume %(volume)s."), - {"lun_id": lun_id, "volume": volume['id']}) + {"lun_id": lun_id, "volume": volume.id}) def manage_existing_get_size(self, volume, external_ref): """Get the size of the existing volume.""" @@ -1452,8 +1457,8 @@ class HuaweiBaseDriver(driver.VolumeDriver): def manage_existing_snapshot(self, snapshot, existing_ref): snapshot_info = self._get_snapshot_info_by_ref(existing_ref) snapshot_id = snapshot_info.get('ID') - volume = snapshot.get('volume') - lun_id = volume.get('provider_location') + volume = snapshot.volume + lun_id = volume.provider_location if lun_id != snapshot_info.get('PARENTID'): msg = (_("Can't import snapshot %s to Cinder. " "Snapshot doesn't belong to volume."), snapshot_id) @@ -1464,8 +1469,8 @@ class HuaweiBaseDriver(driver.VolumeDriver): self._check_snapshot_valid_for_manage(snapshot_info, existing_ref) # Rename the snapshot to make it manageable for Cinder. - description = snapshot['id'] - snapshot_name = huawei_utils.encode_name(snapshot['id']) + description = snapshot.id + snapshot_name = huawei_utils.encode_name(snapshot.id) self.client.rename_snapshot(snapshot_id, snapshot_name, description) if snapshot_info.get('RUNNINGSTATUS') != constants.STATUS_ACTIVE: self.client.activate_snapshot(snapshot_id) @@ -1490,8 +1495,8 @@ class HuaweiBaseDriver(driver.VolumeDriver): def unmanage_snapshot(self, snapshot): """Unmanage the specified snapshot from Cinder management.""" - LOG.debug("Unmanage snapshot: %s.", snapshot['id']) - snapshot_name = huawei_utils.encode_name(snapshot['id']) + LOG.debug("Unmanage snapshot: %s.", snapshot.id) + snapshot_name = huawei_utils.encode_name(snapshot.id) snapshot_id = self.client.get_snapshot_id_by_name(snapshot_name) if not snapshot_id: LOG.warning(_LW("Can't find snapshot on the array: %s."), @@ -1507,7 +1512,7 @@ class HuaweiBaseDriver(driver.VolumeDriver): except Exception: LOG.warning(_LW("Failed to rename snapshot %(snapshot_id)s, " "snapshot name on array is %(snapshot_name)s."), - {'snapshot_id': snapshot['id'], + {'snapshot_id': snapshot.id, 'snapshot_name': snapshot_name}) def remove_host_with_check(self, host_id): @@ -1544,16 +1549,16 @@ class HuaweiBaseDriver(driver.VolumeDriver): model_update = {} volumes_model_update = [] - model_update.update({'status': group['status']}) + model_update.update({'status': group.status}) for volume_ref in volumes: try: self.delete_volume(volume_ref) volumes_model_update.append( - {'id': volume_ref['id'], 'status': 'deleted'}) + {'id': volume_ref.id, 'status': 'deleted'}) except Exception: volumes_model_update.append( - {'id': volume_ref['id'], 'status': 'error_deleting'}) + {'id': volume_ref.id, 'status': 'error_deleting'}) return model_update, volumes_model_update @@ -1579,7 +1584,7 @@ class HuaweiBaseDriver(driver.VolumeDriver): """Create cgsnapshot.""" LOG.info(_LI('Create cgsnapshot for consistency group' ': %(group_id)s'), - {'group_id': cgsnapshot['consistencygroup_id']}) + {'group_id': cgsnapshot.consistencygroup_id}) model_update = {} snapshots_model_update = [] @@ -1587,22 +1592,22 @@ class HuaweiBaseDriver(driver.VolumeDriver): try: for snapshot in snapshots: - volume = snapshot.get('volume') + volume = snapshot.volume if not volume: msg = (_("Can't get volume id from snapshot, " - "snapshot: %(id)s") % {"id": snapshot['id']}) + "snapshot: %(id)s") % {"id": snapshot.id}) LOG.error(msg) raise exception.VolumeBackendAPIException(data=msg) - volume_name = huawei_utils.encode_name(volume['id']) + volume_name = huawei_utils.encode_name(volume.id) lun_id = self.client.get_lun_id(volume, volume_name) - snapshot_name = huawei_utils.encode_name(snapshot['id']) - snapshot_description = snapshot['id'] + snapshot_name = huawei_utils.encode_name(snapshot.id) + snapshot_description = snapshot.id info = self.client.create_snapshot(lun_id, snapshot_name, snapshot_description) - snapshot_model_update = {'id': snapshot['id'], + snapshot_model_update = {'id': snapshot.id, 'status': 'available', 'provider_location': info['ID']} snapshots_model_update.append(snapshot_model_update) @@ -1610,7 +1615,7 @@ class HuaweiBaseDriver(driver.VolumeDriver): except Exception: with excutils.save_and_reraise_exception(): LOG.error(_LE("Create cgsnapshots failed. " - "Cgsnapshot id: %s."), cgsnapshot['id']) + "Cgsnapshot id: %s."), cgsnapshot.id) snapshot_ids = [added_snapshot['ID'] for added_snapshot in added_snapshots_info] try: @@ -1618,7 +1623,7 @@ class HuaweiBaseDriver(driver.VolumeDriver): except Exception: with excutils.save_and_reraise_exception(): LOG.error(_LE("Active cgsnapshots failed. " - "Cgsnapshot id: %s."), cgsnapshot['id']) + "Cgsnapshot id: %s."), cgsnapshot.id) model_update['status'] = 'available' @@ -1628,22 +1633,22 @@ class HuaweiBaseDriver(driver.VolumeDriver): """Delete consistency group snapshot.""" LOG.info(_LI('Delete cgsnapshot %(snap_id)s for consistency group: ' '%(group_id)s'), - {'snap_id': cgsnapshot['id'], - 'group_id': cgsnapshot['consistencygroup_id']}) + {'snap_id': cgsnapshot.id, + 'group_id': cgsnapshot.consistencygroup_id}) model_update = {} snapshots_model_update = [] - model_update['status'] = cgsnapshot['status'] + model_update['status'] = cgsnapshot.status for snapshot in snapshots: try: self.delete_snapshot(snapshot) - snapshots_model_update.append({'id': snapshot['id'], + snapshots_model_update.append({'id': snapshot.id, 'status': 'deleted'}) except Exception: with excutils.save_and_reraise_exception(): LOG.error(_LE("Delete cg snapshots failed. " - "Cgsnapshot id: %s"), cgsnapshot['id']) + "Cgsnapshot id: %s"), cgsnapshot.id) return model_update, snapshots_model_update @@ -1665,7 +1670,7 @@ class HuaweiBaseDriver(driver.VolumeDriver): volumes_update = [] for v in volumes: v_update = {} - v_update['volume_id'] = v['id'] + v_update['volume_id'] = v.id metadata = huawei_utils.get_volume_metadata(v) old_status = 'available' if 'old_status' in metadata: @@ -1705,9 +1710,9 @@ class HuaweiBaseDriver(driver.VolumeDriver): for v in volumes: v_update = {} - v_update['volume_id'] = v['id'] + v_update['volume_id'] = v.id metadata = huawei_utils.get_volume_metadata(v) - metadata.update({'old_status': v['status']}) + metadata.update({'old_status': v.status}) v_update['updates'] = {'status': 'error', 'metadata': metadata} volumes_update.append(v_update) @@ -1845,7 +1850,7 @@ class HuaweiISCSIDriver(HuaweiBaseDriver, driver.ISCSIDriver): # Return iSCSI properties. properties = {} properties['target_discovered'] = False - properties['volume_id'] = volume['id'] + properties['volume_id'] = volume.id multipath = connector.get('multipath', False) hostlun_id = int(hostlun_id) if not multipath: @@ -2068,7 +2073,7 @@ class HuaweiFCDriver(HuaweiBaseDriver, driver.FibreChannelDriver): 'data': {'target_lun': int(host_lun_id), 'target_discovered': True, 'target_wwn': tgt_port_wwns, - 'volume_id': volume['id'], + 'volume_id': volume.id, 'initiator_target_map': init_targ_map, 'map_info': map_info}, } diff --git a/cinder/volume/drivers/huawei/huawei_utils.py b/cinder/volume/drivers/huawei/huawei_utils.py index 8a13690cd1d..b1a3c441194 100644 --- a/cinder/volume/drivers/huawei/huawei_utils.py +++ b/cinder/volume/drivers/huawei/huawei_utils.py @@ -74,8 +74,8 @@ def get_volume_size(volume): calculates volume size with sectors, which is 512 bytes. """ volume_size = units.Gi / 512 # 1G - if int(volume['size']) != 0: - volume_size = int(volume['size']) * units.Gi / 512 + if int(volume.size) != 0: + volume_size = int(volume.size) * units.Gi / 512 return volume_size @@ -94,13 +94,13 @@ def get_volume_metadata(volume): def get_admin_metadata(volume): admin_metadata = {} if 'admin_metadata' in volume: - admin_metadata = volume['admin_metadata'] + admin_metadata = volume.admin_metadata elif 'volume_admin_metadata' in volume: metadata = volume.get('volume_admin_metadata', []) admin_metadata = {item['key']: item['value'] for item in metadata} LOG.debug("Volume ID: %(id)s, admin_metadata: %(admin_metadata)s.", - {"id": volume['id'], "admin_metadata": admin_metadata}) + {"id": volume.id, "admin_metadata": admin_metadata}) return admin_metadata @@ -109,7 +109,7 @@ def get_snapshot_metadata_value(snapshot): return snapshot.metadata if 'snapshot_metadata' in snapshot: - metadata = snapshot.get('snapshot_metadata') + metadata = snapshot.snapshot_metadata return {item['key']: item['value'] for item in metadata} return {} diff --git a/cinder/volume/drivers/huawei/hypermetro.py b/cinder/volume/drivers/huawei/hypermetro.py index db3ded6f1de..468d60bb457 100644 --- a/cinder/volume/drivers/huawei/hypermetro.py +++ b/cinder/volume/drivers/huawei/hypermetro.py @@ -103,7 +103,7 @@ class HuaweiHyperMetro(object): def connect_volume_fc(self, volume, connector): """Create map between a volume and a host for FC.""" wwns = connector['wwpns'] - volume_name = huawei_utils.encode_name(volume['id']) + volume_name = huawei_utils.encode_name(volume.id) LOG.info(_LI( 'initialize_connection_fc, initiator: %(wwpns)s,' @@ -172,7 +172,7 @@ class HuaweiHyperMetro(object): 'data': {'target_lun': int(host_lun_id), 'target_discovered': True, 'target_wwn': tgt_port_wwns, - 'volume_id': volume['id'], + 'volume_id': volume.id, 'initiator_target_map': init_targ_map, 'map_info': map_info}, } @@ -184,7 +184,7 @@ class HuaweiHyperMetro(object): def disconnect_volume_fc(self, volume, connector): """Delete map between a volume and a host for FC.""" wwns = connector['wwpns'] - volume_name = huawei_utils.encode_name(volume['id']) + volume_name = huawei_utils.encode_name(volume.id) metadata = huawei_utils.get_volume_metadata(volume) lun_id = metadata['remote_lun_id'] host_name = connector['host'] @@ -270,8 +270,8 @@ class HuaweiHyperMetro(object): def create_consistencygroup(self, group): LOG.info(_LI("Create Consistency Group: %(group)s."), - {'group': group['id']}) - group_name = huawei_utils.encode_name(group['id']) + {'group': group.id}) + group_name = huawei_utils.encode_name(group.id) domain_name = self.configuration.metro_domain_name domain_id = self.client.get_hyper_domain_id(domain_name) if not domain_name or not domain_id: @@ -279,21 +279,21 @@ class HuaweiHyperMetro(object): LOG.error(msg) raise exception.VolumeBackendAPIException(data=msg) - self.client.create_metrogroup(group_name, group['id'], domain_id) + self.client.create_metrogroup(group_name, group.id, domain_id) def delete_consistencygroup(self, context, group, volumes): LOG.info(_LI("Delete Consistency Group: %(group)s."), - {'group': group['id']}) + {'group': group.id}) model_update = {} volumes_model_update = [] - model_update['status'] = group['status'] + model_update['status'] = group.status metrogroup_id = self.check_consistencygroup_need_to_stop(group) if metrogroup_id: self.client.delete_metrogroup(metrogroup_id) # Deal with the return volumes info for volume_ref in volumes: - volume_update = {'id': volume_ref['id']} + volume_update = {'id': volume_ref.id} volume_update['status'] = 'deleted' volumes_model_update.append(volume_update) @@ -303,9 +303,9 @@ class HuaweiHyperMetro(object): add_volumes, remove_volumes): LOG.info(_LI("Update Consistency Group: %(group)s. " "This adds or removes volumes from a CG."), - {'group': group['id']}) + {'group': group.id}) model_update = {} - model_update['status'] = group['status'] + model_update['status'] = group.status metrogroup_id = self.check_consistencygroup_need_to_stop(group) if metrogroup_id: # Deal with add volumes to CG @@ -350,7 +350,7 @@ class HuaweiHyperMetro(object): return metro_id def check_consistencygroup_need_to_stop(self, group): - group_name = huawei_utils.encode_name(group['id']) + group_name = huawei_utils.encode_name(group.id) metrogroup_id = self.client.get_metrogroup_by_name(group_name) if metrogroup_id: diff --git a/cinder/volume/drivers/huawei/replication.py b/cinder/volume/drivers/huawei/replication.py index b0b3c33486a..5c7eec2d106 100644 --- a/cinder/volume/drivers/huawei/replication.py +++ b/cinder/volume/drivers/huawei/replication.py @@ -314,8 +314,8 @@ class ReplicaCommonDriver(object): def get_replication_driver_data(volume): - if volume.get('replication_driver_data'): - return json.loads(volume['replication_driver_data']) + if volume.replication_driver_data: + return json.loads(volume.replication_driver_data) return {} @@ -531,7 +531,7 @@ class ReplicaPairManager(object): 1. delete replication pair 2. delete remote_lun """ - LOG.debug('Delete replication, volume: %s.', volume['id']) + LOG.debug('Delete replication, volume: %s.', volume.id) info = get_replication_driver_data(volume) pair_id = info.get('pair_id') if pair_id: @@ -555,18 +555,18 @@ class ReplicaPairManager(object): volumes_update = [] for v in volumes: v_update = {} - v_update['volume_id'] = v['id'] + v_update['volume_id'] = v.id drv_data = get_replication_driver_data(v) pair_id = drv_data.get('pair_id') if not pair_id: - LOG.warning(_LW("No pair id in volume %s."), v['id']) + LOG.warning(_LW("No pair id in volume %s."), v.id) v_update['updates'] = {'replication_status': 'error'} volumes_update.append(v_update) continue rmt_lun_id = drv_data.get('rmt_lun_id') if not rmt_lun_id: - LOG.warning(_LW("No remote lun id in volume %s."), v['id']) + LOG.warning(_LW("No remote lun id in volume %s."), v.id) v_update['updates'] = {'replication_status': 'error'} volumes_update.append(v_update) continue @@ -587,7 +587,7 @@ class ReplicaPairManager(object): admin_metadata = huawei_utils.get_admin_metadata(v) admin_metadata.update({'huawei_lun_wwn': lun_info['WWN']}) new_drv_data = {'pair_id': pair_id, - 'rmt_lun_id': v['provider_location']} + 'rmt_lun_id': v.provider_location} new_drv_data = to_string(new_drv_data) v_update['updates'] = {'provider_location': rmt_lun_id, 'replication_status': 'available', @@ -605,18 +605,18 @@ class ReplicaPairManager(object): volumes_update = [] for v in volumes: v_update = {} - v_update['volume_id'] = v['id'] + v_update['volume_id'] = v.id drv_data = get_replication_driver_data(v) pair_id = drv_data.get('pair_id') if not pair_id: - LOG.warning(_LW("No pair id in volume %s."), v['id']) + LOG.warning(_LW("No pair id in volume %s."), v.id) v_update['updates'] = {'replication_status': 'error'} volumes_update.append(v_update) continue rmt_lun_id = drv_data.get('rmt_lun_id') if not rmt_lun_id: - LOG.warning(_LW("No remote lun id in volume %s."), v['id']) + LOG.warning(_LW("No remote lun id in volume %s."), v.id) v_update['updates'] = {'replication_status': 'error'} volumes_update.append(v_update) continue @@ -628,7 +628,7 @@ class ReplicaPairManager(object): admin_metadata.update({'huawei_lun_wwn': lun_info['WWN']}) new_drv_data = {'pair_id': pair_id, - 'rmt_lun_id': v['provider_location']} + 'rmt_lun_id': v.provider_location} new_drv_data = to_string(new_drv_data) v_update['updates'] = {'provider_location': rmt_lun_id, 'replication_status': 'failed-over', diff --git a/cinder/volume/drivers/huawei/rest_client.py b/cinder/volume/drivers/huawei/rest_client.py index fcf9c87c459..84098d2c3b8 100644 --- a/cinder/volume/drivers/huawei/rest_client.py +++ b/cinder/volume/drivers/huawei/rest_client.py @@ -308,12 +308,12 @@ class RestClient(object): return result['data'] def get_lun_id(self, volume, volume_name): - lun_id = (volume.get('provider_location') or + lun_id = (volume.provider_location or self.get_lun_id_by_name(volume_name)) if not lun_id: msg = (_("Can't find lun info on the array. " "volume: %(id)s, lun name: %(name)s.") % - {'id': volume['id'], 'name': volume_name}) + {'id': volume.id, 'name': volume_name}) LOG.error(msg) raise exception.VolumeBackendAPIException(data=msg) return lun_id