Commit b96ac898 authored by Petr Špaček's avatar Petr Špaček

Deckard: move socket binding from Deckard to pydnstest.testserver

Testserver already had all the information so it was unnecessary to pass
them again. The improved TestServer.start() method is going to be
handy in future.
parent d90bbeaa
......@@ -19,7 +19,6 @@ from pydnstest import scenario, testserver, test
from datetime import datetime
import random
import string
import itertools
import calendar
......@@ -257,25 +256,6 @@ def play_object(path, args):
break
sock.close()
# Bind to test servers
for r in case.ranges:
for addr in r.addresses:
family = socket.AF_INET6 if ':' in addr else socket.AF_INET
server.start_srv((addr, 53), family)
# Bind addresses in ad-hoc REPLYs
for s in case.steps:
if s.type == 'REPLY':
reply = s.data[0].message
for rr in itertools.chain(reply.answer,
reply.additional,
reply.question,
reply.authority):
for rd in rr:
if rd.rdtype == dns.rdatatype.A:
server.start_srv((rd.address, 53), socket.AF_INET)
elif rd.rdtype == dns.rdatatype.AAAA:
server.start_srv((rd.address, 53), socket.AF_INET6)
# Play test scenario
try:
server.play(CHILD_IFACE)
......
......@@ -64,6 +64,7 @@ class TestServer:
self.active = True
self.addr, _ = self.start_srv((self.kroot_local, port), self.addr_family)
self.start_srv(self.addr, self.addr_family, socket.IPPROTO_TCP)
self._bind_sockets()
def stop(self):
""" Stop socket server operation. """
......@@ -222,6 +223,30 @@ class TestServer:
sockname = sock.getsockname()
return sockname, proto
def _bind_sockets(self):
"""
Bind test server to port 53 on all addresses referenced by test scenario.
"""
# Bind to test servers
for r in self.scenario.ranges:
for addr in r.addresses:
family = socket.AF_INET6 if ':' in addr else socket.AF_INET
self.start_srv((addr, 53), family)
# Bind addresses in ad-hoc REPLYs
for s in self.scenario.steps:
if s.type == 'REPLY':
reply = s.data[0].message
for rr in itertools.chain(reply.answer,
reply.additional,
reply.question,
reply.authority):
for rd in rr:
if rd.rdtype == dns.rdatatype.A:
self.start_srv((rd.address, 53), socket.AF_INET)
elif rd.rdtype == dns.rdatatype.AAAA:
self.start_srv((rd.address, 53), socket.AF_INET6)
def play(self, subject_addr):
paddr = get_local_addr_str(self.scenario.sockfamily, subject_addr)
self.scenario.play({'': (paddr, 53)})
......
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