File 0003-Parse-FCoE-sysfs-device-paths.patch of Package python-os-brick
From 30596391f494263fff5ca88c609c826cf512da6b Mon Sep 17 00:00:00 2001
From: Lee Yarwood <lyarwood@redhat.com>
Date: Thu, 22 Oct 2015 14:34:54 +0100
Subject: [PATCH 3/5] Parse FCoE sysfs device paths
FCoE devices have slightly different sysfs device paths to FC devices :
/sys/devices/pci0000:20/0000:20:03.0/0000:21:00.2/net/ens2f2/ctlr_2/
host3/fc_host/host3
As with FC devices we want the domain:bus:device.function of the device.
For FCoE devices this is listed prior to `net`.
Change-Id: I2e46af1679982964c0d90289bcf1a1fc702fcb15
(cherry picked from commit 23e40d20ad86739d244119e879f55b6809fb96a7)
---
os_brick/initiator/connector.py | 22 ++++++++--------------
os_brick/tests/initiator/test_connector.py | 17 +++++++++++++++++
2 files changed, 25 insertions(+), 14 deletions(-)
diff --git a/os_brick/initiator/connector.py b/os_brick/initiator/connector.py
index 2dfd011..b2a1818 100644
--- a/os_brick/initiator/connector.py
+++ b/os_brick/initiator/connector.py
@@ -1140,24 +1140,18 @@ class FibreChannelConnector(InitiatorConnector):
def _get_pci_num(self, hba):
# NOTE(walter-boring)
- # device path is in format of
+ # device path is in format of (FC and FCoE) :
# /sys/devices/pci0000:00/0000:00:03.0/0000:05:00.3/host2/fc_host/host2
- # sometimes an extra entry exists before the host2 value
- # we always want the value prior to the host2 value
- pci_num = None
+ # /sys/devices/pci0000:20/0000:20:03.0/0000:21:00.2/net/ens2f2/ctlr_2
+ # /host3/fc_host/host3
+ # we always want the value prior to the host or net value
if hba is not None:
if "device_path" in hba:
- index = 0
device_path = hba['device_path'].split('/')
- for value in device_path:
- if value.startswith('host'):
- break
- index = index + 1
-
- if index > 0:
- pci_num = device_path[index - 1]
-
- return pci_num
+ for index, value in enumerate(device_path):
+ if value.startswith('net') or value.startswith('host'):
+ return device_path[index - 1]
+ return None
class FibreChannelConnectorS390X(FibreChannelConnector):
diff --git a/os_brick/tests/initiator/test_connector.py b/os_brick/tests/initiator/test_connector.py
index c8b421a..d279051 100644
--- a/os_brick/tests/initiator/test_connector.py
+++ b/os_brick/tests/initiator/test_connector.py
@@ -1022,6 +1022,23 @@ class FibreChannelConnectorTestCase(ConnectorTestCase):
'target_lun': 1,
}}
+ def test_get_pci_num(self):
+ hba = {'device_path': "/sys/devices/pci0000:00/0000:00:03.0"
+ "/0000:05:00.3/host2/fc_host/host2"}
+ pci_num = self.connector._get_pci_num(hba)
+ self.assertEqual("0000:05:00.3", pci_num)
+
+ hba = {'device_path': "/sys/devices/pci0000:00/0000:00:03.0"
+ "/0000:05:00.3/0000:06:00.6/host2/fc_host/host2"}
+ pci_num = self.connector._get_pci_num(hba)
+ self.assertEqual("0000:06:00.6", pci_num)
+
+ hba = {'device_path': "/sys/devices/pci0000:20/0000:20:03.0"
+ "/0000:21:00.2/net/ens2f2/ctlr_2/host3"
+ "/fc_host/host3"}
+ pci_num = self.connector._get_pci_num(hba)
+ self.assertEqual("0000:21:00.2", pci_num)
+
@mock.patch.object(os.path, 'exists', return_value=True)
@mock.patch.object(linuxfc.LinuxFibreChannel, 'get_fc_hbas')
@mock.patch.object(linuxfc.LinuxFibreChannel, 'get_fc_hbas_info')
--
2.7.0