Преглед изворни кода

Add `--noautoremove` to `yum` package removal

Removing `open-vm-tools` during osmorphing on RHEL-like distributions
also removed everything `yum/dnf` considered an unused dependency of it,
including generic system packages that must stay on the migrated VM.
Pass `--noautoremove` so only the requested package is removed.

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
Mihaela Balutoiu пре 3 дана
родитељ
комит
0be68d0adb
2 измењених фајлова са 17 додато и 2 уклоњено
  1. 5 1
      coriolis/osmorphing/redhat.py
  2. 12 1
      coriolis/tests/osmorphing/test_redhat.py

+ 5 - 1
coriolis/osmorphing/redhat.py

@@ -188,7 +188,11 @@ class BaseRedHatMorphingTools(base.BaseLinuxOSMorphingTools):
     def _yum_uninstall(self, package_names):
     def _yum_uninstall(self, package_names):
         try:
         try:
             for package_name in package_names:
             for package_name in package_names:
-                yum_cmd = 'yum remove %s -y' % package_name
+                # 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
                 self._exec_cmd_chroot(yum_cmd)
                 self._exec_cmd_chroot(yum_cmd)
         except exception.CoriolisException as err:
         except exception.CoriolisException as err:
             raise exception.FailedPackageUninstallationException(
             raise exception.FailedPackageUninstallationException(

+ 12 - 1
coriolis/tests/osmorphing/test_redhat.py

@@ -626,7 +626,18 @@ class BaseRedHatMorphingToolsTestCase(test_base.CoriolisBaseTestCase):
         self.morphing_tools._yum_uninstall(self.package_names)
         self.morphing_tools._yum_uninstall(self.package_names)
 
 
         mock_exec_cmd_chroot.assert_has_calls(
         mock_exec_cmd_chroot.assert_has_calls(
-            [mock.call("yum remove package1 -y"), mock.call("yum remove package2 -y")]
+            [
+                mock.call("yum remove package1 -y --noautoremove"),
+                mock.call("yum remove package2 -y --noautoremove"),
+            ]
+        )
+
+    @mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot')
+    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"
         )
         )
 
 
     @mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot')
     @mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot')