From 55df41c2c6d12f6bf6586da3a66efec6bdaa75f3 Mon Sep 17 00:00:00 2001 From: Avishay Traeger Date: Sun, 21 Jul 2013 16:18:15 +0300 Subject: [PATCH] Allow connect by FC-only or iSCSI-only systems. Currently the brick code raises exceptions if it cannot determine the initiator name or FC HBA information. This patch makes this information optional, as Nova does. Fixes: bug 1203486 Change-Id: I8efc101d7ac980261a8bc5d74209cafe4b06cc15 --- cinder/brick/initiator/connector.py | 10 ++++++--- cinder/brick/initiator/linuxfc.py | 8 +++++++- cinder/tests/brick/test_brick_connector.py | 24 ++++++++++++++++++++++ cinder/tests/brick/test_brick_linuxfc.py | 14 +++++++++++++ 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/cinder/brick/initiator/connector.py b/cinder/brick/initiator/connector.py index e317b0e21..dfb50cb70 100644 --- a/cinder/brick/initiator/connector.py +++ b/cinder/brick/initiator/connector.py @@ -46,8 +46,12 @@ def get_connector_properties(): props = {} props['ip'] = CONF.my_ip props['host'] = socket.gethostname() - props['initiator'] = iscsi.get_initiator() - props['wwpns'] = fc.get_fc_wwpns() + initiator = iscsi.get_initiator() + if initiator: + props['initiator'] = initiator + wwpns = fc.get_fc_wwpns() + if wwpns: + props['wwpns'] = wwpns return props @@ -253,7 +257,7 @@ class ISCSIConnector(InitiatorConnector): if l.startswith('InitiatorName='): return l[l.index('=') + 1:].strip() except exception.ProcessExecutionError: - raise exception.FileNotFound(file_path=file_path) + return None def _run_iscsiadm(self, connection_properties, iscsi_command, **kwargs): check_exit_code = kwargs.pop('check_exit_code', 0) diff --git a/cinder/brick/initiator/linuxfc.py b/cinder/brick/initiator/linuxfc.py index 1ee144a65..6be22253d 100644 --- a/cinder/brick/initiator/linuxfc.py +++ b/cinder/brick/initiator/linuxfc.py @@ -59,8 +59,9 @@ class LinuxFibreChannel(linuxscsi.LinuxSCSI): LOG.warn(_("systool is not installed")) return [] + # No FC HBAs were found if out is None: - raise RuntimeError(_("Cannot find any Fibre Channel HBAs")) + return [] lines = out.split('\n') # ignore the first 2 lines @@ -91,6 +92,9 @@ class LinuxFibreChannel(linuxscsi.LinuxSCSI): # Note(walter-boring) modern linux kernels contain the FC HBA's in /sys # and are obtainable via the systool app hbas = self.get_fc_hbas() + if not hbas: + return [] + hbas_info = [] for hba in hbas: wwpn = hba['port_name'].replace('0x', '') @@ -125,6 +129,8 @@ class LinuxFibreChannel(linuxscsi.LinuxSCSI): # Note(walter-boring) modern linux kernels contain the FC HBA's in /sys # and are obtainable via the systool app hbas = self.get_fc_hbas() + if not hbas: + return [] wwnns = [] if hbas: diff --git a/cinder/tests/brick/test_brick_connector.py b/cinder/tests/brick/test_brick_connector.py index f56ce2007..d318b8fab 100644 --- a/cinder/tests/brick/test_brick_connector.py +++ b/cinder/tests/brick/test_brick_connector.py @@ -100,6 +100,30 @@ class ISCSIConnectorTestCase(ConnectorTestCase): } } + def test_get_initiator(self): + def initiator_no_file(*args, **kwargs): + raise exception.ProcessExecutionError('No file') + + def initiator_get_text(*arg, **kwargs): + text = ('## DO NOT EDIT OR REMOVE THIS FILE!\n' + '## If you remove this file, the iSCSI daemon ' + 'will not start.\n' + '## If you change the InitiatorName, existing ' + 'access control lists\n' + '## may reject this initiator. The InitiatorName must ' + 'be unique\n' + '## for each iSCSI initiator. Do NOT duplicate iSCSI ' + 'InitiatorNames.\n' + 'InitiatorName=iqn.1234-56.foo.bar:01:23456789abc') + return text, None + + self.stubs.Set(self.connector, '_execute', initiator_no_file) + initiator = self.connector.get_initiator() + self.assertEquals(initiator, None) + self.stubs.Set(self.connector, '_execute', initiator_get_text) + initiator = self.connector.get_initiator() + self.assertEquals(initiator, 'iqn.1234-56.foo.bar:01:23456789abc') + @test.testtools.skipUnless(os.path.exists('/dev/disk/by-path'), 'Test requires /dev/disk/by-path') def test_connect_volume(self): diff --git a/cinder/tests/brick/test_brick_linuxfc.py b/cinder/tests/brick/test_brick_linuxfc.py index 8fbbc89e4..9091dacc5 100644 --- a/cinder/tests/brick/test_brick_linuxfc.py +++ b/cinder/tests/brick/test_brick_linuxfc.py @@ -44,6 +44,20 @@ class LinuxFCTestCase(test.TestCase): 'tee -a /sys/class/scsi_host/bar/scan'] self.assertEquals(expected_commands, self.cmds) + def test_get_fc_hbas_fail(self): + def fake_exec1(a, b, c, d, run_as_root=True, root_helper='sudo'): + raise OSError + + def fake_exec2(a, b, c, d, run_as_root=True, root_helper='sudo'): + return None, 'None found' + + self.stubs.Set(self.lfc, "_execute", fake_exec1) + hbas = self.lfc.get_fc_hbas() + self.assertEquals(0, len(hbas)) + self.stubs.Set(self.lfc, "_execute", fake_exec2) + hbas = self.lfc.get_fc_hbas() + self.assertEquals(0, len(hbas)) + def test_get_fc_hbas(self): def fake_exec(a, b, c, d, run_as_root=True, root_helper='sudo'): return SYSTOOL_FC, None -- 2.45.2