Browse Source

Handle None value 'inititator_target_map'

Should check not only if 'initiator_target_map' is in conn_props but
also its value is not None.

Change-Id: I7ca0bf5fac20a370097f1c39ce005a1b23814459
Closes-Bug: #1746218
(cherry picked from commit 53877a95bc)
changes/84/696384/1
Sam Wan 4 years ago
committed by Gorka Eguileor
parent
commit
c4e616e3a0
  1. 2
      os_brick/initiator/linuxfc.py
  2. 3
      os_brick/tests/initiator/connectors/test_fibre_channel.py
  3. 35
      os_brick/tests/initiator/test_linuxfc.py

2
os_brick/initiator/linuxfc.py

@ -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)

3
os_brick/tests/initiator/connectors/test_fibre_channel.py

@ -645,8 +645,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'])

35
os_brick/tests/initiator/test_linuxfc.py

@ -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', ''],

Loading…
Cancel
Save