author | Tero Marttila <tero.marttila@aalto.fi> |
Thu, 26 Feb 2015 16:37:24 +0200 | |
changeset 502 | ac4e0f2df80c |
parent 501 | 41b362e6074b |
child 503 | a56456f901e8 |
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 |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
2 |
import pvl.args |
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
|
3 |
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
|
4 |
|
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
5 |
from pvl.hosts import config, dhcp, zone |
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
6 |
from pvl.hosts.host import Host |
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
|
7 |
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
|
8 |
|
447
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
9 |
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
|
10 |
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
|
11 |
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
|
12 |
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
|
13 |
|
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 |
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
|
15 |
def setUp(self): |
490
805645dbb9bb
pvl.hosts.tests: cleanup use of options
Tero Marttila <tero.marttila@aalto.fi>
parents:
489
diff
changeset
|
16 |
self.options = pvl.args.options( |
805645dbb9bb
pvl.hosts.tests: cleanup use of options
Tero Marttila <tero.marttila@aalto.fi>
parents:
489
diff
changeset
|
17 |
hosts_charset = 'utf-8', |
805645dbb9bb
pvl.hosts.tests: cleanup use of options
Tero Marttila <tero.marttila@aalto.fi>
parents:
489
diff
changeset
|
18 |
hosts_domain = None, |
805645dbb9bb
pvl.hosts.tests: cleanup use of options
Tero Marttila <tero.marttila@aalto.fi>
parents:
489
diff
changeset
|
19 |
hosts_include = None, |
805645dbb9bb
pvl.hosts.tests: cleanup use of options
Tero Marttila <tero.marttila@aalto.fi>
parents:
489
diff
changeset
|
20 |
) |
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
|
21 |
|
461
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
22 |
def assertHostEqual(self, host, host_str, attrs): |
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
23 |
self.assertEquals(str(host), host_str) |
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
24 |
|
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
25 |
for attr, value in attrs.iteritems(): |
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
26 |
self.assertEquals(getattr(host, attr), value) |
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
27 |
|
447
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
28 |
def assertHostsEqual(self, hosts, expected): |
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
29 |
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
|
30 |
host_str, attrs = expect |
441
f058fff1f272
pvl.hosts.hosts: fix sort_key()
Tero Marttila <tero.marttila@aalto.fi>
parents:
440
diff
changeset
|
31 |
|
461
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
32 |
self.assertHostEqual(host, host_str, attrs) |
441
f058fff1f272
pvl.hosts.hosts: fix sort_key()
Tero Marttila <tero.marttila@aalto.fi>
parents:
440
diff
changeset
|
33 |
|
451
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
34 |
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
|
35 |
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
|
36 |
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
|
37 |
|
1d755df7bf97
pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
38 |
def testApplyHosts(self): |
447
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
39 |
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
|
40 |
[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
|
41 |
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
|
42 |
|
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 |
[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
|
44 |
ip = 127.0.0.2 |
447
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
45 |
""") |
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
46 |
expected = [ |
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
47 |
('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
|
48 |
('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
|
49 |
] |
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
|
50 |
|
447
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
51 |
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
|
52 |
|
451
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
53 |
def testApply(self): |
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
54 |
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
|
55 |
('foo@test', dict( |
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
56 |
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
|
57 |
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
|
58 |
)), |
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
59 |
('bar@test', dict( |
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
60 |
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
|
61 |
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
|
62 |
)), |
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
63 |
]) |
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
64 |
|
447
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
65 |
def testApplyHostsExpand(self): |
449
a19438b781d5
pvl.hosts.config: cleanup apply_host_config
Tero Marttila <tero.marttila@aalto.fi>
parents:
447
diff
changeset
|
66 |
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
|
67 |
('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
|
68 |
('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
|
69 |
('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
|
70 |
]) |
461
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
71 |
|
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
72 |
def testApplyHostConfigDict(self): |
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
73 |
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
|
74 |
'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
|
75 |
}) |
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
76 |
|
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
77 |
self.assertHostEqual(host, 'foo@test', dict( |
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
78 |
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
|
79 |
)) |
502
ac4e0f2df80c
pvl.hosts.tests: test multi-value dicts for host
Tero Marttila <tero.marttila@aalto.fi>
parents:
501
diff
changeset
|
80 |
|
ac4e0f2df80c
pvl.hosts.tests: test multi-value dicts for host
Tero Marttila <tero.marttila@aalto.fi>
parents:
501
diff
changeset
|
81 |
def testApplyHostConfigDictMulti(self): |
ac4e0f2df80c
pvl.hosts.tests: test multi-value dicts for host
Tero Marttila <tero.marttila@aalto.fi>
parents:
501
diff
changeset
|
82 |
host = config.apply_host(self.options, 'foo', 'test', { |
ac4e0f2df80c
pvl.hosts.tests: test multi-value dicts for host
Tero Marttila <tero.marttila@aalto.fi>
parents:
501
diff
changeset
|
83 |
'ethernet.eth0': '00:11:22:33:44:55', |
ac4e0f2df80c
pvl.hosts.tests: test multi-value dicts for host
Tero Marttila <tero.marttila@aalto.fi>
parents:
501
diff
changeset
|
84 |
'ethernet.eth1': '00:11:22:33:44:66', |
ac4e0f2df80c
pvl.hosts.tests: test multi-value dicts for host
Tero Marttila <tero.marttila@aalto.fi>
parents:
501
diff
changeset
|
85 |
}) |
ac4e0f2df80c
pvl.hosts.tests: test multi-value dicts for host
Tero Marttila <tero.marttila@aalto.fi>
parents:
501
diff
changeset
|
86 |
|
ac4e0f2df80c
pvl.hosts.tests: test multi-value dicts for host
Tero Marttila <tero.marttila@aalto.fi>
parents:
501
diff
changeset
|
87 |
self.assertHostEqual(host, 'foo@test', dict( |
ac4e0f2df80c
pvl.hosts.tests: test multi-value dicts for host
Tero Marttila <tero.marttila@aalto.fi>
parents:
501
diff
changeset
|
88 |
ethernet = { |
ac4e0f2df80c
pvl.hosts.tests: test multi-value dicts for host
Tero Marttila <tero.marttila@aalto.fi>
parents:
501
diff
changeset
|
89 |
'eth0': '00:11:22:33:44:55', |
ac4e0f2df80c
pvl.hosts.tests: test multi-value dicts for host
Tero Marttila <tero.marttila@aalto.fi>
parents:
501
diff
changeset
|
90 |
'eth1': '00:11:22:33:44:66', |
ac4e0f2df80c
pvl.hosts.tests: test multi-value dicts for host
Tero Marttila <tero.marttila@aalto.fi>
parents:
501
diff
changeset
|
91 |
} |
ac4e0f2df80c
pvl.hosts.tests: test multi-value dicts for host
Tero Marttila <tero.marttila@aalto.fi>
parents:
501
diff
changeset
|
92 |
)) |
461
e3bddc5eeff5
pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents:
451
diff
changeset
|
93 |
|
451
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
94 |
def testApplyHostsConfigError(self): |
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
95 |
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
|
96 |
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
|
97 |
'ethernet': 'foo', |
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
98 |
'ethernet.eth0': 'bar', |
d302b4957b07
pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents:
449
diff
changeset
|
99 |
}) |
447
6f0357759e9b
pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents:
441
diff
changeset
|
100 |
|
501
41b362e6074b
pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents:
497
diff
changeset
|
101 |
def testApplyHostConfigExtensions(self): |
41b362e6074b
pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents:
497
diff
changeset
|
102 |
host = config.apply_host(self.options, 'foo', 'test', { |
41b362e6074b
pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents:
497
diff
changeset
|
103 |
'link:50': 'foo@test', |
41b362e6074b
pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents:
497
diff
changeset
|
104 |
'link:uplink.49': 'bar@test', |
41b362e6074b
pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents:
497
diff
changeset
|
105 |
}) |
41b362e6074b
pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents:
497
diff
changeset
|
106 |
|
41b362e6074b
pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents:
497
diff
changeset
|
107 |
self.assertHostEqual(host, 'foo@test', dict( |
41b362e6074b
pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents:
497
diff
changeset
|
108 |
extensions = { |
41b362e6074b
pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents:
497
diff
changeset
|
109 |
'link': { |
41b362e6074b
pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents:
497
diff
changeset
|
110 |
'50': 'foo@test', |
41b362e6074b
pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents:
497
diff
changeset
|
111 |
'uplink': { '49': 'bar@test' }, |
41b362e6074b
pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents:
497
diff
changeset
|
112 |
}, |
41b362e6074b
pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents:
497
diff
changeset
|
113 |
}, |
41b362e6074b
pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents:
497
diff
changeset
|
114 |
)) |
41b362e6074b
pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents:
497
diff
changeset
|
115 |
|
41b362e6074b
pvl.hosts.config: fix and test extensions
Tero Marttila <tero.marttila@aalto.fi>
parents:
497
diff
changeset
|
116 |
|
469
cd1f1b51f3a0
pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents:
468
diff
changeset
|
117 |
class TestZoneMixin(object): |
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
|
118 |
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
|
119 |
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
|
120 |
|
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 |
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
|
122 |
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
|
123 |
|
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 |
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
|
125 |
|
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 |
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
|
127 |
|
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 |
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
|
129 |
|
469
cd1f1b51f3a0
pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents:
468
diff
changeset
|
130 |
|
cd1f1b51f3a0
pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents:
468
diff
changeset
|
131 |
class TestForwardZone(TestZoneMixin, unittest.TestCase): |
cd1f1b51f3a0
pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents:
468
diff
changeset
|
132 |
def testHostOutOfOrigin(self): |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
133 |
h = Host('host', 'domain', ip=ipaddr.IPAddress('10.0.0.1')) |
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
|
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 |
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
|
136 |
|
464
f1d3dbf04ca3
pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents:
463
diff
changeset
|
137 |
def testHostIP(self): |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
138 |
h = Host.build('host', 'domain', |
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
|
139 |
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
|
140 |
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
|
141 |
) |
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
|
142 |
|
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
|
143 |
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
|
144 |
('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
|
145 |
('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
|
146 |
}) |
465
133f14810eb5
pvl.hosts.zone: test forward= omit
Tero Marttila <tero.marttila@aalto.fi>
parents:
464
diff
changeset
|
147 |
|
466
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
148 |
def testHostAlias(self): |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
149 |
h = Host.build('host', 'domain', |
466
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
150 |
ip = '192.0.2.1', |
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
151 |
alias = 'test *.test', |
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
152 |
) |
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
153 |
|
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
154 |
self.assertEquals(h.alias, ['test', '*.test']) |
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
155 |
|
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
156 |
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
|
157 |
('host', 'A'): ['192.0.2.1'], |
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
158 |
('test', 'CNAME'): ['host'], |
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
159 |
('*.test', 'CNAME'): ['host'], |
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
160 |
}) |
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
161 |
|
468
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
162 |
def testHostAlias46(self): |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
163 |
h = Host.build('host', 'domain', |
468
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
164 |
ip = '192.0.2.1', |
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
165 |
ip6 = '2001:db8::192.0.2.1', |
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
166 |
alias4 = 'test4', |
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
167 |
alias6 = 'test6', |
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
168 |
) |
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
169 |
|
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
170 |
self.assertZoneEquals(zone.host_forward(h, 'domain'), { |
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
171 |
('host', 'A'): ['192.0.2.1'], |
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
172 |
('host', 'AAAA'): ['2001:db8::c000:201'], |
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
173 |
('test4', 'A'): ['192.0.2.1'], |
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
174 |
('test6', 'AAAA'): ['2001:db8::c000:201'], |
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
175 |
}) |
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
176 |
|
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
177 |
def testHostAlias4Missing(self): |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
178 |
h = Host.build('host', 'domain', |
468
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
179 |
ip6 = '2001:db8::192.0.2.1', |
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
180 |
alias4 = 'test4', |
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
181 |
alias6 = 'test6', |
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
182 |
) |
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
183 |
|
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
184 |
with self.assertRaises(zone.HostZoneError): |
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
185 |
self.assertZoneEquals(zone.host_forward(h, 'domain'), { }) |
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
186 |
|
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
187 |
def testHostAlias6Missing(self): |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
188 |
h = Host.build('host', 'domain', |
468
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
189 |
ip = '192.0.2.1', |
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
190 |
alias4 = 'test4', |
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
191 |
alias6 = 'test6', |
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
192 |
) |
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
193 |
|
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
194 |
with self.assertRaises(zone.HostZoneError): |
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
195 |
self.assertZoneEquals(zone.host_forward(h, 'domain'), { }) |
3e7cb8dd5708
pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents:
467
diff
changeset
|
196 |
|
493
c9725dd0d48c
pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
492
diff
changeset
|
197 |
def testHostFQDN(self): |
c9725dd0d48c
pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
492
diff
changeset
|
198 |
h = Host.build('host.example.net', None, |
c9725dd0d48c
pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
492
diff
changeset
|
199 |
ip = '192.0.2.3', |
c9725dd0d48c
pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
492
diff
changeset
|
200 |
) |
c9725dd0d48c
pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
492
diff
changeset
|
201 |
|
c9725dd0d48c
pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
492
diff
changeset
|
202 |
self.assertZoneEquals(zone.host_forward(h, 'example.com'), { |
c9725dd0d48c
pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
492
diff
changeset
|
203 |
|
c9725dd0d48c
pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
492
diff
changeset
|
204 |
}) |
c9725dd0d48c
pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
492
diff
changeset
|
205 |
|
469
cd1f1b51f3a0
pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents:
468
diff
changeset
|
206 |
def testHostDelegate(self): |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
207 |
h = Host.build('host', 'example.com', |
469
cd1f1b51f3a0
pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents:
468
diff
changeset
|
208 |
forward = 'host.example.net', |
cd1f1b51f3a0
pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents:
468
diff
changeset
|
209 |
) |
cd1f1b51f3a0
pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents:
468
diff
changeset
|
210 |
|
cd1f1b51f3a0
pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents:
468
diff
changeset
|
211 |
self.assertZoneEquals(zone.host_forward(h, 'example.com'), { |
cd1f1b51f3a0
pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents:
468
diff
changeset
|
212 |
('host', 'CNAME'): ['host.example.net.'], |
cd1f1b51f3a0
pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents:
468
diff
changeset
|
213 |
}) |
cd1f1b51f3a0
pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents:
468
diff
changeset
|
214 |
|
467
3bb00e5e79d3
pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
466
diff
changeset
|
215 |
def testHostForwardAlias(self): |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
216 |
h = Host.build('host', 'domain', |
467
3bb00e5e79d3
pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
466
diff
changeset
|
217 |
forward = 'host.example.net', |
3bb00e5e79d3
pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
466
diff
changeset
|
218 |
alias = 'test', |
3bb00e5e79d3
pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
466
diff
changeset
|
219 |
) |
3bb00e5e79d3
pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
466
diff
changeset
|
220 |
|
3bb00e5e79d3
pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
466
diff
changeset
|
221 |
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
|
222 |
('host', 'CNAME'): ['host.example.net.'], |
3bb00e5e79d3
pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
466
diff
changeset
|
223 |
('test', 'CNAME'): ['host'], |
3bb00e5e79d3
pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
466
diff
changeset
|
224 |
}) |
466
ad9d512ec1e7
pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents:
465
diff
changeset
|
225 |
|
470
ac334a55eebc
pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents:
469
diff
changeset
|
226 |
def testHostLocation(self): |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
227 |
h = Host.build('host', 'domain', |
470
ac334a55eebc
pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents:
469
diff
changeset
|
228 |
ip = '192.0.2.1', |
ac334a55eebc
pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents:
469
diff
changeset
|
229 |
location = 'test', |
ac334a55eebc
pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents:
469
diff
changeset
|
230 |
) |
ac334a55eebc
pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents:
469
diff
changeset
|
231 |
|
ac334a55eebc
pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents:
469
diff
changeset
|
232 |
self.assertEquals(h.location, ('test', 'domain')) |
ac334a55eebc
pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents:
469
diff
changeset
|
233 |
|
ac334a55eebc
pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents:
469
diff
changeset
|
234 |
self.assertZoneEquals(zone.host_forward(h, 'domain'), { |
ac334a55eebc
pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents:
469
diff
changeset
|
235 |
('host', 'A'): ['192.0.2.1'], |
ac334a55eebc
pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents:
469
diff
changeset
|
236 |
('test', 'CNAME'): ['host'], |
ac334a55eebc
pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents:
469
diff
changeset
|
237 |
}) |
471
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
238 |
|
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
239 |
def testHostLocationDomain(self): |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
240 |
h = Host.build('host', 'foo.domain', |
471
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
241 |
ip = '192.0.2.1', |
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
242 |
location = 'test@bar.domain', |
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
243 |
) |
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
244 |
|
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
245 |
self.assertEquals(h.location, ('test', 'bar.domain')) |
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
246 |
|
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
247 |
self.assertZoneEquals(zone.host_forward(h, 'domain'), { |
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
248 |
('host.foo', 'A'): ['192.0.2.1'], |
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
249 |
('test.bar', 'CNAME'): ['host.foo'], |
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
250 |
}) |
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
251 |
|
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
252 |
def testHostLocationDomainOutOfOrigin(self): |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
253 |
h = Host.build('host', 'foo.domain', |
471
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
254 |
ip = '192.0.2.1', |
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
255 |
location = 'test@bar.domain', |
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
256 |
) |
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
257 |
|
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
258 |
self.assertEquals(h.location, ('test', 'bar.domain')) |
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
259 |
|
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
260 |
with self.assertRaises(zone.HostZoneError): |
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
261 |
self.assertZoneEquals(zone.host_forward(h, 'foo.domain'), { |
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
262 |
('host', 'A'): ['192.0.2.1'], |
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
263 |
}) |
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
264 |
|
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
265 |
# TODO |
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
266 |
#self.assertZoneEquals(zone.host_forward(h, 'bar.domain'), { |
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
267 |
# ('test', 'CNAME'): ['host.foo'], |
e4b4458d8061
pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents:
470
diff
changeset
|
268 |
#}) |
472
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
269 |
|
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
270 |
def testHostsForward(self): |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
271 |
hosts = [ |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
272 |
Host.build('foo', 'domain', |
472
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
273 |
ip = '192.0.2.1', |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
274 |
ip6 = '2001:db8::192.0.2.1', |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
275 |
alias = 'test', |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
276 |
), |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
277 |
Host.build('bar', 'domain', |
472
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
278 |
ip = '192.0.2.2', |
496
530f22575889
pvl.hosts.zone: label=relative() check handles FQDNs
Tero Marttila <tero.marttila@aalto.fi>
parents:
494
diff
changeset
|
279 |
), |
530f22575889
pvl.hosts.zone: label=relative() check handles FQDNs
Tero Marttila <tero.marttila@aalto.fi>
parents:
494
diff
changeset
|
280 |
Host.build('quux', 'example', |
530f22575889
pvl.hosts.zone: label=relative() check handles FQDNs
Tero Marttila <tero.marttila@aalto.fi>
parents:
494
diff
changeset
|
281 |
ip = '192.0.2.3', |
530f22575889
pvl.hosts.zone: label=relative() check handles FQDNs
Tero Marttila <tero.marttila@aalto.fi>
parents:
494
diff
changeset
|
282 |
), |
472
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
283 |
] |
497
0082d2092d1f
pvl.hosts.zone: should be an fqdn
Tero Marttila <tero.marttila@aalto.fi>
parents:
496
diff
changeset
|
284 |
|
0082d2092d1f
pvl.hosts.zone: should be an fqdn
Tero Marttila <tero.marttila@aalto.fi>
parents:
496
diff
changeset
|
285 |
rrs = zone.apply_hosts_forward(hosts, 'domain', add_origin=True) |
0082d2092d1f
pvl.hosts.zone: should be an fqdn
Tero Marttila <tero.marttila@aalto.fi>
parents:
496
diff
changeset
|
286 |
|
0082d2092d1f
pvl.hosts.zone: should be an fqdn
Tero Marttila <tero.marttila@aalto.fi>
parents:
496
diff
changeset
|
287 |
# handle the $ORIGIN directive |
0082d2092d1f
pvl.hosts.zone: should be an fqdn
Tero Marttila <tero.marttila@aalto.fi>
parents:
496
diff
changeset
|
288 |
rd = next(rrs) |
472
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
289 |
|
497
0082d2092d1f
pvl.hosts.zone: should be an fqdn
Tero Marttila <tero.marttila@aalto.fi>
parents:
496
diff
changeset
|
290 |
self.assertEquals(unicode(rd), '$ORIGIN\tdomain.') |
0082d2092d1f
pvl.hosts.zone: should be an fqdn
Tero Marttila <tero.marttila@aalto.fi>
parents:
496
diff
changeset
|
291 |
|
0082d2092d1f
pvl.hosts.zone: should be an fqdn
Tero Marttila <tero.marttila@aalto.fi>
parents:
496
diff
changeset
|
292 |
self.assertZoneEquals(rrs, { |
472
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
293 |
('foo', 'A'): ['192.0.2.1'], |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
294 |
('foo', 'AAAA'): ['2001:db8::c000:201'], |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
295 |
('test', 'CNAME'): ['foo'], |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
296 |
('bar', 'A'): ['192.0.2.2'], |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
297 |
}) |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
298 |
|
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
299 |
def testHostsConflict(self): |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
300 |
hosts = [ |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
301 |
Host.build('foo', 'domain', |
472
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
302 |
ip = '192.0.2.1', |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
303 |
), |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
304 |
Host.build('foo', 'domain', |
472
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
305 |
ip = '192.0.2.2', |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
306 |
) |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
307 |
] |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
308 |
|
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
309 |
with self.assertRaises(zone.HostZoneError): |
489
7f1bd12e0d54
pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents:
487
diff
changeset
|
310 |
self.assertZoneEquals(zone.apply_hosts_forward(hosts, 'domain'), { }) |
472
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
311 |
|
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
312 |
def testHostsAliasConflict(self): |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
313 |
hosts = [ |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
314 |
Host.build('foo', 'domain', |
472
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
315 |
ip = '192.0.2.1', |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
316 |
), |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
317 |
Host.build('bar', 'domain', |
472
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
318 |
ip = '192.0.2.2', |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
319 |
alias = 'foo', |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
320 |
) |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
321 |
] |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
322 |
|
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
323 |
# with A first |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
324 |
with self.assertRaises(zone.HostZoneError): |
489
7f1bd12e0d54
pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents:
487
diff
changeset
|
325 |
self.assertZoneEquals(zone.apply_hosts_forward(hosts, 'domain'), { }) |
472
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
326 |
|
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
327 |
# also with CNAME first |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
328 |
with self.assertRaises(zone.HostZoneError): |
489
7f1bd12e0d54
pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents:
487
diff
changeset
|
329 |
self.assertZoneEquals(zone.apply_hosts_forward(reversed(hosts), 'domain'), { }) |
472
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
330 |
|
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
331 |
def testHostsAlias4Conflict(self): |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
332 |
hosts = [ |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
333 |
Host.build('foo', 'domain', |
472
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
334 |
ip = '192.0.2.1', |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
335 |
), |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
336 |
Host.build('bar', 'domain', |
472
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
337 |
ip = '192.0.2.2', |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
338 |
alias4 = 'foo', |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
339 |
) |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
340 |
] |
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
341 |
|
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
342 |
with self.assertRaises(zone.HostZoneError): |
489
7f1bd12e0d54
pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents:
487
diff
changeset
|
343 |
self.assertZoneEquals(zone.apply_hosts_forward(hosts, 'domain'), { }) |
472
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
344 |
|
814cc88c531b
pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents:
471
diff
changeset
|
345 |
|
469
cd1f1b51f3a0
pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents:
468
diff
changeset
|
346 |
class TestReverseZone(TestZoneMixin, unittest.TestCase): |
473
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
347 |
def testHostIP(self): |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
348 |
h = Host.build('host', 'domain', |
473
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
349 |
ip = '192.0.2.1', |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
350 |
ip6 = '2001:db8::192.0.2.1', |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
351 |
) |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
352 |
|
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
353 |
self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.2.1/24'))), { |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
354 |
('1', 'PTR'): ['host.domain.'], |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
355 |
}) |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
356 |
|
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
357 |
self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8::/64'))), { |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
358 |
('1.0.2.0.0.0.0.c.0.0.0.0.0.0.0.0', 'PTR'): ['host.domain.'], |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
359 |
}) |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
360 |
|
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
361 |
def testHostIP4(self): |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
362 |
h = Host.build('host', 'domain', |
473
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
363 |
ip = '192.0.2.1', |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
364 |
) |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
365 |
|
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
366 |
self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.2.1/24'))), { |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
367 |
('1', 'PTR'): ['host.domain.'], |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
368 |
}) |
474
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
369 |
|
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
370 |
self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.0.0/16'))), { |
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
371 |
('1.2', 'PTR'): ['host.domain.'], |
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
372 |
}) |
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
373 |
|
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
374 |
self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.0.0/12'))), { |
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
375 |
('1.2.0', 'PTR'): ['host.domain.'], |
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
376 |
}) |
473
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
377 |
|
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
378 |
self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8::/64'))), { |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
379 |
|
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
380 |
}) |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
381 |
|
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
382 |
def testHostIP6(self): |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
383 |
h = Host.build('host', 'domain', |
473
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
384 |
ip6 = '2001:db8::192.0.2.1', |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
385 |
) |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
386 |
|
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
387 |
self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.2.1/24'))), { |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
388 |
}) |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
389 |
|
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
390 |
self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8::/64'))), { |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
391 |
('1.0.2.0.0.0.0.c.0.0.0.0.0.0.0.0', 'PTR'): ['host.domain.'], |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
392 |
}) |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
393 |
|
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
394 |
def testHostIPOutOfPrefix(self): |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
395 |
h = Host.build('host', 'domain', |
473
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
396 |
ip = '192.0.2.1', |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
397 |
ip6 = '2001:db8::192.0.2.1', |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
398 |
) |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
399 |
|
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
400 |
self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.1.0/24'))), { |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
401 |
|
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
402 |
}) |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
403 |
|
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
404 |
self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8:1::/64'))), { |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
405 |
|
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
406 |
}) |
68fd85d850ab
pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents:
472
diff
changeset
|
407 |
|
493
c9725dd0d48c
pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
492
diff
changeset
|
408 |
def testHostFQDN(self): |
c9725dd0d48c
pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
492
diff
changeset
|
409 |
h = Host.build('host.example.net', None, |
c9725dd0d48c
pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
492
diff
changeset
|
410 |
ip = '192.0.2.3', |
c9725dd0d48c
pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
492
diff
changeset
|
411 |
ip6 = '2001:db8::192.0.2.3', |
c9725dd0d48c
pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
492
diff
changeset
|
412 |
) |
c9725dd0d48c
pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
492
diff
changeset
|
413 |
|
c9725dd0d48c
pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
492
diff
changeset
|
414 |
self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.2.1/24'))), { |
c9725dd0d48c
pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
492
diff
changeset
|
415 |
('3', 'PTR'): ['host.example.net.'], |
c9725dd0d48c
pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
492
diff
changeset
|
416 |
|
c9725dd0d48c
pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
492
diff
changeset
|
417 |
}) |
c9725dd0d48c
pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
492
diff
changeset
|
418 |
|
c9725dd0d48c
pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
492
diff
changeset
|
419 |
self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8::/64'))), { |
c9725dd0d48c
pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
492
diff
changeset
|
420 |
('3.0.2.0.0.0.0.c.0.0.0.0.0.0.0.0', 'PTR'): ['host.example.net.'], |
c9725dd0d48c
pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
492
diff
changeset
|
421 |
}) |
c9725dd0d48c
pvl.hosts: test FQDN hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
492
diff
changeset
|
422 |
|
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
|
423 |
def testHostDelegate(self): |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
424 |
h = Host.build('host', 'example.com', |
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
|
425 |
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
|
426 |
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
|
427 |
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
|
428 |
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
|
429 |
) |
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
|
430 |
|
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
|
431 |
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
|
432 |
|
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
|
433 |
}) |
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
|
434 |
|
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
|
435 |
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
|
436 |
('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
|
437 |
}) |
464
f1d3dbf04ca3
pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents:
463
diff
changeset
|
438 |
|
f1d3dbf04ca3
pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents:
463
diff
changeset
|
439 |
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
|
440 |
|
f1d3dbf04ca3
pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents:
463
diff
changeset
|
441 |
}) |
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
|
442 |
|
494
6d258338b363
pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
493
diff
changeset
|
443 |
def testHosts(self): |
6d258338b363
pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
493
diff
changeset
|
444 |
hosts = [ |
6d258338b363
pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
493
diff
changeset
|
445 |
Host.build('foo', 'domain', |
6d258338b363
pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
493
diff
changeset
|
446 |
ip = '192.0.2.1', |
6d258338b363
pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
493
diff
changeset
|
447 |
), |
6d258338b363
pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
493
diff
changeset
|
448 |
Host.build('bar', 'domain', |
6d258338b363
pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
493
diff
changeset
|
449 |
ip = '192.0.2.2', |
6d258338b363
pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
493
diff
changeset
|
450 |
) |
6d258338b363
pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
493
diff
changeset
|
451 |
] |
6d258338b363
pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
493
diff
changeset
|
452 |
|
6d258338b363
pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
493
diff
changeset
|
453 |
self.assertZoneEquals(zone.apply_hosts_reverse(hosts, ipaddr.IPNetwork('192.0.2.1/24')), { |
6d258338b363
pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
493
diff
changeset
|
454 |
('1', 'PTR'): ['foo.domain.'], |
6d258338b363
pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
493
diff
changeset
|
455 |
('2', 'PTR'): ['bar.domain.'], |
6d258338b363
pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
493
diff
changeset
|
456 |
}) |
6d258338b363
pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
493
diff
changeset
|
457 |
|
6d258338b363
pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
493
diff
changeset
|
458 |
# in ip order |
6d258338b363
pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
493
diff
changeset
|
459 |
self.assertZoneEquals(zone.apply_hosts_reverse(reversed(hosts), ipaddr.IPNetwork('192.0.2.1/24')), { |
6d258338b363
pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
493
diff
changeset
|
460 |
('1', 'PTR'): ['foo.domain.'], |
6d258338b363
pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
493
diff
changeset
|
461 |
('2', 'PTR'): ['bar.domain.'], |
6d258338b363
pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
493
diff
changeset
|
462 |
}) |
6d258338b363
pvl.hosts.zone: test forward hosts
Tero Marttila <tero.marttila@aalto.fi>
parents:
493
diff
changeset
|
463 |
|
474
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
464 |
def testHostsConflict(self): |
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
465 |
hosts = [ |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
466 |
Host.build('foo', 'domain', |
474
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
467 |
ip = '192.0.2.1', |
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
468 |
), |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
469 |
Host.build('bar', 'domain', |
474
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
470 |
ip = '192.0.2.1', |
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
471 |
) |
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
472 |
] |
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
473 |
|
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
474 |
with self.assertRaises(zone.HostZoneError): |
489
7f1bd12e0d54
pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents:
487
diff
changeset
|
475 |
self.assertZoneEquals(zone.apply_hosts_reverse(hosts, ipaddr.IPNetwork('192.0.2.1/24')), { }) |
474
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
476 |
|
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
477 |
def testHostsGenerateUnknown(self): |
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
478 |
hosts = [ |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
479 |
Host.build('foo', 'domain', |
474
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
480 |
ip = '192.0.2.1', |
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
481 |
), |
477
6ad810c8039c
pvl.hosts.test: import Host directly
Tero Marttila <tero.marttila@aalto.fi>
parents:
474
diff
changeset
|
482 |
Host.build('bar', 'domain', |
474
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
483 |
ip = '192.0.2.5', |
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
484 |
), |
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
485 |
] |
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
486 |
|
489
7f1bd12e0d54
pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents:
487
diff
changeset
|
487 |
self.assertZoneEquals(zone.apply_hosts_reverse(hosts, ipaddr.IPNetwork('192.0.2.1/29'), |
7f1bd12e0d54
pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents:
487
diff
changeset
|
488 |
unknown_host = 'ufc', |
7f1bd12e0d54
pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents:
487
diff
changeset
|
489 |
unknown_domain = 'domain', |
7f1bd12e0d54
pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents:
487
diff
changeset
|
490 |
), { |
474
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
491 |
('1', 'PTR'): ['foo.domain.'], |
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
492 |
('2', 'PTR'): ['ufc.domain.'], |
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
493 |
('3', 'PTR'): ['ufc.domain.'], |
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
494 |
('4', 'PTR'): ['ufc.domain.'], |
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
495 |
('5', 'PTR'): ['bar.domain.'], |
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
496 |
('6', 'PTR'): ['ufc.domain.'], |
51983fcda6b1
pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents:
473
diff
changeset
|
497 |
}) |
469
cd1f1b51f3a0
pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents:
468
diff
changeset
|
498 |
|
479
1e68e3a30b51
pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents:
477
diff
changeset
|
499 |
class TestDhcp(unittest.TestCase): |
1e68e3a30b51
pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents:
477
diff
changeset
|
500 |
def assertBlocksEqual(self, blockdefs, expected): |
1e68e3a30b51
pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents:
477
diff
changeset
|
501 |
for (_block, _items, _opts), (block, items, opts) in zip(blockdefs, expected): |
1e68e3a30b51
pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents:
477
diff
changeset
|
502 |
self.assertEqual(_block, block) |
1e68e3a30b51
pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents:
477
diff
changeset
|
503 |
self.assertItemsEqual(_items, items) |
1e68e3a30b51
pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents:
477
diff
changeset
|
504 |
|
1e68e3a30b51
pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents:
477
diff
changeset
|
505 |
if opts is not None: |
1e68e3a30b51
pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents:
477
diff
changeset
|
506 |
self.assertEqual(_opts, opts) |
1e68e3a30b51
pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents:
477
diff
changeset
|
507 |
|
1e68e3a30b51
pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents:
477
diff
changeset
|
508 |
self.assertEqual(len(blockdefs), len(expected)) |
1e68e3a30b51
pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents:
477
diff
changeset
|
509 |
|
1e68e3a30b51
pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents:
477
diff
changeset
|
510 |
def testHost(self): |
1e68e3a30b51
pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents:
477
diff
changeset
|
511 |
host = Host.build('foo', 'test', |
1e68e3a30b51
pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents:
477
diff
changeset
|
512 |
ip = '192.0.2.1', |
1e68e3a30b51
pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents:
477
diff
changeset
|
513 |
ethernet = '00:11:22:33:44:55', |
492
ddd13dadf6a8
pvl.hosts.dhcp: test non-dhcp hosts and owner comments
Tero Marttila <tero.marttila@aalto.fi>
parents:
491
diff
changeset
|
514 |
owner = 'foo', |
479
1e68e3a30b51
pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents:
477
diff
changeset
|
515 |
) |
1e68e3a30b51
pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents:
477
diff
changeset
|
516 |
|
1e68e3a30b51
pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents:
477
diff
changeset
|
517 |
self.assertBlocksEqual(list(dhcp.dhcp_host(host)), [ |
1e68e3a30b51
pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents:
477
diff
changeset
|
518 |
(('host', 'foo'), [ |
1e68e3a30b51
pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents:
477
diff
changeset
|
519 |
('option', 'host-name', "foo"), |
1e68e3a30b51
pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents:
477
diff
changeset
|
520 |
('fixed-address', '192.0.2.1'), |
1e68e3a30b51
pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents:
477
diff
changeset
|
521 |
('hardware', 'ethernet', '00:11:22:33:44:55'), |
492
ddd13dadf6a8
pvl.hosts.dhcp: test non-dhcp hosts and owner comments
Tero Marttila <tero.marttila@aalto.fi>
parents:
491
diff
changeset
|
522 |
], dict(comment="Owner: foo")) |
ddd13dadf6a8
pvl.hosts.dhcp: test non-dhcp hosts and owner comments
Tero Marttila <tero.marttila@aalto.fi>
parents:
491
diff
changeset
|
523 |
]) |
ddd13dadf6a8
pvl.hosts.dhcp: test non-dhcp hosts and owner comments
Tero Marttila <tero.marttila@aalto.fi>
parents:
491
diff
changeset
|
524 |
|
ddd13dadf6a8
pvl.hosts.dhcp: test non-dhcp hosts and owner comments
Tero Marttila <tero.marttila@aalto.fi>
parents:
491
diff
changeset
|
525 |
def testHostStatic(self): |
ddd13dadf6a8
pvl.hosts.dhcp: test non-dhcp hosts and owner comments
Tero Marttila <tero.marttila@aalto.fi>
parents:
491
diff
changeset
|
526 |
host = Host.build('foo', 'test', |
ddd13dadf6a8
pvl.hosts.dhcp: test non-dhcp hosts and owner comments
Tero Marttila <tero.marttila@aalto.fi>
parents:
491
diff
changeset
|
527 |
ip = '192.0.2.1', |
ddd13dadf6a8
pvl.hosts.dhcp: test non-dhcp hosts and owner comments
Tero Marttila <tero.marttila@aalto.fi>
parents:
491
diff
changeset
|
528 |
) |
ddd13dadf6a8
pvl.hosts.dhcp: test non-dhcp hosts and owner comments
Tero Marttila <tero.marttila@aalto.fi>
parents:
491
diff
changeset
|
529 |
|
ddd13dadf6a8
pvl.hosts.dhcp: test non-dhcp hosts and owner comments
Tero Marttila <tero.marttila@aalto.fi>
parents:
491
diff
changeset
|
530 |
self.assertBlocksEqual(list(dhcp.dhcp_host(host)), [ |
ddd13dadf6a8
pvl.hosts.dhcp: test non-dhcp hosts and owner comments
Tero Marttila <tero.marttila@aalto.fi>
parents:
491
diff
changeset
|
531 |
|
479
1e68e3a30b51
pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents:
477
diff
changeset
|
532 |
]) |
1e68e3a30b51
pvl.hosts.dhcp: split out of script, refactor using pvl.dhcp.config, and test
Tero Marttila <tero.marttila@aalto.fi>
parents:
477
diff
changeset
|
533 |
|
480
7e44854e85d4
README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents:
479
diff
changeset
|
534 |
def testHostDynamic(self): |
7e44854e85d4
README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents:
479
diff
changeset
|
535 |
host = Host.build('foo', 'test', |
7e44854e85d4
README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents:
479
diff
changeset
|
536 |
ethernet = '00:11:22:33:44:55', |
7e44854e85d4
README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents:
479
diff
changeset
|
537 |
) |
7e44854e85d4
README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents:
479
diff
changeset
|
538 |
|
7e44854e85d4
README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents:
479
diff
changeset
|
539 |
self.assertBlocksEqual(list(dhcp.dhcp_host(host)), [ |
7e44854e85d4
README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents:
479
diff
changeset
|
540 |
(('host', 'foo'), [ |
7e44854e85d4
README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents:
479
diff
changeset
|
541 |
('option', 'host-name', "foo"), |
7e44854e85d4
README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents:
479
diff
changeset
|
542 |
('hardware', 'ethernet', '00:11:22:33:44:55'), |
7e44854e85d4
README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents:
479
diff
changeset
|
543 |
], None) |
7e44854e85d4
README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents:
479
diff
changeset
|
544 |
]) |
7e44854e85d4
README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents:
479
diff
changeset
|
545 |
|
7e44854e85d4
README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents:
479
diff
changeset
|
546 |
def testHostBoot(self): |
491
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
547 |
hosts = [ |
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
548 |
Host.build('foo1', 'test', |
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
549 |
ethernet = '00:11:22:33:44:55', |
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
550 |
boot = 'boot.lan:debian/wheezy/pxelinux.0', |
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
551 |
), |
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
552 |
Host.build('foo2', 'test', |
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
553 |
ethernet = '00:11:22:33:44:55', |
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
554 |
boot = 'boot.lan:', |
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
555 |
), |
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
556 |
Host.build('foo3', 'test', |
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
557 |
ethernet = '00:11:22:33:44:55', |
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
558 |
boot = '/debian/wheezy/pxelinux.0', |
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
559 |
), |
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
560 |
] |
480
7e44854e85d4
README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents:
479
diff
changeset
|
561 |
|
491
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
562 |
self.assertBlocksEqual(list(dhcp.dhcp_hosts(hosts)), [ |
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
563 |
(('host', 'foo1'), [ |
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
564 |
('option', 'host-name', "foo1"), |
480
7e44854e85d4
README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents:
479
diff
changeset
|
565 |
('hardware', 'ethernet', '00:11:22:33:44:55'), |
7e44854e85d4
README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents:
479
diff
changeset
|
566 |
('next-server', 'boot.lan'), |
7e44854e85d4
README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents:
479
diff
changeset
|
567 |
('filename', 'debian/wheezy/pxelinux.0'), |
491
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
568 |
], None), |
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
569 |
(('host', 'foo2'), [ |
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
570 |
('option', 'host-name', "foo2"), |
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
571 |
('hardware', 'ethernet', '00:11:22:33:44:55'), |
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
572 |
('next-server', 'boot.lan'), |
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
573 |
], None), |
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
574 |
(('host', 'foo3'), [ |
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
575 |
('option', 'host-name', "foo3"), |
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
576 |
('hardware', 'ethernet', '00:11:22:33:44:55'), |
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
577 |
('filename', 'debian/wheezy/pxelinux.0'), |
cfcb47a3dc3e
pvl.hosts.dhcp: fix and test boot= variations
Tero Marttila <tero.marttila@aalto.fi>
parents:
490
diff
changeset
|
578 |
], None), |
480
7e44854e85d4
README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents:
479
diff
changeset
|
579 |
]) |
7e44854e85d4
README and test host boot= and dynamic ip=
Tero Marttila <tero.marttila@aalto.fi>
parents:
479
diff
changeset
|
580 |
|
483
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
581 |
def testHosts(self): |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
582 |
hosts = [ |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
583 |
Host.build('foo', 'test', |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
584 |
ip = '192.0.2.1', |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
585 |
ethernet = '00:11:22:33:44:55', |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
586 |
), |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
587 |
Host.build('bar', 'test', |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
588 |
ip = '192.0.2.2', |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
589 |
ethernet = '01:23:45:67:89:ab', |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
590 |
), |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
591 |
] |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
592 |
|
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
593 |
self.assertBlocksEqual(list(dhcp.dhcp_hosts(hosts)), [ |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
594 |
(('host', 'foo'), [ |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
595 |
('option', 'host-name', "foo"), |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
596 |
('fixed-address', '192.0.2.1'), |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
597 |
('hardware', 'ethernet', '00:11:22:33:44:55'), |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
598 |
], None), |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
599 |
(('host', 'bar'), [ |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
600 |
('option', 'host-name', "bar"), |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
601 |
('fixed-address', '192.0.2.2'), |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
602 |
('hardware', 'ethernet', '01:23:45:67:89:ab'), |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
603 |
], None), |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
604 |
]) |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
605 |
|
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
606 |
def testHostConflict(self): |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
607 |
hosts = [ |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
608 |
Host.build('foo', 'test1', |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
609 |
ethernet = '00:11:22:33:44:55', |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
610 |
), |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
611 |
Host.build('foo', 'test2', |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
612 |
ethernet = '01:23:45:67:89:ab', |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
613 |
), |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
614 |
] |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
615 |
|
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
616 |
with self.assertRaises(dhcp.HostDHCPError): |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
617 |
list(dhcp.dhcp_hosts(hosts)) |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
618 |
|
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
619 |
def testHostMultinet(self): |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
620 |
hosts = [ |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
621 |
Host.build('foo', 'test1', |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
622 |
ip = '192.0.1.1', |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
623 |
ethernet = { 'eth1': '00:11:22:33:44:55' }, |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
624 |
), |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
625 |
Host.build('foo', 'test2', |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
626 |
ip = '192.0.2.1', |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
627 |
ethernet = { 'eth2': '01:23:45:67:89:ab' }, |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
628 |
), |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
629 |
] |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
630 |
|
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
631 |
self.assertBlocksEqual(list(dhcp.dhcp_hosts(hosts)), [ |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
632 |
(('host', 'foo-eth1'), [ |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
633 |
('option', 'host-name', "foo"), |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
634 |
('fixed-address', '192.0.1.1'), |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
635 |
('hardware', 'ethernet', '00:11:22:33:44:55'), |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
636 |
], None), |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
637 |
(('host', 'foo-eth2'), [ |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
638 |
('option', 'host-name', "foo"), |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
639 |
('fixed-address', '192.0.2.1'), |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
640 |
('hardware', 'ethernet', '01:23:45:67:89:ab'), |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
641 |
], None), |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
642 |
]) |
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
643 |
|
19d084bb4afd
pvl.hosts.dhcp: test and document hosts on multiple networks
Tero Marttila <tero.marttila@aalto.fi>
parents:
480
diff
changeset
|
644 |
|
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
|
645 |
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
|
646 |
unittest.main() |