From f7d99b07f72037b87d5e9f63b48a7c49f7116fe5 Mon Sep 17 00:00:00 2001 From: Xing Yang Date: Sat, 1 Mar 2014 23:45:45 -0500 Subject: [PATCH] Add initiator target map in EMC SMI-S FC driver. This patch add the initiator target map in initialize_connection and terminate_connection as it is required by the FC Zone Manager. Change-Id: I84729968b8e4e6ee74536fb28d3d921a9baf9f6e Closes-Bug: #1286694 --- .../tests/{test_emc.py => test_emc_smis.py} | 53 ++++++++++++++++--- cinder/volume/drivers/emc/emc_smis_fc.py | 33 +++++++++++- 2 files changed, 78 insertions(+), 8 deletions(-) rename cinder/tests/{test_emc.py => test_emc_smis.py} (96%) diff --git a/cinder/tests/test_emc.py b/cinder/tests/test_emc_smis.py similarity index 96% rename from cinder/tests/test_emc.py rename to cinder/tests/test_emc_smis.py index 1496dfe04..7e5a7ccc2 100644 --- a/cinder/tests/test_emc.py +++ b/cinder/tests/test_emc_smis.py @@ -1186,17 +1186,58 @@ class EMCSMISFCDriverTestCase(test.TestCase): self.data.test_volume['volume_type_id'] = None self.driver.create_volume(self.data.test_volume) - output = {'driver_volume_type': 'fibre_channel', - 'data': {'target_lun': 0, - 'target_wwn': ['1234567890123', '0987654321321'], - 'target_discovered': True}} + output = { + 'driver_volume_type': 'fibre_channel', + 'data': { + 'target_lun': 0, + 'target_wwn': ['1234567890123', '0987654321321'], + 'target_discovered': True, + 'initiator_target_map': {'123456789012345': + ['1234567890123', '0987654321321'], + '123456789054321': + ['1234567890123', '0987654321321'], + }}} + connection_info = self.driver.initialize_connection( self.data.test_volume, self.data.connector) self.assertEqual(connection_info, output) - self.driver.terminate_connection(self.data.test_volume, - self.data.connector) + connection_info = self.driver.terminate_connection( + self.data.test_volume, + self.data.connector) + + # Verify calls in terminate_connection are executed + conf_service = {} + conf_service['SystemName'] = self.data.storage_system + conf_service['CreationClassName'] =\ + self.data.ctrlconf_service_creationclass + + vol_instance = self.driver.common._find_lun(self.data.test_volume) + + expected = [ + mock.call._get_ecom_connection(), + mock.call.find_device_number(self.data.test_volume), + mock.call._find_lun(self.data.test_volume), + mock.call.self._find_controller_configuration_service( + self.data.storage_system), + mock.call._remove_members(conf_service, vol_instance), + mock.call.get_target_wwns( + self.data.storage_system, + self.data.connector)] + + output = { + 'driver_volume_type': 'fibre_channel', + 'data': { + 'target_wwn': ['1234567890123', '0987654321321'], + 'initiator_target_map': {'123456789012345': + ['1234567890123', '0987654321321'], + '123456789054321': + ['1234567890123', '0987654321321'], + }}} + + self.assertEqual(connection_info, output) + self.driver.delete_volume(self.data.test_volume) def test_create_volume_failed(self): diff --git a/cinder/volume/drivers/emc/emc_smis_fc.py b/cinder/volume/drivers/emc/emc_smis_fc.py index 742044937..d05800b45 100644 --- a/cinder/volume/drivers/emc/emc_smis_fc.py +++ b/cinder/volume/drivers/emc/emc_smis_fc.py @@ -157,12 +157,14 @@ class EMCSMISFCDriver(driver.FibreChannelDriver): connector) device_number = device_info['hostlunid'] storage_system = device_info['storagesystem'] - ports = self.common.get_target_wwns(storage_system, connector) + target_wwns, init_targ_map = self._build_initiator_target_map( + storage_system, connector) data = {'driver_volume_type': 'fibre_channel', 'data': {'target_lun': device_number, 'target_discovered': True, - 'target_wwn': ports}} + 'target_wwn': target_wwns, + 'initiator_target_map': init_targ_map}} LOG.debug(_('Return FC data: %(data)s.') % {'data': data}) @@ -173,6 +175,33 @@ class EMCSMISFCDriver(driver.FibreChannelDriver): """Disallow connection from connector.""" self.common.terminate_connection(volume, connector) + loc = volume['provider_location'] + name = eval(loc) + storage_system = name['keybindings']['SystemName'] + target_wwns, init_targ_map = self._build_initiator_target_map( + storage_system, connector) + data = {'driver_volume_type': 'fibre_channel', + 'data': {'target_wwn': target_wwns, + 'initiator_target_map': init_targ_map}} + + LOG.debug(_('Return FC data: %(data)s.') + % {'data': data}) + + return data + + def _build_initiator_target_map(self, storage_system, connector): + """Build the target_wwns and the initiator target map.""" + + target_wwns = self.common.get_target_wwns(storage_system, connector) + + initiator_wwns = connector['wwpns'] + + init_targ_map = {} + for initiator in initiator_wwns: + init_targ_map[initiator] = target_wwns + + return target_wwns, init_targ_map + def extend_volume(self, volume, new_size): """Extend an existing volume.""" self.common.extend_volume(volume, new_size) -- 2.45.2