Merge "Handle None value 'inititator_target_map'"

This commit is contained in:
Zuul 2019-02-20 16:45:47 +00:00 committed by Gerrit Code Review
commit ae0a489b13
4 changed files with 38 additions and 4 deletions

View File

@ -116,7 +116,7 @@ class FibreChannelConnector(base.BaseLinuxConnector):
wwpn_lun_map[wwpn] = lun
# If there is an initiator_target_map we can update it too
if 'initiator_target_map' in connection_properties:
if connection_properties.get('initiator_target_map') is not None:
itmap = connection_properties['initiator_target_map']
new_itmap = dict()
for init_wwpn in itmap:

View File

@ -50,7 +50,7 @@ class LinuxFibreChannel(linuxscsi.LinuxSCSI):
# We want the target's WWPNs, so we use the initiator_target_map if
# present for this hba or default to target_wwns if not present.
targets = conn_props['targets']
if 'initiator_target_map' in conn_props:
if conn_props.get('initiator_target_map') is not None:
targets = conn_props['initiator_target_lun_map'].get(
hba['port_name'], targets)

View File

@ -603,8 +603,7 @@ class FibreChannelConnectorTestCase(test_connector.ConnectorTestCase):
conn = self.fibrechan_connection(volume, "10.0.2.15:3260", wwn)
conn['data'].update(target_info)
if itmap:
conn['data']['initiator_target_map'] = itmap
conn['data']['initiator_target_map'] = itmap
connection_info = self.connector._add_targets_to_connection_properties(
conn['data'])

View File

@ -96,6 +96,41 @@ class LinuxFCTestCase(base.TestCase):
expected = [['0', '1', 1]]
self.assertListEqual(expected, res)
def test__get_hba_channel_scsi_target_with_initiator_target_map(self):
execute_results = ('/sys/class/fc_transport/target6:0:1/port_name\n',
'')
hbas, con_props = self.__get_rescan_info(zone_manager=True)
con_props['target_wwn'] = con_props['target_wwn'][0]
con_props['targets'] = con_props['targets'][0:1]
hbas[0]['port_name'] = '50014380186af83e'
with mock.patch.object(self.lfc, '_execute',
return_value=execute_results) as execute_mock:
res = self.lfc._get_hba_channel_scsi_target(hbas[0], con_props)
execute_mock.assert_called_once_with(
'grep -Gil "514f0c50023f6c01" '
'/sys/class/fc_transport/target6:*/port_name',
shell=True)
expected = [['0', '1', 1]]
self.assertListEqual(expected, res)
def test__get_hba_channel_scsi_target_with_initiator_target_map_none(self):
execute_results = ('/sys/class/fc_transport/target6:0:1/port_name\n',
'')
hbas, con_props = self.__get_rescan_info()
con_props['target_wwn'] = con_props['target_wwn'][0]
con_props['targets'] = con_props['targets'][0:1]
con_props['initiator_target_map'] = None
hbas[0]['port_name'] = '50014380186af83e'
with mock.patch.object(self.lfc, '_execute',
return_value=execute_results) as execute_mock:
res = self.lfc._get_hba_channel_scsi_target(hbas[0], con_props)
execute_mock.assert_called_once_with(
'grep -Gil "514f0c50023f6c00" '
'/sys/class/fc_transport/target6:*/port_name',
shell=True)
expected = [['0', '1', 1]]
self.assertListEqual(expected, res)
def test__get_hba_channel_scsi_target_multiple_wwpn(self):
execute_results = [
['/sys/class/fc_transport/target6:0:1/port_name\n', ''],