[Libguestfs] [PATCH v2 1/2] v2v: bootloaders: Handle no Bootloader::Tools default section (RHBZ#1472208).

Richard W.M. Jones rjones at redhat.com
Tue Jul 18 17:59:20 UTC 2017


In SUSE guests, handle the case where
Bootloader::Tools::GetDefaultSection () returns undef.

Previously this would return an empty string and cause a bogus error
in subsequent code:

virt-v2v: error: libguestfs error: statns: statns_stub: path must start
with a / character
---
 v2v/linux_bootloaders.ml | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/v2v/linux_bootloaders.ml b/v2v/linux_bootloaders.ml
index b5ad25508..d76407670 100644
--- a/v2v/linux_bootloaders.ml
+++ b/v2v/linux_bootloaders.ml
@@ -287,10 +287,21 @@ object (self)
           let cmd =
             [| "/usr/bin/perl"; "-MBootloader::Tools"; "-e"; "
                   InitLibrary();
-                  my $default = Bootloader::Tools::GetDefaultSection();
-                  print $default->{image};
+                  my $default = Bootloader::Tools::GetDefaultSection ();
+                  if (!defined $default) {
+                    print 'NODEFAULTSECTION'
+                  }
+                  elsif (exists $default->{image}) {
+                    print $default->{image}
+                  }
+                  else {
+                    die 'no $default->{image}' # should never happen
+                  }
                " |] in
-          Some (g#command cmd)
+          let res = g#command cmd in
+          (match res with
+           | "NODEFAULTSECTION" -> None
+           | _ -> Some res)
         | MethodNone ->
           None in
       match res with
-- 
2.13.2




More information about the Libguestfs mailing list