[Pkg-libvirt-commits] [libguestfs] 40/233: builder: Add --no-delete-on-failure option to aid debugging.

Hilko Bengen bengen at moszumanska.debian.org
Wed Feb 19 21:10:46 UTC 2014


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

bengen pushed a commit to branch experimental
in repository libguestfs.

commit 5136de98e7f4bd7a967da5b3ede72c729aa7805e
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Mon Jan 13 20:29:50 2014 +0000

    builder: Add --no-delete-on-failure option to aid debugging.
    
    This lets you debug failures in virt-builder, especially when scripts
    or installing packages fails.
---
 builder/builder.ml       |  9 +++++----
 builder/cmdline.ml       |  9 +++++++--
 builder/virt-builder.pod | 17 +++++++++++++++--
 3 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/builder/builder.ml b/builder/builder.ml
index f478a4f..861e029 100644
--- a/builder/builder.ml
+++ b/builder/builder.ml
@@ -36,8 +36,8 @@ let prog = Filename.basename Sys.executable_name
 let main () =
   (* Command line argument parsing - see cmdline.ml. *)
   let mode, arg,
-    attach, cache, check_signature, curl, debug, delete, edit,
-    firstboot, run, format, gpg, hostname, install, list_long, links,
+    attach, cache, check_signature, curl, debug, delete, delete_on_failure,
+    edit, firstboot, run, format, gpg, hostname, install, list_long, links,
     memsize, mkdirs,
     network, output, password_crypto, quiet, root_password, scrub,
     scrub_logfile, size, smp, sources, sync, timezone, update, upload,
@@ -467,9 +467,10 @@ let main () =
   );
 
   (* Delete the output file before we finish.  However don't delete it
-   * if it's block device.
+   * if it's block device, or if --no-delete-on-failure is set.
    *)
-  let delete_output_file = ref (not output_is_block_dev) in
+  let delete_output_file =
+    ref (delete_on_failure && not output_is_block_dev) in
   let delete_file () =
     if !delete_output_file then
       try unlink output_filename with _ -> ()
diff --git a/builder/cmdline.ml b/builder/cmdline.ml
index 58e8a6b..67b142a 100644
--- a/builder/cmdline.ml
+++ b/builder/cmdline.ml
@@ -72,6 +72,8 @@ let parse_cmdline () =
   let delete = ref [] in
   let add_delete s = delete := s :: !delete in
 
+  let delete_on_failure = ref true in
+
   let edit = ref [] in
   let add_edit arg =
     let i =
@@ -235,6 +237,8 @@ let parse_cmdline () =
     "--delete",  Arg.String add_delete,     "name" ^ " " ^ s_"Delete a file or dir";
     "--delete-cache", Arg.Unit delete_cache_mode,
                                             " " ^ s_"Delete the template cache";
+    "--no-delete-on-failure", Arg.Clear delete_on_failure,
+                                            " " ^ s_"Don't delete output file on failure";
     "--edit",    Arg.String add_edit,       "file:expr" ^ " " ^ s_"Edit file with Perl expr";
     "--fingerprint", Arg.String add_fingerprint,
                                             "AAAA.." ^ " " ^ s_"Fingerprint of valid signing key";
@@ -316,6 +320,7 @@ read the man page virt-builder(1).
   let curl = !curl in
   let debug = !debug in
   let delete = List.rev !delete in
+  let delete_on_failure = !delete_on_failure in
   let edit = List.rev !edit in
   let fingerprints = List.rev !fingerprints in
   let firstboot = List.rev !firstboot in
@@ -437,8 +442,8 @@ read the man page virt-builder(1).
     List.combine sources fingerprints in
 
   mode, arg,
-  attach, cache, check_signature, curl, debug, delete, edit,
-  firstboot, run, format, gpg, hostname, install, list_long, links,
+  attach, cache, check_signature, curl, debug, delete, delete_on_failure,
+  edit, firstboot, run, format, gpg, hostname, install, list_long, links,
   memsize, mkdirs,
   network, output, password_crypto, quiet, root_password, scrub,
   scrub_logfile, size, smp, sources, sync, timezone, update, upload,
diff --git a/builder/virt-builder.pod b/builder/virt-builder.pod
index 1e5b9bb..366ff76 100644
--- a/builder/virt-builder.pod
+++ b/builder/virt-builder.pod
@@ -250,6 +250,15 @@ See also: I<--upload>, I<--scrub>.
 
 Delete the template cache.  See L</CACHING>.
 
+=item B<--no-delete-on-failure>
+
+Don't delete the output file on failure to build.  You can use this to
+debug failures to run scripts.  See L</DEBUGGING BUILDS> for ways to
+debug images.
+
+The default is to delete the output file if virt-builder fails (or,
+for example, some script that it runs fails).
+
 =item B<--edit> FILE:EXPR
 
 Edit C<FILE> using the Perl expression C<EXPR>.
@@ -1048,8 +1057,12 @@ chosen.  It will be C<raw> unless the I<--format> option was used.
 
 =head2 DEBUGGING BUILDS
 
-If virt-builder fails with an error, then enable debugging (I<-v>) and
-report a bug (see L</BUGS> below).
+If virt-builder itself fails, then enable debugging (I<-v>) and report
+a bug (see L</BUGS> below).
+
+If virt-builder fails because some script or package it is installing
+fails, try using I<--no-delete-on-failure> to preserve the output
+file, and continue reading this section.
 
 If virt-builder is successful but the image doesn't work, here are
 some things to try:

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