Add a parser for 'multipath -d' output.
We need to find out about multipath topology from /sbin/multipath, which
unfortunately needs some parsing - it's fairly easy, though.
---
storage/devicelibs/mpath.py | 47 +++++++++++++++++++++++++++++++++++++
tests/storage/devicelibs/mpath.py | 29 ++++++++++++++++++++++
2 files changed, 76 insertions(+), 0 deletions(-)
create mode 100644 tests/storage/devicelibs/mpath.py
diff --git a/storage/devicelibs/mpath.py b/storage/devicelibs/mpath.py
index 733437d..b59f00e 100644
--- a/storage/devicelibs/mpath.py
+++ b/storage/devicelibs/mpath.py
@@ -1,5 +1,52 @@
from ..udev import *
+def parseMultipathOutput(output):
+ # this function parses output from "multipath -d", so we can use its
+ # logic for our topology.
+ # The input looks like:
+ # create: mpathb (1ATA ST3120026AS 5M) undef ATA,ST3120026AS
+ # size=112G features='0' hwhandler='0' wp=undef
+ # `-+- policy='round-robin 0' prio=1 status=undef
+ # `- 2:0:0:0 sda 8:0 undef ready running
+ # create: mpatha (36006016092d21800703762872c60db11) undef DGC,RAID 5
+ # size=10G features='1 queue_if_no_path' hwhandler='1 emc' wp=undef
+ # `-+- policy='round-robin 0' prio=2 status=undef
+ # |- 6:0:0:0 sdb 8:16 undef ready running
+ # `- 7:0:0:0 sdc 8:32 undef ready running
+ #
+ # (In anaconda, the first one there won't be included because we blacklist
+ # "ATA" as a vendor.)
+ #
+ # It returns a structure like:
+ # [ {'mpatha':['sdb','sdc']}, ... ]
+ mpaths = {}
+
+ name = None
+ devices = []
+
+ lines = output.split('
')
+ for line in lines:
+ lexemes = line.split()
+ if not lexemes:
+ break
+ if lexemes[0] == 'create:':
+ if name and devices:
+ mpaths.append(mpath)
+ name = None
+ devices = []
+ name = lexemes[1]
+ elif lexemes[0].startswith('size='):
+ pass
+ elif lexemes[0] == '`-+-':
+ pass
+ elif lexemes[0] in ['|-','`-']:
+ devices.append(lexemes[2])
+
+ if name and devices:
+ mpaths[name] = devices
+
+ return mpaths
+
def identifyMultipaths(devices):
# this function does a couple of things
# 1) identifies multipath disks
diff --git a/tests/storage/devicelibs/mpath.py b/tests/storage/devicelibs/mpath.py
new file mode 100644
index 0000000..8210b0b
--- /dev/null
+++ b/tests/storage/devicelibs/mpath.py
@@ -0,0 +1,29 @@
+import baseclass
+import unittest
+import storage.devicelibs.mpath as mpath
+
+class MPathTestCase(baseclass.DevicelibsTestCase):
+ def testMPath(self):
+ ##
+ ## parseMultipathOutput
+ ##
+ output="""
+create: mpathb (1ATA ST3120026AS 5M) undef ATA,ST3120026AS
+size=112G features='0' hwhandler='0' wp=undef
+`-+- policy='round-robin 0' prio=1 status=undef
+ `- 2:0:0:0 sda 8:0 undef ready running
+create: mpatha (36006016092d21800703762872c60db11) undef DGC,RAID 5
+size=10G features='1 queue_if_no_path' hwhandler='1 emc' wp=undef
+`-+- policy='round-robin 0' prio=2 status=undef
+ |- 6:0:0:0 sdb 8:16 undef ready running
+ `- 7:0:0:0 sdc 8:32 undef ready running
+"""
+ topology = mpath.parseMultipathOutput(output)
+ expected = {'mpatha':['sdb','sdc'], 'mpathb':['sda']}
+ self.assertEqual(topology, expected)
+
+def suite():
+ return unittest.TestLoader().loadTestsFromTestCase(MPathT estCase)
+
+if __name__ == '__main__':
+ unittest.main()
--
1.6.5.2
_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
|