From de17bb6812f9127eaef4d8b4b357822b1367e9a3 Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Tue, 7 May 2024 11:58:05 +0200 Subject: utils:fs: add mkfs logs when return code is not 0 Report mkfs failure for every partition. This does not raise an exception as that would skip partprobe operations and the mkfs operations in the next potentially well formated partitions. --- src/utils/fs.py | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/utils/fs.py b/src/utils/fs.py index a4a9ae5..1fd13f1 100644 --- a/src/utils/fs.py +++ b/src/utils/fs.py @@ -170,9 +170,12 @@ def mkfs_ext4(partdev, label=None): else: cmd = shlex.split(f'mkfs.ext4 -F {partdev}') with open('/tmp/command.log', 'wb', 0) as logfile: - subprocess.run(cmd, - stdout=logfile, - stderr=STDOUT) + ret = subprocess.run(cmd, + stdout=logfile, + stderr=STDOUT) + + if ret.returncode != 0: + logging.error(f'mkfs.ext4 reports return code {ret.returncode} for {partdev}') def mkfs_ntfs(partdev, label=None): @@ -181,9 +184,12 @@ def mkfs_ntfs(partdev, label=None): else: cmd = shlex.split(f'mkfs.ntfs -f {partdev}') with open('/tmp/command.log', 'wb', 0) as logfile: - subprocess.run(cmd, - stdout=logfile, - stderr=STDOUT) + ret = subprocess.run(cmd, + stdout=logfile, + stderr=STDOUT) + + if ret.returncode != 0: + logging.error(f'mkfs.ntfs reports return code {ret.returncode} for {partdev}') def mkfs_fat32(partdev, label=None): @@ -192,9 +198,12 @@ def mkfs_fat32(partdev, label=None): else: cmd = shlex.split(f'mkfs.vfat -F32 {partdev}') with open('/tmp/command.log', 'wb', 0) as logfile: - subprocess.run(cmd, - stdout=logfile, - stderr=STDOUT) + ret = subprocess.run(cmd, + stdout=logfile, + stderr=STDOUT) + + if ret.returncode != 0: + logging.error(f'mkfs.vfat reports return code {ret.returncode} for {partdev}') def mkfs_swap(partdev, label=None): @@ -203,9 +212,12 @@ def mkfs_swap(partdev, label=None): else: cmd = shlex.split(f'mkswap -f {partdev}') with open('/tmp/command.log', 'wb', 0) as logfile: - subprocess.run(cmd, - stdout=logfile, - stderr=STDOUT) + ret = subprocess.run(cmd, + stdout=logfile, + stderr=STDOUT) + + if ret.returncode != 0: + logging.error(f'mkswap reports return code {ret.returncode} for {partdev}') def get_filesystem_type(partdev): -- cgit v1.2.3-18-g5258