Commit 4303fcd9 authored by Filip Siroky's avatar Filip Siroky Committed by Daniel Salzman

tests-extra: add config file include test

parent b9e99527
#!/usr/bin/env python3
'''Include zones through config files, tests-extra API, and CLI.'''
import os
from dnstest.libknot import libknot
from dnstest.test import Test
from dnstest.utils import *
t = Test()
ZONE1 = 'zone1.'
ZONE2 = 'zone2.'
ZONE3 = 'example.com.'
ZONE4 = 'zone4.'
knot = t.server("knot")
knot.include(ZONE1 + "conf", ".")
knot.include("server.conf", ".")
knot.include("empty.conf", ".")
knot.include(ZONE2 + "conf", ".")
added_file = knot.data_add(ZONE4 + "conf", ".")
zone = t.zone(ZONE3)
t.link(zone, knot)
ctl = libknot.control.KnotCtl()
t.start()
ctl.connect(os.path.join(knot.dir, "knot.sock"))
ctl.send_block(cmd="conf-begin")
resp = ctl.receive_block()
ctl.send_block(cmd="conf-set", section="include", data=added_file)
resp = ctl.receive_block()
# Cannot commit as it reloads the server without this include!
ctl.send_block(cmd="conf-get", section="zone")
resp = ctl.receive_block()
isset(ZONE1 in resp['zone'], ZONE1)
isset(ZONE2 in resp['zone'], ZONE2)
isset(ZONE3 in resp['zone'], ZONE3)
isset(ZONE4 in resp['zone'], ZONE4)
ctl.send_block(cmd="conf-commit")
resp = ctl.receive_block()
ctl.send_block(cmd="conf-read", section="server")
resp = ctl.receive_block()
isset('max-tcp-clients' in resp['server'], "server section item not set")
isset('5' in resp['server']['max-tcp-clients'], "server section item value not set")
ctl.send(libknot.control.KnotCtlType.END)
ctl.close()
t.end()
......@@ -7,6 +7,9 @@ class KnotConf(object):
self.conf = ""
self.first_item = True
def include(self, path):
self.conf += "include: %s\n" % (path)
def begin(self, name):
self.conf += "%s:\n" % name
self.first_item = True
......
......@@ -922,6 +922,7 @@ class Knot(Server):
self.daemon_bin = params.knot_bin
self.control_bin = params.knot_ctl
self.inquirer = dnstest.inquirer.Inquirer()
self.includes = set()
@property
def keydir(self):
......@@ -979,8 +980,30 @@ class Knot(Server):
if value != None:
conf.item_str(name, value)
def data_add(self, file_name, storage=None):
if storage is ".":
src_dir = self.data_dir
elif storage:
src_dir = storage
else:
src_dir = params.common_data_dir
src_file = src_dir + file_name
dst_file = self.dir + '/' + file_name
shutil.copyfile(src_file, dst_file)
return dst_file
def include(self, file_name, storage=None):
dst_file = self.data_add(file_name, storage)
self.includes.add(dst_file)
def get_config(self):
s = dnstest.config.KnotConf()
for file in self.includes:
s.include(file)
s.begin("server")
self._on_str_hex(s, "identity", self.ident)
self._on_str_hex(s, "version", self.version)
......
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