]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Add initiator_target_map for IBM Storwize/SVC
authorGeraint North <geraint.north@uk.ibm.com>
Tue, 4 Mar 2014 02:18:03 +0000 (21:18 -0500)
committerAvishay Traeger <avishay@gmail.com>
Tue, 4 Mar 2014 05:06:10 +0000 (07:06 +0200)
Basic support to return a map of all initiator to all targets.
Updated unit test.

Change-Id: I886dd63021130003b1b2dd391542fb2b41b9d51f
Closes-Bug: #1287476

cinder/tests/test_storwize_svc.py
cinder/volume/drivers/ibm/storwize_svc/__init__.py
cinder/volume/drivers/ibm/storwize_svc/helpers.py

index 97f86efbff0bf44ba1456f4c2c5f74fd1594f6cb..04b3be474cd5718b298d800d7c8c56ccc844c07c 100644 (file)
@@ -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):
index b2c13eab2ea8a23a8ff297c7037c70931359c68f..e15476cf865d661c521b12ae447546f45c088d30 100644 (file)
@@ -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
index 18c814acb2991c7f6e6dd167f8a57e17a09c5340..27141d4f7a391cba315799a312cb6ad1b4fc0204 100644 (file)
@@ -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."""