summaryrefslogtreecommitdiffstats
path: root/src/utils/fs.py
diff options
context:
space:
mode:
authorOpenGnSys Support Team <soporte-og@soleta.eu>2024-07-25 10:03:55 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2024-07-29 14:22:48 +0200
commit2c10b4c92afc80441493ad9b239952b43d2b761e (patch)
treedcf0712cd8795e9a5ddaf1ac528edffee5d0905b /src/utils/fs.py
parent59fa3bb120a36c231579eab757b6e54ff62c51b7 (diff)
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.
Diffstat (limited to 'src/utils/fs.py')
-rw-r--r--src/utils/fs.py22
1 files changed, 17 insertions, 5 deletions
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):
"""