From 5de2b07daa2919b9be36c8c9b6483c9c909da6e0 Mon Sep 17 00:00:00 2001 From: Tom Krizek Date: Mon, 4 Dec 2023 18:10:42 +0100 Subject: [PATCH] Refactor statschannel test to use isctest Use common utility functions in favor of duplicating the code in a test-specific file. --- bin/tests/system/statschannel/generic.py | 31 +++++++-------------- bin/tests/system/statschannel/tests_json.py | 6 ++-- bin/tests/system/statschannel/tests_xml.py | 6 ++-- 3 files changed, 14 insertions(+), 29 deletions(-) diff --git a/bin/tests/system/statschannel/generic.py b/bin/tests/system/statschannel/generic.py index 78dc458229..6391329ab9 100644 --- a/bin/tests/system/statschannel/generic.py +++ b/bin/tests/system/statschannel/generic.py @@ -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) diff --git a/bin/tests/system/statschannel/tests_json.py b/bin/tests/system/statschannel/tests_json.py index 2cd7a537c9..4f7c4a7d7c 100755 --- a/bin/tests/system/statschannel/tests_json.py +++ b/bin/tests/system/statschannel/tests_json.py @@ -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) diff --git a/bin/tests/system/statschannel/tests_xml.py b/bin/tests/system/statschannel/tests_xml.py index 5f92a69900..53296155da 100755 --- a/bin/tests/system/statschannel/tests_xml.py +++ b/bin/tests/system/statschannel/tests_xml.py @@ -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)