]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Allow connect by FC-only or iSCSI-only systems.
authorAvishay Traeger <avishay@il.ibm.com>
Sun, 21 Jul 2013 13:18:15 +0000 (16:18 +0300)
committerAvishay Traeger <avishay@il.ibm.com>
Sun, 28 Jul 2013 13:24:27 +0000 (16:24 +0300)
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
cinder/brick/initiator/linuxfc.py
cinder/tests/brick/test_brick_connector.py
cinder/tests/brick/test_brick_linuxfc.py

index e317b0e211825b044c70c3f1423d84e3792c8aaf..dfb50cb70514c33d996047916cb1e6e41db3d188 100644 (file)
@@ -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)
index 1ee144a65a55ff2b85364c0d0eb001b6957dd253..6be22253d3c10d57295a9e032728d006fd25e0b7 100644 (file)
@@ -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:
index f56ce200774e1372d780e78cd7b036f5266e01fd..d318b8fab2f41ed586aa417d67c431afa2d01a62 100644 (file)
@@ -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):
index 8fbbc89e4a137173fba8c1f10ec7053fd8f4cd0d..9091dacc52d41cd7e054c607b4d9186fd03d3dcb 100644 (file)
@@ -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