From: Geraint North Date: Tue, 4 Mar 2014 02:18:03 +0000 (-0500) Subject: Add initiator_target_map for IBM Storwize/SVC X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=0e44ba4c273f41195d0361d3c48df76e2e5add76;p=openstack-build%2Fcinder-build.git Add initiator_target_map for IBM Storwize/SVC Basic support to return a map of all initiator to all targets. Updated unit test. Change-Id: I886dd63021130003b1b2dd391542fb2b41b9d51f Closes-Bug: #1287476 --- diff --git a/cinder/tests/test_storwize_svc.py b/cinder/tests/test_storwize_svc.py index 97f86efbf..04b3be474 100644 --- a/cinder/tests/test_storwize_svc.py +++ b/cinder/tests/test_storwize_svc.py @@ -2444,6 +2444,55 @@ class StorwizeSVCDriverTestCase(test.TestCase): 'Storwize driver delete vdisk copy error') self._delete_volume(volume) + def test_storwize_initiator_target_map(self): + # Create two volumes to be used in mappings + ctxt = context.get_admin_context() + + # Generate us a test volume + volume = self._generate_vol_info(None, None) + self.driver.create_volume(volume) + + # FIbre Channel volume type + vol_type = volume_types.create(ctxt, 'FC', {'protocol': 'FC'}) + + volume['volume_type_id'] = vol_type['id'] + + # Make sure that the volumes have been created + self._assert_vol_exists(volume['name'], True) + + wwpns = ['ff00000000000000', 'ff00000000000001'] + connector = {'host': 'storwize-svc-test', 'wwpns': wwpns} + + # Initialise the connection + init_ret = self.driver.initialize_connection(volume, connector) + + # Check that the initiator_target_map is as expected + init_data = {'driver_volume_type': 'fibre_channel', + 'data': {'initiator_target_map': + {'ff00000000000000': ['AABBCCDDEEFF0011'], + 'ff00000000000001': ['AABBCCDDEEFF0011']}, + 'target_discovered': False, + 'target_lun': '0', + 'target_wwn': 'AABBCCDDEEFF0011', + 'volume_id': volume['id'] + } + } + + self.assertEqual(init_data, init_ret) + + # Terminate connection + term_ret = self.driver.terminate_connection(volume, connector) + + # Check that the initiator_target_map is as expected + term_data = {'driver_volume_type': 'fibre_channel', + 'data': {'initiator_target_map': + {'ff00000000000000': ['AABBCCDDEEFF0011'], + 'ff00000000000001': ['AABBCCDDEEFF0011']} + } + } + + self.assertEqual(term_data, term_ret) + class CLIResponseTestCase(test.TestCase): def test_empty(self): diff --git a/cinder/volume/drivers/ibm/storwize_svc/__init__.py b/cinder/volume/drivers/ibm/storwize_svc/__init__.py index b2c13eab2..e15476cf8 100644 --- a/cinder/volume/drivers/ibm/storwize_svc/__init__.py +++ b/cinder/volume/drivers/ibm/storwize_svc/__init__.py @@ -414,6 +414,10 @@ class StorwizeSVCDriver(san.SanDriver): properties['target_wwn'] = conn_wwpns[0] else: properties['target_wwn'] = conn_wwpns + + i_t_map = self._make_initiator_target_map(connector['wwpns'], + conn_wwpns) + properties['initiator_target_map'] = i_t_map except Exception: with excutils.save_and_reraise_exception(): self.terminate_connection(volume, connector) @@ -430,6 +434,16 @@ class StorwizeSVCDriver(san.SanDriver): return {'driver_volume_type': type_str, 'data': properties, } + def _make_initiator_target_map(self, initiator_wwpns, target_wwpns): + """Build a simplistic all-to-all mapping.""" + i_t_map = {} + for i_wwpn in initiator_wwpns: + i_t_map[str(i_wwpn)] = [] + for t_wwpn in target_wwpns: + i_t_map[i_wwpn].append(t_wwpn) + + return i_t_map + @utils.synchronized('storwize-host', external=True) def terminate_connection(self, volume, connector, **kwargs): """Cleanup after an iSCSI connection has been terminated. @@ -457,12 +471,22 @@ class StorwizeSVCDriver(san.SanDriver): # See bug #1244257 host_name = None + info = {} + if 'wwpns' in connector and host_name: + target_wwpns = self._helpers.get_conn_fc_wwpns(host_name) + init_targ_map = self._make_initiator_target_map(connector['wwpns'], + target_wwpns) + info = {'driver_volume_type': 'fibre_channel', + 'data': {'initiator_target_map': init_targ_map}} + self._helpers.unmap_vol_from_host(vol_name, host_name) LOG.debug(_('leave: terminate_connection: volume %(vol)s with ' 'connector %(conn)s') % {'vol': str(volume), 'conn': str(connector)}) + return info + def create_volume(self, volume): opts = self._get_vdisk_params(volume['volume_type_id']) pool = self.configuration.storwize_svc_volpool_name diff --git a/cinder/volume/drivers/ibm/storwize_svc/helpers.py b/cinder/volume/drivers/ibm/storwize_svc/helpers.py index 18c814acb..27141d4f7 100644 --- a/cinder/volume/drivers/ibm/storwize_svc/helpers.py +++ b/cinder/volume/drivers/ibm/storwize_svc/helpers.py @@ -167,12 +167,12 @@ class StorwizeHelpers(object): return None def get_conn_fc_wwpns(self, host): - wwpns = [] + wwpns = set() resp = self.ssh.lsfabric(host=host) for wwpn in resp.select('local_wwpn'): if wwpn is not None: - wwpns.append(wwpn) - return wwpns + wwpns.add(wwpn) + return list(wwpns) def get_host_from_connector(self, connector): """Return the Storwize host described by the connector."""