Blame SOURCES/0114-p2v-Don-t-display-debugging-messages-in-the-run-dial.patch

e76f14
From 60edfe4cb0126a27de8c7f264dde6eaa49135436 Mon Sep 17 00:00:00 2001
e76f14
From: "Richard W.M. Jones" <rjones@redhat.com>
e76f14
Date: Sat, 18 Jun 2016 15:12:08 +0100
e76f14
Subject: [PATCH] p2v: Don't display debugging messages in the run dialog.
e76f14
e76f14
Previously we displayed the complete output of virt-v2v in the run
e76f14
dialog.  This output included all the debugging messages, and was very
e76f14
long and confusing for users (especially we had false bug reports
e76f14
about "errors" appearing in the debug output).
e76f14
e76f14
Only display stdout in the run dialog.  However make sure everything
e76f14
(stdout and stderr) is still logged to the conversion log.
e76f14
e76f14
(cherry picked from commit 7447fe2478e49f5121a40db973f8a1fb1daaec53)
e76f14
---
e76f14
 p2v/conversion.c | 50 ++++++++++++++++++++++++++++++++++++++++++--------
e76f14
 p2v/virt-p2v.pod |  7 ++++---
e76f14
 2 files changed, 46 insertions(+), 11 deletions(-)
e76f14
e76f14
diff --git a/p2v/conversion.c b/p2v/conversion.c
e76f14
index decaf7c..a7d1f11 100644
e76f14
--- a/p2v/conversion.c
e76f14
+++ b/p2v/conversion.c
e76f14
@@ -962,11 +962,15 @@ generate_wrapper_script (struct config *config, const char *remote_dir)
e76f14
   if (fp == NULL)
e76f14
     error (EXIT_FAILURE, errno, "open_memstream");
e76f14
 
e76f14
-  fprintf (fp, "#!/bin/sh -\n");
e76f14
+  fprintf (fp, "#!/bin/bash -\n");
e76f14
   fprintf (fp, "\n");
e76f14
 
e76f14
-  /* The virt-v2v command. */
e76f14
-  fprintf (fp, "(\n");
e76f14
+  fprintf (fp, "cd %s\n", remote_dir);
e76f14
+  fprintf (fp, "\n");
e76f14
+
e76f14
+  /* The virt-v2v command, as a shell function called "v2v". */
e76f14
+  fprintf (fp, "v2v ()\n");
e76f14
+  fprintf (fp, "{\n");
e76f14
   if (config->sudo)
e76f14
     fprintf (fp, "sudo -n ");
e76f14
   fprintf (fp, "virt-v2v");
e76f14
@@ -1006,15 +1010,45 @@ generate_wrapper_script (struct config *config, const char *remote_dir)
e76f14
   }
e76f14
 
e76f14
   fprintf (fp, " --root first");
e76f14
-  fprintf (fp, " %s/physical.xml", remote_dir);
e76f14
-  /* no stdin, and send stdout and stderr to the same place */
e76f14
-  fprintf (fp, " </dev/null 2>&1");
e76f14
+  fprintf (fp, " physical.xml");
e76f14
+  fprintf (fp, " 
e76f14
   fprintf (fp, "\n");
e76f14
-  fprintf (fp, "echo $? > %s/status", remote_dir);
e76f14
+  fprintf (fp,
e76f14
+           "# Save the exit code of virt-v2v into the 'status' file.\n");
e76f14
+  fprintf (fp, "echo $? > status\n");
e76f14
+  fprintf (fp, "}\n");
e76f14
   fprintf (fp, "\n");
e76f14
-  fprintf (fp, " ) | tee %s/virt-v2v-conversion-log.txt", remote_dir);
e76f14
+
e76f14
+  fprintf (fp,
e76f14
+           "# Write a pre-emptive error status, in case the virt-v2v\n"
e76f14
+           "# command doesn't get to run at all.  This will be\n"
e76f14
+           "# overwritten with the true exit code when virt-v2v runs.\n");
e76f14
+  fprintf (fp, "echo 99 > status\n");
e76f14
   fprintf (fp, "\n");
e76f14
 
e76f14
+  fprintf (fp, "log=virt-v2v-conversion-log.txt\n");
e76f14
+  fprintf (fp, "rm -f $log\n");
e76f14
+  fprintf (fp, "\n");
e76f14
+
e76f14
+  fprintf (fp,
e76f14
+           "# Run virt-v2v.  Send stdout back to virt-p2v.  Send stdout\n"
e76f14
+           "# and stderr (debugging info) to the log file.\n");
e76f14
+  fprintf (fp, "v2v 2>> $log | tee -a $log\n");
e76f14
+  fprintf (fp, "\n");
e76f14
+
e76f14
+  fprintf (fp,
e76f14
+           "# If virt-v2v failed then the error message (sent to stderr)\n"
e76f14
+           "# will not be seen in virt-p2v.  Send the last few lines of\n"
e76f14
+           "# the log back to virt-p2v in this case.\n");
e76f14
+  fprintf (fp,
e76f14
+           "if [ \"$(< status)\" -ne 0 ]; then\n"
e76f14
+           "    echo\n"
e76f14
+           "    echo\n"
e76f14
+           "    echo\n"
e76f14
+           "    echo '*** virt-v2v command failed ***'\n"
e76f14
+           "    tail -30 $log\n"
e76f14
+           "fi\n");
e76f14
+
e76f14
   fclose (fp);
e76f14
 
e76f14
   return output;                /* caller frees */
e76f14
diff --git a/p2v/virt-p2v.pod b/p2v/virt-p2v.pod
e76f14
index 0c233c5..b996541 100644
e76f14
--- a/p2v/virt-p2v.pod
e76f14
+++ b/p2v/virt-p2v.pod
e76f14
@@ -267,7 +267,7 @@ When conversion is running you will see this dialog:
e76f14
  │                                                        │
e76f14
  └────────────────────────────────────────────────────────┘
e76f14
 
e76f14
-In the main scrolling area you will see log messages from the virt-v2v
e76f14
+In the main scrolling area you will see messages from the virt-v2v
e76f14
 process.
e76f14
 
e76f14
 Below the main area, virt-p2v shows you the location of the directory
e76f14
@@ -744,8 +744,9 @@ file (see above), which in turn references the NBD listening port(s)
e76f14
 of the data connection(s).
e76f14
 
e76f14
 Output from the virt-v2v command (messages, debugging etc) is saved
e76f14
-both in the log file on the conversion server, and sent over the
e76f14
-control connection to be displayed in the graphical UI.
e76f14
+both in the log file on the conversion server.  Only informational
e76f14
+messages are sent back over the control connection to be displayed in
e76f14
+the graphical UI.
e76f14
 
e76f14
 =head1 SEE ALSO
e76f14
 
e76f14
-- 
e76f14
1.8.3.1
e76f14