From be8ad60b8ecac51037ba2815c0675e3cac5edaa1 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Tue, 4 Oct 2016 14:45:18 +0200 Subject: [PATCH] v2v: linux: try to fix removal of VMware tools 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 | 52 +++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml index 6b4197de2..8771869fb 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 + List.filter ( + fun s -> + not (library = s || String.is_prefix s (library ^ " = ")) + ) 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. + (* 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 + if provides <> [] then ( + (* Trim whitespace. *) + let rex = Str.regexp "^[ \t]*\\([^ \t]+\\)[ \t]*$" in + let provides = List.map (Str.replace_first rex "\\1") provides 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 + (* 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 )