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

Pino Toscano ptoscano at redhat.com
Tue Oct 4 12:57:53 UTC 2016


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
---
 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




More information about the Libguestfs mailing list