From a327bf650b4bbfbb92152e502314f5f2806b9ec1 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 21 Apr 2020 18:42:58 -0700 Subject: [PATCH] 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 Reviewed-by: James Valleroy --- plinth/modules/storage/tests/test_storage.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/plinth/modules/storage/tests/test_storage.py b/plinth/modules/storage/tests/test_storage.py index c277ef762..df5fcfda7 100644 --- a/plinth/modules/storage/tests/test_storage.py +++ b/plinth/modules/storage/tests/test_storage.py @@ -81,6 +81,15 @@ class Disk(): subprocess.run(command, stdout=subprocess.DEVNULL, 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): """Undo the loopback device setup.""" subprocess.run(['losetup', '--detach', self.device]) @@ -99,6 +108,7 @@ class Disk(): def __exit__(self, *exc): """Exit the context, destroy the test disk.""" + self._unmount_file_systems() self._cleanup_loopback() self._remove_disk_file() @@ -221,7 +231,7 @@ class TestActions: def assert_btrfs_file_system_healthy(self, partition_number): """Perform a successful ext4 file system check.""" device = _get_partition_device(self.device, partition_number) - command = ['btrfs', 'check', device] + command = ['btrfs', 'check', '--force', device] subprocess.run(command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)