[Libguestfs] [PATCH 5/7] p2v: Don't display debugging messages in the run dialog.

Richard W.M. Jones rjones at redhat.com
Sat Jun 18 15:09:15 UTC 2016


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.
---
 p2v/conversion.c | 46 +++++++++++++++++++++++++++++++++++++++-------
 p2v/virt-p2v.pod |  7 ++++---
 2 files changed, 43 insertions(+), 10 deletions(-)

diff --git a/p2v/conversion.c b/p2v/conversion.c
index c948bf8..7538fea 100644
--- a/p2v/conversion.c
+++ b/p2v/conversion.c
@@ -986,11 +986,12 @@ 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");
+  /* 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");
@@ -1031,14 +1032,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, " </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, "status=%s/status\n", remote_dir);
+  fprintf (fp, "echo 99 > $status\n");
   fprintf (fp, "\n");
 
+  fprintf (fp, "log=%s/virt-v2v-conversion-log.txt\n", remote_dir);
+  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 923aed0..945d8c2 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
@@ -749,8 +749,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
 
-- 
2.7.4




More information about the Libguestfs mailing list