ClickHouse/tests/integration/test_reverse_dns_query/test.py

51 lines
1.3 KiB
Python
Raw Normal View History

2023-01-29 14:24:47 +00:00
import pytest
from helpers.cluster import ClickHouseCluster, get_docker_compose_path, run_and_check
from time import sleep
import os
DOCKER_COMPOSE_PATH = get_docker_compose_path()
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
cluster = ClickHouseCluster(__file__)
ch_server = cluster.add_instance(
"clickhouse-server",
with_coredns=True,
2023-02-02 16:28:50 +00:00
main_configs=[
"configs/config.xml",
"configs/reverse_dns_function.xml",
2023-02-02 16:42:17 +00:00
"configs/listen_host.xml",
2023-02-02 16:28:50 +00:00
],
2023-01-29 14:24:47 +00:00
)
2023-01-29 14:35:04 +00:00
2023-01-29 14:24:47 +00:00
@pytest.fixture(scope="module")
def started_cluster():
global cluster
try:
cluster.start()
yield cluster
finally:
cluster.shutdown()
def setup_ch_server(dns_server_ip):
ch_server.exec_in_container(
(["bash", "-c", f"echo 'nameserver {dns_server_ip}' > /etc/resolv.conf"])
)
ch_server.exec_in_container(
(["bash", "-c", "echo 'options ndots:0' >> /etc/resolv.conf"])
)
ch_server.query("SYSTEM DROP DNS CACHE")
2023-02-02 14:30:16 +00:00
def test_reverse_dns_query(started_cluster):
2023-01-29 14:24:47 +00:00
dns_server_ip = cluster.get_instance_ip(cluster.coredns_host)
setup_ch_server(dns_server_ip)
2023-02-02 14:30:16 +00:00
for _ in range(0, 200):
response = ch_server.query("select reverseDNSQuery('2001:4860:4860::8888')")
2023-01-29 14:35:04 +00:00
assert response == "['dns.google']\n"