Skip to content

Commit

Permalink
Allow connect by FC-only or iSCSI-only systems.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
avishay-traeger committed Jul 28, 2013
1 parent 9f0bb80 commit 55df41c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
10 changes: 7 additions & 3 deletions cinder/brick/initiator/connector.py
Expand Up @@ -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

Expand Down Expand Up @@ -253,7 +257,7 @@ def get_initiator(self):
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)
Expand Down
8 changes: 7 additions & 1 deletion cinder/brick/initiator/linuxfc.py
Expand Up @@ -59,8 +59,9 @@ def get_fc_hbas(self):
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
Expand Down Expand Up @@ -91,6 +92,9 @@ def get_fc_hbas_info(self):
# 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', '')
Expand Down Expand Up @@ -125,6 +129,8 @@ def get_fc_wwnns(self):
# 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:
Expand Down
24 changes: 24 additions & 0 deletions cinder/tests/brick/test_brick_connector.py
Expand Up @@ -100,6 +100,30 @@ def iscsi_connection(self, volume, location, iqn):
}
}

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):
Expand Down
14 changes: 14 additions & 0 deletions cinder/tests/brick/test_brick_linuxfc.py
Expand Up @@ -44,6 +44,20 @@ def test_rescan_hosts(self):
'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
Expand Down

0 comments on commit 55df41c

Please sign in to comment.