Blame SOURCES/0215-p2v-Wait-for-network-to-come-online-before-testing-c.patch

ffd6ed
From c6215f789896e06540a0da1db8d6b7d250cbef08 Mon Sep 17 00:00:00 2001
ffd6ed
From: "Richard W.M. Jones" <rjones@redhat.com>
ffd6ed
Date: Mon, 24 Aug 2015 14:56:30 +0100
ffd6ed
Subject: [PATCH] p2v: Wait for network to come online before testing
ffd6ed
 connection (RHBZ#1256222).
ffd6ed
ffd6ed
When using the virt-p2v ISO in command line mode, we did not wait for
ffd6ed
the network to come online before starting virt-p2v.  Therefore
ffd6ed
virt-p2v could exit with an error when testing the ssh connection (or
ffd6ed
on the other hand, it might work randomly).  If the user logs in and
ffd6ed
runs 'launch-virt-p2v' by hand, then it would usually work because the
ffd6ed
network had been brought online in the meantime.
ffd6ed
ffd6ed
Fix this by waiting for NetworkManager to bring the connection online
ffd6ed
before calling test_connection().  Note that the obvious way to fix
ffd6ed
this (changing the systemd service to wait for network-online.target)
ffd6ed
does *not* work - I added a comment to the service about this.
ffd6ed
ffd6ed
Thanks: Tingting Zheng
ffd6ed
(cherry picked from commit 4c34d240a1f152ec257a75f148a8e4a1d91a67c5)
ffd6ed
---
ffd6ed
 p2v/gui.c       |  3 +++
ffd6ed
 p2v/kernel.c    |  1 +
ffd6ed
 p2v/p2v.h       |  1 +
ffd6ed
 p2v/p2v.service |  5 +++++
ffd6ed
 p2v/utils.c     | 22 ++++++++++++++++++++++
ffd6ed
 5 files changed, 32 insertions(+)
ffd6ed
ffd6ed
diff --git a/p2v/gui.c b/p2v/gui.c
ffd6ed
index c0079aa..2e9c9e2 100644
ffd6ed
--- a/p2v/gui.c
ffd6ed
+++ b/p2v/gui.c
ffd6ed
@@ -316,8 +316,11 @@ test_connection_thread (void *data)
ffd6ed
                       _("Testing the connection to the conversion server ..."));
ffd6ed
   gtk_spinner_start (GTK_SPINNER (spinner));
ffd6ed
   gdk_threads_leave ();
ffd6ed
+
ffd6ed
+  wait_network_online (copy);
ffd6ed
   r = test_connection (copy);
ffd6ed
   free_config (copy);
ffd6ed
+
ffd6ed
   gdk_threads_enter ();
ffd6ed
   gtk_spinner_stop (GTK_SPINNER (spinner));
ffd6ed
 
ffd6ed
diff --git a/p2v/kernel.c b/p2v/kernel.c
ffd6ed
index fd67921..950bb79 100644
ffd6ed
--- a/p2v/kernel.c
ffd6ed
+++ b/p2v/kernel.c
ffd6ed
@@ -81,6 +81,7 @@ kernel_configuration (struct config *config, char **cmdline, int cmdline_source)
ffd6ed
    */
ffd6ed
   p = get_cmdline_key (cmdline, "p2v.skip_test_connection");
ffd6ed
   if (!p) {
ffd6ed
+    wait_network_online (config);
ffd6ed
     if (test_connection (config) == -1) {
ffd6ed
       const char *err = get_ssh_error ();
ffd6ed
 
ffd6ed
diff --git a/p2v/p2v.h b/p2v/p2v.h
ffd6ed
index a588893..2827fb3 100644
ffd6ed
--- a/p2v/p2v.h
ffd6ed
+++ b/p2v/p2v.h
ffd6ed
@@ -119,6 +119,7 @@ extern const char *get_ssh_error (void);
ffd6ed
 /* utils.c */
ffd6ed
 extern char *get_if_addr (const char *if_name);
ffd6ed
 extern char *get_if_vendor (const char *if_name, int truncate);
ffd6ed
+extern void wait_network_online (const struct config *);
ffd6ed
 
ffd6ed
 /* virt-v2v version and features (read from remote). */
ffd6ed
 extern int v2v_major;
ffd6ed
diff --git a/p2v/p2v.service b/p2v/p2v.service
ffd6ed
index 4ff055c..0b04bae 100644
ffd6ed
--- a/p2v/p2v.service
ffd6ed
+++ b/p2v/p2v.service
ffd6ed
@@ -20,6 +20,11 @@
ffd6ed
 
ffd6ed
 [Unit]
ffd6ed
 Description=p2v service
ffd6ed
+# For the GUI, we cannot necessarily wait for the network to come
ffd6ed
+# online, since that may require the "Configure Network" dialog.  For
ffd6ed
+# the command line, we would like the network to be online, but we
ffd6ed
+# test that within virt-p2v itself.  Therefore use network.target
ffd6ed
+# here, not network-online.target.
ffd6ed
 After=network.target
ffd6ed
 
ffd6ed
 [Service]
ffd6ed
diff --git a/p2v/utils.c b/p2v/utils.c
ffd6ed
index 0b30be3..3781a8d 100644
ffd6ed
--- a/p2v/utils.c
ffd6ed
+++ b/p2v/utils.c
ffd6ed
@@ -26,6 +26,8 @@
ffd6ed
 #include <locale.h>
ffd6ed
 #include <libintl.h>
ffd6ed
 
ffd6ed
+#include "ignore-value.h"
ffd6ed
+
ffd6ed
 #include "p2v.h"
ffd6ed
 
ffd6ed
 #define CHOMP(line,len)                         \
ffd6ed
@@ -134,3 +136,23 @@ get_if_vendor (const char *if_name, int truncate)
ffd6ed
   free (line);
ffd6ed
   return NULL;
ffd6ed
 }
ffd6ed
+
ffd6ed
+/* Wait for the network to come online, but don't error out if that
ffd6ed
+ * fails.  The caller will call test_connection immediately after this
ffd6ed
+ * which will fail if the network didn't come online.
ffd6ed
+ */
ffd6ed
+
ffd6ed
+/* XXX We could make this configurable. */
ffd6ed
+#define NETWORK_ONLINE_COMMAND "nm-online -t 30"
ffd6ed
+
ffd6ed
+void
ffd6ed
+wait_network_online (const struct config *config)
ffd6ed
+{
ffd6ed
+  if (config->verbose) {
ffd6ed
+    printf ("waiting for the network to come online ...\n");
ffd6ed
+    printf ("%s\n", NETWORK_ONLINE_COMMAND);
ffd6ed
+    fflush (stdout);
ffd6ed
+  }
ffd6ed
+
ffd6ed
+  ignore_value (system (NETWORK_ONLINE_COMMAND));
ffd6ed
+}
ffd6ed
-- 
ffd6ed
1.8.3.1
ffd6ed