[Libguestfs] [PATCH] v2v: linux: try to fix removal of VMware tools

Richard W.M. Jones rjones at redhat.com
Tue Oct 4 13:04:50 UTC 2016


On Tue, Oct 04, 2016 at 02:57:53PM +0200, Pino Toscano wrote:
> Try to improve the way packages of VMware tools are removed from
> YUM-based guests:
> 
> - when filtering the package itself from its providers, do a stricter
>   check so either the provide is the unversioned package, or it is
>   exactly its own name
> 
> - if the package has no other providers, then going further will cause
>   the invocation of 'yum install' with no packages, and thus the package
>   itself will not be added to the list of packages to be removed; to
>   overcome this issue, just mark the package as "to be removed" in that
>   case
> 
> Related to: RHBZ#1155150

This patch is a bit nicer to look at when viewed with the '-w' flag.

ACK.

That said, I don't know if this is going to work.  Is there some
plan to test it?

Rich.

> ---
>  v2v/convert_linux.ml | 56 +++++++++++++++++++++++++++++++---------------------
>  1 file changed, 34 insertions(+), 22 deletions(-)
> 
> diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml
> index 6b4197d..8771869 100644
> --- a/v2v/convert_linux.ml
> +++ b/v2v/convert_linux.ml
> @@ -252,29 +252,41 @@ let rec convert ~keep_serial_console (g : G.guestfs) inspect source rcaps =
>  
>              (* The packages provide themselves, filter this out. *)
>              let provides =
> -              List.filter (fun s -> String.find s library = -1) provides in
> -
> -            (* Trim whitespace. *)
> -            let rex = Str.regexp "^[ \t]*\\([^ \t]+\\)[ \t]*$" in
> -            let provides = List.map (Str.replace_first rex "\\1") provides in
> -
> -            (* Install the dependencies with yum.  Use yum explicitly
> -             * because we don't have package names and local install is
> -             * impractical.
> +              List.filter (
> +                fun s ->
> +                  not (library = s || String.is_prefix s (library ^ " = "))
> +              ) provides in
> +
> +            (* If the package provides something other than itself, then
> +             * proceed installing the replacements; in the other case,
> +             * just mark the package for removal, as it means no other
> +             * package can depend on something provided.
>               *)
> -            let cmd = ["yum"; "-q"; "resolvedep"] @ provides in
> -            let cmd = Array.of_list cmd in
> -            let replacements = g#command_lines cmd in
> -            let replacements = Array.to_list replacements in
> -
> -            let cmd = [ "yum"; "install"; "-y" ] @ replacements in
> -            let cmd = Array.of_list cmd in
> -            (try
> -               ignore (g#command cmd);
> -               push_front library remove
> -             with G.Error msg ->
> -               eprintf "%s: could not install replacement for %s.  Error was: %s.  %s was not removed.\n"
> -                 prog library msg library
> +            if provides <> [] then (
> +              (* Trim whitespace. *)
> +              let rex = Str.regexp "^[ \t]*\\([^ \t]+\\)[ \t]*$" in
> +              let provides = List.map (Str.replace_first rex "\\1") provides in
> +
> +              (* Install the dependencies with yum.  Use yum explicitly
> +               * because we don't have package names and local install is
> +               * impractical.
> +               *)
> +              let cmd = ["yum"; "-q"; "resolvedep"] @ provides in
> +              let cmd = Array.of_list cmd in
> +              let replacements = g#command_lines cmd in
> +              let replacements = Array.to_list replacements in
> +
> +              let cmd = [ "yum"; "install"; "-y" ] @ replacements in
> +              let cmd = Array.of_list cmd in
> +              (try
> +                 ignore (g#command cmd);
> +                 push_front library remove
> +               with G.Error msg ->
> +                 eprintf "%s: could not install replacement for %s.  Error was: %s.  %s was not removed.\n"
> +                   prog library msg library
> +              );
> +            ) else (
> +              push_front library remove;
>              );
>          ) libraries
>        )
> -- 
> 2.7.4
> 
> _______________________________________________
> Libguestfs mailing list
> Libguestfs at redhat.com
> https://www.redhat.com/mailman/listinfo/libguestfs

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines.  Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v




More information about the Libguestfs mailing list