author | Tero Marttila <tero.marttila@aalto.fi> |
Wed, 25 Feb 2015 14:59:48 +0200 | |
changeset 467 | 3bb00e5e79d3 |
parent 466 | ad9d512ec1e7 |
child 468 | 3e7cb8dd5708 |
permissions | -rw-r--r-- |
440
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
1 |
import ipaddr |
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
2 |
import unittest |
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
3 |
|
463
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
4 |
from pvl.hosts import config, host, zone |
440
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
5 |
from StringIO import StringIO |
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
6 |
|
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
7 |
class Options(object): |
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
8 |
hosts_charset = 'utf-8' |
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
9 |
hosts_domain = None |
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
10 |
hosts_include = None |
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
11 |
|
447
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
12 |
class ConfFile(StringIO): |
440
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
13 |
def __init__(self, name, buffer): |
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
14 |
StringIO.__init__(self, buffer) |
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
15 |
self.name = name |
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
16 |
|
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
17 |
class TestConfig(unittest.TestCase): |
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
18 |
def setUp(self): |
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
19 |
self.options = Options() |
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
20 |
|
461
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
21 |
def assertHostEqual(self, host, host_str, attrs): |
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
22 |
self.assertEquals(str(host), host_str) |
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
23 |
|
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
24 |
for attr, value in attrs.iteritems(): |
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
25 |
self.assertEquals(getattr(host, attr), value) |
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
26 |
|
447
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
27 |
def assertHostsEqual(self, hosts, expected): |
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
28 |
for host, expect in zip(hosts, expected): |
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
29 |
host_str, attrs = expect |
441
f058fff1f272
pvl.hosts.hosts: fix sort_key()
Tero Marttila <tero.marttila@aalto.fi>
parents:
440
diff
changeset
|
30 |
|
461
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
31 |
self.assertHostEqual(host, host_str, attrs) |
441
f058fff1f272
pvl.hosts.hosts: fix sort_key()
Tero Marttila <tero.marttila@aalto.fi>
parents:
440
diff
changeset
|
32 |
|
451
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
33 |
def testApplyHostsFileError(self): |
440
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
34 |
with self.assertRaises(config.HostConfigError): |
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
35 |
list(config.apply_hosts(self.options, ['nonexistant'])) |
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
36 |
|
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
37 |
def testApplyHosts(self): |
447
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
38 |
conf_file = ConfFile('test', """ |
440
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
39 |
[foo] |
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
40 |
ip = 127.0.0.1 |
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
41 |
|
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
42 |
[bar] |
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
43 |
ip = 127.0.0.2 |
447
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
44 |
""") |
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
45 |
expected = [ |
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
46 |
('foo@test', dict(ip=ipaddr.IPAddress('127.0.0.1'))), |
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
47 |
('bar@test', dict(ip=ipaddr.IPAddress('127.0.0.2'))), |
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
48 |
] |
440
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
49 |
|
447
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
50 |
self.assertHostsEqual(config.apply_hosts_file(self.options, conf_file), expected) |
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
51 |
|
451
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
52 |
def testApply(self): |
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
53 |
self.assertHostsEqual(config.apply(self.options, ['etc/hosts/test']), [ |
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
54 |
('foo@test', dict( |
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
55 |
ip = ipaddr.IPAddress('127.0.0.1'), |
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
56 |
ethernet = {None: '00:11:22:33:44:55'}, |
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
57 |
)), |
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
58 |
('bar@test', dict( |
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
59 |
ip = ipaddr.IPAddress('127.0.0.2'), |
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
60 |
ethernet = {None: '01:23:45:67:89:ab'}, |
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
61 |
)), |
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
62 |
]) |
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
63 |
|
447
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
64 |
def testApplyHostsExpand(self): |
449
a19438b781d5
pvl.hosts.config: cleanup apply_host_config
Tero Marttila <tero.marttila@aalto.fi>
parents:
447
diff
changeset
|
65 |
self.assertHostsEqual(config.apply_host_config(self.options, 'asdf', 'asdf{1-3}', ip='10.100.100.$'), [ |
447
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
66 |
('asdf1@asdf', dict(ip=ipaddr.IPAddress('10.100.100.1'))), |
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
67 |
('asdf2@asdf', dict(ip=ipaddr.IPAddress('10.100.100.2'))), |
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
68 |
('asdf3@asdf', dict(ip=ipaddr.IPAddress('10.100.100.3'))), |
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
69 |
]) |
461
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
70 |
|
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
71 |
def testApplyHostConfigDict(self): |
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
72 |
host = config.apply_host(self.options, 'foo', 'test', { |
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
73 |
'ethernet.eth0': '00:11:22:33:44:55', |
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
74 |
}) |
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
75 |
|
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
76 |
self.assertHostEqual(host, 'foo@test', dict( |
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
77 |
ethernet = { 'eth0': '00:11:22:33:44:55' } |
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
78 |
)) |
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
79 |
|
451
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
80 |
def testApplyHostsConfigError(self): |
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
81 |
with self.assertRaises(config.HostConfigError): |
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
82 |
config.apply_host(self.options, 'foo', 'test', { |
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
83 |
'ethernet': 'foo', |
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
84 |
'ethernet.eth0': 'bar', |
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
85 |
}) |
447
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
86 |
|
462
6d699c76d75d
pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents:
461
diff
changeset
|
87 |
class TestForwardZone(unittest.TestCase): |
6d699c76d75d
pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents:
461
diff
changeset
|
88 |
def setUp(self): |
6d699c76d75d
pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents:
461
diff
changeset
|
89 |
self.options = Options() |
6d699c76d75d
pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents:
461
diff
changeset
|
90 |
self.options.add_origin = False |
6d699c76d75d
pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents:
461
diff
changeset
|
91 |
|
463
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
92 |
def assertZoneEquals(self, rrs, expected): |
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
93 |
gather = { } |
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
94 |
|
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
95 |
for rr in rrs: |
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
96 |
key = (rr.name.lower(), rr.type.upper()) |
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
97 |
|
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
98 |
self.assertNotIn(key, gather) |
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
99 |
|
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
100 |
gather[key] = rr.data |
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
101 |
|
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
102 |
self.assertDictEqual(gather, expected) |
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
103 |
|
462
6d699c76d75d
pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents:
461
diff
changeset
|
104 |
def testResolve(self): |
6d699c76d75d
pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents:
461
diff
changeset
|
105 |
self.assertEquals(zone.resolve(None, None, 'host'), 'host.') |
6d699c76d75d
pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents:
461
diff
changeset
|
106 |
self.assertEquals(zone.resolve(None, 'domain', 'host'), 'host.domain.') |
6d699c76d75d
pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents:
461
diff
changeset
|
107 |
|
6d699c76d75d
pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents:
461
diff
changeset
|
108 |
with self.assertRaises(zone.HostZoneError): |
6d699c76d75d
pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents:
461
diff
changeset
|
109 |
zone.resolve('origin', 'domain', 'host') |
6d699c76d75d
pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents:
461
diff
changeset
|
110 |
|
6d699c76d75d
pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents:
461
diff
changeset
|
111 |
self.assertEquals(zone.resolve('domain', 'domain', 'host'), 'host') |
6d699c76d75d
pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents:
461
diff
changeset
|
112 |
self.assertEquals(zone.resolve('origin', 'domain.origin', 'host'), 'host.domain') |
6d699c76d75d
pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents:
461
diff
changeset
|
113 |
|
6d699c76d75d
pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents:
461
diff
changeset
|
114 |
with self.assertRaises(zone.HostZoneError): |
6d699c76d75d
pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents:
461
diff
changeset
|
115 |
zone.resolve('origin', 'domainorigin', 'host') |
6d699c76d75d
pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents:
461
diff
changeset
|
116 |
|
6d699c76d75d
pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents:
461
diff
changeset
|
117 |
with self.assertRaises(zone.HostZoneError): |
6d699c76d75d
pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents:
461
diff
changeset
|
118 |
zone.resolve('origin', None, 'host.domain') |
6d699c76d75d
pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents:
461
diff
changeset
|
119 |
|
463
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
120 |
def testHostForwardOutOfOrigin(self): |
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
121 |
h = host.Host('host', 'domain', ip=ipaddr.IPAddress('10.0.0.1')) |
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
122 |
|
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
123 |
self.assertZoneEquals(zone.host_forward(h, 'test'), { }) |
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
124 |
|
464
f1d3dbf04ca3
pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents:
463
diff
changeset
|
125 |
def testHostIP(self): |
463
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
126 |
h = host.Host.build('host', 'domain', |
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
127 |
ip = '192.0.2.1', |
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
128 |
ip6 = '2001:db8::192.0.2.1', |
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
129 |
) |
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
130 |
|
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
131 |
self.assertZoneEquals(zone.host_forward(h, 'domain'), { |
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
132 |
('host', 'A'): ['192.0.2.1'], |
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
133 |
('host', 'AAAA'): ['2001:db8::c000:201'], |
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
134 |
}) |
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
135 |
|
464
f1d3dbf04ca3
pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents:
463
diff
changeset
|
136 |
self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.2.1/24'))), { |
f1d3dbf04ca3
pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents:
463
diff
changeset
|
137 |
('1', 'PTR'): ['host.domain.'], |
f1d3dbf04ca3
pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents:
463
diff
changeset
|
138 |
}) |
f1d3dbf04ca3
pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents:
463
diff
changeset
|
139 |
|
f1d3dbf04ca3
pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents:
463
diff
changeset
|
140 |
self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8::/64'))), { |
f1d3dbf04ca3
pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents:
463
diff
changeset
|
141 |
('1.0.2.0.0.0.0.c.0.0.0.0.0.0.0.0', 'PTR'): ['host.domain.'], |
f1d3dbf04ca3
pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents:
463
diff
changeset
|
142 |
}) |
465
133f14810eb5
pvl.hosts.zone: test forward= omit
Tero Marttila <tero.marttila@aalto.fi>
parents:
464
diff
changeset
|
143 |
|
466
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
144 |
def testHostAlias(self): |
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
145 |
h = host.Host.build('host', 'domain', |
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
146 |
ip = '192.0.2.1', |
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
147 |
alias = 'test *.test', |
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
148 |
) |
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
149 |
|
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
150 |
self.assertEquals(h.alias, ['test', '*.test']) |
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
151 |
|
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
152 |
self.assertZoneEquals(zone.host_forward(h, 'domain'), { |
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
153 |
('host', 'A'): ['192.0.2.1'], |
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
154 |
('test', 'CNAME'): ['host'], |
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
155 |
('*.test', 'CNAME'): ['host'], |
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
156 |
}) |
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
157 |
|
467
3bb00e5e79d3
pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
466
diff
changeset
|
158 |
def testHostForwardAlias(self): |
3bb00e5e79d3
pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
466
diff
changeset
|
159 |
h = host.Host.build('host', 'domain', |
3bb00e5e79d3
pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
466
diff
changeset
|
160 |
forward = 'host.example.net', |
3bb00e5e79d3
pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
466
diff
changeset
|
161 |
alias = 'test', |
3bb00e5e79d3
pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
466
diff
changeset
|
162 |
) |
3bb00e5e79d3
pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
466
diff
changeset
|
163 |
|
3bb00e5e79d3
pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
466
diff
changeset
|
164 |
self.assertZoneEquals(zone.host_forward(h, 'domain'), { |
3bb00e5e79d3
pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
466
diff
changeset
|
165 |
('host', 'CNAME'): ['host.example.net.'], |
3bb00e5e79d3
pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
466
diff
changeset
|
166 |
('test', 'CNAME'): ['host'], |
3bb00e5e79d3
pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
466
diff
changeset
|
167 |
}) |
466
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
168 |
|
465
133f14810eb5
pvl.hosts.zone: test forward= omit
Tero Marttila <tero.marttila@aalto.fi>
parents:
464
diff
changeset
|
169 |
def testHostDelegateForward(self): |
133f14810eb5
pvl.hosts.zone: test forward= omit
Tero Marttila <tero.marttila@aalto.fi>
parents:
464
diff
changeset
|
170 |
h = host.Host.build('host', 'example.com', |
133f14810eb5
pvl.hosts.zone: test forward= omit
Tero Marttila <tero.marttila@aalto.fi>
parents:
464
diff
changeset
|
171 |
forward = 'host.example.net', |
133f14810eb5
pvl.hosts.zone: test forward= omit
Tero Marttila <tero.marttila@aalto.fi>
parents:
464
diff
changeset
|
172 |
) |
133f14810eb5
pvl.hosts.zone: test forward= omit
Tero Marttila <tero.marttila@aalto.fi>
parents:
464
diff
changeset
|
173 |
|
133f14810eb5
pvl.hosts.zone: test forward= omit
Tero Marttila <tero.marttila@aalto.fi>
parents:
464
diff
changeset
|
174 |
self.assertZoneEquals(zone.host_forward(h, 'example.com'), { |
133f14810eb5
pvl.hosts.zone: test forward= omit
Tero Marttila <tero.marttila@aalto.fi>
parents:
464
diff
changeset
|
175 |
('host', 'CNAME'): ['host.example.net.'], |
133f14810eb5
pvl.hosts.zone: test forward= omit
Tero Marttila <tero.marttila@aalto.fi>
parents:
464
diff
changeset
|
176 |
}) |
464
f1d3dbf04ca3
pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents:
463
diff
changeset
|
177 |
|
463
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
178 |
def testHostDelegate(self): |
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
179 |
h = host.Host.build('host', 'example.com', |
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
180 |
ip = '192.0.2.1', |
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
181 |
ip6 = '2001:db8::192.0.2.1', |
465
133f14810eb5
pvl.hosts.zone: test forward= omit
Tero Marttila <tero.marttila@aalto.fi>
parents:
464
diff
changeset
|
182 |
forward = '', |
463
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
183 |
reverse = '1.0/28.2.0.192.in-addr.arpa', |
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
184 |
) |
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
185 |
|
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
186 |
self.assertZoneEquals(zone.host_forward(h, 'example.com'), { |
465
133f14810eb5
pvl.hosts.zone: test forward= omit
Tero Marttila <tero.marttila@aalto.fi>
parents:
464
diff
changeset
|
187 |
|
463
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
188 |
}) |
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
189 |
|
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
190 |
self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.2.1/24'))), { |
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
191 |
('1', 'CNAME'): ['1.0/28.2.0.192.in-addr.arpa.'], |
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
192 |
}) |
464
f1d3dbf04ca3
pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents:
463
diff
changeset
|
193 |
|
f1d3dbf04ca3
pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents:
463
diff
changeset
|
194 |
self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8::/64'))), { |
f1d3dbf04ca3
pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents:
463
diff
changeset
|
195 |
|
f1d3dbf04ca3
pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents:
463
diff
changeset
|
196 |
}) |
463
2cbdb2435487
pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents:
462
diff
changeset
|
197 |
|
440
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
198 |
if __name__ == '__main__': |
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
199 |
unittest.main() |