Commit 19d1bbb3 authored by Romain Courteaud's avatar Romain Courteaud

Change dns import declaration

Python seems confused with the local dns.py conflict
parent 3e29a335
......@@ -17,7 +17,11 @@
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
import dns
from dns import (
resolver as dns_resolver,
name as dns_name,
exception as dns_exception,
)
from .network import logNetwork
from peewee import fn
......@@ -90,7 +94,7 @@ def logDnsQuery(db, status_id, resolver_ip, domain_text, rdtype, answer_list):
def buildResolver(resolver_ip, timeout):
resolver = dns.resolver.Resolver(configure=False)
resolver = dns_resolver.Resolver(configure=False)
resolver.nameservers.append(resolver_ip)
resolver.timeout = timeout
resolver.lifetime = timeout
......@@ -111,10 +115,10 @@ def queryDNS(db, status_id, resolver_ip, domain_text, rdtype, timeout=TIMEOUT):
)
]
except (
dns.resolver.NXDOMAIN,
dns.resolver.NoAnswer,
dns.exception.Timeout,
dns.resolver.NoNameservers,
dns_resolver.NXDOMAIN,
dns_resolver.NoAnswer,
dns_exception.Timeout,
dns_resolver.NoNameservers,
):
answer_list = []
......@@ -148,10 +152,12 @@ def getReachableResolverList(db, status_id, resolver_ip_list, timeout=TIMEOUT):
def expandDomainList(domain_list, public_suffix_list=None):
for domain_text in domain_list:
dns_name = dns.name.from_text(domain_text)
if (len(dns_name.labels) - 1) > 2:
dns_name_value = dns_name.from_text(domain_text)
if (len(dns_name_value.labels) - 1) > 2:
# https://publicsuffix.org/list/public_suffix_list.dat
parent_domain_text = dns_name.parent().to_text(omit_final_dot=True)
parent_domain_text = dns_name_value.parent().to_text(
omit_final_dot=True
)
if (public_suffix_list is None) or (
parent_domain_text not in public_suffix_list
):
......
......@@ -84,13 +84,13 @@ class SurykatkaBotTestCase(unittest.TestCase):
def test_emptyConfiguration(self):
resolver_ip = "192.168.0.254"
resolver = surykatka.dns.dns.resolver.Resolver(configure=False)
resolver = surykatka.dns.dns_resolver.Resolver(configure=False)
resolver.nameservers.append(resolver_ip)
with mock.patch(
"surykatka.configuration.get_default_resolver"
) as mock_get_default_resolver, mock.patch(
"surykatka.dns.dns.resolver.Resolver.query"
"surykatka.dns.dns_resolver.Resolver.query"
) as mock_query:
mock_get_default_resolver.return_value = resolver
......@@ -117,7 +117,7 @@ class SurykatkaBotTestCase(unittest.TestCase):
def test_oneNameserverOneDomainOneIp(self):
resolver_ip = "127.0.0.1"
resolver = surykatka.dns.dns.resolver.Resolver(configure=False)
resolver = surykatka.dns.dns_resolver.Resolver(configure=False)
resolver.nameservers.append(resolver_ip)
with mock.patch(
......@@ -125,7 +125,7 @@ class SurykatkaBotTestCase(unittest.TestCase):
) as mock_whois, mock.patch(
"surykatka.configuration.get_default_resolver"
) as mock_get_default_resolver, mock.patch(
"surykatka.dns.dns.resolver.Resolver.query"
"surykatka.dns.dns_resolver.Resolver.query"
) as mock_query, mock.patch(
"surykatka.network.socket.socket"
) as mock_socket, mock.patch(
......@@ -212,7 +212,7 @@ class SurykatkaBotTestCase(unittest.TestCase):
with mock.patch(
"surykatka.domain.whois.whois"
) as mock_whois, mock.patch(
"surykatka.dns.dns.resolver.Resolver.query"
"surykatka.dns.dns_resolver.Resolver.query"
) as mock_query, mock.patch(
"surykatka.network.socket.socket"
) as mock_socket, mock.patch(
......@@ -302,7 +302,7 @@ class SurykatkaBotTestCase(unittest.TestCase):
with mock.patch(
"surykatka.domain.whois.whois"
) as mock_whois, mock.patch(
"surykatka.dns.dns.resolver.Resolver.query"
"surykatka.dns.dns_resolver.Resolver.query"
) as mock_query, mock.patch(
"surykatka.network.socket.socket"
) as mock_socket, mock.patch(
......@@ -394,7 +394,7 @@ class SurykatkaBotTestCase(unittest.TestCase):
with mock.patch(
"surykatka.domain.whois.whois"
) as mock_whois, mock.patch(
"surykatka.dns.dns.resolver.Resolver.query"
"surykatka.dns.dns_resolver.Resolver.query"
) as mock_query, mock.patch(
"surykatka.network.socket.socket"
) as mock_socket, mock.patch(
......@@ -498,7 +498,7 @@ class SurykatkaBotTestCase(unittest.TestCase):
with mock.patch(
"surykatka.domain.whois.whois"
) as mock_whois, mock.patch(
"surykatka.dns.dns.resolver.Resolver.query"
"surykatka.dns.dns_resolver.Resolver.query"
) as mock_query, mock.patch(
"surykatka.network.socket.socket"
) as mock_socket, mock.patch(
......@@ -592,7 +592,7 @@ class SurykatkaBotTestCase(unittest.TestCase):
with mock.patch(
"surykatka.domain.whois.whois"
) as mock_whois, mock.patch(
"surykatka.dns.dns.resolver.Resolver.query"
"surykatka.dns.dns_resolver.Resolver.query"
) as mock_query, mock.patch(
"surykatka.network.socket.socket"
) as mock_socket, mock.patch(
......@@ -675,7 +675,7 @@ class SurykatkaBotTestCase(unittest.TestCase):
with mock.patch(
"surykatka.domain.whois.whois"
) as mock_whois, mock.patch(
"surykatka.dns.dns.resolver.Resolver.query"
"surykatka.dns.dns_resolver.Resolver.query"
) as mock_query, mock.patch(
"surykatka.network.socket.socket"
) as mock_socket, mock.patch(
......@@ -756,7 +756,7 @@ class SurykatkaBotTestCase(unittest.TestCase):
with mock.patch(
"surykatka.domain.whois.whois"
) as mock_whois, mock.patch(
"surykatka.dns.dns.resolver.Resolver.query"
"surykatka.dns.dns_resolver.Resolver.query"
) as mock_query, mock.patch(
"surykatka.network.socket.socket"
) as mock_socket, mock.patch(
......@@ -805,7 +805,7 @@ class SurykatkaBotStatusTestCase(unittest.TestCase):
def test_status_emptyConfiguration(self):
resolver_ip = "192.168.0.254"
resolver = surykatka.dns.dns.resolver.Resolver(configure=False)
resolver = surykatka.dns.dns_resolver.Resolver(configure=False)
resolver.nameservers.append(resolver_ip)
with mock.patch(
......
......@@ -260,7 +260,7 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo")
with mock.patch(
"surykatka.dns.dns.resolver.Resolver.query"
"surykatka.dns.dns_resolver.Resolver.query"
) as mock_query:
mock_query.return_value = [
MockAnswer("4.3.2.1"),
......@@ -301,11 +301,11 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo")
with mock.patch(
"surykatka.dns.dns.resolver.Resolver.query"
"surykatka.dns.dns_resolver.Resolver.query"
) as mock_query:
def sideEffect(*args, **kw):
raise surykatka.dns.dns.resolver.NXDOMAIN()
raise surykatka.dns.dns_resolver.NXDOMAIN()
mock_query.side_effect = sideEffect
result = queryDNS(self.db, status_id, resolver_ip, domain, rdtype)
......@@ -330,11 +330,11 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo")
with mock.patch(
"surykatka.dns.dns.resolver.Resolver.query"
"surykatka.dns.dns_resolver.Resolver.query"
) as mock_query:
def sideEffect(*args, **kw):
raise surykatka.dns.dns.resolver.NoAnswer()
raise surykatka.dns.dns_resolver.NoAnswer()
mock_query.side_effect = sideEffect
result = queryDNS(self.db, status_id, resolver_ip, domain, rdtype)
......@@ -359,11 +359,11 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo")
with mock.patch(
"surykatka.dns.dns.resolver.Resolver.query"
"surykatka.dns.dns_resolver.Resolver.query"
) as mock_query:
def sideEffect(*args, **kw):
raise surykatka.dns.dns.exception.Timeout()
raise surykatka.dns.dns_exception.Timeout()
mock_query.side_effect = sideEffect
result = queryDNS(self.db, status_id, resolver_ip, domain, rdtype)
......@@ -388,11 +388,11 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo")
with mock.patch(
"surykatka.dns.dns.resolver.Resolver.query"
"surykatka.dns.dns_resolver.Resolver.query"
) as mock_query:
def sideEffect(*args, **kw):
raise surykatka.dns.dns.resolver.NoNameservers()
raise surykatka.dns.dns_resolver.NoNameservers()
mock_query.side_effect = sideEffect
result = queryDNS(self.db, status_id, resolver_ip, domain, rdtype)
......@@ -420,7 +420,7 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo")
with mock.patch(
"surykatka.dns.dns.resolver.Resolver.query"
"surykatka.dns.dns_resolver.Resolver.query"
) as mock_query:
mock_query.return_value = [
MockAnswer("4.3.2.1"),
......@@ -457,11 +457,11 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo")
with mock.patch(
"surykatka.dns.dns.resolver.Resolver.query"
"surykatka.dns.dns_resolver.Resolver.query"
) as mock_query:
def sideEffect(*args, **kw):
raise surykatka.dns.dns.exception.Timeout()
raise surykatka.dns.dns_exception.Timeout()
mock_query.side_effect = sideEffect
......@@ -499,7 +499,7 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo")
with mock.patch(
"surykatka.dns.dns.resolver.Resolver.query"
"surykatka.dns.dns_resolver.Resolver.query"
) as mock_query:
mock_query.return_value = [
MockAnswer("4.3.2.1"),
......@@ -528,7 +528,7 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo")
with mock.patch(
"surykatka.dns.dns.resolver.Resolver.query"
"surykatka.dns.dns_resolver.Resolver.query"
) as mock_query:
mock_query.side_effect = [
[MockAnswer("4.3.2.1"), MockAnswer("1.2.3.4")],
......@@ -561,7 +561,7 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo")
with mock.patch(
"surykatka.dns.dns.resolver.Resolver.query"
"surykatka.dns.dns_resolver.Resolver.query"
) as mock_query:
mock_query.side_effect = [
[MockAnswer("4.3.2.1"), MockAnswer("1.2.3.4")],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment