Skip to content

Commit

Permalink
Merge pull request #296 from Altinity/backports/23.3.8/53286_dns_test…
Browse files Browse the repository at this point in the history
…s_coredns_version

23.3 Backport of ClickHouse#53286 - Bring back **garbage** dns tests
  • Loading branch information
Enmk authored Aug 15, 2023
2 parents 03a6d8e + b0d1e48 commit 7ed789a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "2.3"

services:
coredns:
image: coredns/coredns:latest
image: coredns/coredns:1.9.3 # :latest broke this test
restart: always
volumes:
- ${COREDNS_CONFIG_DIR}/example.com:/example.com
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<yandex>
<clickhouse>
<listen_host>::</listen_host>
<listen_host>0.0.0.0</listen_host>
<listen_try>1</listen_try>
</yandex>
</clickhouse>
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
. {
hosts /example.com {
reload "20ms"
fallthrough
}
forward . 127.0.0.11
log
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
filled in runtime, but needs to exist in order to be volume mapped in docker
30 changes: 27 additions & 3 deletions tests/integration/test_reverse_dns_query/test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
import socket
from helpers.cluster import ClickHouseCluster, get_docker_compose_path, run_and_check
from time import sleep
import os
Expand Down Expand Up @@ -30,6 +31,28 @@ def started_cluster():
cluster.shutdown()


def check_ptr_record(ip, hostname):
try:
host, aliaslist, ipaddrlist = socket.gethostbyaddr(ip)
if hostname.lower() == host.lower():
return True
except socket.herror:
pass
return False


def setup_dns_server(ip):
domains_string = "test.example.com"
example_file_path = f'{ch_server.env_variables["COREDNS_CONFIG_DIR"]}/example.com'
run_and_check(f"echo '{ip} {domains_string}' > {example_file_path}", shell=True)

# DNS server takes time to reload the configuration.
for try_num in range(10):
if all(check_ptr_record(ip, host) for host in domains_string.split()):
break
sleep(1)


def setup_ch_server(dns_server_ip):
ch_server.exec_in_container(
(["bash", "-c", f"echo 'nameserver {dns_server_ip}' > /etc/resolv.conf"])
Expand All @@ -42,9 +65,10 @@ def setup_ch_server(dns_server_ip):

def test_reverse_dns_query(started_cluster):
dns_server_ip = cluster.get_instance_ip(cluster.coredns_host)

random_ipv6 = "4ae8:fa0f:ee1d:68c5:0b76:1b79:7ae6:1549" # https://commentpicker.com/ip-address-generator.php
setup_dns_server(random_ipv6)
setup_ch_server(dns_server_ip)

for _ in range(0, 200):
response = ch_server.query("select reverseDNSQuery('2001:4860:4860::8888')")
assert response == "['dns.google']\n"
response = ch_server.query(f"select reverseDNSQuery('{random_ipv6}')")
assert response == "['test.example.com']\n"

0 comments on commit 7ed789a

Please sign in to comment.