Commit 24f9e485 authored by Daniel Salzman's avatar Daniel Salzman

func-tests: add zone file update in random method

parent 0ee4ca24
......@@ -21,7 +21,8 @@ old_nsec3_serial = master.zone_wait(nsec3_zone)
# Enable autosigning.
master.dnssec_enable = True
master.use_gen_keys()
master.use_keys(nsec_zone)
master.use_keys(nsec3_zone)
master.gen_confile()
master.reload()
......
......@@ -571,15 +571,22 @@ class Server(object):
return key
def use_gen_keys(self):
def use_keys(self, zone):
# Convert one item list to single object.
if isinstance(zone, list):
if len(zone) != 1:
raise Exception("One zone required.")
zone = zone[0]
# Copy generated keys to server key directory.
prepare_dir(self.keydir)
src_files = os.listdir(params.test.key_dir)
src_files = os.listdir(zone.key_dir)
for file_name in src_files:
full_file_name = os.path.join(params.test.key_dir, file_name)
if (os.path.isfile(full_file_name)):
shutil.copy(full_file_name, self.keydir)
if zone.name[:-1] in file_name:
full_file_name = os.path.join(zone.key_dir, file_name)
if (os.path.isfile(full_file_name)):
shutil.copy(full_file_name, self.keydir)
def enable_nsec3(self, zone, **args):
# Convert one item list to single object.
......
......@@ -33,7 +33,6 @@ class Test(object):
self.out_dir = params.out_dir
self.data_dir = params.test_dir + "/data/"
self.zones_dir = self.out_dir + "/zones/"
self.key_dir = self.out_dir + "/keys/"
self.ip = ip if ip else random.choice([4, 6])
if self.ip not in [4, 6]:
......@@ -226,7 +225,7 @@ class Test(object):
zone = dnstest.zonefile.ZoneFile(self.zones_dir)
zone.set_name(name)
zone.gen_file(dnssec=dnssec, nsec3=nsec3, records=records,
serial=serial, keydir=self.key_dir)
serial=serial)
zones.append(zone)
return zones
......
......@@ -13,12 +13,14 @@ class ZoneFile(object):
def __init__(self, file_dir):
prepare_dir(file_dir)
self.file_dir = file_dir
self.key_dir = file_dir + "/keys/"
self.file_name = ""
self.name = ""
# Directory containing source zone file/updates.
self.storage = None
self.backup_num = 1
@property
......@@ -72,8 +74,7 @@ class ZoneFile(object):
self.set_file(file_name=file_name, storage=storage, version=version)
def gen_file(self, dnssec=None, nsec3=None, records=None, serial=None,
keydir=None):
def gen_file(self, dnssec=None, nsec3=None, records=None, serial=None):
'''Generate zone file.'''
if dnssec == None:
......@@ -90,8 +91,8 @@ class ZoneFile(object):
try:
params = ["-i", serial, "-o", self.path, self.name, records]
if dnssec:
prepare_dir(keydir)
params = ["-s", "-3", "y" if nsec3 else "n", "-k", keydir] \
prepare_dir(self.key_dir)
params = ["-s", "-3", "y" if nsec3 else "n", "-k", self.key_dir] \
+ params
zone_generate.main(params)
except OSError:
......@@ -175,3 +176,33 @@ class ZoneFile(object):
new_file.write(line)
os.remove(old_name)
def update_rnd(self):
'''Add random records or resign zone.'''
dnssec = False
nsec3 = False
self.update_serial()
old_name = self.path + ".old"
os.rename(self.path, old_name)
with open(old_name, 'r') as old_file:
for line in old_file:
if "RRSIG" in line:
dnssec = True
if "NSEC3PARAM" in line:
nsec3 = True
try:
params = ["-u", old_name, "-o", self.path, self.name]
if dnssec:
prepare_dir(self.key_dir)
params = ["-s", "-3", "y" if nsec3 else "n", "-k", self.key_dir] \
+ params
zone_generate.main(params)
except OSError:
raise Exception("Can't modify zone file %s" % self.path)
os.remove(old_name)
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