summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen D. Huston <shuston@apache.org>2010-10-28 01:05:16 +0000
committerStephen D. Huston <shuston@apache.org>2010-10-28 01:05:16 +0000
commit5e9bd057a21f3d29d9ed3c4879a8b952dba4bae0 (patch)
tree4334c5156cc8d0f8b522725f62b3c953e8b5544e
parent8877175399d8e36a39860d994b183dc79a46ff8b (diff)
downloadqpid-python-5e9bd057a21f3d29d9ed3c4879a8b952dba4bae0.tar.gz
Ported to work on Windows; uses subprocess, not popen3. Resolves QPID-2492.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1028156 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/python/qpid/brokertest.py45
1 files changed, 33 insertions, 12 deletions
diff --git a/qpid/python/qpid/brokertest.py b/qpid/python/qpid/brokertest.py
index 4571712ca6..ab779fe8d2 100644
--- a/qpid/python/qpid/brokertest.py
+++ b/qpid/python/qpid/brokertest.py
@@ -20,7 +20,7 @@
# Support library for tests that start multiple brokers, e.g. cluster
# or federation
-import os, signal, string, tempfile, popen2, socket, threading, time, imp, re
+import os, signal, string, tempfile, subprocess, socket, threading, time, imp, re
import qpid, traceback
from qpid import connection, messaging, util
from qpid.compat import format_exc
@@ -104,9 +104,8 @@ def retry(function, timeout=10, delay=.01):
delay *= 2
return True
-class Popen(popen2.Popen3):
+class Popen(subprocess.Popen):
"""
- Similar to subprocess.Popen but using popen2 classes for portability.
Can set and verify expectation of process status at end of test.
Dumps command line, stdout, stderr to data dir for debugging.
"""
@@ -154,12 +153,12 @@ class Popen(popen2.Popen3):
self.cmd = [ str(x) for x in cmd ]
self.returncode = None
self.expect = expect
- popen2.Popen3.__init__(self, self.cmd, True)
+ subprocess.Popen.__init__(self, self.cmd, 0, None, subprocess.PIPE, subprocess.PIPE, subprocess.PIPE)
self.pname = "%s-%d" % (os.path.split(self.cmd[0])[1], self.pid)
msg = "Process %s" % self.pname
- self.stdin = ExceptionWrapper(self.tochild, msg)
- self.stdout = Popen.OutStream(self.fromchild, self.outfile("out"), msg)
- self.stderr = Popen.OutStream(self.childerr, self.outfile("err"), msg)
+ self.stdin = ExceptionWrapper(self.stdin, msg)
+ self.stdout = Popen.OutStream(self.stdout, self.outfile("out"), msg)
+ self.stderr = Popen.OutStream(self.stderr, self.outfile("err"), msg)
f = open(self.outfile("cmd"), "w")
try: f.write(self.cmd_str())
finally: f.close()
@@ -196,7 +195,18 @@ class Popen(popen2.Popen3):
except: pass
elif self.expect == EXPECT_RUNNING:
try:
- self.kill()
+ self.terminate()
+ except AttributeError:
+ # no terminate method to Popen..
+ try:
+ import signal
+ os.kill( self.pid , signal.SIGTERM)
+ except AttributeError:
+ # no os.kill, using taskkill.. (Windows only)
+ try:
+ os.popen('TASKKILL /PID ' +str(self.pid) + ' /F')
+ except:
+ print " ERROR: could not terminate process."
except:
self.unexpected("expected running, exit code %d" % self.wait())
else:
@@ -227,7 +237,7 @@ class Popen(popen2.Popen3):
def poll(self):
if self.returncode is None:
- ret = popen2.Popen3.poll(self)
+ ret = subprocess.poll(self)
if (ret != -1):
self.returncode = ret
self._cleanup()
@@ -236,7 +246,7 @@ class Popen(popen2.Popen3):
def wait(self):
if self.returncode is None:
self.drain()
- try: self.returncode = popen2.Popen3.wait(self)
+ try: self.returncode = subprocess.Popen.wait(self)
except OSError,e: raise OSError("Wait failed %s: %s"%(self.pname, e))
self._cleanup()
return self.returncode
@@ -283,6 +293,14 @@ class Broker(Popen):
self.test = test
self._port=port
+ if BrokerTest.store_lib:
+ args = args + ['--load-module', BrokerTest.store_lib]
+ if BrokerTest.sql_store_lib:
+ args = args + ['--load-module', BrokerTest.sql_store_lib]
+ args = args + ['--catalog', BrokerTest.sql_catalog]
+ if BrokerTest.sql_clfs_store_lib:
+ args = args + ['--load-module', BrokerTest.sql_clfs_store_lib]
+ args = args + ['--catalog', BrokerTest.sql_catalog]
cmd = [BrokerTest.qpidd_exec, "--port", port, "--no-module-dir"] + args
if not "--auth" in args: cmd.append("--auth=no")
if wait != None:
@@ -443,13 +461,16 @@ class BrokerTest(TestCase):
"""
# Environment settings.
- qpidd_exec = checkenv("QPIDD_EXEC")
+ qpidd_exec = os.path.abspath(checkenv("QPIDD_EXEC"))
cluster_lib = os.getenv("CLUSTER_LIB")
xml_lib = os.getenv("XML_LIB")
qpid_config_exec = os.getenv("QPID_CONFIG_EXEC")
qpid_route_exec = os.getenv("QPID_ROUTE_EXEC")
receiver_exec = os.getenv("RECEIVER_EXEC")
sender_exec = os.getenv("SENDER_EXEC")
+ sql_store_lib = os.getenv("STORE_SQL_LIB")
+ sql_clfs_store_lib = os.getenv("STORE_SQL_CLFS_LIB")
+ sql_catalog = os.getenv("STORE_CATALOG")
store_lib = os.getenv("STORE_LIB")
test_store_lib = os.getenv("TEST_STORE_LIB")
rootdir = os.getcwd()
@@ -468,7 +489,7 @@ class BrokerTest(TestCase):
for p in self.stopem:
try: p.stop()
except Exception, e: err.append(str(e))
-
+ os.chdir(self.rootdir)
if err: raise Exception("Unexpected process status:\n "+"\n ".join(err))
def cleanup_stop(self, stopable):