diff --git a/os_brick/initiator/linuxfc.py b/os_brick/initiator/linuxfc.py index f3ab8aed1..6ace4d89e 100644 --- a/os_brick/initiator/linuxfc.py +++ b/os_brick/initiator/linuxfc.py @@ -27,6 +27,14 @@ LOG = logging.getLogger(__name__) 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): """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): """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 try: out, _err = self._execute('systool', '-c', 'fc_host', '-v', diff --git a/os_brick/tests/initiator/test_linuxfc.py b/os_brick/tests/initiator/test_linuxfc.py index 1cac9a725..c455edf3b 100644 --- a/os_brick/tests/initiator/test_linuxfc.py +++ b/os_brick/tests/initiator/test_linuxfc.py @@ -27,12 +27,23 @@ class LinuxFCTestCase(base.TestCase): self.cmds = [] 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) def fake_execute(self, *cmd, **kwargs): self.cmds.append(" ".join(cmd)) 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): # We check that we try to get the HBA channel and SCSI target execute_results = (