Skip to content
Browse files

Merge branch 'readconfig' of git://github.com/sambrightman/zk-smoketest

Conflicts:
	zk-smoketest.py
  • Loading branch information...
2 parents fd120ee + 8592a04 commit 9a7281b0cab861ee69b1ec63dc2c29ed79416a67 @phunt committed
Showing with 57 additions and 10 deletions.
  1. +19 −5 README.textile
  2. +20 −4 zk-latencies.py
  3. +18 −1 zk-smoketest.py
View
24 README.textile
@@ -38,11 +38,12 @@ h3. Usage
Usage: zk-smoketest.py [options]
Options:
- -h, --help show this help message and exit
- --servers=SERVERS comma separated list of host:port (default localhost:2181)
- --timeout=TIMEOUT session timeout in milliseconds (default 5000)
- -v, --verbose verbose output, include more detail
- -q, --quiet quiet output, basically just success/failure
+ -h, --help show this help message and exit
+ --servers=SERVERS comma separated list of host:port (default localhost:2181)
+ --config=CONFIGFILE zookeeper configuration file to lookup servers from
+ --timeout=TIMEOUT session timeout in milliseconds (default 5000)
+ -v, --verbose verbose output, include more detail
+ -q, --quiet quiet output, basically just success/failure
</pre>
The exit code is 0 on success, non-0 exit code on failure.
@@ -68,6 +69,12 @@ Say you have a ZooKeeper ensemble with 5 servers (host1,host2,host3,host4,host5,
PYTHONPATH=lib.linux-i686-2.6 LD_LIBRARY_PATH=lib.linux-i686-2.6 ./zk-smoketest.py --servers "host1:2181,host2:2181,host3:2181,host4:2181,host5:2181"
</code>
+or, for a ZK-style configuration file:
+
+<code>
+PYTHONPATH=lib.linux-i686-2.6 LD_LIBRARY_PATH=lib.linux-i686-2.6 ./zk-smoketest.py --config zk.conf
+</code>
+
h2. zk-latencies.py
This tool uses the ZooKeeper python binding to test various operation latencies. In general the script does the following:
@@ -92,6 +99,7 @@ Options:
localhost:2181)
--cluster=CLUSTER comma separated list of host:port, test as a cluster,
alternative to --servers
+ --config=CONFIGFILE zookeeper configuration file to lookup servers from
--timeout=TIMEOUT session timeout in milliseconds (default 5000)
--root_znode=ROOT_ZNODE
root for the test, will be created as part of test
@@ -133,6 +141,12 @@ Say you have a ZooKeeper ensemble with 5 servers (host1,host2,host3,host4,host5,
PYTHONPATH=lib.linux-i686-2.6 LD_LIBRARY_PATH=lib.linux-i686-2.6 ./zk-latencies.py --servers "host1:2181,host2:2181,host3:2181,host4:2181,host5:2181" --znode_count=100 --znode_size=100 --synchronous
</code>
+or, for a ZK-style configuration file:
+
+<code>
+PYTHONPATH=lib.linux-i686-2.6 LD_LIBRARY_PATH=lib.linux-i686-2.6 ./zk-latencies.py --config zk.conf --znode_count=100 --znode_size=100 --synchronous
+</code>
+
Result:
<pre>
View
24 zk-latencies.py
@@ -28,6 +28,9 @@
default="localhost:2181", help="comma separated list of host:port (default %default), test each in turn")
parser.add_option("", "--cluster", dest="cluster",
default=None, help="comma separated list of host:port, test as a cluster, alternative to --servers")
+parser.add_option("", "--config",
+ dest="configfile", default=None,
+ help="zookeeper configuration file to lookup cluster from")
parser.add_option("", "--timeout", dest="timeout", type="int",
default=5000, help="session timeout in milliseconds (default %default)")
parser.add_option("", "--root_znode", dest="root_znode",
@@ -261,12 +264,25 @@ def func():
"notif %7d watches" % (options.watch_multiple * options.znode_count),
(options.watch_multiple * options.znode_count))
-if __name__ == '__main__':
- data = options.znode_size * "x"
+def read_zk_config(filename):
+ with open(filename) as f:
+ config = dict(tuple(line.rstrip().split('=', 1)) for line in f if line.rstrip())
+ return config
+
+def get_zk_servers(filename):
if options.cluster:
- servers = [options.cluster]
+ return [options.cluster]
+ elif filename:
+ config = read_zk_config(options.configfile)
+ client_port = config['clientPort']
+ return [",".join("%s:%s" % (v.split(':', 1)[0], client_port)
+ for k, v in config.items() if k.startswith('server.'))]
else:
- servers = options.servers.split(",")
+ return options.servers.split(",")
+
+if __name__ == '__main__':
+ data = options.znode_size * "x"
+ servers = get_zk_servers(options.configfile)
# create all the sessions first to ensure that all servers are
# at least available & quorum has been formed. otw this will
View
19 zk-smoketest.py
@@ -26,6 +26,9 @@
parser = OptionParser(usage=usage)
parser.add_option("", "--servers", dest="servers",
default="localhost:2181", help="comma separated list of host:port (default %default)")
+parser.add_option("", "--config",
+ dest="configfile", default=None,
+ help="zookeeper configuration file to lookup servers from")
parser.add_option("", "--timeout", dest="timeout", type="int",
default=5000, help="session timeout in milliseconds (default %default)")
parser.add_option("-v", "--verbose",
@@ -48,8 +51,22 @@ def __str__(self):
return repr(self.value)
+def read_zk_config(filename):
+ with open(filename) as f:
+ config = dict(tuple(line.rstrip().split('=', 1)) for line in f if line.rstrip())
+ return config
+
+def get_zk_servers(filename):
+ if filename:
+ config = read_zk_config(options.configfile)
+ client_port = config['clientPort']
+ return ["%s:%s" % (v.split(':', 1)[0], client_port)
+ for k, v in config.items() if k.startswith('server.')]
+ else:
+ return options.servers.split(",")
+
if __name__ == '__main__':
- servers = options.servers.split(",")
+ servers = get_zk_servers(options.configfile)
# create all the sessions first to ensure that all servers are
# at least available & quorum has been formed. otw this will

0 comments on commit 9a7281b

Please sign in to comment.
Something went wrong with that request. Please try again.