19 hosts_domain = None, |
19 hosts_domain = None, |
20 hosts_include = None, |
20 hosts_include = None, |
21 hosts_include_trace = None, |
21 hosts_include_trace = None, |
22 ) |
22 ) |
23 |
23 |
|
24 def assertHostExtensionEquals(self, host, extension, value): |
|
25 host_extension = host.extensions.get(extension) |
|
26 |
|
27 self.assertIsNotNone(host_extension, (host, extension)) |
|
28 |
|
29 for attr, value in value.iteritems(): |
|
30 self.assertEquals(getattr(host_extension, attr), value, (host, extension, value)) |
|
31 |
24 def assertHostEqual(self, host, host_str, attrs): |
32 def assertHostEqual(self, host, host_str, attrs): |
25 self.assertEquals(str(host), host_str) |
33 self.assertEquals(str(host), host_str) |
26 |
34 |
27 for attr, value in attrs.iteritems(): |
35 for attr, value in attrs.iteritems(): |
28 self.assertEquals(getattr(host, attr), value) |
36 if attr == 'extensions': |
|
37 for extension, value in value.iteritems(): |
|
38 self.assertHostExtensionEquals(host, extension, value) |
|
39 else: |
|
40 self.assertEquals(getattr(host, attr), value) |
29 |
41 |
30 def assertHostsEqual(self, hosts, expected): |
42 def assertHostsEqual(self, hosts, expected): |
31 hosts = list(hosts) |
43 hosts = list(hosts) |
32 |
44 |
33 for host, expect in itertools.izip_longest(hosts, expected): |
45 for host, expect in itertools.izip_longest(hosts, expected): |
73 } |
85 } |
74 )) |
86 )) |
75 |
87 |
76 |
88 |
77 def testApplyHostConfigExtensions(self): |
89 def testApplyHostConfigExtensions(self): |
|
90 @pvl.hosts.host.register_extension |
|
91 class HostLinkTest(pvl.hosts.host.HostExtension): |
|
92 EXTENSION = 'link' |
|
93 |
|
94 @classmethod |
|
95 def build(cls, uplink, downlink): |
|
96 obj = cls() |
|
97 obj.uplink = uplink |
|
98 obj.downlink = downlink |
|
99 |
|
100 return obj |
|
101 |
78 host = config.apply_host('foo', 'test', { |
102 host = config.apply_host('foo', 'test', { |
79 'link:50': 'foo@test', |
103 'link:downlink.50': 'foo@test', |
80 'link:uplink.49': 'bar@test', |
104 'link:uplink.49': 'bar@test', |
81 }) |
105 }) |
82 |
106 |
83 self.assertHostEqual(host, 'foo@test', dict( |
107 self.assertHostEqual(host, 'foo@test', dict( |
84 extensions = { |
108 extensions = dict(link={ |
85 'link': { |
109 'downlink': { '50': 'foo@test' }, |
86 '50': 'foo@test', |
|
87 'uplink': { '49': 'bar@test' }, |
110 'uplink': { '49': 'bar@test' }, |
88 }, |
111 }), |
89 }, |
|
90 )) |
112 )) |
91 |
113 |
92 def testApplyHostFqdn(self): |
114 def testApplyHostFqdn(self): |
93 self.assertHostsEqual(config.apply_hosts('test', 'asdf@foo.test', { }), [ |
115 self.assertHostsEqual(config.apply_hosts('test', 'asdf@foo.test', { }), [ |
94 ('asdf@foo.test', dict()), |
116 ('asdf@foo.test', dict()), |
153 |
175 |
154 self.assertHostsEqual(hosts, [ |
176 self.assertHostsEqual(hosts, [ |
155 ('foo@test', dict( |
177 ('foo@test', dict( |
156 ip4 = ipaddr.IPAddress('192.0.2.1'), |
178 ip4 = ipaddr.IPAddress('192.0.2.1'), |
157 ethernet = { 'eth0': '00:11:22:33:44:55' }, |
179 ethernet = { 'eth0': '00:11:22:33:44:55' }, |
158 boot = { 'next-server': 'boot.lan', 'filename': '/pxelinux.0' }, |
180 extensions = dict( |
|
181 dhcp = { 'next_server': 'boot.lan', 'filename': '/pxelinux.0' } |
|
182 ), |
159 )), |
183 )), |
160 ]) |
184 ]) |
161 |
185 |
162 |
186 |
163 |
187 |