mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
storage: Fix tests by wrestling with auto-mounting of disks
- Also properly cleanup mounted file systems. - When a file system is created, it is automatically mounted by udiskie (or FreedomBox itself). This leads loop back setups not getting cleaned and btrfs check failing to check a mounted disk. Force check in case of btrfs and umount ignoring errors before cleanup. Closes: #1839. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
41498ba9f6
commit
a327bf650b
@ -81,6 +81,15 @@ class Disk():
|
|||||||
subprocess.run(command, stdout=subprocess.DEVNULL,
|
subprocess.run(command, stdout=subprocess.DEVNULL,
|
||||||
stderr=subprocess.DEVNULL, check=True)
|
stderr=subprocess.DEVNULL, check=True)
|
||||||
|
|
||||||
|
def _unmount_file_systems(self):
|
||||||
|
"""Unmount al partitions if it is mounted by external party."""
|
||||||
|
if not self.file_system_info:
|
||||||
|
return
|
||||||
|
|
||||||
|
for partition, _ in self.file_system_info:
|
||||||
|
device = _get_partition_device(self.device, partition)
|
||||||
|
subprocess.run(['umount', device], check=False)
|
||||||
|
|
||||||
def _cleanup_loopback(self):
|
def _cleanup_loopback(self):
|
||||||
"""Undo the loopback device setup."""
|
"""Undo the loopback device setup."""
|
||||||
subprocess.run(['losetup', '--detach', self.device])
|
subprocess.run(['losetup', '--detach', self.device])
|
||||||
@ -99,6 +108,7 @@ class Disk():
|
|||||||
|
|
||||||
def __exit__(self, *exc):
|
def __exit__(self, *exc):
|
||||||
"""Exit the context, destroy the test disk."""
|
"""Exit the context, destroy the test disk."""
|
||||||
|
self._unmount_file_systems()
|
||||||
self._cleanup_loopback()
|
self._cleanup_loopback()
|
||||||
self._remove_disk_file()
|
self._remove_disk_file()
|
||||||
|
|
||||||
@ -221,7 +231,7 @@ class TestActions:
|
|||||||
def assert_btrfs_file_system_healthy(self, partition_number):
|
def assert_btrfs_file_system_healthy(self, partition_number):
|
||||||
"""Perform a successful ext4 file system check."""
|
"""Perform a successful ext4 file system check."""
|
||||||
device = _get_partition_device(self.device, partition_number)
|
device = _get_partition_device(self.device, partition_number)
|
||||||
command = ['btrfs', 'check', device]
|
command = ['btrfs', 'check', '--force', device]
|
||||||
subprocess.run(command, stdout=subprocess.DEVNULL,
|
subprocess.run(command, stdout=subprocess.DEVNULL,
|
||||||
stderr=subprocess.DEVNULL, check=True)
|
stderr=subprocess.DEVNULL, check=True)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user