Author: justi9
Date: 2008-12-12 13:51:44 -0500 (Fri, 12 Dec 2008)
New Revision: 2993
Modified:
mgmt/trunk/mint/bin/mint-test
mgmt/trunk/mint/python/mint/tools.py
Log:
Fix mint-test, and make it work like the other mint commands
Modified: mgmt/trunk/mint/bin/mint-test
===================================================================
--- mgmt/trunk/mint/bin/mint-test 2008-12-12 17:46:11 UTC (rev 2992)
+++ mgmt/trunk/mint/bin/mint-test 2008-12-12 18:51:44 UTC (rev 2993)
@@ -1,84 +1,14 @@
-#!/usr/bin/env python
+#!/usr/bin/python
import sys, os, logging
-from time import sleep
-from mint import *
+from mint.tools import MintTestTool
-def usage():
- print "Usage: mint-test [DATABASE-URI] [BROKER-ADDRESSES...]"
- print "Example: mint-test postgresql://cumin@localhost/cumin
localhost:5672"
- sys.exit(1)
-
-def do_main(uri, spec, hostports):
- model = MintModel(uri, spec, debug=False)
- model.check()
- model.init()
-
- conns = list()
-
- for host, port in hostports:
- conn = BrokerConnection(model, host, port)
- conns.append(conn)
-
- model.start()
- try:
- try:
- for conn in conns:
- conn.open()
-
- while True:
- sleep(5)
- finally:
- for conn in conns:
- try:
- conn.close()
- except:
- pass
- finally:
- model.stop()
-
def main():
- root = logging.getLogger("mint")
- root.setLevel(logging.DEBUG)
+ MintTestTool("mint-test").main()
- h = logging.StreamHandler()
- h.setLevel(logging.DEBUG)
- root.addHandler(h)
-
- if "-h" in sys.argv or "--help" in sys.argv:
- usage()
-
+if __name__ == "__main__":
try:
- uri = sys.argv[1]
- except IndexError:
- uri = "postgresql://cumin@localhost/cumin"
-
- if uri == "-":
- uri = "postgresql://cumin@localhost/cumin"
-
- addrs = sys.argv[2:]
-
- if not addrs:
- addrs = ["localhost:5672"]
-
- hostports = list()
-
- for addr in addrs:
- try:
- host, port = addr.split(":")
- hostports.append((host, int(port)))
- except ValueError, e:
- print "Error: Cannot parse '%s': %s" % (addr, e)
- sys.exit(1)
-
- spec = os.environ.get("AMQP_SPEC",
- os.path.normpath("/usr/share/amqp/amqp.0-10.xml"))
-
- try:
- do_main(uri, spec, hostports)
+ main()
except KeyboardInterrupt:
pass
-
-if __name__ == "__main__":
- main()
Modified: mgmt/trunk/mint/python/mint/tools.py
===================================================================
--- mgmt/trunk/mint/python/mint/tools.py 2008-12-12 17:46:11 UTC (rev 2992)
+++ mgmt/trunk/mint/python/mint/tools.py 2008-12-12 18:51:44 UTC (rev 2993)
@@ -65,9 +65,15 @@
if "debug" in opts:
enable_logging("mint", "debug", sys.stderr)
- self.do_run(opts, args)
+ data = opts.get("data",
"postgresql://cumin@localhost/cumin")
+ freq = int(opts.get("expire-frequency", 600))
+ threshold = int(opts.get("expire-threshold", 24 * 3600))
- def do_run(self, opts, args):
+ model = MintModel(data, freq, threshold, debug="debug" in opts)
+
+ self.do_run(opts, args, model)
+
+ def do_run(self, opts, args, model):
raise Exception("Not implemented")
def main(self):
@@ -82,15 +88,7 @@
def init(self):
super(MintServerTool, self).init()
- def do_run(self, opts, args):
- ddef = "postgresql://cumin@localhost/cumin"
- freqDefault = 600 # 10 minutes
- thresholdDefault = 24 * 3600 # 1 day
- model = MintModel(opts.get("data", ddef),
- int(opts.get("expire-frequency", freqDefault)),
- int(opts.get("expire-threshold", thresholdDefault)),
- debug="debug" in opts)
-
+ def do_run(self, opts, args, model):
model.check()
model.init()
model.start()
@@ -104,6 +102,31 @@
finally:
model.stop()
+class MintTestTool(BaseMintTool):
+ def __init__(self, name):
+ super(MintTestTool, self).__init__(name)
+
+ def do_run(self, opts, args, model):
+ model.pollRegistrations = False
+
+ model.check()
+ model.init()
+ model.start()
+
+ added = list()
+
+ try:
+ for arg in args[1:]:
+ added.append(model.addBroker(arg))
+
+ while True:
+ sleep(2)
+ finally:
+ for broker in added:
+ model.delBroker(broker)
+
+ model.stop()
+
class MintBenchTool(BaseMintTool):
def __init__(self, name):
super(MintBenchTool, self).__init__(name)
@@ -111,14 +134,7 @@
def init(self):
super(MintBenchTool, self).init()
- def do_run(self, opts, args):
- ddef = "postgresql://cumin@localhost/cumin"
- freqDefault = 600 # 10 minutes
- thresholdDefault = 24 * 3600 # 1 day
- model = MintModel(opts.get("data", ddef),
- int(opts.get("expire-frequency", freqDefault)),
- int(opts.get("expire-threshold", thresholdDefault)),
- debug="debug" in opts)
+ def do_run(self, opts, args, model):
model.pollRegistrations = False
model.check()
@@ -154,4 +170,3 @@
model.delBroker(broker)
model.stop()
-