Commit 8e55de0e authored by Ales Mrazek's avatar Ales Mrazek

doctest correction, generator update, converter update

parent 48facc9b
......@@ -73,23 +73,87 @@ Call generator functions to generate `unbound.conf` and `kresd.conf`.
.. doctest::
>>> unbound_conf = gen_unbound(json_data)
>>> unbound_conf
'server:\n\tinterface: 127.0.0.1@53\n\tinterface: ::1@53\n\tinterface: 198.51.100.1@8853\n\toutgoing-interface: 2001:db8:0:2::1\n\tdo-ip6 = yes\n\tdo-ip4 = yes\n\tedns-buffer-size: 4096\n\tusername: "jetconf"\n\troot-hints: "/etc/resolver/root.hints"\n\tharden-glue: yes\n\tqname-minimisation: yes\n\trrset-roundrobin: yes\n\tdo-not-query-localhost: no\n\tverbosity: 2\n\tauto-trust-anchor-file: "/var/tmp/root.keys"\n\tdomain-insecure: "bad.example.com"\n\tdomain-insecure: "worse.example.com"\n\tmsg-cache-size: 104857600\n\tcache-max-ttl: 172800\n\tcache-min-ttl: 0\n\tdns64-prefix: 64:ff9b::/96\n\nstub-zone:\n\tname: "stub.example.com"\n\tstub-addr: "192.0.2.1@53"\n\nstub-zone:\n\tname: "stub.example.net"\n\tstub-addr: "198.51.100.1@53"\n'
>>> print(unbound_conf) # doctest: +NORMALIZE_WHITESPACE
server:
interface: 127.0.0.1@53
interface: ::1@53
interface: 198.51.100.1@8853
outgoing-interface: 2001:db8:0:2::1
do-ip6 = yes
do-ip4 = yes
edns-buffer-size: 4096
username: "jetconf"
root-hints: "/etc/resolver/root.hints"
harden-glue: yes
qname-minimisation: yes
rrset-roundrobin: yes
do-not-query-localhost: no
verbosity: 2
auto-trust-anchor-file: "/var/tmp/root.keys"
domain-insecure: "bad.example.com"
domain-insecure: "worse.example.com"
msg-cache-size: 104857600
cache-max-ttl: 172800
cache-min-ttl: 0
dns64-prefix: 64:ff9b::/96
<BLANKLINE>
stub-zone:
name: "stub.example.com"
stub-addr: "192.0.2.1@53"
<BLANKLINE>
stub-zone:
name: "stub.example.net"
stub-addr: "198.51.100.1@53"
<BLANKLINE>
.. doctest::
>>> kresd_conf = gen_kresd(json_data)
>>> kresd_conf
'net = {\'127.0.0.1@53\', \'::1@53\', \'198.51.100.1@8853\'}\nnet.outgoing_v6(\'2001:db8:0:2::1\')\nnet.ipv6 = true\nnet.ipv4 = true\nnet.bufsize(4096)\nuser(\'jetconf\',\'wheel\')\nSTUB(\'192.0.2.1@53\', \'198.51.100.1@53\')\nmodules.load(\'hints\')\nhints.set("loopback 127.0.0.1")\nhints.set("localhost 127.0.0.1")\nhints.set("localhost ::1")\nhints.add_hosts(/etc/hosts)\nhints.root({[\'a.root-servers.net\'] = {\'198.41.0.4\', \'2001:503:ba3e::2:30\'}})\nhints.root_file(\'/etc/resolver/root.hints\')\nmode(\'strict\')\noption(\'NO_MINIMIZE\', false)\nreorder_RR(true)\noption(\'ALLOW_LOCAL\', true)\nverbose(true)\ntrust_anchors.add_file(\'/var/tmp/root.keys\',false)\ntrust_anchors.set_insecure({\'bad.example.com\', \'worse.example.com\'})\ncache.size = 104857600\ncache.max_ttl(172800)\ncache.min_ttl(0)\nmodules.load(\'prefill\')\nprefill.config({\n\t[\'.\'] = {\n\t\turl = \'https://www.internic.net/domain/root.zone\', \n\t\tca_file = \'/etc/pki/tls/certs/ca-bundle.crt\', \n\t\tinterval = 86400\n\t}\n})\nmodules.load(\'dns64\')\ndns64.config(\'64:ff9b::/96\')\n'
>>> print(kresd_conf) # doctest: +NORMALIZE_WHITESPACE
net = {'127.0.0.1@53', '::1@53', '198.51.100.1@8853'}
net.outgoing_v6('2001:db8:0:2::1')
net.ipv6 = true
net.ipv4 = true
net.bufsize(4096)
user('jetconf','wheel')
STUB('192.0.2.1@53', '198.51.100.1@53')
modules.load('hints')
hints.set("loopback 127.0.0.1")
hints.set("localhost 127.0.0.1")
hints.set("localhost ::1")
hints.add_hosts(/etc/hosts)
hints.root({['a.root-servers.net'] = {'198.41.0.4', '2001:503:ba3e::2:30'}})
hints.root_file('/etc/resolver/root.hints')
mode('strict')
option('NO_MINIMIZE', false)
reorder_RR(true)
option('ALLOW_LOCAL', true)
verbose(true)
trust_anchors.add_file('/var/tmp/root.keys',false)
trust_anchors.set_insecure({'bad.example.com', 'worse.example.com'})
cache.size = 104857600
cache.max_ttl(172800)
cache.min_ttl(0)
modules.load('prefill')
prefill.config({
['.'] = {
url = 'https://www.internic.net/domain/root.zone',
ca_file = '/etc/pki/tls/certs/ca-bundle.crt',
interval = 86400
}
})
modules.load('dns64')
dns64.config('64:ff9b::/96')
<BLANKLINE>
``unbound_conf`` and ``kresd_conf`` are raw strings , which can be save as text files.
.. doctest::
>>> unb_file = open("unbound.conf", "w+")
>>> unb_file.write(unbound_conf) # doctest: +hide
>>> unb_file.close()
>>> with open("unbound.conf", "w") as unb_file:
... unb_file.write(unbound_conf)
689
Converter module
----------------
......@@ -115,7 +179,8 @@ Input parameter of ``from_unbound`` function is a list of string lines loaded fr
>>> json_data = from_unbound(unbconf_data)
>>> json_data
{'cznic-resolver-common:dns-resolver': {'dns64': {'prefix': '64:ff9b::/96'}, 'cache': {'max-size': 104857600, 'max-ttl': 172800, 'min-ttl': 0}, 'dnssec': {'negative-trust-anchors': ['bad.example.com', 'worse.example.com'], 'trust-anchors': {'key-files': [{'domain': 'domain0', 'file': '/var/tmp/root.keys'}]}}, 'logging': {'verbosity': 2}, 'resolver': {'options': {'glue-checking': 'strict', 'qname-minimisation': True, 'reorder-rrset': True, 'query-loopback': True}, 'stub-zones': [{'domain': 'stub.example.com', 'nameserver': '192.0.2.1', 'port': 53}, {'domain': 'stub.example.net', 'nameserver': '198.51.100.1', 'port': 53}], 'hints': {'root-zone-file': '/etc/resolver/root.hints'}}, 'network': {'listen-interfaces': [{'name': 'interface0', 'ip-address': '127.0.0.1', 'port': 53}, {'name': 'interface1', 'ip-address': '::1', 'port': 53}, {'name': 'interface2', 'ip-address': '198.51.100.1', 'port': 8853}], 'source-address': {'ipv6': '2001:db8:0:2::1'}, 'udp-payload-size': 4096, 'recursion-transport': {'l2-protocols': 'ipv4 ipv6'}}, 'server': {'user-name': 'jetconf'}}}
{'cznic-resolver-common:dns-resolver': {'server': {'user-name': 'jetconf'}, 'network': {'listen-interfaces': [{'name': 'interface0', 'ip-address': '127.0.0.1', 'port': 53}, {'name': 'interface1', 'ip-address': '::1', 'port': 53}, {'name': 'interface2', 'ip-address': '198.51.100.1', 'port': 8853}], 'source-address': {'ipv6': '2001:db8:0:2::1'}, 'udp-payload-size': 4096, 'recursion-transport': {'l2-protocols': 'ipv4 ipv6'}}, 'resolver': {'options': {'glue-checking': 'strict', 'qname-minimisation': True, 'reorder-rrset': True, 'query-loopback': True}, 'stub-zones': [{'domain': 'stub.example.com', 'nameserver': '192.0.2.1', 'port': 53}, {'domain': 'stub.example.net', 'nameserver': '198.51.100.1', 'port': 53}], 'hints': {'root-zone-file': '/etc/resolver/root.hints'}}, 'logging': {'verbosity': 2}, 'dnssec': {'negative-trust-anchors': ['bad.example.com', 'worse.example.com'], 'trust-anchors': {'key-files': [{'domain': 'domain0', 'file': '/var/tmp/root.keys'}]}}, 'cache': {'max-size': 104857600, 'max-ttl': 172800, 'min-ttl': 0}, 'dns64': {'prefix': '64:ff9b::/96'}}}
``json_data`` variable is python dictionary, which can be easily validate against data model by ``Yangson`` library and save to Json-encoded file.
......
......@@ -34,11 +34,9 @@ unb_conf = gen_unbound(data_defaults)
kresd_conf = gen_kresd(data_defaults)
# write Knot Resolver configuration
knot_file = open(kresd_path, "w+")
knot_file.write(kresd_conf)
knot_file.close()
with open(kresd_path, "w") as knot_file:
knot_file.write(kresd_conf)
# write Unbound configuration
unb_file = open(unb_path, "w+")
unb_file.write(unb_conf)
unb_file.close()
with open(unb_path, "w") as unb_file:
unb_file.write(unb_conf)
......@@ -226,19 +226,19 @@ def from_unbound(unbound_data: list):
network['recursion-transport'] = {}
network['recursion-transport']['l2-protocols'] = 'ipv6'
if dns64:
data['cznic-resolver-common:dns-resolver']['dns64'] = dns64
if cache:
data['cznic-resolver-common:dns-resolver']['cache'] = cache
if dnssec:
data['cznic-resolver-common:dns-resolver']['dnssec'] = dnssec
if logging:
data['cznic-resolver-common:dns-resolver']['logging'] = logging
if resolver:
data['cznic-resolver-common:dns-resolver']['resolver'] = resolver
if network:
data['cznic-resolver-common:dns-resolver']['network'] = network
if server:
data['cznic-resolver-common:dns-resolver']['server'] = server
if network:
data['cznic-resolver-common:dns-resolver']['network'] = network
if resolver:
data['cznic-resolver-common:dns-resolver']['resolver'] = resolver
if logging:
data['cznic-resolver-common:dns-resolver']['logging'] = logging
if dnssec:
data['cznic-resolver-common:dns-resolver']['dnssec'] = dnssec
if cache:
data['cznic-resolver-common:dns-resolver']['cache'] = cache
if dns64:
data['cznic-resolver-common:dns-resolver']['dns64'] = dns64
return data
This diff is collapsed.
......@@ -44,10 +44,9 @@ data_defaults = data.add_defaults()
# generate configuration strings
unb_conf = gen_unbound(data_defaults)
# write Unbound configuration
unb_file = open(unb_path, "w+")
unb_file.write(unb_conf)
unb_file.close()
# write Unbound configurationwith
with open(unb_path, "w") as unb_file:
unb_file.write(unb_conf)
#################################################################################
# Converting unbound-test.conf
......
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