Skip to content

Commit 3033091

Browse files
StephenSorriauxjeffwidman
authored andcommitted
feat(tests): update Zookeeper 3.5.2-alpha to 3.5.4-beta
Version of Zookeeper is upgraded from 3.5.2-alpha to 3.5.4-beta for automated tests. Reconfig now needs superuser authentification, a test is added to cover this feature. Additionnal configuration and jvm parameters can be added when initializing ManagedZookeeper. This is needed to ensure reconfig's tests to pass and can be used in the future for similar needs. Closes #477
1 parent 8ecf8a5 commit 3033091

File tree

4 files changed

+73
-17
lines changed

4 files changed

+73
-17
lines changed

.travis.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,44 @@ matrix:
1818
env: ZOOKEEPER_VERSION=3.3.6 TOX_VENV=py27
1919
- python: '2.7'
2020
env: ZOOKEEPER_VERSION=3.4.13 TOX_VENV=py27
21+
- python: '2.7'
22+
env: ZOOKEEPER_VERSION=3.5.4-beta TOX_VENV=py27
2123
- python: '2.7'
2224
env: ZOOKEEPER_VERSION=3.3.6 TOX_VENV=py27-gevent
2325
- python: '2.7'
2426
env: ZOOKEEPER_VERSION=3.4.13 TOX_VENV=py27-gevent
27+
- python: '2.7'
28+
env: ZOOKEEPER_VERSION=3.5.4-beta TOX_VENV=py27-gevent
2529
- python: '2.7'
2630
env: ZOOKEEPER_VERSION=3.3.6 TOX_VENV=py27-eventlet
2731
- python: '2.7'
2832
env: ZOOKEEPER_VERSION=3.4.13 TOX_VENV=py27-eventlet
2933
- python: '2.7'
30-
env: ZOOKEEPER_VERSION=3.5.2-alpha TOX_VENV=py27
34+
env: ZOOKEEPER_VERSION=3.5.4-beta TOX_VENV=py27-eventlet
3135
- python: '3.4'
3236
env: ZOOKEEPER_VERSION=3.3.6 TOX_VENV=py34
3337
- python: '3.4'
3438
env: ZOOKEEPER_VERSION=3.4.13 TOX_VENV=py34
39+
- python: '3.4'
40+
env: ZOOKEEPER_VERSION=3.5.4-beta TOX_VENV=py34
3541
- python: '3.5'
3642
env: ZOOKEEPER_VERSION=3.3.6 TOX_VENV=py35
3743
- python: '3.5'
3844
env: ZOOKEEPER_VERSION=3.4.13 TOX_VENV=py35
45+
- python: '3.5'
46+
env: ZOOKEEPER_VERSION=3.5.4-beta TOX_VENV=py35
3947
- python: '3.6'
4048
env: ZOOKEEPER_VERSION=3.3.6 TOX_VENV=py36
4149
- python: '3.6'
4250
env: ZOOKEEPER_VERSION=3.4.13 TOX_VENV=py36
51+
- python: '3.6'
52+
env: ZOOKEEPER_VERSION=3.5.4-beta TOX_VENV=py36
4353
- python: pypy
4454
env: ZOOKEEPER_VERSION=3.3.6 TOX_VENV=pypy
4555
- python: pypy
4656
env: ZOOKEEPER_VERSION=3.4.13 TOX_VENV=pypy
57+
- python: 'pypy'
58+
env: ZOOKEEPER_VERSION=3.5.4-beta TOX_VENV=pypy
4759
notifications:
4860
email: false
4961
install:

kazoo/testing/common.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ class ManagedZooKeeper(object):
7474
future, we may want to do that, especially when run in a
7575
Hudson/Buildbot context, to ensure more test robustness."""
7676

77-
def __init__(self, software_path, server_info, peers=(), classpath=None):
77+
def __init__(self, software_path, server_info, peers=(), classpath=None,
78+
configuration_entries=[], java_system_properties=[]):
7879
"""Define the ZooKeeper test instance.
7980
8081
@param install_path: The path to the install for ZK
@@ -87,6 +88,8 @@ def __init__(self, software_path, server_info, peers=(), classpath=None):
8788
self.peers = peers
8889
self.working_path = tempfile.mkdtemp()
8990
self._running = False
91+
self.configuration_entries = configuration_entries
92+
self.java_system_properties = java_system_properties
9093

