diff --git a/os_brick/initiator/connectors/fibre_channel_ppc64.py b/os_brick/initiator/connectors/fibre_channel_ppc64.py index e0ba4ee36..32537fb2b 100644 --- a/os_brick/initiator/connectors/fibre_channel_ppc64.py +++ b/os_brick/initiator/connectors/fibre_channel_ppc64.py @@ -45,13 +45,13 @@ class FibreChannelConnectorPPC64(fibre_channel.FibreChannelConnector): self._linuxfc.set_execute(execute) def _get_host_devices(self, possible_devs, lun): - host_devices = [] + host_devices = set() for pci_num, target_wwn in possible_devs: host_device = "/dev/disk/by-path/fc-%s-lun-%s" % ( target_wwn, self._linuxscsi.process_lun_id(lun)) - host_devices.append(host_device) - return host_devices + host_devices.add(host_device) + return list(host_devices) def _get_possible_volume_paths(self, connection_properties, hbas): ports = connection_properties['target_wwn'] diff --git a/os_brick/initiator/linuxfc.py b/os_brick/initiator/linuxfc.py index 2d6252fbc..7d6492800 100644 --- a/os_brick/initiator/linuxfc.py +++ b/os_brick/initiator/linuxfc.py @@ -280,8 +280,8 @@ class LinuxFibreChannelPPC64(LinuxFibreChannel): if host_device and len(host_device) > 4: host_device = host_device[4:] path = '/sys/class/fc_transport/target%s:' % host_device - cmd = 'grep -l %(wwpn)s %(path)s*/port_name' % {'wwpn': wwpn, - 'path': path} + cmd = 'grep -il %(wwpn)s %(path)s*/port_name' % {'wwpn': wwpn, + 'path': path} try: out, _err = self._execute(cmd, shell=True) return [line.split('/')[4].split(':')[1:] diff --git a/os_brick/tests/initiator/connectors/test_fibre_channel_ppc64.py b/os_brick/tests/initiator/connectors/test_fibre_channel_ppc64.py index 83398cbae..36d279417 100644 --- a/os_brick/tests/initiator/connectors/test_fibre_channel_ppc64.py +++ b/os_brick/tests/initiator/connectors/test_fibre_channel_ppc64.py @@ -37,7 +37,14 @@ class FibreChannelConnectorPPC64TestCase(test_connector.ConnectorTestCase): (3, "0x5005076802332ade"), ] devices = self.connector._get_host_devices(possible_devs, lun) self.assertEqual(2, len(devices)) - device_path = "/dev/disk/by-path/fc-0x5005076802232ade-lun-2" - self.assertEqual(devices[0], device_path) device_path = "/dev/disk/by-path/fc-0x5005076802332ade-lun-2" - self.assertEqual(devices[1], device_path) + self.assertIn(device_path, devices) + device_path = "/dev/disk/by-path/fc-0x5005076802232ade-lun-2" + self.assertIn(device_path, devices) + # test duplicates + possible_devs = [(3, "0x5005076802232ade"), + (3, "0x5005076802232ade"), ] + devices = self.connector._get_host_devices(possible_devs, lun) + self.assertEqual(1, len(devices)) + device_path = "/dev/disk/by-path/fc-0x5005076802232ade-lun-2" + self.assertIn(device_path, devices)