Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions coriolis/osmorphing/redhat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 7 additions & 3 deletions coriolis/tests/osmorphing/test_redhat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
),
]
)

Expand All @@ -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')
Expand Down
Loading