Merge "ISCSI be careful parsing iscsiadm output"
This commit is contained in:
commit
ff27d3f6c3
os_brick
@ -475,7 +475,15 @@ class ISCSIConnector(InitiatorConnector):
|
||||
|
||||
def _get_target_portals_from_iscsiadm_output(self, output):
|
||||
# return both portals and iqns
|
||||
return [line.split() for line in output.splitlines()]
|
||||
#
|
||||
# as we are parsing a command line utility, allow for the
|
||||
# possibility that additional debug data is spewed in the
|
||||
# stream, and only grab actual ip / iqn lines.
|
||||
targets = []
|
||||
for data in [line.split() for line in output.splitlines()]:
|
||||
if len(data) == 2 and data[1].startswith('iqn.'):
|
||||
targets.append(data)
|
||||
return targets
|
||||
|
||||
def _disconnect_volume_multipath_iscsi(self, connection_properties,
|
||||
multipath_name):
|
||||
|
@ -675,6 +675,29 @@ class ISCSIConnectorTestCase(ConnectorTestCase):
|
||||
# Target not in use by other mp devices, disconnect
|
||||
disconnect_mock.assert_called_once_with(fake_property)
|
||||
|
||||
def test_iscsiadm_discover_parsing(self):
|
||||
# Ensure that parsing iscsiadm discover ignores cruft.
|
||||
|
||||
targets = [
|
||||
["192.168.204.82:3260,1",
|
||||
("iqn.2010-10.org.openstack:volume-"
|
||||
"f9b12623-6ce3-4dac-a71f-09ad4249bdd3")],
|
||||
["192.168.204.82:3261,1",
|
||||
("iqn.2010-10.org.openstack:volume-"
|
||||
"f9b12623-6ce3-4dac-a71f-09ad4249bdd4")]]
|
||||
|
||||
# This slight wonkiness brought to you by pep8, as the actual
|
||||
# example output runs about 97 chars wide.
|
||||
sample_input = """Loading iscsi modules: done
|
||||
Starting iSCSI initiator service: done
|
||||
Setting up iSCSI targets: unused
|
||||
%s %s
|
||||
%s %s
|
||||
""" % (targets[0][0], targets[0][1], targets[1][0], targets[1][1])
|
||||
out = self.connector.\
|
||||
_get_target_portals_from_iscsiadm_output(sample_input)
|
||||
self.assertEqual(out, targets)
|
||||
|
||||
|
||||
class FibreChannelConnectorTestCase(ConnectorTestCase):
|
||||
def setUp(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user