convert: Use yum/apt/... for package removals

resolves: RHEL-71522
This commit is contained in:
Richard W.M. Jones 2025-02-11 15:29:15 +00:00
parent 7e0bcda907
commit d9760b8da3
2 changed files with 91 additions and 2 deletions

View File

@ -0,0 +1,86 @@
From 1d3017a30a2f831ee1461c1828c63c9a196805dd Mon Sep 17 00:00:00 2001
From: Cole Robinson <crobinso@redhat.com>
Date: Mon, 10 Feb 2025 10:53:00 -0500
Subject: [PATCH] convert: Use yum/apt/... for package removals, not rpm/dpkg
Current package removal implementation uses `rpm -e`, which will
fail if anything depends on the package we are trying to remove.
Like when `spausedd` is dependent on `open-vm-tools`.
Reuse the package uninstall logic from virt-customize, which
will handle this no problem.
Just print a warning when package removal goes sideways.
Fixes: https://issues.redhat.com/browse/RHEL-71522
Signed-off-by: Cole Robinson <crobinso@redhat.com>
(cherry picked from commit b3268a13beca4da218e7ffe4648a18420296103a)
---
convert/convert_linux.ml | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/convert/convert_linux.ml b/convert/convert_linux.ml
index 3d0e2b88..cbae5e3d 100644
--- a/convert/convert_linux.ml
+++ b/convert/convert_linux.ml
@@ -131,6 +131,23 @@ let convert (g : G.guestfs) source inspect i_firmware _ keep_serial_console _ =
(*----------------------------------------------------------------------*)
(* Conversion step. *)
+ let uninstall_packages pkgs =
+ if pkgs <> [] then (
+ let cmd =
+ try Guest_packages.uninstall_command pkgs inspect.i_package_management
+ with
+ | Guest_packages.Unknown_package_manager msg
+ | Guest_packages.Unimplemented_package_manager msg ->
+ error "%s" msg
+ in
+ (try ignore (g#sh cmd)
+ with G.Error msg ->
+ warning (f_"could not uninstall packages %s: %s (ignored)")
+ (String.concat " " pkgs) msg
+ )
+ )
+ in
+
let rec do_convert () =
augeas_grub_configuration ();
@@ -237,7 +254,7 @@ let convert (g : G.guestfs) source inspect i_firmware _ keep_serial_console _ =
else
None
) inspect.i_apps in
- Linux.remove g inspect.i_root xenmods;
+ uninstall_packages xenmods;
(* Undo related nastiness if kmod-xenpv was installed. *)
if xenmods <> [] then (
@@ -310,7 +327,7 @@ let convert (g : G.guestfs) source inspect i_firmware _ keep_serial_console _ =
fun { G.app2_name = name } -> name = package_name
) inspect.i_apps in
if has_guest_additions then
- Linux.remove g inspect.i_root [package_name];
+ uninstall_packages [package_name];
(* Guest Additions might have been installed from a tarball. The
* above code won't detect this case. Look for the uninstall tool
@@ -455,8 +472,7 @@ let convert (g : G.guestfs) source inspect i_firmware _ keep_serial_console _ =
)
);
- let remove = !remove in
- Linux.remove g inspect.i_root remove;
+ uninstall_packages !remove;
(* VMware Tools may have been installed from a tarball, so the
* above code won't remove it. Look for the uninstall tool and run
@@ -503,7 +519,7 @@ let convert (g : G.guestfs) source inspect i_firmware _ keep_serial_console _ =
let pkgs = List.map (fun { G.app2_name = name } -> name) pkgs in
if pkgs <> [] then (
- Linux.remove g inspect.i_root pkgs;
+ uninstall_packages pkgs;
(* Installing these guest utilities automatically unconfigures
* ttys in /etc/inittab if the system uses it. We need to put

View File

@ -8,7 +8,7 @@
Name: virt-v2v
Epoch: 1
Version: 2.7.1
Release: 3%{?dist}
Release: 4%{?dist}
Summary: Convert a virtual machine to run on KVM
License: GPL-2.0-or-later AND LGPL-2.0-or-later
@ -58,6 +58,7 @@ Patch0027: 0027-build-Define-MLOBJECT-OCaml-object-file-as-either-cm.patch
Patch0028: 0028-in-place-Add-new-O-option-to-write-inspector-XML.patch
Patch0029: 0029-convert-Mention-operating-system-in-error-message.patch
Patch0030: 0030-Update-common-submodule.patch
Patch0031: 0031-convert-Use-yum-apt-.-for-package-removals-not-rpm-d.patch
%if !0%{?rhel}
# libguestfs hasn't been built on i686 for a while since there is no
@ -359,7 +360,7 @@ make -C tests TESTS=test-fedora-luks-on-lvm-conversion.sh check
%changelog
* Sun Feb 09 2025 Richard W.M. Jones <rjones@redhat.com> - 1:2.7.1-3
* Tue Feb 11 2025 Richard W.M. Jones <rjones@redhat.com> - 1:2.7.1-4
- Rebase to upstream development version 2.7.1
resolves: RHEL-56813
- Replace Jansson with json-c
@ -370,6 +371,8 @@ make -C tests TESTS=test-fedora-luks-on-lvm-conversion.sh check
resolves: RHEL-58032
- mldrivers/linux_bootloaders.ml: Don't overwrite EFI grub2 wrapper
resolves: RHEL-77989
- convert: Use yum/apt/... for package removals
resolves: RHEL-71522
* Thu Sep 05 2024 Richard W.M. Jones <rjones@redhat.com> - 1:2.5.9-1
- Rebase to upstream development version 2.5.9