diff options
author | Kim van der Riet <kpvdr@apache.org> | 2009-05-26 15:30:47 +0000 |
---|---|---|
committer | Kim van der Riet <kpvdr@apache.org> | 2009-05-26 15:30:47 +0000 |
commit | 03fdb8e9e281cc317099fdcf67d05098b9d38131 (patch) | |
tree | 2805fbfef193089797071c87f276b919414c2c77 /python/qpid/testlib.py | |
parent | fdba1a9ed5074286fe58ebf9be543bbebea0bb79 (diff) | |
download | qpid-python-03fdb8e9e281cc317099fdcf67d05098b9d38131.tar.gz |
Added installable python cluster tests that can be run from an external store build/test environment and can test persistent clusters.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@778751 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'python/qpid/testlib.py')
-rw-r--r-- | python/qpid/testlib.py | 195 |
1 files changed, 1 insertions, 194 deletions
diff --git a/python/qpid/testlib.py b/python/qpid/testlib.py index ac81b6d240..25137769bf 100644 --- a/python/qpid/testlib.py +++ b/python/qpid/testlib.py @@ -21,7 +21,7 @@ # Support library for qpid python tests. # -import sys, re, unittest, os, signal, random, logging, traceback +import sys, re, unittest, os, random, logging, traceback import qpid.client, qpid.spec, qmf.console import Queue from fnmatch import fnmatch @@ -429,196 +429,3 @@ class TestBase010(unittest.TestCase): session.message_subscribe(**keys) session.message_flow(destination=consumer_tag, unit=0, value=0xFFFFFFFFL) session.message_flow(destination=consumer_tag, unit=1, value=0xFFFFFFFFL) - - -class TestBaseCluster(unittest.TestCase): - """ - Base class for cluster tests. Provides methods for starting and stopping clusters and cluster nodes. - """ - _tempStoreDir = os.getenv("TMP_STORE_DIR") - _qpidd = os.getenv("QPIDD") - _storeLib = os.getenv("LIBSTORE") - _clusterLib = os.getenv("LIBCLUSTER") - - # --- Cluster helper functions --- - - """ - _clusterDict is a dictionary of clusters: - key = cluster name (string) - val = dictionary of node numbers: - key = node number (int) - val = tuple containing (pid, port) - For example, two clusters "TestCluster0" and "TestCluster1" containing several nodes would look as follows: - {"TestCluster0": {0: (pid0-0, port0-0), 1: (pid0-1, port0-1), ...}, "TestCluster1": {0: (pid1-0, port1-0), 1: (pid1-1, port1-1), ...}} - where pidm-n and portm-n are the int pid and port for TestCluster m node n respectively. - """ - _clusterDict = {} - - """Index for (pid, port) tuple""" - PID = 0 - PORT = 1 - - def startBroker(self, qpiddArgs, logFile = None): - """Start a single broker daemon, returns tuple (pid, port)""" - if self._qpidd == None: - raise Exception("Environment variable QPIDD is not set") - cmd = "%s --daemon --port=0 %s" % (self._qpidd, qpiddArgs) - portStr = os.popen(cmd).read() - if len(portStr) == 0: - err = "Broker daemon startup failed." - if logFile != None: - err += " See log file %s" % logFile - raise Exception(err) - port = int(portStr) - pid = int(os.popen("%s -p %d -c" % (self._qpidd, port)).read()) - #print "started broker: pid=%d, port=%d" % (pid, port) - return (pid, port) - - def createClusterNode(self, nodeNumber, clusterName): - """Create a node and add it to the named cluster""" - if self._tempStoreDir == None: - raise Exception("Environment variable TMP_STORE_DIR is not set") - if self._storeLib == None: - raise Exception("Environment variable LIBSTORE is not set") - if self._clusterLib == None: - raise Exception("Environment variable LIBCLUSTER is not set") - name = "%s-%d" % (clusterName, nodeNumber) - dataDir = os.path.join(self._tempStoreDir, "cluster", name) - logFile = "%s.log" % dataDir - args = "--no-module-dir --load-module=%s --load-module=%s --data-dir=%s --cluster-name=%s --auth=no --log-enable=error+ --log-to-file=%s" % \ - (self._storeLib, self._clusterLib, dataDir, clusterName, logFile) - self._clusterDict[clusterName][nodeNumber] = self.startBroker(args, logFile) - - def createCluster(self, clusterName, numberNodes): - """Create a cluster containing an initial number of nodes""" - self._clusterDict[clusterName] = {} - for n in range(0, numberNodes): - self.createClusterNode(n, clusterName) - - def getTupleList(self): - """Get list of (pid, port) tuples of all known cluster brokers""" - tList = [] - for l in self._clusterDict.itervalues(): - for t in l.itervalues(): - tList.append(t) - return tList - - def getNumBrokers(self): - """Get total number of brokers in all known clusters""" - return len(self.getTupleList()) - - def checkNumBrokers(self, expected): - """Check that the total number of brokers in all known clusters is the expected value""" - if self.getNumBrokers() != expected: - raise Exception("Unexpected number of brokers: expected %d, found %d" % (expected, self.getNumBrokers())) - - def getClusterTupleList(self, clusterName): - """Get list of (pid, port) tuples of all nodes in named cluster""" - return self._clusterDict[clusterName].values() - - def getNumClusterBrokers(self, clusterName): - """Get total number of brokers in named cluster""" - return len(self.getClusterTupleList(clusterName)) - - def getNodeTuple(self, nodeNumber, clusterName): - """Get the (pid, port) tuple for the given cluster node""" - return self._clusterDict[clusterName][nodeNumber] - - def checkNumClusterBrokers(self, clusterName, expected): - """Check that the total number of brokers in the named cluster is the expected value""" - if self.getNumClusterBrokers(clusterName) != expected: - raise Exception("Unexpected number of brokers in cluster %s: expected %d, found %d" % \ - (clusterName, expected, self.getNumClusterBrokers(clusterName))) - - def clusterExists(self, clusterName): - """ Return True if clusterName exists, False otherwise""" - return clusterName in self._clusterDict.keys() - - def clusterNodeExists(self, clusterName, nodeNumber): - """ Return True if nodeNumber in clusterName exists, False otherwise""" - if clusterName in self._clusterDict.keys(): - return nodeNumber in self._clusterDict[nodeName] - return False - - def createCheckCluster(self, clusterName, size): - """Create a cluster using the given name and size, then check the number of brokers""" - self.createCluster(clusterName, size) - self.checkNumClusterBrokers(clusterName, size) - - # Kill cluster nodes using signal 9 - - def killNode(self, nodeNumber, clusterName, updateDict = True): - """Kill the given node in the named cluster using kill -9""" - pid = self.getNodeTuple(nodeNumber, clusterName)[self.PID] - os.kill(pid, signal.SIGTERM) - #print "killed broker: pid=%d" % pid - if updateDict: - del(self._clusterDict[clusterName][nodeNumber]) - - def killCluster(self, clusterName, updateDict = True): - """Kill all nodes in the named cluster""" - for n in self._clusterDict[clusterName].iterkeys(): - self.killNode(n, clusterName, False) - if updateDict: - del(self._clusterDict[clusterName]) - - def killClusterCheck(self, clusterName): - """Kill the named cluster and check that the name is removed from the cluster dictionary""" - self.killCluster(clusterName) - if self.clusterExists(clusterName): - raise Exception("Unable to kill cluster %s; %d nodes still exist" % \ - (clusterName, self.getNumClusterBrokers(clusterName))) - - def killAllClusters(self): - """Kill all known clusters""" - for n in self._clusterDict.iterkeys(): - self.killCluster(n, False) - self._clusterDict.clear() - - def killAllClustersCheck(self): - """Kill all known clusters and check that the cluster dictionary is empty""" - self.killAllClusters() - self.checkNumBrokers(0) - - # Stop cluster nodes using qpidd -q - - def stopNode(self, nodeNumber, clusterName, updateDict = True): - """Stop the given node in the named cluster using qpidd -q""" - port = self.getNodeTuple(nodeNumber, clusterName)[self.PORT] - ret = os.spawnl(os.P_WAIT, self._qpidd, self._qpidd, "--port=%d" % port, "-q") - if ret != 0: - raise Exception("stop_node(): cluster=\"%s\" nodeNumber=%d pid=%d port=%d: qpidd -q returned %d" % \ - (clusterName, nodeNumber, self.getNodeTuple(nodeNumber, clusterName)[self.PID], port, ret)) - #print "stopped broker: port=%d" % port - if updateDict: - del(self._clusterDict[clusterName][nodeNumber]) - - def stopAllClusters(self): - """Stop all known clusters""" - for n in self._clusterDict.iterkeys(): - self.stopCluster(n, False) - self._clusterDict.clear() - - - def stopCluster(self, clusterName, updateDict = True): - """Stop all nodes in the named cluster""" - for n in self._clusterDict[clusterName].iterkeys(): - self.stopNode(n, clusterName, False) - if updateDict: - del(self._clusterDict[clusterName]) - - def stopCheckCluster(self, clusterName): - """Stop the named cluster and check that the name is removed from the cluster dictionary""" - self.stopCluster(clusterName) - if self.clusterExists(clusterName): - raise Exception("Unable to kill cluster %s; %d nodes still exist" % (clusterName, self.getNumClusterBrokers(clusterName))) - def stopCheckAll(self): - """Kill all known clusters and check that the cluster dictionary is empty""" - self.stopAllClusters() - self.checkNumBrokers(0) - - def setUp(self): - pass - - def tearDown(self): - pass |