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.
master
Alejandro Sirgo Rica 2024-05-07 11:58:05 +02:00
parent 9ffe1c81bf
commit de17bb6812
1 changed files with 24 additions and 12 deletions

View File

@ -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):