9194
def run(self):
9295
"""Run the ZooKeeper instance under a temporary directory.
@@ -117,9 +120,12 @@ def run(self):
117120
maxClientCnxns=0
118121
admin.serverPort=%s
119122
authProvider.1=org.apache.zookeeper.server.auth.SASLAuthenticationProvider
123+
%s
120124
""" % (to_java_compatible_path(data_path),
121125
self.server_info.client_port,
122-
self.server_info.admin_port)) # NOQA
126+
self.server_info.admin_port,
127+
"\n".join(self.configuration_entries))) # NOQA
128+
123129

124130
# setup a replicated setup if peers are specified
125131
if self.peers:
@@ -175,7 +181,7 @@ def run(self):
175181

176182
# JAAS configuration for SASL authentication
177183
"-Djava.security.auth.login.config=%s" % jass_config_path,
178-
184+
] + self.java_system_properties + [
179185
"org.apache.zookeeper.server.quorum.QuorumPeerMain",
180186
config_path,
181187
]
@@ -265,11 +271,14 @@ def destroy(self):
265271
class ZookeeperCluster(object):
266272

267273
def __init__(self, install_path=None, classpath=None,
268-
size=3, port_offset=20000, observer_start_id=-1):
274+
size=3, port_offset=20000, observer_start_id=-1,
275+
configuration_entries=[],
276+
java_system_properties=[]):
269277
self._install_path = install_path
270278
self._classpath = classpath
271279
self._servers = []
272280

281+
273282
# Calculate ports and peer group
274283
port = port_offset
275284
peers = []
@@ -292,7 +301,9 @@ def __init__(self, install_path=None, classpath=None,
292301
self._servers.append(
293302
ManagedZooKeeper(
294303
self._install_path, server_info, server_peers,
295-
classpath=self._classpath))
304+
classpath=self._classpath,
305+
configuration_entries=configuration_entries,
306+
java_system_properties=java_system_properties))
296307

297308
def __getitem__(self, k):
298309
return self._servers[k]

kazoo/testing/harness.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
)
1414
from kazoo.testing.common import ZookeeperCluster
1515

16-
1716
log = logging.getLogger(__name__)
1817

1918
CLUSTER = None
@@ -26,20 +25,41 @@ def get_global_cluster():
2625
ZK_CLASSPATH = os.environ.get("ZOOKEEPER_CLASSPATH")
2726
ZK_PORT_OFFSET = int(os.environ.get("ZOOKEEPER_PORT_OFFSET", 20000))
2827
ZK_CLUSTER_SIZE = int(os.environ.get("ZOOKEEPER_CLUSTER_SIZE", 3))
28+
ZK_VERSION = os.environ.get("ZOOKEEPER_VERSION")
29+
if '-' in ZK_VERSION:
30+
# Ignore pre-release markers like -alpha
31+
ZK_VERSION = ZK_VERSION.split('-')[0]
32+
ZK_VERSION = tuple([int(n) for n in ZK_VERSION.split('.')])
33+
2934
ZK_OBSERVER_START_ID = int(
3035
os.environ.get("ZOOKEEPER_OBSERVER_START_ID", -1))
3136

