devices/lvm2.lv: separate stdout and stderr

In all invocations of `subprocess.run` stderr and stdout were both
combined in a shared pipe, but lvm sometimes spits out notices and
informational messages on stderr and thus potentially interfering
with the data we are interested in on stdout. Separate the two.
This commit is contained in:
Christian Kellner 2022-03-01 23:34:19 +01:00 committed by Tomáš Hozza
parent 5a5da44c06
commit 81c9444cd5

View file

@ -67,12 +67,12 @@ class LVService(devices.DeviceService):
]
res = subprocess.run(cmd,
check=False,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE,
encoding="UTF-8")
if res.returncode != 0:
data = res.stdout.strip()
data = res.stderr.strip()
msg = f"Failed to set LV device ({fullname}) status: {data}"
raise RuntimeError(msg)
@ -90,7 +90,7 @@ class LVService(devices.DeviceService):
res = subprocess.run(cmd,
check=False,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
stderr=subprocess.PIPE,
encoding="UTF-8")
if res.returncode == 5:
@ -101,7 +101,7 @@ class LVService(devices.DeviceService):
continue
if res.returncode != 0:
json.dump({"error": res.stdout.strip()}, sys.stdout)
json.dump({"error": res.stderr.strip()}, sys.stdout)
return 1
vg_name = res.stdout.strip()
@ -125,11 +125,11 @@ class LVService(devices.DeviceService):
res = subprocess.run(cmd,
check=False,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
stderr=subprocess.PIPE,
encoding="UTF-8")
if res.returncode != 0:
raise RuntimeError(res.stdout.strip())
raise RuntimeError(res.stderr.strip())
data = res.stdout.strip()
devnum = list(map(int, data.split(";")))