Handle lsblk output bytes in json.loads() (#2741)
This commit is contained in:
parent
481b570dae
commit
7437668f1e
|
|
@ -1435,7 +1435,7 @@ def _fetch_lsblk_info(
|
||||||
cmd.append(str(dev_path))
|
cmd.append(str(dev_path))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = SysCommand(cmd).decode()
|
worker = SysCommand(cmd)
|
||||||
except SysCallError as err:
|
except SysCallError as err:
|
||||||
# Get the output minus the message/info from lsblk if it returns a non-zero exit code.
|
# Get the output minus the message/info from lsblk if it returns a non-zero exit code.
|
||||||
if err.worker:
|
if err.worker:
|
||||||
|
|
@ -1448,12 +1448,12 @@ def _fetch_lsblk_info(
|
||||||
raise err
|
raise err
|
||||||
|
|
||||||
try:
|
try:
|
||||||
block_devices = json.loads(result)
|
data = json.loads(worker.output(remove_cr=False))
|
||||||
except json.decoder.JSONDecodeError as err:
|
except json.decoder.JSONDecodeError as err:
|
||||||
error(f"Could not decode lsblk JSON: {result}")
|
error(f"Could not decode lsblk JSON:\n{worker.output().decode().rstrip()}")
|
||||||
raise err
|
raise err
|
||||||
|
|
||||||
blockdevices = block_devices['blockdevices']
|
blockdevices = data['blockdevices']
|
||||||
return [LsblkInfo.from_json(device) for device in blockdevices]
|
return [LsblkInfo.from_json(device) for device in blockdevices]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -442,11 +442,14 @@ class SysCommand:
|
||||||
return val.strip()
|
return val.strip()
|
||||||
return val
|
return val
|
||||||
|
|
||||||
def output(self) -> bytes:
|
def output(self, remove_cr: bool = True) -> bytes:
|
||||||
if not self.session:
|
if not self.session:
|
||||||
raise ValueError('No session available')
|
raise ValueError('No session available')
|
||||||
|
|
||||||
return self.session._trace_log.replace(b'\r\n', b'\n')
|
if remove_cr:
|
||||||
|
return self.session._trace_log.replace(b'\r\n', b'\n')
|
||||||
|
|
||||||
|
return self.session._trace_log
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def exit_code(self) -> Optional[int]:
|
def exit_code(self) -> Optional[int]:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue