Files
system-config/testinfra/test_zookeeper.py
Clark Boylan 5a27433022 Replace zk04 with zk03
This replaces the old zk04 server with a new zk03 server. This is part
of Noble replacements for older servers.

Note that zk04 was also our test node and I've updated that node to be
zk99 in testing. This way we don't need to update our tests the next
time we replace zookeeper servers.

Change-Id: Icb33befb9042a1d09358a6918df9576127b68931
2025-06-30 12:41:38 -07:00

83 lines
2.9 KiB
Python

# Copyright 2020 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import json
import util
testinfra_hosts = ['zk99.opendev.org']
def test_id_file(host):
# Test that wacky hostname regex works
myid = host.file('/var/zookeeper/data/myid')
assert myid.content == b'99\n'
def test_zk_myid_is_set(host):
# Test that our wacky hostname regex results in the correct
# myid value in the running service.
cmd = host.run("docker logs zookeeper-compose-zk-1")
assert "[myid:99]" in cmd.stdout
def test_zk_listening(host):
zk = host.socket("tcp://0.0.0.0:2181")
assert zk.is_listening
def test_zk_listening_ssl(host):
zk = host.socket("tcp://0.0.0.0:2281")
assert zk.is_listening
def test_l4_commands(host):
cmd = host.run("echo srvr | nc localhost 2181")
assert "Zookeeper version" in cmd.stdout
assert "not executed because it is not in the whitelist" not in cmd.stdout
cmd = host.run("echo stat | nc localhost 2181")
assert "Zookeeper version" in cmd.stdout
assert "not executed because it is not in the whitelist" not in cmd.stdout
cmd = host.run("echo dump | nc localhost 2181")
assert "SessionTracker dump" in cmd.stdout
assert "not executed because it is not in the whitelist" not in cmd.stdout
cmd = host.run("echo mntr | nc localhost 2181")
assert "zk_version" in cmd.stdout
assert "not executed because it is not in the whitelist" not in cmd.stdout
def test_zookeeper_statsd_running(host):
cmd = host.run("docker inspect zookeeper-compose-zookeeper-statsd-1")
out = json.loads(cmd.stdout)
assert out[0]["State"]["Status"] == "running"
assert out[0]["RestartCount"] == 0
def test_zk_2181_accessibility(host):
# Ask the host to report its own IP addresses. This will use our test
# local /etc/hosts values and not DNS.
zk = host.addr("zk99.opendev.org")
# Verify it is using our local /etc/hosts values
print(zk.ipv4_addresses)
print(zk.ipv6_addresses)
for addr in zk.ipv4_addresses + zk.ipv6_addresses:
if addr.startswith("::ffff:"):
# This is an ipv4 address mapped to ipv6 and is covered by
# the ipv4_addresses list
continue
if addr.startswith("127.") or addr == "::1":
# We don't want to talk to localhost as we are connecting
# from our test bridge instance.
continue
util.check_unreachable(addr, 2181)
util.check_unreachable(addr, 2281)