Change exit status indications to exit codes (#1685)
This commit is contained in:
parent
79eb6bba62
commit
f6113107d6
|
|
@ -233,7 +233,7 @@ def get_blockdevice_info(device_path, exclude_iso_dev :bool = True) -> Dict[str,
|
||||||
information = blkid(f'blkid -p -o export {device_path}')
|
information = blkid(f'blkid -p -o export {device_path}')
|
||||||
return enrich_blockdevice_information(information)
|
return enrich_blockdevice_information(information)
|
||||||
except SysCallError as ex:
|
except SysCallError as ex:
|
||||||
if ex.exit_code in (512, 2):
|
if ex.exit_code == 2:
|
||||||
# Assume that it's a loop device, and try to get info on it
|
# Assume that it's a loop device, and try to get info on it
|
||||||
try:
|
try:
|
||||||
resolved_device_name = device_path.readlink().name
|
resolved_device_name = device_path.readlink().name
|
||||||
|
|
|
||||||
|
|
@ -186,8 +186,7 @@ class Partition:
|
||||||
try:
|
try:
|
||||||
output = SysCommand(f"lsblk --json -b -o+LOG-SEC,SIZE,PTTYPE,PARTUUID,UUID,FSTYPE {self.device_path}").decode('UTF-8')
|
output = SysCommand(f"lsblk --json -b -o+LOG-SEC,SIZE,PTTYPE,PARTUUID,UUID,FSTYPE {self.device_path}").decode('UTF-8')
|
||||||
except SysCallError as error:
|
except SysCallError as error:
|
||||||
# It appears as if lsblk can return exit codes like 8192 to indicate something.
|
# Get the output minus the message/info from lsblk if it returns a non-zero exit code.
|
||||||
# But it does return output in stderr so we'll try to catch it minus the message/info.
|
|
||||||
output = error.worker.decode('UTF-8')
|
output = error.worker.decode('UTF-8')
|
||||||
if '{' in output:
|
if '{' in output:
|
||||||
output = output[output.find('{'):]
|
output = output[output.find('{'):]
|
||||||
|
|
@ -632,14 +631,7 @@ class Partition:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def unmount(self) -> bool:
|
def unmount(self) -> bool:
|
||||||
worker = SysCommand(f"/usr/bin/umount {self._path}")
|
SysCommand(f"/usr/bin/umount {self._path}")
|
||||||
exit_code = worker.exit_code
|
|
||||||
|
|
||||||
# Without to much research, it seams that low error codes are errors.
|
|
||||||
# And above 8k is indicators such as "/dev/x not mounted.".
|
|
||||||
# So anything in between 0 and 8k are errors (?).
|
|
||||||
if exit_code and 0 < exit_code < 8000:
|
|
||||||
raise SysCallError(f"Could not unmount {self._path} properly: {worker}", exit_code=exit_code)
|
|
||||||
|
|
||||||
# Update the partition info since the mount info has changed after this call.
|
# Update the partition info since the mount info has changed after this call.
|
||||||
self._partition_info = self._fetch_information()
|
self._partition_info = self._fetch_information()
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ class luks2:
|
||||||
if cmd_handle.exit_code != 0:
|
if cmd_handle.exit_code != 0:
|
||||||
raise DiskError(f'Could not encrypt volume "{partition.path}": {b"".join(cmd_handle)}')
|
raise DiskError(f'Could not encrypt volume "{partition.path}": {b"".join(cmd_handle)}')
|
||||||
except SysCallError as err:
|
except SysCallError as err:
|
||||||
if err.exit_code == 256:
|
if err.exit_code == 1:
|
||||||
log(f'{partition} is being used, trying to unmount and crypt-close the device and running one more attempt at encrypting the device.', level=logging.DEBUG)
|
log(f'{partition} is being used, trying to unmount and crypt-close the device and running one more attempt at encrypting the device.', level=logging.DEBUG)
|
||||||
# Partition was in use, unmount it and try again
|
# Partition was in use, unmount it and try again
|
||||||
partition.unmount()
|
partition.unmount()
|
||||||
|
|
|
||||||
|
|
@ -97,8 +97,6 @@ class Boot:
|
||||||
shutdown = SysCommand(f'systemd-run --machine={self.container_name} --pty shutdown now')
|
shutdown = SysCommand(f'systemd-run --machine={self.container_name} --pty shutdown now')
|
||||||
except SysCallError as error:
|
except SysCallError as error:
|
||||||
shutdown_exit_code = error.exit_code
|
shutdown_exit_code = error.exit_code
|
||||||
# if error.exit_code == 256:
|
|
||||||
# pass
|
|
||||||
|
|
||||||
while self.session.is_alive():
|
while self.session.is_alive():
|
||||||
time.sleep(0.25)
|
time.sleep(0.25)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue