[ovs-dev] [PATCH 4/5] Python tests: Set CREATE_NO_WINDOW flag for Popen

Alin Balutoiu abalutoiu at cloudbasesolutions.com
Thu Dec 29 17:40:45 UTC 2016


On Windows if the flag CREATE_NO_WINDOW is not
specified when using subprocess.Popen, a new
window will appear with the new process.

The window is not necessary for the tests.
This patch addresses this issue by adding
the flag CREATE_NO_WINDOW for all subprocess.Popen
calls if the machine is running Windows.

Signed-off-by: Alin-Gheorghe Balutoiu <abalutoiu at cloudbasesolutions.com>
---
 ovn/utilities/ovn-docker-overlay-driver                     |  7 ++++++-
 ovn/utilities/ovn-docker-underlay-driver                    |  7 ++++++-
 python/ovstest/util.py                                      | 13 +++++++++++--
 utilities/bugtool/ovs-bugtool.in                            | 12 ++++++++++--
 utilities/ovs-dev.py                                        |  6 +++++-
 utilities/ovs-dpctl-top.in                                  |  6 +++++-
 utilities/ovs-parse-backtrace.in                            |  6 +++++-
 utilities/ovs-tcpdump.in                                    |  5 ++++-
 vtep/ovs-vtep                                               |  6 +++++-
 xenserver/etc_xapi.d_plugins_openvswitch-cfg-update         |  7 ++++++-
 .../opt_xensource_libexec_InterfaceReconfigureVswitch.py    |  7 ++++++-
 xenserver/opt_xensource_libexec_interface-reconfigure       |  6 +++++-
 12 files changed, 74 insertions(+), 14 deletions(-)

diff --git a/ovn/utilities/ovn-docker-overlay-driver b/ovn/utilities/ovn-docker-overlay-driver
index 52de3db..25c45b3 100755
--- a/ovn/utilities/ovn-docker-overlay-driver
+++ b/ovn/utilities/ovn-docker-overlay-driver
@@ -42,7 +42,12 @@ PLUGIN_FILE = "/etc/docker/plugins/openvswitch.spec"
 
 
 def call_popen(cmd):
-    child = subprocess.Popen(cmd, stdout=subprocess.PIPE)
+    creationFlags = 0
+    if sys.platform == 'win32':
+        creationFlags = 0x08000000  # CREATE_NO_WINDOW
+    child = subprocess.Popen(cmd,
+                             stdout=subprocess.PIPE,
+                             creationflags=creationFlags)
     output = child.communicate()
     if child.returncode:
         raise RuntimeError("Fatal error executing %s" % (cmd))
diff --git a/ovn/utilities/ovn-docker-underlay-driver b/ovn/utilities/ovn-docker-underlay-driver
index 2c9c4b6..7905611 100755
--- a/ovn/utilities/ovn-docker-underlay-driver
+++ b/ovn/utilities/ovn-docker-underlay-driver
@@ -51,7 +51,12 @@ VIF_ID = ""
 
 
 def call_popen(cmd):
-    child = subprocess.Popen(cmd, stdout=subprocess.PIPE)
+    creationFlags = 0
+    if sys.platform == 'win32':
+        creationFlags = 0x08000000  # CREATE_NO_WINDOW
+    child = subprocess.Popen(cmd,
+                             stdout=subprocess.PIPE,
+                             creationflags=creationFlags)
     output = child.communicate()
     if child.returncode:
         raise RuntimeError("Fatal error executing %s" % (cmd))
diff --git a/python/ovstest/util.py b/python/ovstest/util.py
index 830feba..8ae4c79 100644
--- a/python/ovstest/util.py
+++ b/python/ovstest/util.py
@@ -23,6 +23,7 @@ import select
 import socket
 import struct
 import signal
+import sys
 import subprocess
 import re
 
@@ -81,10 +82,14 @@ def uname():
 
 def start_process(args):
     try:
+        creationFlags = 0
+        if sys.platform == 'win32':
+            creationFlags = 0x08000000  # CREATE_NO_WINDOW
         p = subprocess.Popen(args,
                              stdin=subprocess.PIPE,
                              stdout=subprocess.PIPE,
-                             stderr=subprocess.PIPE)
+                             stderr=subprocess.PIPE,
+                             creationflags=creationFlags)
         out, err = p.communicate()
         return (p.returncode, out, err)
     except exceptions.OSError:
