summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-07-07 21:27:42 +0000
committerGerrit Code Review <review@openstack.org>2016-07-07 21:27:42 +0000
commit3a2ed8a755737f34bf4d9842bb44404cc40ecee5 (patch)
tree252c061e15420ca6588e0c57847213816bfbb094
parentd37222ded0bc13311a347e8a8e0e8369bf653e9e (diff)
parenta0dca6ae128ea85213917e9141e1d4af52490711 (diff)
Merge "Allow testing with external zookeeper"0.3.0
-rw-r--r--nodepool/tests/__init__.py53
-rw-r--r--nodepool/tests/test_builder.py5
-rw-r--r--tox.ini1
3 files changed, 55 insertions, 4 deletions
diff --git a/nodepool/tests/__init__.py b/nodepool/tests/__init__.py
index ab4b7a9..afae79e 100644
--- a/nodepool/tests/__init__.py
+++ b/nodepool/tests/__init__.py
@@ -29,6 +29,7 @@ import time
29 29
30import fixtures 30import fixtures
31import gear 31import gear
32import kazoo.client
32import testresources 33import testresources
33import testtools 34import testtools
34 35
@@ -116,6 +117,24 @@ class ZookeeperServerFixture(fixtures.Fixture):
116 def setUp(self): 117 def setUp(self):
117 super(ZookeeperServerFixture, self).setUp() 118 super(ZookeeperServerFixture, self).setUp()
118 119
120 if 'NODEPOOL_ZK_HOST' in os.environ:
121 if ':' in os.environ['NODEPOOL_ZK_HOST']:
122 host, port = os.environ['NODEPOOL_ZK_HOST'].split(':')
123 else:
124 host = os.environ['NODEPOOL_ZK_HOST']
125 port = None
126
127 self.zookeeper_host = host
128
129 if not port:
130 self.zookeeper_port = 2181
131 else:
132 self.zookeeper_port = int(port)
133
134 return
135
136 self.zookeeper_host = '127.0.0.1'
137
119 # Get the local port range, we're going to pick one at a time 138 # Get the local port range, we're going to pick one at a time
120 # at random to try. 139 # at random to try.
121 with open('/proc/sys/net/ipv4/ip_local_port_range') as f: 140 with open('/proc/sys/net/ipv4/ip_local_port_range') as f:
@@ -500,4 +519,38 @@ class ZKTestCase(BaseTestCase):
500 super(ZKTestCase, self).setUp() 519 super(ZKTestCase, self).setUp()
501 f = ZookeeperServerFixture() 520 f = ZookeeperServerFixture()
502 self.useFixture(f) 521 self.useFixture(f)
522 self.zookeeper_host = f.zookeeper_host
503 self.zookeeper_port = f.zookeeper_port 523 self.zookeeper_port = f.zookeeper_port
524 self.chroot_path = "/nodepool_test/%s" % self.getUniqueInteger()
525
526 # Ensure the chroot path exists and clean up an pre-existing znodes
527 _tmp_client = kazoo.client.KazooClient(
528 hosts='%s:%s' % (self.zookeeper_host, self.zookeeper_port))
529 _tmp_client.start()
530
531 if _tmp_client.exists(self.chroot_path):
532 _tmp_client.delete(self.chroot_path, recursive=True)
533
534 _tmp_client.ensure_path(self.chroot_path)
535 _tmp_client.stop()
536
537 # Create a chroot'ed client
538 self.zkclient = kazoo.client.KazooClient(
539 hosts='%s:%s%s' % (self.zookeeper_host,
540 self.zookeeper_port,
541 self.chroot_path)
542 )
543 self.zkclient.start()
544
545 self.addCleanup(self._cleanup)
546
547 def _cleanup(self):
548 '''Stop the client and remove the chroot path.'''
549 self.zkclient.stop()
550
551 # Need a non-chroot'ed client to remove the chroot path
552 _tmp_client = kazoo.client.KazooClient(
553 hosts='%s:%s' % (self.zookeeper_host, self.zookeeper_port))
554 _tmp_client.start()
555 _tmp_client.delete(self.chroot_path, recursive=True)
556 _tmp_client.stop()
diff --git a/nodepool/tests/test_builder.py b/nodepool/tests/test_builder.py
index 0cc1af7..622cc0c 100644
--- a/nodepool/tests/test_builder.py
+++ b/nodepool/tests/test_builder.py
@@ -18,7 +18,6 @@ import time
18import threading 18import threading
19 19
20import fixtures 20import fixtures
21import kazoo.client
22 21
23from nodepool import builder, exceptions, fakeprovider, tests 22from nodepool import builder, exceptions, fakeprovider, tests
24 23
@@ -151,6 +150,4 @@ class TestNodepoolBuilder(tests.DBTestCase):
151 150
152class TestZookeeper(tests.ZKTestCase): 151class TestZookeeper(tests.ZKTestCase):
153 def test_zk(self): 152 def test_zk(self):
154 zk = kazoo.client.KazooClient(hosts='127.0.0.1:%s' % self.zookeeper_port) 153 self.zkclient.get('/')
155 zk.start()
156 zk.get('/')
diff --git a/tox.ini b/tox.ini
index 9052863..b2bafeb 100644
--- a/tox.ini
+++ b/tox.ini
@@ -12,6 +12,7 @@ usedevelop = True
12install_command = pip install {opts} {packages} 12install_command = pip install {opts} {packages}
13deps = -r{toxinidir}/requirements.txt 13deps = -r{toxinidir}/requirements.txt
14 -r{toxinidir}/test-requirements.txt 14 -r{toxinidir}/test-requirements.txt
15passenv = NODEPOOL_ZK_HOST
15commands = 16commands =
16 python setup.py testr --slowest --testr-args='{posargs}' 17 python setup.py testr --slowest --testr-args='{posargs}'
17 18