From b0b9d2ddd2f43bb754777b63560540d121adb3fe Mon Sep 17 00:00:00 2001 From: Mihaela Balutoiu Date: Fri, 30 Oct 2026 22:10:08 +0200 Subject: [PATCH] Fix `yum` package removal on RHEL 7 YUM 3 rejects the DNF-only `--noautoremove` option, which broke osmorphing on RHEL 7. Use `--setopt=clean_requirements_on_remove=0`, which works on both. Signed-off-by: Mihaela Balutoiu --- coriolis/osmorphing/redhat.py | 15 ++++++++++----- coriolis/tests/osmorphing/test_redhat.py | 10 +++++++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/coriolis/osmorphing/redhat.py b/coriolis/osmorphing/redhat.py index 35a0bacd..302c897e 100644 --- a/coriolis/osmorphing/redhat.py +++ b/coriolis/osmorphing/redhat.py @@ -224,11 +224,16 @@ def _yum_install(self, package_names): def _yum_uninstall(self, package_names): try: for package_name in package_names: - # NOTE: '--noautoremove' prevents yum/dnf from also removing - # generic system packages (tar, pciutils, fuse, libxslt, etc.) - # which it considers unused dependencies of the package being - # removed, but which must be kept on the migrated VM. - yum_cmd = 'yum remove %s -y --noautoremove' % package_name + # NOTE: 'clean_requirements_on_remove=0' prevents yum/dnf from + # also removing generic system packages (tar, pciutils, fuse, + # libxslt, etc.) which it considers unused dependencies of the + # package being removed, but which must be kept on the migrated + # VM. This is set through '--setopt' as '--noautoremove' is + # DNF-only and is rejected by YUM 3 (RHEL 7 and derivatives). + yum_cmd = ( + f'yum remove {package_name} -y ' + '--setopt=clean_requirements_on_remove=0' + ) self._exec_cmd_chroot(yum_cmd) except exception.CoriolisException as err: raise exception.FailedPackageUninstallationException( diff --git a/coriolis/tests/osmorphing/test_redhat.py b/coriolis/tests/osmorphing/test_redhat.py index e22a8bf6..c007d616 100644 --- a/coriolis/tests/osmorphing/test_redhat.py +++ b/coriolis/tests/osmorphing/test_redhat.py @@ -684,8 +684,12 @@ def test__yum_uninstall(self, mock_exec_cmd_chroot): mock_exec_cmd_chroot.assert_has_calls( [ - mock.call("yum remove package1 -y --noautoremove"), - mock.call("yum remove package2 -y --noautoremove"), + mock.call( + "yum remove package1 -y --setopt=clean_requirements_on_remove=0" + ), + mock.call( + "yum remove package2 -y --setopt=clean_requirements_on_remove=0" + ), ] ) @@ -694,7 +698,7 @@ def test__yum_uninstall_open_vm_tools(self, mock_exec_cmd_chroot): self.morphing_tools._yum_uninstall(['open-vm-tools']) mock_exec_cmd_chroot.assert_called_once_with( - "yum remove open-vm-tools -y --noautoremove" + "yum remove open-vm-tools -y --setopt=clean_requirements_on_remove=0" ) @mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot')