Commit df4c2628 authored by Iustin Pop's avatar Iustin Pop

Fix backend.GetVolumeList handling of LVM output

Sometimes ‘lvs’ can spit error messages on stdout, even when one wants
to parse the output:
...
Inconsistent metadata copies found - updating to use version 2776
...

So we need to validate the output to guard against such cases.

The patch converts the split on the separater to match against a regex
and extract the fields via groups. The original separator choice is a
bad one now :(

Reviewed-by: imsnah
parent 1df6506c
......@@ -258,11 +258,14 @@ def GetVolumeList(vg_name):
result.output)
return result.output
valid_line_re = re.compile("^ *([^|]+)\|([0-9.]+)\|([^|]{6})\|?$")
for line in result.stdout.splitlines():
line = line.strip().rstrip(sep)
name, size, attr = line.split(sep)
if len(attr) != 6:
attr = '------'
line = line.strip()
match = valid_line_re.match(line)
if not match:
logger.Error("Invalid line returned from lvs output: '%s'" % line)
continue
name, size, attr = match.groups()
inactive = attr[4] == '-'
online = attr[5] == 'o'
lvs[name] = (size, inactive, online)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment