psss / rpms / libguestfs

Forked from rpms/libguestfs 5 years ago
Clone

Blame 0050-builder-Add-no-delete-on-failure-option-to-aid-debug.patch

4bf3775
From 0777aa0b2e29f451e15e6e8c40f66112059aa957 Mon Sep 17 00:00:00 2001
dd3ad1c
From: "Richard W.M. Jones" <rjones@redhat.com>
dd3ad1c
Date: Mon, 13 Jan 2014 20:29:50 +0000
dd3ad1c
Subject: [PATCH] builder: Add --no-delete-on-failure option to aid debugging.
dd3ad1c
dd3ad1c
This lets you debug failures in virt-builder, especially when scripts
dd3ad1c
or installing packages fails.
dd3ad1c
dd3ad1c
(cherry picked from commit 5136de98e7f4bd7a967da5b3ede72c729aa7805e)
dd3ad1c
---
dd3ad1c
 builder/builder.ml       |  9 +++++----
dd3ad1c
 builder/cmdline.ml       |  9 +++++++--
dd3ad1c
 builder/virt-builder.pod | 17 +++++++++++++++--
dd3ad1c
 3 files changed, 27 insertions(+), 8 deletions(-)
dd3ad1c
dd3ad1c
diff --git a/builder/builder.ml b/builder/builder.ml
bf9044c
index 6105c75..79f82a2 100644
dd3ad1c
--- a/builder/builder.ml
dd3ad1c
+++ b/builder/builder.ml
bf9044c
@@ -38,8 +38,8 @@ let () = Random.self_init ()
dd3ad1c
 let main () =
dd3ad1c
   (* Command line argument parsing - see cmdline.ml. *)
dd3ad1c
   let mode, arg,
dd3ad1c
-    attach, cache, check_signature, curl, debug, delete, edit,
dd3ad1c
-    firstboot, run, format, gpg, hostname, install, list_long, links,
dd3ad1c
+    attach, cache, check_signature, curl, debug, delete, delete_on_failure,
dd3ad1c
+    edit, firstboot, run, format, gpg, hostname, install, list_long, links,
dd3ad1c
     memsize, mkdirs,
dd3ad1c
     network, output, password_crypto, quiet, root_password, scrub,
dd3ad1c
     scrub_logfile, size, smp, sources, sync, timezone, update, upload,
bf9044c
@@ -469,9 +469,10 @@ let main () =
dd3ad1c
   );
dd3ad1c
 
dd3ad1c
   (* Delete the output file before we finish.  However don't delete it
dd3ad1c
-   * if it's block device.
dd3ad1c
+   * if it's block device, or if --no-delete-on-failure is set.
dd3ad1c
    *)
dd3ad1c
-  let delete_output_file = ref (not output_is_block_dev) in
dd3ad1c
+  let delete_output_file =
dd3ad1c
+    ref (delete_on_failure && not output_is_block_dev) in
dd3ad1c
   let delete_file () =
dd3ad1c
     if !delete_output_file then
dd3ad1c
       try unlink output_filename with _ -> ()
dd3ad1c
diff --git a/builder/cmdline.ml b/builder/cmdline.ml
dd3ad1c
index 58e8a6b..67b142a 100644
dd3ad1c
--- a/builder/cmdline.ml
dd3ad1c
+++ b/builder/cmdline.ml
dd3ad1c
@@ -72,6 +72,8 @@ let parse_cmdline () =
dd3ad1c
   let delete = ref [] in
dd3ad1c
   let add_delete s = delete := s :: !delete in
dd3ad1c
 
dd3ad1c
+  let delete_on_failure = ref true in
dd3ad1c
+
dd3ad1c
   let edit = ref [] in
dd3ad1c
   let add_edit arg =
dd3ad1c
     let i =
dd3ad1c
@@ -235,6 +237,8 @@ let parse_cmdline () =
dd3ad1c
     "--delete",  Arg.String add_delete,     "name" ^ " " ^ s_"Delete a file or dir";
dd3ad1c
     "--delete-cache", Arg.Unit delete_cache_mode,
dd3ad1c
                                             " " ^ s_"Delete the template cache";
dd3ad1c
+    "--no-delete-on-failure", Arg.Clear delete_on_failure,
dd3ad1c
+                                            " " ^ s_"Don't delete output file on failure";
dd3ad1c
     "--edit",    Arg.String add_edit,       "file:expr" ^ " " ^ s_"Edit file with Perl expr";
dd3ad1c
     "--fingerprint", Arg.String add_fingerprint,
dd3ad1c
                                             "AAAA.." ^ " " ^ s_"Fingerprint of valid signing key";
dd3ad1c
@@ -316,6 +320,7 @@ read the man page virt-builder(1).
dd3ad1c
   let curl = !curl in
dd3ad1c
   let debug = !debug in
dd3ad1c
   let delete = List.rev !delete in
dd3ad1c
+  let delete_on_failure = !delete_on_failure in
dd3ad1c
   let edit = List.rev !edit in
dd3ad1c
   let fingerprints = List.rev !fingerprints in
dd3ad1c
   let firstboot = List.rev !firstboot in
dd3ad1c
@@ -437,8 +442,8 @@ read the man page virt-builder(1).
dd3ad1c
     List.combine sources fingerprints in
dd3ad1c
 
dd3ad1c
   mode, arg,
dd3ad1c
-  attach, cache, check_signature, curl, debug, delete, edit,
dd3ad1c
-  firstboot, run, format, gpg, hostname, install, list_long, links,
dd3ad1c
+  attach, cache, check_signature, curl, debug, delete, delete_on_failure,
dd3ad1c
+  edit, firstboot, run, format, gpg, hostname, install, list_long, links,
dd3ad1c
   memsize, mkdirs,
dd3ad1c
   network, output, password_crypto, quiet, root_password, scrub,
dd3ad1c
   scrub_logfile, size, smp, sources, sync, timezone, update, upload,
dd3ad1c
diff --git a/builder/virt-builder.pod b/builder/virt-builder.pod
bf9044c
index ec41078..f3ddce5 100644
dd3ad1c
--- a/builder/virt-builder.pod
dd3ad1c
+++ b/builder/virt-builder.pod
dd3ad1c
@@ -250,6 +250,15 @@ See also: I<--upload>, I<--scrub>.
dd3ad1c
 
dd3ad1c
 Delete the template cache.  See L</CACHING>.
dd3ad1c
 
dd3ad1c
+=item B<--no-delete-on-failure>
dd3ad1c
+
dd3ad1c
+Don't delete the output file on failure to build.  You can use this to
dd3ad1c
+debug failures to run scripts.  See L</DEBUGGING BUILDS> for ways to
dd3ad1c
+debug images.
dd3ad1c
+
dd3ad1c
+The default is to delete the output file if virt-builder fails (or,
dd3ad1c
+for example, some script that it runs fails).
dd3ad1c
+
dd3ad1c
 =item B<--edit> FILE:EXPR
dd3ad1c
 
dd3ad1c
 Edit C<FILE> using the Perl expression C<EXPR>.
51fb412
@@ -1065,8 +1074,12 @@ chosen.  It will be C<raw> unless the I<--format> option was used.
dd3ad1c
 
dd3ad1c
 =head2 DEBUGGING BUILDS
dd3ad1c
 
dd3ad1c
-If virt-builder fails with an error, then enable debugging (I<-v>) and
dd3ad1c
-report a bug (see L</BUGS> below).
dd3ad1c
+If virt-builder itself fails, then enable debugging (I<-v>) and report
dd3ad1c
+a bug (see L</BUGS> below).
dd3ad1c
+
dd3ad1c
+If virt-builder fails because some script or package it is installing
dd3ad1c
+fails, try using I<--no-delete-on-failure> to preserve the output
dd3ad1c
+file, and continue reading this section.
dd3ad1c
 
dd3ad1c
 If virt-builder is successful but the image doesn't work, here are
dd3ad1c
 some things to try:
dd3ad1c
-- 
4bf3775
1.8.5.3
dd3ad1c