[PATCH 1/5] Split out common lvm parsing code.

Anne Mulhern amulhern at redhat.com
Mon Mar 31 12:40:54 UTC 2014





----- Original Message -----
> From: "David Lehman" <dlehman at redhat.com>
> To: anaconda-patches at lists.fedorahosted.org
> Sent: Friday, March 28, 2014 4:32:50 PM
> Subject: [PATCH 1/5] Split out common lvm parsing code.
> 
> ---
>  blivet/devicelibs/lvm.py | 50
>  ++++++++++++++++++++----------------------------
>  1 file changed, 21 insertions(+), 29 deletions(-)
> 
> diff --git a/blivet/devicelibs/lvm.py b/blivet/devicelibs/lvm.py
> index bc6d563..67e8fe2 100644
> --- a/blivet/devicelibs/lvm.py
> +++ b/blivet/devicelibs/lvm.py
> @@ -273,6 +273,22 @@ def pvmove(source, dest=None):
>      except LVMError as msg:
>          raise LVMError("pvmove failed for %s->%s: %s" % (source, dest, msg))
>  
> +def parse_lvm_vars(line):
> +    info = {}
> +    for var in line.split():
> +        (name, equals, value) = var.partition("=")
> +        if not equals:
> +            continue
> +
> +        if "," in value:
> +            val = value.strip().split(",")
> +        else:
> +            val = value.strip()
> +
> +        info[name] = val
> +
> +    return info
> +

Is this a candidate for pushing out all the way to utils or some devicelibs/utils.py?
I'm not sure about the significance of the comma for lvm, but I believe that the if
block above is equivalent to:

val = value.strip().split(",")

anyways.

>  def pvinfo(device):
>      """
>          If the PV was created with '--metadacopies 0', lvm will do some
> @@ -289,20 +305,10 @@ def pvinfo(device):
>              _getConfigArgs(read_only_locking=True) + \
>              [device]
>  
> -    rc = util.capture_output(["lvm"] + args)
> -    _vars = rc.split()
> -    info = {}
> -    for var in _vars:
> -        (name, equals, value) = var.partition("=")
> -        if not equals:
> -            continue
> -
> -        if "," in value:
> -            val = value.strip().split(",")
> -        else:
> -            val = value.strip()
> -
> -        info[name] = val
> +    buf = util.capture_output(["lvm"] + args)
> +    info = parse_lvm_vars(buf)
> +    if len(info.keys()) != 10:
> +        raise LVMError(_("pvinfo failed for %s" % device))
>  
>      return info
>  
> @@ -394,22 +400,8 @@ def vginfo(vg_name):
>              "-o",
>              "uuid,size,free,extent_size,extent_count,free_count,pv_count"]
>              + \
>              _getConfigArgs(read_only_locking=True) + [vg_name]
>  
> -    # TODO: make this a common code reused many functions
>      buf = util.capture_output(["lvm"] + args)
> -    fields = buf.split()
> -    info = {}
> -    for field in fields:
> -        (name, equals, value) = field.partition("=")
> -        if not equals:
> -            continue
> -
> -        if "," in value:
> -            val = value.strip().split(",")
> -        else:
> -            val = value.strip()
> -
> -        info[name] = val
> -
> +    info = parse_lvm_vars(buf)
>      if len(info.keys()) != 7:
>          raise LVMError(_("vginfo failed for %s" % vg_name))
>  
> --
> 1.9.0
> 
> _______________________________________________
> anaconda-patches mailing list
> anaconda-patches at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
> 

Just the one comment.

- mulhern


More information about the anaconda-patches mailing list