2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 14:35:26 +00:00

Refactor statschannel test to use isctest

Use common utility functions in favor of duplicating the code in a
test-specific file.
This commit is contained in:
Tom Krizek
2023-12-04 18:10:42 +01:00
parent cba5a1d62c
commit 5de2b07daa
3 changed files with 14 additions and 29 deletions

View File

@@ -17,6 +17,8 @@ import dns.message
import dns.query
import dns.rcode
import isctest
# ISO datetime format without msec
fmt = "%Y-%m-%dT%H:%M:%SZ"
@@ -26,8 +28,6 @@ max_refresh = timedelta(seconds=2419200) # 4 weeks
max_expires = timedelta(seconds=14515200) # 24 weeks
dayzero = datetime.utcfromtimestamp(0).replace(microsecond=0)
TIMEOUT = 10
# Generic helper functions
def check_expires(expires, min_time, max_time):
@@ -121,20 +121,6 @@ def create_msg(qname, qtype):
return msg
def udp_query(ip, port, msg):
ans = dns.query.udp(msg, ip, TIMEOUT, port=port)
assert ans.rcode() == dns.rcode.NOERROR
return ans
def tcp_query(ip, port, msg):
ans = dns.query.tcp(msg, ip, TIMEOUT, port=port)
assert ans.rcode() == dns.rcode.NOERROR
return ans
def create_expected(data):
expected = {
"dns-tcp-requests-sizes-received-ipv4": defaultdict(int),
@@ -184,14 +170,14 @@ def check_traffic(data, expected):
def test_traffic(fetch_traffic, **kwargs):
statsip = kwargs["statsip"]
statsport = kwargs["statsport"]
port = kwargs["port"]
data = fetch_traffic(statsip, statsport)
exp = create_expected(data)
msg = create_msg("short.example.", "TXT")
update_expected(exp, "dns-udp-requests-sizes-received-ipv4", msg)
ans = udp_query(statsip, port, msg)
ans = isctest.query.udp(msg, statsip)
isctest.check.noerror(ans)
update_expected(exp, "dns-udp-responses-sizes-sent-ipv4", ans)
data = fetch_traffic(statsip, statsport)
@@ -199,7 +185,8 @@ def test_traffic(fetch_traffic, **kwargs):
msg = create_msg("long.example.", "TXT")
update_expected(exp, "dns-udp-requests-sizes-received-ipv4", msg)
ans = udp_query(statsip, port, msg)
ans = isctest.query.udp(msg, statsip)
isctest.check.noerror(ans)
update_expected(exp, "dns-udp-responses-sizes-sent-ipv4", ans)
data = fetch_traffic(statsip, statsport)
@@ -207,7 +194,8 @@ def test_traffic(fetch_traffic, **kwargs):
msg = create_msg("short.example.", "TXT")
update_expected(exp, "dns-tcp-requests-sizes-received-ipv4", msg)
ans = tcp_query(statsip, port, msg)
ans = isctest.query.tcp(msg, statsip)
isctest.check.noerror(ans)
update_expected(exp, "dns-tcp-responses-sizes-sent-ipv4", ans)
data = fetch_traffic(statsip, statsport)
@@ -215,7 +203,8 @@ def test_traffic(fetch_traffic, **kwargs):
msg = create_msg("long.example.", "TXT")
update_expected(exp, "dns-tcp-requests-sizes-received-ipv4", msg)
ans = tcp_query(statsip, port, msg)
ans = isctest.query.tcp(msg, statsip)
isctest.check.noerror(ans)
update_expected(exp, "dns-tcp-responses-sizes-sent-ipv4", ans)
data = fetch_traffic(statsip, statsport)

View File

@@ -100,7 +100,5 @@ def test_zone_with_many_keys_json(statsport):
)
def test_traffic_json(named_port, statsport):
generic.test_traffic(
fetch_traffic_json, statsip="10.53.0.2", statsport=statsport, port=named_port
)
def test_traffic_json(statsport):
generic.test_traffic(fetch_traffic_json, statsip="10.53.0.2", statsport=statsport)

View File

@@ -130,7 +130,5 @@ def test_zone_with_many_keys_xml(statsport):
)
def test_traffic_xml(named_port, statsport):
generic.test_traffic(
fetch_traffic_xml, statsip="10.53.0.2", statsport=statsport, port=named_port
)
def test_traffic_xml(statsport):
generic.test_traffic(fetch_traffic_xml, statsip="10.53.0.2", statsport=statsport)