[blivet:master 11/14] Add a method to extract information about an mdraid array
Anne Mulhern
amulhern at redhat.com
Fri Jul 18 13:34:32 UTC 2014
----- Original Message -----
> From: "Vratislav Podzimek" <vpodzime at redhat.com>
> To: "anaconda patch review" <anaconda-patches at lists.fedorahosted.org>
> Sent: Thursday, July 17, 2014 10:27:52 AM
> Subject: Re: [blivet:master 11/14] Add a method to extract information about an mdraid array
>
> On Wed, 2014-07-16 at 12:56 -0400, mulhern wrote:
> > mdadm --detail can give useful information about the number of spare
> > devices
> > and other things that mdadm --examine can not. According to the man page
> > --examine applies to devices which are components of an array, while
> > --detail
> > applies to a whole array which is currently active.
> >
> > Signed-off-by: mulhern <amulhern at redhat.com>
> > ---
> > blivet/devicelibs/mdraid.py | 33 +++++++++++++++++++++++++++++++++
> > 1 file changed, 33 insertions(+)
> >
> > diff --git a/blivet/devicelibs/mdraid.py b/blivet/devicelibs/mdraid.py
> > index 2f0ac86..83f87cf 100644
> > --- a/blivet/devicelibs/mdraid.py
> > +++ b/blivet/devicelibs/mdraid.py
> > @@ -21,6 +21,7 @@
> > #
> >
> > import os
> > +import re
> > import uuid
> >
> > from .. import util
> > @@ -286,6 +287,38 @@ def mdexamine(device):
> >
> > return info
> >
> > +def mddetail(device):
> > + """Run mdadm --detail in order to read information about an array.
> > +
> > + Note: The --export flag is not used. According to the man pages
> > + the export flag just formats the output as key=value pairs for
> > + easy import, but in the case of --detail it also omits the majority
> > + of the information, including information of real use like the
> > + number of spares in the array.
> > +
> > + :param str device: path of the array device
> > + :rtype: a dict of strings
> > + :returns: a dict containing labels and values extracted from output
> > + """
> > + lines = mdadm(["--detail", device], capture=True).split("\n")
> > + info = {}
> > + for (name, colon, value) in (line.strip().partition(":") for line in
> > lines):
> > + value = value.strip()
> > + name = name.strip().upper()
> > + if colon and value and name:
> > + info[name] = value
> > +
> > + for k, v in ((k,info[k]) for k in ('UUID',) if k in info):
> I know this is a copy-paste from a different place, but by removing the
> second thing from the tuple it became quite weird, overly complex and
> cryptic.
>
> --
> Vratislav Podzimek
>
> Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic
>
> _______________________________________________
> anaconda-patches mailing list
> anaconda-patches at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
>
OK. That action is factored into a separate method, and used in both
mdexamine and mddetail.
The method looks like this:
def process_UUIDS(info, UUID_keys):
""" Extract and convert expected UUIDs to canonical form.
Reassign canonicalized UUIDs to corresponding keys.
:param dict info: a dictionary of key/value pairs
:param tuple UUID_keys: a list of keys known to be UUIDs
"""
for k, v in ((k, info[k]) for k in UUID_keys if k in info):
try:
# extract the UUID proper
the_uuid = re.match(r"(([a-f0-9]){8}:){3}([a-f0-9]){8}", v)
info[k] = canonicalize_UUID(the_uuid.group())
except ValueError as e:
# the unlikely event that mdadm's UUIDs cease to be proper UUIDs
log.warning('uuid value %s could not be canonicalized: %s', v, e)
info[k] = v # record the value, since mdadm provided something
- mulhern
More information about the anaconda-patches
mailing list