From 4b57c9329766ee294dd3ff4d38ed00e9ffdc5d43 Mon Sep 17 00:00:00 2001 From: Mihaela Balutoiu Date: Wed, 27 May 2026 20:39:27 +0300 Subject: [PATCH 1/2] Replace `dismount_os` sorting logic with `umount -R` Signed-off-by: Mihaela Balutoiu --- coriolis/osmorphing/osmount/base.py | 18 +----------------- coriolis/tests/osmorphing/osmount/test_base.py | 15 +-------------- 2 files changed, 2 insertions(+), 31 deletions(-) diff --git a/coriolis/osmorphing/osmount/base.py b/coriolis/osmorphing/osmount/base.py index b7a1a585..e5c00a66 100644 --- a/coriolis/osmorphing/osmount/base.py +++ b/coriolis/osmorphing/osmount/base.py @@ -635,24 +635,8 @@ def mount_os(self): def dismount_os(self, root_dir): self._exec_cmd('sudo fuser --kill --mount %s || true' % root_dir) - mounted_fs = self._get_mount_destinations() - # Sort all mounted filesystems by length. This will ensure that - # the first in the list is a subfolder of the next in the list, - # and we unmount them in the proper order - mounted_fs = list(reversed(sorted(mounted_fs, key=len))) - for d in mounted_fs: - # umount these two at the very end - if d.endswith('/dev') or d.rstrip('/') == root_dir.rstrip('/'): - continue - if d.startswith(root_dir): - # mounted filesystem is a subfolder of our root_dir - self._exec_cmd('sudo umount %s' % d) - - dev_fs = "%s/%s" % (root_dir.rstrip('/'), "dev") - self._exec_cmd('mountpoint -q %s && sudo umount %s' % - (dev_fs, dev_fs)) self._exec_cmd( - 'mountpoint -q %s && sudo umount %s' % (root_dir, root_dir)) + 'mountpoint -q %s && sudo umount -R %s' % (root_dir, root_dir)) def set_proxy(self, proxy_settings): url = proxy_settings.get('url') diff --git a/coriolis/tests/osmorphing/osmount/test_base.py b/coriolis/tests/osmorphing/osmount/test_base.py index e4068439..9dcdca8e 100644 --- a/coriolis/tests/osmorphing/osmount/test_base.py +++ b/coriolis/tests/osmorphing/osmount/test_base.py @@ -982,26 +982,13 @@ def test_mount_os_run_xfs(self, mock_check_mount_fstab_partitions, @mock.patch.object(base.BaseSSHOSMountTools, '_exec_cmd') def test_dismount_os(self, mock_exec_cmd): root_dir = "/mnt/root_dir" - mock_exec_cmd.side_effect = [ - None, - ("/dev/sda1 /mnt/root_dir/sub_dir type ext4\n" - "/dev/sda2 /mnt/root_dir/dev type ext4\n" - "/dev/sda3 /mnt/root_dir type ext4\n"), - None, - None, - None, - ] self.base_os_mount_tools.dismount_os(root_dir) mock_exec_cmd.assert_has_calls([ mock.call("sudo fuser --kill --mount /mnt/root_dir || true"), - mock.call("cat /proc/mounts"), - mock.call("sudo umount /mnt/root_dir/sub_dir"), - mock.call("mountpoint -q /mnt/root_dir/dev" - " && sudo umount /mnt/root_dir/dev"), mock.call( - "mountpoint -q /mnt/root_dir && sudo umount /mnt/root_dir"), + "mountpoint -q /mnt/root_dir && sudo umount -R /mnt/root_dir"), ]) @mock.patch.object(base.utils, 'get_url_with_credentials') From f9076ee61c434de650159ca54b3060491d5af4a7 Mon Sep 17 00:00:00 2001 From: Mihaela Balutoiu Date: Wed, 27 May 2026 20:39:56 +0300 Subject: [PATCH 2/2] Remove redundant boot partition mounts from `_get_grub2_cfg_location` Signed-off-by: Mihaela Balutoiu --- coriolis/osmorphing/redhat.py | 2 -- coriolis/osmorphing/suse.py | 2 -- coriolis/tests/osmorphing/test_redhat.py | 24 +++----------------- coriolis/tests/osmorphing/test_suse.py | 28 ++++-------------------- 4 files changed, 7 insertions(+), 49 deletions(-) diff --git a/coriolis/osmorphing/redhat.py b/coriolis/osmorphing/redhat.py index b7ac1449..e4db56fc 100644 --- a/coriolis/osmorphing/redhat.py +++ b/coriolis/osmorphing/redhat.py @@ -76,8 +76,6 @@ def _get_grub2_cfg_location(self): refuses to overwrite the wrapper and requires output to /boot/grub2/grub.cfg. Prefer the BIOS path when it exists. """ - self._exec_cmd_chroot("mount /boot || true") - self._exec_cmd_chroot("mount /boot/efi || true") uefi_cfg = os.path.join(self.UEFI_GRUB_LOCATION, "grub.cfg") bios_cfg = os.path.join(self.BIOS_GRUB_LOCATION, "grub.cfg") # Prefer /boot/grub2/grub.cfg - on RHEL 9.4+ UEFI, the EFI file is a diff --git a/coriolis/osmorphing/suse.py b/coriolis/osmorphing/suse.py index 6c4fd8a6..d7f5dd23 100644 --- a/coriolis/osmorphing/suse.py +++ b/coriolis/osmorphing/suse.py @@ -82,8 +82,6 @@ def get_update_grub2_command(self): return "grub2-mkconfig -o %s" % location def _get_grub2_cfg_location(self): - self._exec_cmd_chroot("mount /boot || true") - self._exec_cmd_chroot("mount /boot/efi || true") uefi_cfg = os.path.join(self.UEFI_GRUB_LOCATION, "grub.cfg") bios_cfg = os.path.join(self.BIOS_GRUB_LOCATION, "grub.cfg") if self._test_path_chroot(uefi_cfg): diff --git a/coriolis/tests/osmorphing/test_redhat.py b/coriolis/tests/osmorphing/test_redhat.py index f3c1e459..d2c005c5 100644 --- a/coriolis/tests/osmorphing/test_redhat.py +++ b/coriolis/tests/osmorphing/test_redhat.py @@ -68,44 +68,30 @@ def test_get_update_grub2_command(self, mock_get_grub2_cfg_location): 'grub2-mkconfig -o %s' % mock_get_grub2_cfg_location.return_value ) - @mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot') @mock.patch.object(base.BaseLinuxOSMorphingTools, '_test_path_chroot') - def test__get_grub2_cfg_location_bios(self, mock_test_path_chroot, - mock_exec_cmd_chroot): + def test__get_grub2_cfg_location_bios(self, mock_test_path_chroot): mock_test_path_chroot.return_value = True result = self.morphing_tools._get_grub2_cfg_location() self.assertEqual(result, '/boot/grub2/grub.cfg') - mock_exec_cmd_chroot.assert_has_calls([ - mock.call("mount /boot || true"), - mock.call("mount /boot/efi || true") - ]) mock_test_path_chroot.assert_called_once_with( '/boot/grub2/grub.cfg') - @mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot') @mock.patch.object(base.BaseLinuxOSMorphingTools, '_test_path_chroot') - def test__get_grub2_cfg_location_uefi(self, mock_test_path_chroot, - mock_exec_cmd_chroot): + def test__get_grub2_cfg_location_uefi(self, mock_test_path_chroot): mock_test_path_chroot.side_effect = [False, True] result = self.morphing_tools._get_grub2_cfg_location() self.assertEqual(result, '/boot/efi/EFI/redhat/grub.cfg') - mock_exec_cmd_chroot.assert_has_calls([ - mock.call("mount /boot || true"), - mock.call("mount /boot/efi || true") - ]) mock_test_path_chroot.assert_has_calls([ mock.call('/boot/grub2/grub.cfg'), mock.call('/boot/efi/EFI/redhat/grub.cfg') ]) - @mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot') @mock.patch.object(base.BaseLinuxOSMorphingTools, '_test_path_chroot') - def test__get_grub2_cfg_location_unknown(self, mock_test_path_chroot, - mock_exec_cmd_chroot): + def test__get_grub2_cfg_location_unknown(self, mock_test_path_chroot): mock_test_path_chroot.return_value = False self.assertRaisesRegex( @@ -114,10 +100,6 @@ def test__get_grub2_cfg_location_unknown(self, mock_test_path_chroot, self.morphing_tools._get_grub2_cfg_location ) - mock_exec_cmd_chroot.assert_has_calls([ - mock.call("mount /boot || true"), - mock.call("mount /boot/efi || true") - ]) mock_test_path_chroot.assert_has_calls([ mock.call('/boot/grub2/grub.cfg'), mock.call('/boot/efi/EFI/redhat/grub.cfg') diff --git a/coriolis/tests/osmorphing/test_suse.py b/coriolis/tests/osmorphing/test_suse.py index fd526cda..3e3c9358 100644 --- a/coriolis/tests/osmorphing/test_suse.py +++ b/coriolis/tests/osmorphing/test_suse.py @@ -117,43 +117,27 @@ def test_get_update_grub2_command(self, mock_get_grub2_cfg_location): "grub2-mkconfig -o %s" % mock_get_grub2_cfg_location.return_value ) - @mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot') @mock.patch.object(base.BaseLinuxOSMorphingTools, '_test_path_chroot') - def test__get_grub2_cfg_location_uefi(self, mock_test_path_chroot, - mock_exec_cmd_chroot): + def test__get_grub2_cfg_location_uefi(self, mock_test_path_chroot): mock_test_path_chroot.return_value = True result = self.morphing_tools._get_grub2_cfg_location() self.assertEqual(result, '/boot/efi/EFI/suse/grub.cfg') - mock_exec_cmd_chroot.assert_has_calls([ - mock.call("mount /boot || true"), - mock.call("mount /boot/efi || true") - ]) mock_test_path_chroot.assert_called_once_with( '/boot/efi/EFI/suse/grub.cfg') - @mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot') @mock.patch.object(base.BaseLinuxOSMorphingTools, '_test_path_chroot') - def test__get_grub2_cfg_location_bios(self, mock_test_path_chroot, - mock_exec_cmd_chroot): + def test__get_grub2_cfg_location_bios(self, mock_test_path_chroot): mock_test_path_chroot.side_effect = [False, True] result = self.morphing_tools._get_grub2_cfg_location() - mock_exec_cmd_chroot.assert_has_calls([ - mock.call("mount /boot || true"), - mock.call("mount /boot/efi || true") - ]) - mock_test_path_chroot.assert_called_with( - '/boot/grub2/grub.cfg') - + mock_test_path_chroot.assert_called_with('/boot/grub2/grub.cfg') self.assertEqual(result, '/boot/grub2/grub.cfg') - @mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot') @mock.patch.object(base.BaseLinuxOSMorphingTools, '_test_path_chroot') - def test__get_grub2_cfg_location_not_found(self, mock_test_path_chroot, - mock_exec_cmd_chroot): + def test__get_grub2_cfg_location_not_found(self, mock_test_path_chroot): mock_test_path_chroot.return_value = False self.assertRaisesRegex( @@ -161,10 +145,6 @@ def test__get_grub2_cfg_location_not_found(self, mock_test_path_chroot, "could not determine grub location. boot partition not mounted?", self.morphing_tools._get_grub2_cfg_location ) - mock_exec_cmd_chroot.assert_has_calls([ - mock.call("mount /boot || true"), - mock.call("mount /boot/efi || true") - ]) mock_test_path_chroot.assert_has_calls([ mock.call('/boot/efi/EFI/suse/grub.cfg'), mock.call('/boot/grub2/grub.cfg')