97 self.assertHostsEqual(config.apply_hosts('test', 'asdf.test2', { }), [ |
97 self.assertHostsEqual(config.apply_hosts('test', 'asdf.test2', { }), [ |
98 ('asdf.test2@', dict()), |
98 ('asdf.test2@', dict()), |
99 ]) |
99 ]) |
100 |
100 |
101 def testApplyHostExpand(self): |
101 def testApplyHostExpand(self): |
102 self.assertHostsEqual(config.apply_hosts('test', 'asdf{1-3}', { 'ip': '10.100.100.$' }), [ |
102 self.assertHostsEqual(config.apply_hosts('test', 'asdf{1-3}', |
103 ('asdf1@test', dict(ip=ipaddr.IPAddress('10.100.100.1'))), |
103 { 'ip': '10.100.100.$' } |
104 ('asdf2@test', dict(ip=ipaddr.IPAddress('10.100.100.2'))), |
104 ), [ |
105 ('asdf3@test', dict(ip=ipaddr.IPAddress('10.100.100.3'))), |
105 ('asdf1@test', dict(ip4=ipaddr.IPAddress('10.100.100.1'))), |
|
106 ('asdf2@test', dict(ip4=ipaddr.IPAddress('10.100.100.2'))), |
|
107 ('asdf3@test', dict(ip4=ipaddr.IPAddress('10.100.100.3'))), |
106 ]) |
108 ]) |
107 |
109 |
108 def testApplyHostsFileError(self): |
110 def testApplyHostsFileError(self): |
109 with self.assertRaises(config.HostConfigError): |
111 with self.assertRaises(config.HostConfigError): |
110 list(config.apply_hosts_files(self.options, ['nonexistant'])) |
112 list(config.apply_hosts_files(self.options, ['nonexistant'])) |
117 [bar] |
119 [bar] |
118 ip = 127.0.0.2 |
120 ip = 127.0.0.2 |
119 """) |
121 """) |
120 |
122 |
121 self.assertHostsEqual(config.apply_hosts_config(self.options, conf_file), [ |
123 self.assertHostsEqual(config.apply_hosts_config(self.options, conf_file), [ |
122 ('foo@test', dict(ip=ipaddr.IPAddress('127.0.0.1'))), |
124 ('foo@test', dict(ip4=ipaddr.IPAddress('127.0.0.1'))), |
123 ('bar@test', dict(ip=ipaddr.IPAddress('127.0.0.2'))), |
125 ('bar@test', dict(ip4=ipaddr.IPAddress('127.0.0.2'))), |
124 ]) |
126 ]) |
125 |
127 |
126 def testApplyHostsConfigNested(self): |
128 def testApplyHostsConfigNested(self): |
127 conf_file = ConfFile('test', """ |
129 conf_file = ConfFile('test', """ |
128 [asdf] |
130 [asdf] |
133 [[bar]] |
135 [[bar]] |
134 ip = 127.0.0.2 |
136 ip = 127.0.0.2 |
135 """) |
137 """) |
136 |
138 |
137 self.assertHostsEqual(config.apply_hosts_config(self.options, conf_file), [ |
139 self.assertHostsEqual(config.apply_hosts_config(self.options, conf_file), [ |
138 ('foo@asdf.test', dict(ip=ipaddr.IPAddress('127.0.0.1'))), |
140 ('foo@asdf.test', dict(ip4=ipaddr.IPAddress('127.0.0.1'))), |
139 ('bar@quux.test', dict(ip=ipaddr.IPAddress('127.0.0.2'))), |
141 ('bar@quux.test', dict(ip4=ipaddr.IPAddress('127.0.0.2'))), |
140 ]) |
142 ]) |
141 |
143 |
142 def testHostsConfigDdefaults(self): |
144 def testHostsConfigDdefaults(self): |
143 hosts = config.apply_hosts_config(self.options, ConfFile('test', """ |
145 hosts = config.apply_hosts_config(self.options, ConfFile('test', """ |
144 boot.next-server = boot.lan |
146 boot.next-server = boot.lan |
149 boot.filename = /pxelinux.0 |
151 boot.filename = /pxelinux.0 |
150 """)) |
152 """)) |
151 |
153 |
152 self.assertHostsEqual(hosts, [ |
154 self.assertHostsEqual(hosts, [ |
153 ('foo@test', dict( |
155 ('foo@test', dict( |
154 ip = ipaddr.IPAddress('192.0.2.1'), |
156 ip4 = ipaddr.IPAddress('192.0.2.1'), |
155 ethernet = { 'eth0': '00:11:22:33:44:55' }, |
157 ethernet = { 'eth0': '00:11:22:33:44:55' }, |
156 boot = { 'next-server': 'boot.lan', 'filename': '/pxelinux.0' }, |
158 boot = { 'next-server': 'boot.lan', 'filename': '/pxelinux.0' }, |
157 )), |
159 )), |
158 ]) |
160 ]) |
159 |
161 |
160 |
162 |
161 |
163 |
162 def testApplyIncludes(self): |
164 def testApplyIncludes(self): |
163 self.assertHostsEqual(config.apply_hosts_files(self.options, ['etc/hosts/test']), [ |
165 self.assertHostsEqual(config.apply_hosts_files(self.options, ['etc/hosts/test']), [ |
164 ('bar@test', dict( |
166 ('bar@test', dict( |
165 ip = ipaddr.IPAddress('192.0.2.2'), |
167 ip4 = ipaddr.IPAddress('192.0.2.2'), |
166 )), |
168 )), |
167 ('foo@test', dict( |
169 ('foo@test', dict( |
168 ip = ipaddr.IPAddress('192.0.2.1'), |
170 ip4 = ipaddr.IPAddress('192.0.2.1'), |
169 )), |
171 )), |
170 ]) |
172 ]) |
171 |
173 |
172 def testApplyIncludesDefaults(self): |
174 def testApplyIncludesDefaults(self): |
173 self.assertHostsEqual(config.apply_hosts_config(self.options, ConfFile('test', """ |
175 self.assertHostsEqual(config.apply_hosts_config(self.options, ConfFile('test', """ |
174 boot.next-server = boot.lan |
176 boot.next-server = boot.lan |
175 |
177 |
176 include = etc/hosts/test |
178 include = etc/hosts/test |
177 """)), [ |
179 """)), [ |
178 ('bar@test', dict( |
180 ('bar@test', dict( |
179 ip = ipaddr.IPAddress('192.0.2.2'), |
181 ip4 = ipaddr.IPAddress('192.0.2.2'), |
180 )), |
182 )), |
181 ('foo@test', dict( |
183 ('foo@test', dict( |
182 ip = ipaddr.IPAddress('192.0.2.1'), |
184 ip4 = ipaddr.IPAddress('192.0.2.1'), |
183 )), |
185 )), |
184 ]) |
186 ]) |
185 |
187 |
186 |
188 |
187 def testApplyIncludePath(self): |
189 def testApplyIncludePath(self): |
192 include_trace = include_trace, |
194 include_trace = include_trace, |
193 )) |
195 )) |
194 |
196 |
195 self.assertHostsEqual(hosts, [ |
197 self.assertHostsEqual(hosts, [ |
196 ('quux@asdf.test', dict( |
198 ('quux@asdf.test', dict( |
197 ip = ipaddr.IPAddress('192.0.2.5'), |
199 ip4 = ipaddr.IPAddress('192.0.2.5'), |
198 )), |
200 )), |
199 ('bar@test', dict( |
201 ('bar@test', dict( |
200 ip = ipaddr.IPAddress('192.0.2.2'), |
202 ip4 = ipaddr.IPAddress('192.0.2.2'), |
201 )), |
203 )), |
202 ('foo@test', dict( |
204 ('foo@test', dict( |
203 ip = ipaddr.IPAddress('192.0.2.1'), |
205 ip4 = ipaddr.IPAddress('192.0.2.1'), |
204 )), |
206 )), |
205 ]) |
207 ]) |
206 |
208 |
207 self.assertEqual(include_trace, [ |
209 self.assertEqual(include_trace, [ |
208 'etc/zones/forward/test', |
210 'etc/zones/forward/test', |
214 ]) |
216 ]) |
215 |
217 |
216 def testApply(self): |
218 def testApply(self): |
217 self.assertHostsEqual(config.apply(self.options, ['etc/hosts/example.com']), [ |
219 self.assertHostsEqual(config.apply(self.options, ['etc/hosts/example.com']), [ |
218 ('foo@example.com', dict( |
220 ('foo@example.com', dict( |
219 ip = ipaddr.IPAddress('192.0.2.1'), |
221 ip4 = ipaddr.IPAddress('192.0.2.1'), |
220 ethernet = {None: '00:11:22:33:44:55'}, |
222 ethernet = {None: '00:11:22:33:44:55'}, |
221 )), |
223 )), |
222 ('bar@example.com', dict( |
224 ('bar@example.com', dict( |
223 ip = ipaddr.IPAddress('192.0.2.2'), |
225 ip4 = ipaddr.IPAddress('192.0.2.2'), |
224 ethernet = {None: '01:23:45:67:89:ab'}, |
226 ethernet = {None: '01:23:45:67:89:ab'}, |
225 )), |
227 )), |
226 ]) |
228 ]) |
227 |
229 |
228 class TestZoneMixin(object): |
230 class TestZoneMixin(object): |