From 2c10b4c92afc80441493ad9b239952b43d2b761e Mon Sep 17 00:00:00 2001 From: OpenGnSys Support Team Date: Thu, 25 Jul 2024 10:03:55 +0200 Subject: utils: fs: error out if mkfs fails If formatting fails, log shows: mkfs.ntfs reports return code 1 for /dev/sda2 but ogclient reports success to the ogserver. Raise an exception so front-end gets an indication that formatting has failed. --- src/utils/fs.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/utils') diff --git a/src/utils/fs.py b/src/utils/fs.py index fc326ab..8f45ad5 100644 --- a/src/utils/fs.py +++ b/src/utils/fs.py @@ -165,10 +165,11 @@ def mkfs(fs, disk, partition, label=None): except ValueError as e: raise OgError(f'mkfs aborted: {e}') from e - fsdict[fs](partdev, label) + return fsdict[fs](partdev, label) def mkfs_ext4(partdev, label=None): + err = -1 if label: cmd = shlex.split(f'mkfs.ext4 -L {label} -F {partdev}') else: @@ -177,12 +178,15 @@ def mkfs_ext4(partdev, label=None): ret = subprocess.run(cmd, stdout=logfile, stderr=STDOUT) - + err = ret.returncode if ret.returncode != 0: logging.error(f'mkfs.ext4 reports return code {ret.returncode} for {partdev}') + return err + def mkfs_ntfs(partdev, label=None): + err = -1 if label: cmd = shlex.split(f'mkfs.ntfs -f -L {label} {partdev}') else: @@ -191,12 +195,15 @@ def mkfs_ntfs(partdev, label=None): ret = subprocess.run(cmd, stdout=logfile, stderr=STDOUT) - + err = ret.returncode if ret.returncode != 0: logging.error(f'mkfs.ntfs reports return code {ret.returncode} for {partdev}') + return err + def mkfs_fat32(partdev, label=None): + err = -1 if label: cmd = shlex.split(f'mkfs.vfat -n {label} -F32 {partdev}') else: @@ -205,12 +212,15 @@ def mkfs_fat32(partdev, label=None): ret = subprocess.run(cmd, stdout=logfile, stderr=STDOUT) - + err = ret.returncode if ret.returncode != 0: logging.error(f'mkfs.vfat reports return code {ret.returncode} for {partdev}') + return err + def mkfs_swap(partdev, label=None): + err = -1 if label: cmd = shlex.split(f'mkswap -f -L {label} {partdev}') else: @@ -219,10 +229,12 @@ def mkfs_swap(partdev, label=None): ret = subprocess.run(cmd, stdout=logfile, stderr=STDOUT) - + err = ret.returncode if ret.returncode != 0: logging.error(f'mkswap reports return code {ret.returncode} for {partdev}') + return err + def get_filesystem_type(partdev): """ -- cgit v1.2.3-18-g5258