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