Skip to content

Commit b4e9c41

Browse files
Bump the dnspython version to 2.4.2 on Python 3
1 parent 3b5473e commit b4e9c41

File tree

8 files changed

+42
-37
lines changed

8 files changed

+42
-37
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Bump the dnspython version to 2.4.2 on Python 3

datadog_checks_base/datadog_checks/base/data/agent_requirements.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ cryptography==41.0.5; python_version > '3.0'
2424
ddtrace==0.32.2; sys_platform == 'win32' and python_version < '3.0'
2525
ddtrace==0.53.2; sys_platform != 'win32' and python_version < '3.0'
2626
ddtrace==1.11.2; python_version > '3.0'
27-
dnspython==1.16.0
27+
dnspython==1.16.0; python_version < '3.0'
28+
dnspython==2.4.2; python_version > '3.0'
2829
enum34==1.1.10; python_version < '3.0'
2930
foundationdb==6.3.24; python_version > '3.0'
3031
futures==3.4.0; python_version < '3.0'

dns_check/changelog.d/16150.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Bump the dnspython version to 2.4.2 on Python 3

dns_check/datadog_checks/dns_check/dns_check.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import List, Optional # noqa: F401
88

99
import dns.resolver
10+
from six import PY3
1011

1112
from datadog_checks.base import AgentCheck, ConfigurationError
1213
from datadog_checks.base.utils.time import get_precise_time
@@ -78,7 +79,10 @@ def check(self, _):
7879
raise AssertionError("Expected an NXDOMAIN, got a result.")
7980
else:
8081
answer = resolver.query(self.hostname, rdtype=self.record_type) # dns.resolver.Answer
81-
assert answer.rrset.items[0].to_text()
82+
83+
items = list(answer.rrset.items.keys()) if PY3 else answer.rrset.items
84+
assert items[0].to_text()
85+
8286
if self.resolves_as_ips:
8387
self._check_answer(answer)
8488

@@ -105,7 +109,7 @@ def _check_answer(self, answer):
105109

106110
assert len(self.resolves_as_ips) == number_of_results
107111
result_ips = []
108-
for rip in answer.rrset.items:
112+
for rip in answer.rrset.items.keys() if PY3 else answer.rrset.items:
109113
result = rip.to_text().lower()
110114
if result.endswith('.'):
111115
result = result[:-1]

dns_check/pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ dynamic = [
3939

4040
[project.optional-dependencies]
4141
deps = [
42-
"dnspython==1.16.0",
42+
"dnspython==1.16.0; python_version < '3.0'",
43+
"dnspython==2.4.2; python_version > '3.0'",
4344
]
4445

4546
[project.urls]

dns_check/tests/common.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,6 @@
5151
'nameserver': '127.0.0.1',
5252
}
5353

54-
CONFIG_INVALID = [
55-
# invalid hostname
56-
({'name': 'invalid_hostname', 'hostname': 'example'}, "DNS resolution of example has failed"),
57-
# invalid nameserver
58-
(
59-
{'name': 'invalid_nameserver', 'hostname': 'www.example.org', 'nameserver': '0.0.0.0'},
60-
"DNS resolution of www.example.org timed out",
61-
),
62-
# invalid record type
63-
(
64-
{'name': 'invalid_rcrd_type', 'hostname': 'www.example.org', 'record_type': 'FOO'},
65-
"DNS resolution of www.example.org has failed",
66-
),
67-
# valid domain when NXDOMAIN is expected
68-
(
69-
{'name': 'valid_domain_for_nxdomain_type', 'hostname': 'example.com', 'record_type': 'NXDOMAIN'},
70-
"DNS resolution of example.com has failed",
71-
),
72-
]
73-
7454
E2E_METADATA = {'docker_platform': 'windows' if using_windows_containers() else 'linux'}
7555

7656

dns_check/tests/mocks.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Licensed under Simplified BSD License (see LICENSE)
44

55
from dns.resolver import NXDOMAIN
6+
from six import PY3
67

78

89
class MockDNSAnswer:
@@ -13,12 +14,11 @@ class MockRrset:
1314
def __init__(self, address):
1415
addresses = [x.strip().lower() for x in address.split(',')]
1516
if len(addresses) > 1:
16-
items = []
17-
for address in addresses:
18-
items.append(MockDNSAnswer.MockItem(address))
19-
self.items = items
17+
items = [MockDNSAnswer.MockItem(address) for address in addresses]
2018
else:
21-
self.items = [MockDNSAnswer.MockItem(address)]
19+
items = [MockDNSAnswer.MockItem(address)]
20+
21+
self.items = {item: None for item in items} if PY3 else items
2222

2323
class MockItem:
2424
def __init__(self, address):

dns_check/tests/test_dns_check.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,28 @@ def test_instance_timeout(mocked_query, mocked_time, aggregator):
124124
aggregator.assert_all_metrics_covered()
125125

126126

127-
def test_invalid_config(aggregator):
128-
for instance, message in common.CONFIG_INVALID:
129-
integration = DNSCheck('dns_check', {}, [instance])
130-
integration.check(instance)
131-
aggregator.assert_service_check(DNSCheck.SERVICE_CHECK_NAME, status=DNSCheck.CRITICAL, count=1, message=message)
132-
133-
# Assert coverage for this check on this instance
134-
aggregator.assert_all_metrics_covered()
127+
@pytest.mark.parametrize(
128+
'instance, message',
129+
[
130+
pytest.param(
131+
{'name': 'invalid_hostname', 'hostname': 'example'},
132+
"DNS resolution of example has failed",
133+
id='invalid hostname',
134+
),
135+
pytest.param(
136+
{'name': 'invalid_rcrd_type', 'hostname': 'www.example.org', 'record_type': 'FOO'},
137+
"DNS resolution of www.example.org has failed",
138+
id='invalid record type',
139+
),
140+
pytest.param(
141+
{'name': 'valid_domain_for_nxdomain_type', 'hostname': 'example.com', 'record_type': 'NXDOMAIN'},
142+
"DNS resolution of example.com has failed",
143+
id='valid domain when NXDOMAIN is expected',
144+
),
145+
],
146+
)
147+
def test_invalid_config(aggregator, instance, message):
148+
integration = DNSCheck('dns_check', {}, [instance])
149+
integration.check(instance)
150+
aggregator.assert_service_check(DNSCheck.SERVICE_CHECK_NAME, status=DNSCheck.CRITICAL, count=1, message=message)
151+
aggregator.assert_all_metrics_covered()

0 commit comments

Comments
 (0)