self.driver.initialize_connection,
volume2, self._connector)
+ # with storwize_svc_npiv_compatibility_mode set to True,
+ # lsfabric can return [] and initilize_connection will still
+ # complete successfully
+
+ with mock.patch.object(helpers.StorwizeHelpers,
+ 'get_conn_fc_wwpns') as conn_fc_wwpns:
+ conn_fc_wwpns.return_value = []
+ self._set_flag('storwize_svc_npiv_compatibility_mode',
+ True)
+ expected_fc_npiv = {
+ 'driver_volume_type': 'fibre_channel',
+ 'data': {'target_lun': 1,
+ 'target_wwn': '500507680220C744',
+ 'target_discovered': False}}
+ ret = self.driver.initialize_connection(volume2,
+ self._connector)
+ self.assertEqual(
+ ret['driver_volume_type'],
+ expected_fc_npiv['driver_volume_type'])
+ for k, v in expected_fc_npiv['data'].iteritems():
+ self.assertEqual(ret['data'][k], v)
+ self._set_flag('storwize_svc_npiv_compatibility_mode',
+ False)
+
self.driver.terminate_connection(volume1, self._connector)
+ # for npiv compatibility test case, we need to terminate connection
+ # to the 2nd volume
+ if protocol == 'FC' and self.USESIM:
+ self.driver.terminate_connection(volume2, self._connector)
if self.USESIM:
ret = self.driver._helpers.get_host_from_connector(
self._connector)
self.assertEqual(term_data, term_ret)
+ def test_storwize_initiator_target_map_npiv(self):
+ # Create two volumes to be used in mappings
+ ctxt = context.get_admin_context()
+ self._set_flag('storwize_svc_npiv_compatibility_mode', True)
+
+ # 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
+ with mock.patch.object(helpers.StorwizeHelpers,
+ 'get_conn_fc_wwpns') as conn_fc_wwpns:
+ conn_fc_wwpns.return_value = []
+ 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': ['500507680220C744',
+ '500507680210C744',
+ '500507680220C745',
+ '500507680230C745'],
+ 'ff00000000000001': ['500507680220C744',
+ '500507680210C744',
+ '500507680220C745',
+ '500507680230C745']},
+ 'target_discovered': False,
+ 'target_lun': 0,
+ 'target_wwn': '500507680220C744',
+ '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)
+
def _get_vdisk_uid(self, vdisk_name):
"""Return vdisk_UID for given vdisk.
cfg.BoolOpt('storwize_svc_multihostmap_enabled',
default=True,
help='Allows vdisk to multi host mapping'),
+ cfg.BoolOpt('storwize_svc_npiv_compatibility_mode',
+ default=False,
+ help='Indicate whether svc driver is compatible for NPIV '
+ 'setup. If it is compatible, it will allow no wwpns '
+ 'being returned on get_conn_fc_wwpns during '
+ 'initialize_connection'),
]
CONF = cfg.CONF
else:
type_str = 'fibre_channel'
conn_wwpns = self._helpers.get_conn_fc_wwpns(host_name)
+
+ # If conn_wwpns is empty, then that means that there were
+ # no target ports with visibility to any of the initiators.
+ # We will either fail the attach, or return all target
+ # ports, depending on the value of the
+ # storwize_svc_npiv_compatibity_mode flag.
if len(conn_wwpns) == 0:
- msg = (_('Could not get FC connection information for the '
- 'host-volume connection. Is the host configured '
- 'properly for FC connections?'))
- LOG.error(msg)
- raise exception.VolumeBackendAPIException(data=msg)
+ npiv_compat = self.configuration.\
+ storwize_svc_npiv_compatibility_mode
+ if not npiv_compat:
+ msg = (_('Could not get FC connection information for '
+ 'the host-volume connection. Is the host '
+ 'configured properly for FC connections?'))
+ LOG.error(msg)
+ raise exception.VolumeBackendAPIException(data=msg)
+ else:
+ for node in self._state['storage_nodes'].itervalues():
+ conn_wwpns.extend(node['WWPN'])
+
if not vol_opts['multipath']:
# preferred_node_entry can have a list of WWPNs while only
# one WWPN may be available on the storage host. Here we