[Pkg-libvirt-commits] [libguestfs] 27/35: v2v: Fix code for editing grub2 console=... parameter (RHBZ#1143883).

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:46:45 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag debian/1%1.27.49-1
in repository libguestfs.

commit 035f47cdde4052e77613c77d2e5e0f24dbab082f
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Thu Sep 18 14:43:12 2014 +0100

    v2v: Fix code for editing grub2 console=... parameter (RHBZ#1143883).
    
    When presented with a RHEL 7 guest, virt-v2v would print the following
    warning message:
    
      virt-v2v: warning: could not update grub2 console: aug_get: no matching
      node (ignored)
    
    This happened because on RHEL 7, /etc/sysconfig/grub is a symlink to
    /etc/default/grub, and the Augeas grub2 lens returns entries under
    /files/etc/default/grub/*, but the code was checking for
    /files/etc/sysconfig/grub/*.
    
    The fix is to check all the possible Augeas paths until one matches.
    (Only the first match gets updated however).
    
    Also, don't rebuild the grub2 config unless we've actually changed it.
    This avoids doing a potentially failure-prone operation when it's not
    necessary.
    
    I suspect that the old virt-v2v code did not work correctly for RHEL 7
    guests, but old virt-v2v didn't print a warning here, it just failed
    to update silently.
---
 v2v/convert_linux.ml | 55 +++++++++++++++++++++++++++++-----------------------
 1 file changed, 31 insertions(+), 24 deletions(-)

diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml
index 08c153a..92293d6 100644
--- a/v2v/convert_linux.ml
+++ b/v2v/convert_linux.ml
@@ -998,31 +998,38 @@ let rec convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source =
   and grub2_update_console ~remove =
     let rex = Str.regexp "\\(.*\\)\\bconsole=[xh]vc0\\b\\(.*\\)" in
 
-    let grub_cmdline_expr =
-      if g#exists "/etc/sysconfig/grub" then
-        "/files/etc/sysconfig/grub/GRUB_CMDLINE_LINUX"
+    let paths = [
+      "/files/etc/sysconfig/grub/GRUB_CMDLINE_LINUX";
+      "/files/etc/default/grub/GRUB_CMDLINE_LINUX";
+      "/files/etc/default/grub/GRUB_CMDLINE_LINUX_DEFAULT"
+    ] in
+    let paths = List.map g#aug_match paths in
+    let paths = List.map Array.to_list paths in
+    let paths = List.flatten paths in
+    match paths with
+    | [] ->
+      if not remove then
+        warning ~prog (f_"could not add grub2 serial console (ignored)")
       else
-        "/files/etc/default/grub/GRUB_CMDLINE_LINUX_DEFAULT" in
-
-    (try
-       let grub_cmdline = g#aug_get grub_cmdline_expr in
-       let grub_cmdline =
-         if Str.string_match rex grub_cmdline 0 then (
-           if remove then
-             Str.global_replace rex "\\1\\3" grub_cmdline
-           else
-             Str.global_replace rex "\\1console=ttyS0\\3" grub_cmdline
-         )
-         else grub_cmdline in
-       g#aug_set grub_cmdline_expr grub_cmdline;
-       g#aug_save ();
-
-       ignore (g#command [| "grub2-mkconfig"; "-o"; grub_config |])
-     with
-       G.Error msg ->
-         warning ~prog (f_"could not update grub2 console: %s (ignored)")
-           msg
-    )
+        warning ~prog (f_"could not remove grub2 serial console (ignored)")
+    | path :: _ ->
+      let grub_cmdline = g#aug_get path in
+      if Str.string_match rex grub_cmdline 0 then (
+        let new_grub_cmdline =
+          if not remove then
+            Str.global_replace rex "\\1console=ttyS0\\3" grub_cmdline
+          else
+            Str.global_replace rex "\\1\\3" grub_cmdline in
+        g#aug_set path new_grub_cmdline;
+        g#aug_save ();
+
+        try
+          ignore (g#command [| "grub2-mkconfig"; "-o"; grub_config |])
+        with
+          G.Error msg ->
+            warning ~prog (f_"could not rebuild grub2 configuration file (%s).  This may mean that grub output will not be sent to the serial port, but otherwise should be harmless.  Original error message: %s")
+              grub_config msg
+      )
 
   and supports_acpi () =
     (* ACPI known to cause RHEL 3 to fail. *)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list