Commit 592a5b51 authored by Daniel Salzman's avatar Daniel Salzman

func-tests: improve zonefile interface

parent 12a36eaa
......@@ -133,6 +133,7 @@ def main(args):
try:
out_dir = outs_dir + "/" + test + "/" + case
os.makedirs(out_dir, exist_ok=True)
params.module = TESTS_DIR + "." + test + "." + case
params.test_dir = case_dir
params.out_dir = out_dir
params.case_log = open(out_dir + "/case.log", mode="a")
......
......@@ -9,7 +9,7 @@ t = Test()
knot = t.server("knot")
knot.DIG_TIMEOUT = 2
bind = t.server("bind")
zone = t.zone("example.", "example.zone.nsec", local=True)
zone = t.zone("example.", "example.zone.nsec", storage=".")
t.link(zone, knot)
t.link(zone, bind)
......
......@@ -9,7 +9,7 @@ t = Test()
knot = t.server("knot")
knot.DIG_TIMEOUT = 2
bind = t.server("bind")
zone = t.zone("example.", "example.zone.nsec3", local=True)
zone = t.zone("example.", "example.zone.nsec3", storage=".")
t.link(zone, knot)
t.link(zone, bind)
......
......@@ -7,7 +7,7 @@ from dnstest.test import Test
t = Test()
srv = t.server("knot")
zone = t.zone("ddns.", local=True)
zone = t.zone("ddns.", storage=".")
t.link(zone, srv, ddns=True)
......
......@@ -8,7 +8,7 @@ t = Test()
master = t.server("knot")
slave = t.server("knot")
zone = t.zone("empty.", local=True)
zone = t.zone("empty.", storage=".")
t.link(zone, master, slave)
......
......@@ -8,7 +8,7 @@ t = Test()
knot = t.server("knot")
bind = t.server("bind")
zone = t.zone("rdatacase.", "rdatacase.zone.signed", local=True)
zone = t.zone("rdatacase.", "rdatacase.zone.signed", storage=".")
t.link(zone, knot)
t.link(zone, bind)
......
......@@ -8,7 +8,7 @@ t = Test()
master = t.server("bind")
slave = t.server("knot")
zone = t.zone("obsolete.", local=True)
zone = t.zone("obsolete.", storage=".")
t.link(zone, master, slave)
......
......@@ -51,6 +51,8 @@ bind_ctl = get_binary("KNOT_TEST_BINDC", "rndc")
# Common data directory (e.g. zone files).
common_data_dir = ""
# Current module name.
module = ""
# Current case relative directory.
test_dir = ""
# Current case absolute output directory.
......
......@@ -532,6 +532,15 @@ class Server(object):
self.zones[zone.name].zfile.backup()
def update_zonefile(self, zone, version):
# Convert one item list to single object.
if isinstance(zone, list):
if len(zone) != 1:
raise Exception("One zone required.")
zone = zone[0]
self.zones[zone.name].zfile.upd_file(version=version)
class Bind(Server):
def __init__(self):
......
......@@ -135,7 +135,8 @@ class Test(object):
self.servers.discard(server)
return
for server in self.servers:
servers = [srv for srv in self.servers]
for server in servers:
self.server_remove(server)
def generate_conf(self):
......@@ -187,18 +188,19 @@ class Test(object):
def sleep(self, seconds):
time.sleep(seconds)
def zone(self, name, file_name=None, local=False, dnssec=None, serial=None,
exists=True):
def zone(self, name, file_name=None, storage=None, version=None, exists=True):
zone = dnstest.zonefile.ZoneFile(self.zones_dir)
zone.set_name(name)
if local:
if storage is ".":
src_dir = self.data_dir
elif storage:
src_dir = storage
else:
src_dir = params.common_data_dir
zone.set_file(file_name=file_name, storage=src_dir, dnssec=dnssec,
zone.set_file(file_name=file_name, storage=src_dir, version=version,
exists=exists)
return [zone]
......
......@@ -20,9 +20,9 @@ class ZoneFile(object):
self.file_dir = file_dir
self.file_name = ""
self.name = ""
self.serial = None
self.dnssec = None
self.nsec3 = None
# Directory containing source zone file/updates.
self.storage = None
self.backup_num = 1
......@@ -42,39 +42,40 @@ class ZoneFile(object):
else:
self.name = zone_generate.main(["-n", 1]).strip()
def set_file(self, file_name=None, storage=None, dnssec=None, serial=None,
exists=True):
def set_file(self, file_name=None, storage=None, version=None, exists=True):
'''Make a copy of an existing zone file. If no file name is specified,
the file name is constructed from the zone name (zname.zone).
If version is specified, file_name.version is used.
The storage is a directory containg the zone file.'''
if not file_name:
file_name = self.name + "zone"
if storage:
self.storage = storage
self.file_name = os.path.basename(file_name)
if os.path.isabs(file_name):
src_file = file_name
else:
src_file = os.path.join(storage, self.file_name)
if not exists:
return
try:
if os.path.isabs(file_name):
src_file = file_name
else:
src_file = os.path.join(self.storage, self.file_name)
if version:
src_file += "." + str(version)
shutil.copyfile(src_file, self.path)
except:
raise Exception("Can't use zone file %s" % src_file)
if dnssec is not None:
self.dnssec = dnssec
if serial:
self.serial = int(serial)
def upd_file(self, file_name=None, storage=None, dnssec=None, serial=None):
def upd_file(self, file_name=None, storage=None, version=None):
'''Replace zone file with a different one.'''
self.set_file(file_name=file_name, storage=storage, dnssec=dnssec,
serial=serial)
self.set_file(file_name=file_name, storage=storage, version=version)
def gen_file(self, dnssec=None, nsec3=None, records=None, serial=None):
'''Generate zone file.'''
......@@ -89,14 +90,11 @@ class ZoneFile(object):
serial = random.randint(1, 4294967295)
self.file_name = self.name + "rndzone"
self.serial = int(serial)
self.dnssec = dnssec
self.nsec3 = nsec3
try:
params = ["-i", self.serial, "-o", self.path, self.name, records]
if self.dnssec:
params = ["-s", "-3", "y" if self.nsec3 else "n"] + params
params = ["-i", serial, "-o", self.path, self.name, records]
if dnssec:
params = ["-s", "-3", "y" if nsec3 else "n"] + params
zone_generate.main(params)
except OSError:
err("Can't create zone file %s" % self.path)
......@@ -121,8 +119,7 @@ class ZoneFile(object):
new = ZoneFile(file_dir)
new.set_name(self.name)
new.set_file(file_name=self.path, dnssec=self.dnssec,
serial=self.serial,
new.set_file(file_name=self.path, storage=self.storage,
exists=exists and os.path.isfile(self.path))
return new
......
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