[blivet:master 6/8] Add a method to extract information about an mdraid array

Brian C. Lane bcl at redhat.com
Tue Jul 15 22:33:41 UTC 2014


On Tue, Jul 15, 2014 at 05:35:05PM -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 | 30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
> 
> diff --git a/blivet/devicelibs/mdraid.py b/blivet/devicelibs/mdraid.py
> index af04aa2..a2745b6 100644
> --- a/blivet/devicelibs/mdraid.py
> +++ b/blivet/devicelibs/mdraid.py
> @@ -21,6 +21,7 @@
>  #
>  
>  import os
> +import re
>  import uuid
>  
>  from .. import util
> @@ -269,6 +270,35 @@ 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.
> +

It should document that device is a device path

> +       :rtype: a dict of strings
> +       :returns: a dict containing labels and values extracted from output
> +    """
> +    lines = util.capture_output(["mdadm", "--detail", device]).split("\n")

It would be a good idea to catch OSError here, mdadm may not be
installed.

> +    info = {}
> +    for (name, equals, value) in (line.strip().partition(":") for line in lines):
> +        if equals and value.strip():
> +            name = name.strip().upper()
> +            value = value.strip()
> +
> +            info[name] = value
> +
> +    # extract the UUID proper
> +    the_uuid = re.match(r"(([a-f0-9]){8}:){3}([a-f0-9]){8}", info['UUID'])
> +
> +    # canonicalize the extracted UUID
> +    info['UUID'] = canonicalizeUUID(the_uuid.group())

If the device isn't an md device it won't have UUID set so we should
check for that.

-- 
Brian C. Lane | Anaconda Team | IRC: bcl #anaconda | Port Orchard, WA (PST8PDT)


More information about the anaconda-patches mailing list