mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone
Blob Blame History Raw
From 60edfe4cb0126a27de8c7f264dde6eaa49135436 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Sat, 18 Jun 2016 15:12:08 +0100
Subject: [PATCH] p2v: Don't display debugging messages in the run dialog.

Previously we displayed the complete output of virt-v2v in the run
dialog.  This output included all the debugging messages, and was very
long and confusing for users (especially we had false bug reports
about "errors" appearing in the debug output).

Only display stdout in the run dialog.  However make sure everything
(stdout and stderr) is still logged to the conversion log.

(cherry picked from commit 7447fe2478e49f5121a40db973f8a1fb1daaec53)
---
 p2v/conversion.c | 50 ++++++++++++++++++++++++++++++++++++++++++--------
 p2v/virt-p2v.pod |  7 ++++---
 2 files changed, 46 insertions(+), 11 deletions(-)

diff --git a/p2v/conversion.c b/p2v/conversion.c
index decaf7c..a7d1f11 100644
--- a/p2v/conversion.c
+++ b/p2v/conversion.c
@@ -962,11 +962,15 @@ generate_wrapper_script (struct config *config, const char *remote_dir)
   if (fp == NULL)
     error (EXIT_FAILURE, errno, "open_memstream");
 
-  fprintf (fp, "#!/bin/sh -\n");
+  fprintf (fp, "#!/bin/bash -\n");
   fprintf (fp, "\n");
 
-  /* The virt-v2v command. */
-  fprintf (fp, "(\n");
+  fprintf (fp, "cd %s\n", remote_dir);
+  fprintf (fp, "\n");
+
+  /* The virt-v2v command, as a shell function called "v2v". */
+  fprintf (fp, "v2v ()\n");
+  fprintf (fp, "{\n");
   if (config->sudo)
     fprintf (fp, "sudo -n ");
   fprintf (fp, "virt-v2v");
@@ -1006,15 +1010,45 @@ generate_wrapper_script (struct config *config, const char *remote_dir)
   }
 
   fprintf (fp, " --root first");
-  fprintf (fp, " %s/physical.xml", remote_dir);
-  /* no stdin, and send stdout and stderr to the same place */
-  fprintf (fp, " </dev/null 2>&1");
+  fprintf (fp, " physical.xml");
+  fprintf (fp, " </dev/null");  /* no stdin */
   fprintf (fp, "\n");
-  fprintf (fp, "echo $? > %s/status", remote_dir);
+  fprintf (fp,
+           "# Save the exit code of virt-v2v into the 'status' file.\n");
+  fprintf (fp, "echo $? > status\n");
+  fprintf (fp, "}\n");
   fprintf (fp, "\n");
-  fprintf (fp, " ) | tee %s/virt-v2v-conversion-log.txt", remote_dir);
+
+  fprintf (fp,
+           "# Write a pre-emptive error status, in case the virt-v2v\n"
+           "# command doesn't get to run at all.  This will be\n"
+           "# overwritten with the true exit code when virt-v2v runs.\n");
+  fprintf (fp, "echo 99 > status\n");
   fprintf (fp, "\n");
 
+  fprintf (fp, "log=virt-v2v-conversion-log.txt\n");
+  fprintf (fp, "rm -f $log\n");
+  fprintf (fp, "\n");
+
+  fprintf (fp,
+           "# Run virt-v2v.  Send stdout back to virt-p2v.  Send stdout\n"
+           "# and stderr (debugging info) to the log file.\n");
+  fprintf (fp, "v2v 2>> $log | tee -a $log\n");
+  fprintf (fp, "\n");
+
+  fprintf (fp,
+           "# If virt-v2v failed then the error message (sent to stderr)\n"
+           "# will not be seen in virt-p2v.  Send the last few lines of\n"
+           "# the log back to virt-p2v in this case.\n");
+  fprintf (fp,
+           "if [ \"$(< status)\" -ne 0 ]; then\n"
+           "    echo\n"
+           "    echo\n"
+           "    echo\n"
+           "    echo '*** virt-v2v command failed ***'\n"
+           "    tail -30 $log\n"
+           "fi\n");
+
   fclose (fp);
 
   return output;                /* caller frees */
diff --git a/p2v/virt-p2v.pod b/p2v/virt-p2v.pod
index 0c233c5..b996541 100644
--- a/p2v/virt-p2v.pod
+++ b/p2v/virt-p2v.pod
@@ -267,7 +267,7 @@ When conversion is running you will see this dialog:
  │                                                        │
  └────────────────────────────────────────────────────────┘
 
-In the main scrolling area you will see log messages from the virt-v2v
+In the main scrolling area you will see messages from the virt-v2v
 process.
 
 Below the main area, virt-p2v shows you the location of the directory
@@ -744,8 +744,9 @@ file (see above), which in turn references the NBD listening port(s)
 of the data connection(s).
 
 Output from the virt-v2v command (messages, debugging etc) is saved
-both in the log file on the conversion server, and sent over the
-control connection to be displayed in the graphical UI.
+both in the log file on the conversion server.  Only informational
+messages are sent back over the control connection to be displayed in
+the graphical UI.
 
 =head1 SEE ALSO
 
-- 
1.8.3.1