FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Ubuntu Kernel Team

 
 
LinkBack Thread Tools
 
Old 01-15-2010, 08:23 PM
Peter Jones
 
Default 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 | 32 ++++++++++++++++++++++++++++++++
1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/storage/devicelibs/mpath.py b/storage/devicelibs/mpath.py
index 733437d..4d1b262 100644
--- a/storage/devicelibs/mpath.py
+++ b/storage/devicelibs/mpath.py
@@ -1,5 +1,37 @@
from ..udev import *

+def parseMultipathOutput(output):
+ # this function parses output from "multipath -d", so we can use its
+ # logic for our topology. It returns a structure like:
+ # [ {'mpathb':['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
--
1.6.5.2

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 01-20-2010, 04:04 PM
Chris Lumens
 
Default 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.

In IRC, you suggested adding a comment with sample output, which I think
is a great idea.

In general...

(1) I worry that we're setting ourselves up for future problems if the
output format changes. Any idea how stable it's going to be?

(2) This seems like the perfect sort of thing to have a test case for.

- Chris

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 01-20-2010, 08:38 PM
Peter Jones
 
Default 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
 
Old 01-20-2010, 08:51 PM
Chris Lumens
 
Default 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.

Looks good to me.

- Chris

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 

Thread Tools




All times are GMT. The time now is 06:10 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org