Commit f8306d34 authored by Daniel Salzman's avatar Daniel Salzman

func-test: add update functionality

parent 20e9e676
Prerequisites:
Python >=3.3
python3-dnspython
python3-dnspython >1.11
dnssec-keygen
dnssec-signzone
Bind 9.9
......
......@@ -21,7 +21,7 @@ fail_cnt = 0
log("Starting Knot test suite %s" % outs_dir)
def save_traceback(outdir):
file = open(params.out_dir + "/traceback", mode="w")
file = open(params.out_dir + "/traceback", mode="a")
traceback.print_exc(file=file)
file.close()
......
......@@ -4,12 +4,11 @@
import dnstest
t = dnstest.DnsTest(tsig=True)
t = dnstest.DnsTest()
master = t.server("knot")
slave = t.server("bind")
#zones = t.zone_rnd(2)
zones = t.zone("mysqb8.fluid", "mysqb8.fluid.zone")
zones = t.zone_rnd(2)
t.link(zones, master, slave)
......
$ORIGIN .
$TTL 3601 ; 1 hour
example.com IN SOA dns1.example.com. hostmaster.example.com. (
2010111217 ; serial
21600 ; refresh (6 hours)
3600 ; retry (1 hour)
604800 ; expire (1 week)
86400 ; minimum (1 day)
)
NS dns1.example.com.
NS dns2.example.com.
MX 10 mail.example.com.
$ORIGIN example.com.
12345 A 1.2.3.5
dns1 A 192.0.2.1
AAAA 2001:db8::1
dns2 A 192.0.2.2
AAAA 2001:db8::2
mail A 192.0.2.3
AAAA 2001:db8::3
#!/usr/bin/env python3
''' '''
import dnstest
t = dnstest.DnsTest()
master = t.server("knot")
zone = t.zone("example.com.", "example.com.zone")
t.link(zone, master, ddns=True)
t.start()
update = master.update(zone)
update.add("t1.example.com.", 1234, "A", "1.2.3.4")
update.add("t2.example.com.", 1234, "A", "1.2.3.4")
update.add("t3.example.com.", 1234, "A", "1.2.3.4")
update.send()
update.delete("t2.example.com.")
update.send()
t.stop()
......@@ -12,6 +12,8 @@ import time
import dns.message
import dns.query
import dns.tsigkeyring
import dns.update
import dns.zone
from subprocess import Popen, PIPE, DEVNULL, check_call
import zone_generate, params
......@@ -165,7 +167,7 @@ class BindConf(object):
self.conf += "%s%s \"%s\";\n" % (self.indent, name, value)
class Zone(object):
''' DNS zone description'''
'''DNS zone description'''
def __init__(self, name, filename, ddns=None):
self.name = name
......@@ -175,6 +177,24 @@ class Zone(object):
# ddns: True - ddns, False - ixfrFromDiff, None - empty
self.ddns = ddns
class Update(object):
'''DNS update context'''
def __init__(self, server, upd):
self.server = server
self.upd = upd
def add(self, owner, ttl, rtype, rdata):
self.upd.add(owner, ttl, rtype, rdata)
def delete(self, owner, args=dict()):
self.upd.delete(owner, **args)
def send(self):
resp = dns.query.tcp(self.upd, self.server.addr, port=self.server.port)
if resp.rcode() != 0:
raise Exception("Update rcode %i" % resp.rcode())
class DnsServer(object):
'''Specification of DNS server'''
......@@ -410,6 +430,15 @@ class DnsServer(object):
raise Exception("Can't get %s SOA from %s." % \
(zone, self.name))
def update(self, zone):
if len(zone) != 1:
raise Exception("One zone required.")
key_params = self.tsig.key_params if self.tsig else dict()
zname = list(zone.keys())[0]
return Update(self, dns.update.Update(zname, **key_params))
class Bind(DnsServer):
def __init__(self):
......@@ -884,4 +913,3 @@ class DnsTest(object):
if slave not in self.servers:
raise Exception("Uncovered server in test")
slave.zone_slave(zone, zones[zone], master)
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