Detect if Fibre Channel support exists
This patch adds a simple check to see if the kernel even supports Fibre Channel before calling systool -c fc_host -v to find the active HBA's on the system. The problem is that privsep can't quietly run systool without puking out a bunch of errors to stderr. We know that most systems don't have FC and that's why we always wrapped out call to putils executing systool with a try block. putils allows callers to expect exceptions and then handle the exception logging or not themselves. privsep doesn't allow that. Change-Id: Idd254303c9cca2b57d358de2fdbaf8abdd76b553
This commit is contained in:
parent
76af9fcecb
commit
4cc4f0dda2
@ -27,6 +27,14 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class LinuxFibreChannel(linuxscsi.LinuxSCSI):
|
class LinuxFibreChannel(linuxscsi.LinuxSCSI):
|
||||||
|
|
||||||
|
def has_fc_support(self):
|
||||||
|
FC_HOST_SYSFS_PATH = '/sys/class/fc_host'
|
||||||
|
if os.path.isdir(FC_HOST_SYSFS_PATH):
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
def _get_hba_channel_scsi_target(self, hba):
|
def _get_hba_channel_scsi_target(self, hba):
|
||||||
"""Try to get the HBA channel and SCSI target for an HBA.
|
"""Try to get the HBA channel and SCSI target for an HBA.
|
||||||
|
|
||||||
@ -72,6 +80,13 @@ class LinuxFibreChannel(linuxscsi.LinuxSCSI):
|
|||||||
|
|
||||||
def get_fc_hbas(self):
|
def get_fc_hbas(self):
|
||||||
"""Get the Fibre Channel HBA information."""
|
"""Get the Fibre Channel HBA information."""
|
||||||
|
|
||||||
|
if not self.has_fc_support():
|
||||||
|
# there is no FC support in the kernel loaded
|
||||||
|
# so there is no need to even try to run systool
|
||||||
|
LOG.debug("No Fibre Channel support detected on system.")
|
||||||
|
return []
|
||||||
|
|
||||||
out = None
|
out = None
|
||||||
try:
|
try:
|
||||||
out, _err = self._execute('systool', '-c', 'fc_host', '-v',
|
out, _err = self._execute('systool', '-c', 'fc_host', '-v',
|
||||||
|
@ -27,12 +27,23 @@ class LinuxFCTestCase(base.TestCase):
|
|||||||
self.cmds = []
|
self.cmds = []
|
||||||
|
|
||||||
self.mock_object(os.path, 'exists', return_value=True)
|
self.mock_object(os.path, 'exists', return_value=True)
|
||||||
|
self.mock_object(os.path, 'isdir', return_value=True)
|
||||||
self.lfc = linuxfc.LinuxFibreChannel(None, execute=self.fake_execute)
|
self.lfc = linuxfc.LinuxFibreChannel(None, execute=self.fake_execute)
|
||||||
|
|
||||||
def fake_execute(self, *cmd, **kwargs):
|
def fake_execute(self, *cmd, **kwargs):
|
||||||
self.cmds.append(" ".join(cmd))
|
self.cmds.append(" ".join(cmd))
|
||||||
return "", None
|
return "", None
|
||||||
|
|
||||||
|
def test_has_fc_support(self):
|
||||||
|
|
||||||
|
self.mock_object(os.path, 'isdir', return_value=False)
|
||||||
|
has_fc = self.lfc.has_fc_support()
|
||||||
|
self.assertFalse(has_fc)
|
||||||
|
|
||||||
|
self.mock_object(os.path, 'isdir', return_value=True)
|
||||||
|
has_fc = self.lfc.has_fc_support()
|
||||||
|
self.assertTrue(has_fc)
|
||||||
|
|
||||||
def test_rescan_hosts(self):
|
def test_rescan_hosts(self):
|
||||||
# We check that we try to get the HBA channel and SCSI target
|
# We check that we try to get the HBA channel and SCSI target
|
||||||
execute_results = (
|
execute_results = (
|
||||||
|
Loading…
Reference in New Issue
Block a user