32-
assert ZK_HOME or ZK_CLASSPATH, (
33-
"Either ZOOKEEPER_PATH or ZOOKEEPER_CLASSPATH environment "
34-
"variable must be defined.\n"
37+
assert ZK_HOME or ZK_CLASSPATH or ZK_VERSION, (
38+
"Either ZOOKEEPER_PATH or ZOOKEEPER_CLASSPATH or "
39+
"ZOOKEEPER_VERSION environment variable must be defined.\n"
3540
"For deb package installations this is /usr/share/java")
3641

42+
if ZK_VERSION >= (3, 5):
43+
additional_configuration_entries = [
44+
"4lw.commands.whitelist=*",
45+
"reconfigEnabled=true"
46+
]
47+
# If defines, this sets the superuser password to "test"
48+
additional_java_system_properties = [
49+
"-Dzookeeper.DigestAuthenticationProvider.superDigest="
50+
"super:D/InIHSb7yEEbrWz8b9l71RjZJU="
51+
]
52+
else:
53+
additional_configuration_entries = []
54+
additional_java_system_properties = []
3755
CLUSTER = ZookeeperCluster(
3856
install_path=ZK_HOME,
3957
classpath=ZK_CLASSPATH,
4058
port_offset=ZK_PORT_OFFSET,
4159
size=ZK_CLUSTER_SIZE,
42-
observer_start_id=ZK_OBSERVER_START_ID
60+
observer_start_id=ZK_OBSERVER_START_ID,
61+
configuration_entries=additional_configuration_entries,
62+
java_system_properties=additional_java_system_properties
4363
)
4464
atexit.register(lambda cluster: cluster.terminate(), CLUSTER)
4565
return CLUSTER

kazoo/tests/test_client.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,22 +1204,35 @@ def test_unchroot(self):
12041204

12051205

12061206
class TestReconfig(KazooTestCase):
1207-
12081207
def setUp(self):
12091208
KazooTestCase.setUp(self)
1209+
12101210
if TRAVIS_ZK_VERSION:
12111211
version = TRAVIS_ZK_VERSION
12121212
else:
12131213
version = self.client.server_version()
12141214
if not version or version < (3, 5):
12151215
raise SkipTest("Must use Zookeeper 3.5 or above")
12161216

1217+
def test_no_super_auth(self):
1218+
self.assertRaises(NoAuthError,
1219+
self.client.reconfig,
1220+
joining='server.999=0.0.0.0:1234:2345:observer;3456',
1221+
leaving=None,
1222+
new_members=None)
1223+
12171224
def test_add_remove_observer(self):
12181225
def free_sock_port():
12191226
s = socket.socket()
12201227
s.bind(('', 0))
12211228
return s, s.getsockname()[1]
12221229

1230+
username = "super"
1231+
password = "test"
1232+
digest_auth = "%s:%s" % (username, password)
1233+
client = self._get_client(auth_data=[('digest', digest_auth)])
1234+
client.start()
1235+
12231236
# get ports for election, zab and client endpoints. we need to use
12241237
# ports for which we'd immediately get a RST upon connect(); otherwise
12251238
# the cluster could crash if it gets a SocketTimeoutException:
@@ -1230,18 +1243,18 @@ def free_sock_port():
12301243

12311244
joining = 'server.100=0.0.0.0:%d:%d:observer;0.0.0.0:%d' % (
12321245
port1, port2, port3)
1233-
data, _ = self.client.reconfig(joining=joining,
1246+
data, _ = client.reconfig(joining=joining,
12341247
leaving=None,
12351248
new_members=None)
1236-
self.assertIn(joining, data)
1249+
self.assertIn(joining.encode('utf8'), data)
12371250

1238-
data, _ = self.client.reconfig(joining=None,
1251+
data, _ = client.reconfig(joining=None,
12391252
leaving='100',
12401253
new_members=None)
1241-
self.assertNotIn(joining, data)
1254+
self.assertNotIn(joining.encode('utf8'), data)
12421255

12431256
# try to add it again, but a config number in the future
1244-
curver = int(data.split('\n')[-1].split('=')[1], base=16)
1257+
curver = int(data.decode().split('\n')[-1].split('=')[1], base=16)
12451258
self.assertRaises(BadVersionError,
12461259
self.client.reconfig,
12471260
joining=joining,

0 commit comments

Comments
 (0)