@@ -186,9 +191,13 @@ def start_local_server(port):
     and blocks till the spawned ovs-test server is ready to accept XML RPC
     connections.
     """
+    creationFlags = 0
+    if sys.platform == 'win32':
+        creationFlags = 0x08000000  # CREATE_NO_WINDOW
     p = subprocess.Popen(["ovs-test", "-s", str(port)],
                          stdout=subprocess.PIPE, stderr=subprocess.PIPE,
-                         preexec_fn=sigint_intercept)
+                         preexec_fn=sigint_intercept,
+                         creationflags=creationFlags)
     fcntl.fcntl(p.stdout.fileno(), fcntl.F_SETFL,
         fcntl.fcntl(p.stdout.fileno(), fcntl.F_GETFL) | os.O_NONBLOCK)
 
diff --git a/utilities/bugtool/ovs-bugtool.in b/utilities/bugtool/ovs-bugtool.in
index 963c50c..905f598 100755
--- a/utilities/bugtool/ovs-bugtool.in
+++ b/utilities/bugtool/ovs-bugtool.in
@@ -775,8 +775,12 @@ def module_info(cap):
 
 
 def multipathd_topology(cap):
+    creationFlags = 0
+    if sys.platform == 'win32':
+        creationFlags = 0x08000000  # CREATE_NO_WINDOW
     pipe = Popen([MULTIPATHD, '-k'], bufsize=1, stdin=PIPE,
-                     stdout=PIPE, stderr=dev_null)
+                     stdout=PIPE, stderr=dev_null,
+                     creationflags=creationFlags)
     stdout, stderr = pipe.communicate('show topology')
 
     return stdout
@@ -1236,9 +1240,13 @@ class ProcOutput(object):
         try:
             if ProcOutput.debug:
                 output_ts("Starting '%s'" % self.cmdAsStr())
+            creationFlags = 0
+            if sys.platform == 'win32':
+                creationFlags = 0x08000000  # CREATE_NO_WINDOW
             self.proc = Popen(self.command, bufsize=self.bufsize,
                               stdin=dev_null, stdout=PIPE, stderr=dev_null,
-                              shell=isinstance(self.command, str))
+                              shell=isinstance(self.command, str),
+                              creationflags=creationFlags)
             old = fcntl.fcntl(self.proc.stdout.fileno(), fcntl.F_GETFD)
             fcntl.fcntl(self.proc.stdout.fileno(),
                         fcntl.F_SETFD, old | fcntl.FD_CLOEXEC)
diff --git a/utilities/ovs-dev.py b/utilities/ovs-dev.py
index 9ce0f04..a52e5a5 100755
--- a/utilities/ovs-dev.py
+++ b/utilities/ovs-dev.py
@@ -45,7 +45,11 @@ def _sh(*args, **kwargs):
     print("------> " + " ".join(args))
     shell = len(args) == 1
     if kwargs.get("capture", False):
-        proc = subprocess.Popen(args, stdout=subprocess.PIPE, shell=shell)
+        creationFlags = 0
+        if sys.platform == 'win32':
+            creationFlags = 0x08000000  # CREATE_NO_WINDOW
+        proc = subprocess.Popen(args, stdout=subprocess.PIPE, shell=shell,
+                                creationflags=creationFlags)
         return proc.stdout.readlines()
     elif kwargs.get("check", True):
         subprocess.check_call(args, shell=shell)
diff --git a/utilities/ovs-dpctl-top.in b/utilities/ovs-dpctl-top.in
index 401a80e..79e5eb7 100755
--- a/utilities/ovs-dpctl-top.in
+++ b/utilities/ovs-dpctl-top.in
@@ -336,8 +336,12 @@ def top_input_get(args):
         cmd += ["ssh", args.host]
     cmd += ["ovs-dpctl", "dump-flows"]
 
+    creationFlags = 0
+    if sys.platform == 'win32':
+        creationFlags = 0x08000000  # CREATE_NO_WINDOW
     return subprocess.Popen(cmd, stderr=subprocess.STDOUT,
-                            stdout=subprocess.PIPE).stdout
+                            stdout=subprocess.PIPE,
+                            creationflags=creationFlags).stdout
 
 
 def args_get():
diff --git a/utilities/ovs-parse-backtrace.in b/utilities/ovs-parse-backtrace.in
index c8a4385..52e9a6c 100755
--- a/utilities/ovs-parse-backtrace.in
+++ b/utilities/ovs-parse-backtrace.in
@@ -35,8 +35,12 @@ def addr2line(binary, addr):
 
     cmd = ["addr2line", "-f", "-s", "-e", binary, addr]
     try:
+        creationFlags = 0
+        if sys.platform == 'win32':
+            creationFlags = 0x08000000  # CREATE_NO_WINDOW
         proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
-                                stderr=subprocess.PIPE)
+                                stderr=subprocess.PIPE,
+                                creationflags=creationFlags)
         lines = proc.stdout.readlines()
         failed = proc.returncode
     except OSError:
diff --git a/utilities/ovs-tcpdump.in b/utilities/ovs-tcpdump.in
index a6e4ada..91ea324 100755
--- a/utilities/ovs-tcpdump.in
+++ b/utilities/ovs-tcpdump.in
@@ -43,8 +43,11 @@ def _doexec(*args, **kwargs):
     """Executes an application and returns a set of pipes"""
 
     shell = len(args) == 1
+    creationFlags = 0
+    if sys.platform == 'win32':
+        creationFlags = 0x08000000  # CREATE_NO_WINDOW
     proc = subprocess.Popen(args, stdout=subprocess.PIPE, shell=shell,
-                            bufsize=0)
+                            bufsize=0, creationflags=creationFlags)
     return proc
 
 
diff --git a/vtep/ovs-vtep b/vtep/ovs-vtep
index 9a5aa3d..fd652d4 100755
--- a/vtep/ovs-vtep
+++ b/vtep/ovs-vtep
@@ -53,7 +53,11 @@ bfd_ref = {}
 
 def call_prog(prog, args_list):
     cmd = [prog, "-vconsole:off"] + args_list
-    output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()
+    creationFlags = 0
+    if sys.platform == 'win32':
+        creationFlags = 0x08000000  # CREATE_NO_WINDOW
+    output = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+                              creationflags=creationFlags).communicate()
     if len(output) == 0 or output[0] is None:
         output = ""
     else:
diff --git a/xenserver/etc_xapi.d_plugins_openvswitch-cfg-update b/xenserver/etc_xapi.d_plugins_openvswitch-cfg-update
index e7404e3..2464454 100755
--- a/xenserver/etc_xapi.d_plugins_openvswitch-cfg-update
+++ b/xenserver/etc_xapi.d_plugins_openvswitch-cfg-update
@@ -24,6 +24,7 @@
 import XenAPIPlugin
 import os
 import subprocess
+import sys
 import syslog
 import re
 
@@ -230,7 +231,11 @@ def setControllerCfg(controller):
 
 def vswitchCfgQuery(action_args):
     cmd = [vsctl, '-vconsole:off'] + action_args
-    output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()
+    creationFlags = 0
+    if sys.platform == 'win32':
+        creationFlags = 0x08000000  # CREATE_NO_WINDOW
+    output = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+                              creationflags=creationFlags).communicate()
     if len(output) == 0 or output[0] is None:
         output = ''
     else:
diff --git a/xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py b/xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py
index c65fb3d..3b1e338 100644
--- a/xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py
+++ b/xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py
@@ -15,6 +15,7 @@ from InterfaceReconfigure import *
 import os
 import re
 import subprocess
+import sys
 
 #
 # Bare Network Devices -- network devices without IP configuration
@@ -722,7 +723,11 @@ class DatapathVswitch(Datapath):
 def vswitchCfgQuery(action_args):
     cmd = ['%s/usr/bin/ovs-vsctl' % root_prefix(),
            '-vconsole:off'] + action_args
-    output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()
+    creationFlags = 0
+    if sys.platform == 'win32':
+        creationFlags = 0x08000000  # CREATE_NO_WINDOW
+    output = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+                              creationflags=creationFlags).communicate()
     if len(output) == 0 or output[0] == None:
         output = ""
     else:
diff --git a/xenserver/opt_xensource_libexec_interface-reconfigure b/xenserver/opt_xensource_libexec_interface-reconfigure
index ea4a742..caf9819 100755
--- a/xenserver/opt_xensource_libexec_interface-reconfigure
+++ b/xenserver/opt_xensource_libexec_interface-reconfigure
@@ -483,7 +483,11 @@ def action_rewrite():
 def action_force_rewrite(bridge, config):
     def getUUID():
         import subprocess
-        uuid,_ = subprocess.Popen(['uuidgen'], stdout = subprocess.PIPE).communicate()
+        creationFlags = 0
+        if sys.platform == 'win32':
+            creationFlags = 0x08000000  # CREATE_NO_WINDOW
+        uuid,_ = subprocess.Popen(['uuidgen'], stdout = subprocess.PIPE,
+                                  creationflags=creationFlags).communicate()
         return uuid.strip()
 
     # Notes:
-- 
2.10.0.windows.1


More information about the dev mailing list