[node-patches] Change in ovirt-node[master]: ping: Fix ping page

fabiand at fedoraproject.org fabiand at fedoraproject.org
Mon Jul 8 12:11:44 UTC 2013


Fabian Deutsch has uploaded a new change for review.

Change subject: ping: Fix ping page
......................................................................

ping: Fix ping page

Previously pinging while the network wasn't available or pinging an
unreachable host lead to problems on the ping page.
The code has now been refactored and simplified to prevent those
problems.

Change-Id: I7f3fcbb7fca8b904e3531d7b6334f3e4aa5bc918
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=980420
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M src/ovirt/node/setup/core/ping.py
M src/ovirt/node/utils/process.py
2 files changed, 13 insertions(+), 24 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/70/16570/1

diff --git a/src/ovirt/node/setup/core/ping.py b/src/ovirt/node/setup/core/ping.py
index 0872597..b76b3c4 100644
--- a/src/ovirt/node/setup/core/ping.py
+++ b/src/ovirt/node/setup/core/ping.py
@@ -73,8 +73,6 @@
               ui.Divider("divider[1]"),
               ui.SaveButton("ping.do_ping", "Ping"),
               ui.Divider("divider[2]"),
-              ui.ProgressBar("ping.progress"),
-              ui.Divider("divider[3]"),
               ui.Label("ping.result", "Result:"),
               ]
 
@@ -122,24 +120,14 @@
 
     def run(self):
         try:
-            self.__run()
-        except Exception as e:
-            self.p.logger.debug("Exception while pinging: %s" % e,
-                                exc_info=True)
-        self.p.widgets["ping.do_ping"].enabled(True)
-
-    def __run(self):
-            self.p.widgets["ping.do_ping"].enabled(False)
-
-            progressbar = self.p.widgets["ping.progress"]
-            stdoutdump = self.p.widgets["ping.result"]
             ui_thread = self.p.application.ui.thread_connection()
-            out = []
-            current = 0
+            stdoutdump = self.p.widgets["ping.result"]
 
-            for line in process.pipe_async(self.cmd):
-                out += [line]
-                if "time=" in line:
-                    current += 100.0 / float(self.count)
-                    ui_thread.call(lambda: progressbar.current(current))
-                ui_thread.call(lambda: stdoutdump.text("\n".join(out[-3:])))
+            self.p.widgets["ping.do_ping"].enabled(False)
+            ui_thread.call(lambda: stdoutdump.text("Pinging ..."))
+            out = process.pipe(self.cmd)
+            ui_thread.call(lambda: stdoutdump.text(out))
+        except:
+            self.p.logger.exception("Exception while pinging")
+        finally:
+            self.p.widgets["ping.do_ping"].enabled(True)
diff --git a/src/ovirt/node/utils/process.py b/src/ovirt/node/utils/process.py
index d1287db..3878174 100644
--- a/src/ovirt/node/utils/process.py
+++ b/src/ovirt/node/utils/process.py
@@ -93,10 +93,11 @@
     Returns:
         stdout, stderr of the process (as one blob)
     """
-    return unicode(popen(cmd, shell=True,
+    return unicode(popen(cmd,
                          stdin=PIPE,
                          stdout=PIPE,
-                         stderr=STDOUT).communicate(stdin)[0])
+                         stderr=STDOUT
+                         ).communicate(stdin)[0])
 
 
 def pipe_async(cmd, stdin=None):
@@ -117,6 +118,6 @@
     # pylint: disable-msg=E1101
     if stdin:
         process.stdin.write(stdin)
-    while process.poll() != 0:
+    while process.poll() is None:
         yield process.stdout.readline()
     # pylint: enable-msg=E1101


-- 
To view, visit http://gerrit.ovirt.org/16570
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7f3fcbb7fca8b904e3531d7b6334f3e4aa5bc918
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>



More information about the node-patches mailing list