[PATCH 0/2] convert: Use yum/apt/... for package removals
https://issues.redhat.com/browse/RHEL-71522 Switch package removal from rpm/dep to yum/dnf/etc, to handle the case when other packages depend on ex. open-vm-tools Changes since RFC: + use cached `inspect` data -> fixes test suite + make failure non-fatal + ignore empty package list This may still break some really old cases. Notable `unconfigure_xen` has a comment referencing RHEL 3, which lacks yum AFAIK. Which would cause Guest_packages.uninstall_command to error. Maybe we don't care about RHEL-3? Or turn the error into a warning and be done with it? Cole Robinson (2): convert: Use yum/apt/... for package removals, not rpm/dpkg convert: make package removal failure non-fatal convert/convert_linux.ml | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) -- 2.48.1
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. Fixes: https://issues.redhat.com/browse/RHEL-71522 Signed-off-by: Cole Robinson <crobinso@redhat.com> --- convert/convert_linux.ml | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/convert/convert_linux.ml b/convert/convert_linux.ml index 3d0e2b88..08a4a9de 100644 --- a/convert/convert_linux.ml +++ b/convert/convert_linux.ml @@ -131,6 +131,18 @@ 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 + ignore (g#sh cmd); + ) + in + let rec do_convert () = augeas_grub_configuration (); @@ -237,7 +249,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 +322,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 +467,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 +514,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 -- 2.48.1
Just print a warning when package removal goes sideways Signed-off-by: Cole Robinson <crobinso@redhat.com> --- convert/convert_linux.ml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/convert/convert_linux.ml b/convert/convert_linux.ml index 08a4a9de..5dfeff90 100644 --- a/convert/convert_linux.ml +++ b/convert/convert_linux.ml @@ -139,7 +139,11 @@ let convert (g : G.guestfs) source inspect i_firmware _ keep_serial_console _ = | Guest_packages.Unimplemented_package_manager msg -> error "%s" msg in - ignore (g#sh cmd); + (try ignore (g#sh cmd) + with G.Error msg -> + warning (f_"could not uninstall packages ā%sā: %s (ignored)") + (String.concat " " pkgs) msg + ) ) in -- 2.48.1
Thanks, I pushed these as commit b3268a13bec. I squashed them into one commit since they're logically a single change, and made a small whitespace change so that we don't go beyond 80 cols. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
On 2/10/25 11:28 AM, Richard W.M. Jones wrote:
Thanks, I pushed these as commit b3268a13bec.
Great, thanks. I had some questions in the cover letter FYI
This may still break some really old cases. Notable `unconfigure_xen` has a comment referencing RHEL 3, which lacks yum AFAIK. Which would cause Guest_packages.uninstall_command to error.
Maybe we don't care about RHEL-3? Or turn the error into a warning and be done with it?
Thoughts?
I squashed them into one commit since they're logically a single change, and made a small whitespace change so that we don't go beyond 80 cols.
Noted. Is there any `make syntax-check` or style checking tools I should be aware of? Thanks, Cole
On Mon, Feb 10, 2025 at 03:26:57PM -0500, Cole Robinson wrote:
On 2/10/25 11:28 AM, Richard W.M. Jones wrote:
Thanks, I pushed these as commit b3268a13bec.
Great, thanks. I had some questions in the cover letter FYI
This may still break some really old cases. Notable `unconfigure_xen` has a comment referencing RHEL 3, which lacks yum AFAIK. Which would cause Guest_packages.uninstall_command to error.
Maybe we don't care about RHEL-3? Or turn the error into a warning and be done with it?
Thoughts?
Right, sorry, meant to comment on this. We dropped support for RHEL 3 a couple of years ago, for other reasons: https://github.com/libguestfs/virt-v2v/commit/1ea99fb2a7aee63aabe02aa40e9429... Downstream in RHEL we don't support anything before RHEL 7 on current hosts: https://access.redhat.com/articles/1351473 So I think we're all good here.
I squashed them into one commit since they're logically a single change, and made a small whitespace change so that we don't go beyond 80 cols.
Noted. Is there any `make syntax-check` or style checking tools I should be aware of?
I think we used to have something like that but deleted it. Laszlo went through all the code a few years ago making sure everything was under 80 columns, so I'm trying to stick with that. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
participants (2)
-
Cole Robinson -
Richard W.M. Jones