]>
Commit | Line | Data |
---|---|---|
1f0e3109 SS |
1 | #!/usr/bin/env python3 |
2 | # SPDX-License-Identifier: LGPL-2.1+ | |
3 | # systemd-networkd tests | |
4 | ||
5 | import os | |
201bf07f | 6 | import re |
1f0e3109 SS |
7 | import shutil |
8 | import signal | |
9 | import socket | |
a9bc5e37 YW |
10 | import subprocess |
11 | import sys | |
1f0e3109 | 12 | import threading |
a9bc5e37 YW |
13 | import time |
14 | import unittest | |
1f0e3109 SS |
15 | from shutil import copytree |
16 | ||
d486a2d0 | 17 | network_unit_file_path='/run/systemd/network' |
bad4969b | 18 | networkd_runtime_directory='/run/systemd/netif' |
d486a2d0 | 19 | networkd_ci_path='/run/networkd-ci' |
1f0e3109 SS |
20 | network_sysctl_ipv6_path='/proc/sys/net/ipv6/conf' |
21 | network_sysctl_ipv4_path='/proc/sys/net/ipv4/conf' | |
22 | ||
d486a2d0 YW |
23 | dnsmasq_config_file='/run/networkd-ci/test-dnsmasq.conf' |
24 | dnsmasq_pid_file='/run/networkd-ci/test-test-dnsmasq.pid' | |
25 | dnsmasq_log_file='/run/networkd-ci/test-dnsmasq-log-file' | |
1f0e3109 | 26 | |
7a0a37b2 | 27 | def is_module_available(module_name): |
201bf07f EV |
28 | lsmod_output = subprocess.check_output('lsmod', universal_newlines=True) |
29 | module_re = re.compile(r'^{0}\b'.format(re.escape(module_name)), re.MULTILINE) | |
30 | return module_re.search(lsmod_output) or not subprocess.call(["modprobe", module_name]) | |
7a0a37b2 EV |
31 | |
32 | def expectedFailureIfModuleIsNotAvailable(module_name): | |
33 | def f(func): | |
34 | if not is_module_available(module_name): | |
35 | return unittest.expectedFailure(func) | |
36 | return func | |
37 | ||
38 | return f | |
39 | ||
1f0e3109 SS |
40 | def setUpModule(): |
41 | ||
42 | os.makedirs(network_unit_file_path, exist_ok=True) | |
43 | os.makedirs(networkd_ci_path, exist_ok=True) | |
44 | ||
45 | shutil.rmtree(networkd_ci_path) | |
6aea9276 | 46 | copytree(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'conf'), networkd_ci_path) |
1f0e3109 | 47 | |
c0bf6733 YW |
48 | subprocess.check_call('systemctl stop systemd-networkd.socket', shell=True) |
49 | ||
1f0e3109 SS |
50 | def tearDownModule(): |
51 | shutil.rmtree(networkd_ci_path) | |
52 | ||
c0bf6733 YW |
53 | subprocess.check_call('systemctl stop systemd-networkd.service', shell=True) |
54 | subprocess.check_call('systemctl start systemd-networkd.socket', shell=True) | |
55 | subprocess.check_call('systemctl start systemd-networkd.service', shell=True) | |
56 | ||
1f0e3109 SS |
57 | class Utilities(): |
58 | dhcp_server_data = [] | |
59 | ||
60 | def read_link_attr(self, link, dev, attribute): | |
61 | with open(os.path.join(os.path.join(os.path.join('/sys/class/net/', link), dev), attribute)) as f: | |
62 | return f.readline().strip() | |
63 | ||
4d7ed14f SS |
64 | def read_bridge_port_attr(self, bridge, link, attribute): |
65 | ||
66 | path_bridge = os.path.join('/sys/devices/virtual/net', bridge) | |
67 | path_port = 'lower_' + link + '/brport' | |
68 | path = os.path.join(path_bridge, path_port) | |
69 | ||
70 | with open(os.path.join(path, attribute)) as f: | |
71 | return f.readline().strip() | |
72 | ||
1f0e3109 SS |
73 | def link_exits(self, link): |
74 | return os.path.exists(os.path.join('/sys/class/net', link)) | |
75 | ||
76 | def link_remove(self, links): | |
77 | for link in links: | |
78 | if os.path.exists(os.path.join('/sys/class/net', link)): | |
79 | subprocess.call(['ip', 'link', 'del', 'dev', link]) | |
9a4720a9 | 80 | time.sleep(1) |
1f0e3109 SS |
81 | |
82 | def read_ipv6_sysctl_attr(self, link, attribute): | |
83 | with open(os.path.join(os.path.join(network_sysctl_ipv6_path, link), attribute)) as f: | |
84 | return f.readline().strip() | |
85 | ||
86 | def read_ipv4_sysctl_attr(self, link, attribute): | |
87 | with open(os.path.join(os.path.join(network_sysctl_ipv4_path, link), attribute)) as f: | |
88 | return f.readline().strip() | |
89 | ||
90 | def copy_unit_to_networkd_unit_path(self, *units): | |
91 | for unit in units: | |
92 | shutil.copy(os.path.join(networkd_ci_path, unit), network_unit_file_path) | |
013c8dc9 YW |
93 | if (os.path.exists(os.path.join(networkd_ci_path, unit + '.d'))): |
94 | copytree(os.path.join(networkd_ci_path, unit + '.d'), os.path.join(network_unit_file_path, unit + '.d')) | |
1f0e3109 SS |
95 | |
96 | def remove_unit_from_networkd_path(self, units): | |
97 | for unit in units: | |
98 | if (os.path.exists(os.path.join(network_unit_file_path, unit))): | |
99 | os.remove(os.path.join(network_unit_file_path, unit)) | |
013c8dc9 YW |
100 | if (os.path.exists(os.path.join(network_unit_file_path, unit + '.d'))): |
101 | shutil.rmtree(os.path.join(network_unit_file_path, unit + '.d')) | |
1f0e3109 SS |
102 | |
103 | def start_dnsmasq(self): | |
104 | subprocess.check_call('dnsmasq -8 /var/run/networkd-ci/test-dnsmasq-log-file --log-queries=extra --log-dhcp --pid-file=/var/run/networkd-ci/test-test-dnsmasq.pid --conf-file=/dev/null --interface=veth-peer --enable-ra --dhcp-range=2600::10,2600::20 --dhcp-range=192.168.5.10,192.168.5.200 -R --dhcp-leasefile=/var/run/networkd-ci/lease --dhcp-option=26,1492 --dhcp-option=option:router,192.168.5.1 --dhcp-option=33,192.168.5.4,192.168.5.5', shell=True) | |
105 | ||
106 | time.sleep(10) | |
107 | ||
108 | def stop_dnsmasq(self, pid_file): | |
109 | if os.path.exists(pid_file): | |
110 | with open(pid_file, 'r') as f: | |
111 | pid = f.read().rstrip(' \t\r\n\0') | |
112 | os.kill(int(pid), signal.SIGTERM) | |
113 | ||
114 | os.remove(pid_file) | |
115 | ||
131717cb | 116 | def search_words_in_dnsmasq_log(self, words, show_all=False): |
1f0e3109 SS |
117 | if os.path.exists(dnsmasq_log_file): |
118 | with open (dnsmasq_log_file) as in_file: | |
119 | contents = in_file.read() | |
131717cb YW |
120 | if show_all: |
121 | print(contents) | |
122 | for line in contents.split('\n'): | |
123 | if words in line: | |
1f0e3109 | 124 | in_file.close() |
131717cb | 125 | print("%s, %s" % (words, line)) |
1f0e3109 SS |
126 | return True |
127 | return False | |
128 | ||
129 | def remove_lease_file(self): | |
130 | if os.path.exists(os.path.join(networkd_ci_path, 'lease')): | |
131 | os.remove(os.path.join(networkd_ci_path, 'lease')) | |
132 | ||
133 | def remove_log_file(self): | |
134 | if os.path.exists(dnsmasq_log_file): | |
135 | os.remove(dnsmasq_log_file) | |
136 | ||
137 | def start_networkd(self): | |
bad4969b YW |
138 | if (os.path.exists(os.path.join(networkd_runtime_directory, 'state'))): |
139 | subprocess.check_call('systemctl stop systemd-networkd', shell=True) | |
140 | os.remove(os.path.join(networkd_runtime_directory, 'state')) | |
141 | subprocess.check_call('systemctl start systemd-networkd', shell=True) | |
142 | else: | |
143 | subprocess.check_call('systemctl restart systemd-networkd', shell=True) | |
1f0e3109 | 144 | time.sleep(5) |
fa7cd602 | 145 | print() |
1f0e3109 SS |
146 | |
147 | global ip | |
148 | global port | |
149 | ||
150 | class DHCPServer(threading.Thread): | |
151 | def __init__(self, name): | |
152 | threading.Thread.__init__(self) | |
153 | self.name = name | |
154 | ||
155 | def run(self): | |
156 | self.start_dhcp_server() | |
157 | ||
158 | def start_dhcp_server(self): | |
159 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
160 | ||
161 | server_address = ('0.0.0.0', 67) | |
162 | sock.bind(server_address) | |
163 | ||
164 | print('Starting DHCP Server ...\n') | |
165 | data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes | |
166 | ||
167 | global ip | |
168 | ip = addr[0] | |
169 | ||
170 | global port | |
171 | port = addr[1] | |
172 | sock.close() | |
173 | ||
174 | class NetworkdNetDevTests(unittest.TestCase, Utilities): | |
175 | ||
09ea6724 YW |
176 | links =[ |
177 | '6rdtun99', | |
178 | 'bond99', | |
179 | 'bridge99', | |
180 | 'dropin-test', | |
181 | 'dummy98', | |
182 | 'erspan-test', | |
183 | 'geneve99', | |
184 | 'gretap99', | |
185 | 'gretun99', | |
186 | 'ip6gretap99', | |
187 | 'ip6tnl99', | |
188 | 'ipiptun99', | |
189 | 'ipvlan99', | |
190 | 'isataptun99', | |
191 | 'macvlan99', | |
192 | 'macvtap99', | |
193 | 'sittun99', | |
194 | 'tap99', | |
195 | 'test1', | |
196 | 'tun99', | |
197 | 'vcan99', | |
198 | 'veth99', | |
199 | 'vlan99', | |
200 | 'vrf99', | |
201 | 'vti6tun99', | |
202 | 'vtitun99', | |
203 | 'vxlan99', | |
204 | 'wg99'] | |
205 | ||
206 | units = [ | |
207 | '10-dropin-test.netdev', | |
208 | '11-dummy.netdev', | |
209 | '12-dummy.netdev', | |
210 | '21-macvlan.netdev', | |
211 | '21-macvtap.netdev', | |
212 | '21-vlan.netdev', | |
213 | '21-vlan.network', | |
214 | '25-6rd-tunnel.netdev', | |
215 | '25-bond.netdev', | |
fde60a42 | 216 | '25-bond-balanced-tlb.netdev', |
09ea6724 YW |
217 | '25-bridge.netdev', |
218 | '25-erspan-tunnel.netdev', | |
219 | '25-geneve.netdev', | |
220 | '25-gretap-tunnel.netdev', | |
221 | '25-gre-tunnel.netdev', | |
222 | '25-ip6gre-tunnel.netdev', | |
223 | '25-ip6tnl-tunnel.netdev', | |
224 | '25-ipip-tunnel-independent.netdev', | |
225 | '25-ipip-tunnel.netdev', | |
226 | '25-ipvlan.netdev', | |
227 | '25-isatap-tunnel.netdev', | |
228 | '25-sit-tunnel.netdev', | |
229 | '25-tap.netdev', | |
230 | '25-tun.netdev', | |
231 | '25-vcan.netdev', | |
232 | '25-veth.netdev', | |
233 | '25-vrf.netdev', | |
234 | '25-vti6-tunnel.netdev', | |
235 | '25-vti-tunnel.netdev', | |
236 | '25-vxlan.netdev', | |
237 | '25-wireguard.netdev', | |
238 | '6rd.network', | |
239 | 'gre.network', | |
240 | 'gretap.network', | |
241 | 'gretun.network', | |
242 | 'ip6gretap.network', | |
243 | 'ip6tnl.network', | |
244 | 'ipip.network', | |
245 | 'ipvlan.network', | |
246 | 'isatap.network', | |
247 | 'macvlan.network', | |
248 | 'macvtap.network', | |
249 | 'sit.network', | |
250 | 'vti6.network', | |
251 | 'vti.network', | |
252 | 'vxlan.network'] | |
1f0e3109 SS |
253 | |
254 | def setUp(self): | |
255 | self.link_remove(self.links) | |
256 | ||
257 | def tearDown(self): | |
258 | self.link_remove(self.links) | |
259 | self.remove_unit_from_networkd_path(self.units) | |
260 | ||
d80734f7 YW |
261 | def test_dropin(self): |
262 | self.copy_unit_to_networkd_unit_path('10-dropin-test.netdev') | |
d80734f7 YW |
263 | self.start_networkd() |
264 | ||
265 | self.assertTrue(self.link_exits('dropin-test')) | |
266 | ||
267 | output = subprocess.check_output(['ip', 'link', 'show', 'dropin-test']).rstrip().decode('utf-8') | |
268 | print(output) | |
269 | self.assertRegex(output, '00:50:56:c0:00:28') | |
270 | ||
1f0e3109 SS |
271 | def test_bridge(self): |
272 | self.copy_unit_to_networkd_unit_path('25-bridge.netdev') | |
273 | self.start_networkd() | |
274 | ||
275 | self.assertTrue(self.link_exits('bridge99')) | |
276 | ||
277 | self.assertEqual('900', self.read_link_attr('bridge99', 'bridge', 'hello_time')) | |
278 | self.assertEqual('900', self.read_link_attr('bridge99', 'bridge', 'max_age')) | |
279 | self.assertEqual('900', self.read_link_attr('bridge99', 'bridge','forward_delay')) | |
280 | self.assertEqual('900', self.read_link_attr('bridge99', 'bridge','ageing_time')) | |
281 | self.assertEqual('9', self.read_link_attr('bridge99', 'bridge','priority')) | |
282 | self.assertEqual('1', self.read_link_attr('bridge99', 'bridge','multicast_querier')) | |
283 | self.assertEqual('1', self.read_link_attr('bridge99', 'bridge','multicast_snooping')) | |
284 | self.assertEqual('1', self.read_link_attr('bridge99', 'bridge','stp_state')) | |
285 | ||
286 | def test_bond(self): | |
287 | self.copy_unit_to_networkd_unit_path('25-bond.netdev') | |
288 | self.start_networkd() | |
289 | ||
290 | self.assertTrue(self.link_exits('bond99')) | |
291 | ||
99f68ef0 TJ |
292 | self.assertEqual('802.3ad 4', self.read_link_attr('bond99', 'bonding', 'mode')) |
293 | self.assertEqual('layer3+4 1', self.read_link_attr('bond99', 'bonding', 'xmit_hash_policy')) | |
294 | self.assertEqual('1000', self.read_link_attr('bond99', 'bonding', 'miimon')) | |
295 | self.assertEqual('fast 1', self.read_link_attr('bond99', 'bonding', 'lacp_rate')) | |
296 | self.assertEqual('2000', self.read_link_attr('bond99', 'bonding', 'updelay')) | |
297 | self.assertEqual('2000', self.read_link_attr('bond99', 'bonding', 'downdelay')) | |
298 | self.assertEqual('4', self.read_link_attr('bond99', 'bonding', 'resend_igmp')) | |
299 | self.assertEqual('1', self.read_link_attr('bond99', 'bonding', 'min_links')) | |
300 | self.assertEqual('1218', self.read_link_attr('bond99', 'bonding', 'ad_actor_sys_prio')) | |
301 | self.assertEqual('811', self.read_link_attr('bond99', 'bonding', 'ad_user_port_key')) | |
302 | self.assertEqual('00:11:22:33:44:55', self.read_link_attr('bond99', 'bonding', 'ad_actor_system')) | |
1f0e3109 | 303 | |
fde60a42 SS |
304 | def test_bond_balanced_tlb(self): |
305 | self.copy_unit_to_networkd_unit_path('25-bond-balanced-tlb.netdev') | |
306 | self.start_networkd() | |
307 | ||
308 | self.assertTrue(self.link_exits('bond99')) | |
309 | ||
310 | self.assertEqual('balance-tlb 5', self.read_link_attr('bond99', 'bonding', 'mode')) | |
311 | self.assertEqual('1', self.read_link_attr('bond99', 'bonding', 'tlb_dynamic_lb')) | |
312 | ||
1f0e3109 SS |
313 | def test_vlan(self): |
314 | self.copy_unit_to_networkd_unit_path('21-vlan.netdev', '11-dummy.netdev', '21-vlan.network') | |
1f0e3109 SS |
315 | self.start_networkd() |
316 | ||
317 | self.assertTrue(self.link_exits('vlan99')) | |
318 | ||
319 | output = subprocess.check_output(['ip', '-d', 'link', 'show', 'vlan99']).rstrip().decode('utf-8') | |
14ecd604 | 320 | print(output) |
1f0e3109 SS |
321 | self.assertTrue(output, 'REORDER_HDR') |
322 | self.assertTrue(output, 'LOOSE_BINDING') | |
323 | self.assertTrue(output, 'GVRP') | |
324 | self.assertTrue(output, 'MVRP') | |
325 | self.assertTrue(output, '99') | |
326 | ||
327 | def test_macvtap(self): | |
328 | self.copy_unit_to_networkd_unit_path('21-macvtap.netdev', '11-dummy.netdev', 'macvtap.network') | |
1f0e3109 SS |
329 | self.start_networkd() |
330 | ||
331 | self.assertTrue(self.link_exits('macvtap99')) | |
332 | ||
333 | def test_macvlan(self): | |
334 | self.copy_unit_to_networkd_unit_path('21-macvlan.netdev', '11-dummy.netdev', 'macvlan.network') | |
1f0e3109 SS |
335 | self.start_networkd() |
336 | ||
337 | self.assertTrue(self.link_exits('macvlan99')) | |
338 | ||
7a0a37b2 | 339 | @expectedFailureIfModuleIsNotAvailable('ipvlan') |
1f0e3109 SS |
340 | def test_ipvlan(self): |
341 | self.copy_unit_to_networkd_unit_path('25-ipvlan.netdev', '11-dummy.netdev', 'ipvlan.network') | |
1f0e3109 SS |
342 | self.start_networkd() |
343 | ||
344 | self.assertTrue(self.link_exits('ipvlan99')) | |
345 | ||
346 | def test_veth(self): | |
347 | self.copy_unit_to_networkd_unit_path('25-veth.netdev') | |
1f0e3109 SS |
348 | self.start_networkd() |
349 | ||
350 | self.assertTrue(self.link_exits('veth99')) | |
351 | ||
352 | def test_dummy(self): | |
353 | self.copy_unit_to_networkd_unit_path('11-dummy.netdev') | |
1f0e3109 SS |
354 | self.start_networkd() |
355 | ||
356 | self.assertTrue(self.link_exits('test1')) | |
357 | ||
358 | def test_tun(self): | |
359 | self.copy_unit_to_networkd_unit_path('25-tun.netdev') | |
1f0e3109 SS |
360 | self.start_networkd() |
361 | ||
362 | self.assertTrue(self.link_exits('tun99')) | |
363 | ||
364 | def test_tap(self): | |
365 | self.copy_unit_to_networkd_unit_path('25-tap.netdev') | |
1f0e3109 SS |
366 | self.start_networkd() |
367 | ||
368 | self.assertTrue(self.link_exits('tap99')) | |
369 | ||
7a0a37b2 | 370 | @expectedFailureIfModuleIsNotAvailable('vrf') |
1f0e3109 SS |
371 | def test_vrf(self): |
372 | self.copy_unit_to_networkd_unit_path('25-vrf.netdev') | |
1f0e3109 SS |
373 | self.start_networkd() |
374 | ||
375 | self.assertTrue(self.link_exits('vrf99')) | |
376 | ||
7a0a37b2 | 377 | @expectedFailureIfModuleIsNotAvailable('vcan') |
1f0e3109 SS |
378 | def test_vcan(self): |
379 | self.copy_unit_to_networkd_unit_path('25-vcan.netdev') | |
1f0e3109 SS |
380 | self.start_networkd() |
381 | ||
382 | self.assertTrue(self.link_exits('vcan99')) | |
383 | ||
7a3bc5a8 EV |
384 | @expectedFailureIfModuleIsNotAvailable('wireguard') |
385 | def test_wireguard(self): | |
386 | self.copy_unit_to_networkd_unit_path('25-wireguard.netdev') | |
7a3bc5a8 EV |
387 | self.start_networkd() |
388 | ||
389 | if shutil.which('wg'): | |
390 | subprocess.call('wg') | |
391 | ||
392 | self.assertTrue(self.link_exits('wg99')) | |
393 | ||
1f0e3109 SS |
394 | def test_geneve(self): |
395 | self.copy_unit_to_networkd_unit_path('25-geneve.netdev') | |
1f0e3109 SS |
396 | self.start_networkd() |
397 | ||
398 | self.assertTrue(self.link_exits('geneve99')) | |
399 | ||
400 | output = subprocess.check_output(['ip', '-d', 'link', 'show', 'geneve99']).rstrip().decode('utf-8') | |
14ecd604 | 401 | print(output) |
1f0e3109 SS |
402 | self.assertTrue(output, '192.168.22.1') |
403 | self.assertTrue(output, '6082') | |
404 | self.assertTrue(output, 'udpcsum') | |
405 | self.assertTrue(output, 'udp6zerocsumrx') | |
406 | ||
407 | def test_ipip_tunnel(self): | |
408 | self.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-ipip-tunnel.netdev', 'ipip.network') | |
409 | self.start_networkd() | |
410 | ||
411 | self.assertTrue(self.link_exits('dummy98')) | |
412 | self.assertTrue(self.link_exits('ipiptun99')) | |
413 | ||
414 | def test_gre_tunnel(self): | |
415 | self.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-gre-tunnel.netdev', 'gretun.network') | |
416 | self.start_networkd() | |
417 | ||
418 | self.assertTrue(self.link_exits('dummy98')) | |
419 | self.assertTrue(self.link_exits('gretun99')) | |
420 | ||
421 | def test_gretap_tunnel(self): | |
422 | self.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-gretap-tunnel.netdev', 'gretap.network') | |
423 | self.start_networkd() | |
424 | ||
425 | self.assertTrue(self.link_exits('dummy98')) | |
426 | self.assertTrue(self.link_exits('gretap99')) | |
427 | ||
428 | def test_ip6gretap_tunnel(self): | |
429 | self.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-ip6gre-tunnel.netdev', 'ip6gretap.network') | |
430 | self.start_networkd() | |
431 | ||
432 | self.assertTrue(self.link_exits('dummy98')) | |
433 | self.assertTrue(self.link_exits('ip6gretap99')) | |
434 | ||
435 | def test_vti_tunnel(self): | |
436 | self.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-vti-tunnel.netdev', 'vti.network') | |
437 | self.start_networkd() | |
438 | ||
439 | self.assertTrue(self.link_exits('dummy98')) | |
440 | self.assertTrue(self.link_exits('vtitun99')) | |
441 | ||
442 | def test_vti6_tunnel(self): | |
443 | self.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-vti6-tunnel.netdev', 'vti6.network') | |
444 | self.start_networkd() | |
445 | ||
446 | self.assertTrue(self.link_exits('dummy98')) | |
447 | self.assertTrue(self.link_exits('vti6tun99')) | |
448 | ||
449 | def test_ip6tnl_tunnel(self): | |
450 | self.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-ip6tnl-tunnel.netdev', 'ip6tnl.network') | |
451 | self.start_networkd() | |
452 | ||
453 | self.assertTrue(self.link_exits('dummy98')) | |
454 | self.assertTrue(self.link_exits('ip6tnl99')) | |
455 | ||
456 | def test_sit_tunnel(self): | |
457 | self.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-sit-tunnel.netdev', 'sit.network') | |
458 | self.start_networkd() | |
459 | ||
460 | self.assertTrue(self.link_exits('dummy98')) | |
461 | self.assertTrue(self.link_exits('sittun99')) | |
462 | ||
d0e728b6 SS |
463 | def test_isatap_tunnel(self): |
464 | self.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-isatap-tunnel.netdev', 'isatap.network') | |
465 | self.start_networkd() | |
466 | ||
467 | self.assertTrue(self.link_exits('dummy98')) | |
468 | self.assertTrue(self.link_exits('isataptun99')) | |
e40a58b5 | 469 | |
d0e728b6 | 470 | output = subprocess.check_output(['ip', '-d', 'link', 'show', 'isataptun99']).rstrip().decode('utf-8') |
14ecd604 | 471 | print(output) |
d0e728b6 SS |
472 | self.assertRegex(output, "isatap ") |
473 | ||
d29dc4f1 DA |
474 | def test_6rd_tunnel(self): |
475 | self.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-6rd-tunnel.netdev', '6rd.network') | |
476 | self.start_networkd() | |
477 | ||
478 | self.assertTrue(self.link_exits('dummy98')) | |
479 | self.assertTrue(self.link_exits('sittun99')) | |
480 | ||
2266864b SS |
481 | def test_erspan_tunnel(self): |
482 | self.copy_unit_to_networkd_unit_path('25-erspan-tunnel.netdev') | |
483 | self.start_networkd() | |
484 | ||
485 | self.assertTrue(self.link_exits('erspan-test')) | |
486 | ||
487 | output = subprocess.check_output(['ip', '-d', 'link', 'show', 'erspan-test']).rstrip().decode('utf-8') | |
488 | print(output) | |
489 | self.assertTrue(output, '172.16.1.200') | |
490 | self.assertTrue(output, '172.16.1.100') | |
491 | self.assertTrue(output, '101') | |
492 | ||
1f0e3109 SS |
493 | def test_tunnel_independent(self): |
494 | self.copy_unit_to_networkd_unit_path('25-ipip-tunnel-independent.netdev') | |
1f0e3109 | 495 | self.start_networkd() |
e40a58b5 | 496 | |
1f0e3109 SS |
497 | self.assertTrue(self.link_exits('ipiptun99')) |
498 | ||
499 | def test_vxlan(self): | |
500 | self.copy_unit_to_networkd_unit_path('25-vxlan.netdev', 'vxlan.network','11-dummy.netdev') | |
1f0e3109 SS |
501 | self.start_networkd() |
502 | ||
503 | self.assertTrue(self.link_exits('vxlan99')) | |
504 | ||
505 | output = subprocess.check_output(['ip', '-d', 'link', 'show', 'vxlan99']).rstrip().decode('utf-8') | |
14ecd604 | 506 | print(output) |
1f0e3109 SS |
507 | self.assertRegex(output, "999") |
508 | self.assertRegex(output, '5555') | |
509 | self.assertRegex(output, 'l2miss') | |
510 | self.assertRegex(output, 'l3miss') | |
511 | self.assertRegex(output, 'udpcsum') | |
512 | self.assertRegex(output, 'udp6zerocsumtx') | |
513 | self.assertRegex(output, 'udp6zerocsumrx') | |
514 | self.assertRegex(output, 'remcsumtx') | |
515 | self.assertRegex(output, 'remcsumrx') | |
516 | self.assertRegex(output, 'gbp') | |
517 | ||
518 | class NetworkdNetWorkTests(unittest.TestCase, Utilities): | |
09ea6724 YW |
519 | links = [ |
520 | 'bond199', | |
521 | 'dummy98', | |
522 | 'test1'] | |
523 | ||
524 | units = [ | |
525 | '11-dummy.netdev', | |
526 | '12-dummy.netdev', | |
527 | '23-active-slave.network', | |
528 | '23-bond199.network', | |
529 | '23-primary-slave.network', | |
530 | '23-test1-bond199.network', | |
531 | '25-address-link-section.network', | |
532 | '25-address-section-miscellaneous.network', | |
533 | '25-address-section.network', | |
534 | '25-bond-active-backup-slave.netdev', | |
535 | '25-fibrule-invert.network', | |
536 | '25-fibrule-port-range.network', | |
537 | '25-ipv6-address-label-section.network', | |
e4a71bf3 | 538 | '25-neighbor-section.network', |
09ea6724 YW |
539 | '25-link-section-unmanaged.network', |
540 | '25-route-gateway.network', | |
541 | '25-route-gateway-on-link.network', | |
542 | '25-route-reverse-order.network', | |
543 | '25-route-section.network', | |
544 | '25-route-tcp-window-settings.network', | |
545 | '25-route-type.network', | |
546 | '25-sysctl.network', | |
547 | 'configure-without-carrier.network', | |
548 | 'routing-policy-rule.network', | |
549 | 'test-static.network'] | |
1f0e3109 SS |
550 | |
551 | def setUp(self): | |
552 | self.link_remove(self.links) | |
553 | ||
554 | def tearDown(self): | |
555 | self.link_remove(self.links) | |
556 | self.remove_unit_from_networkd_path(self.units) | |
557 | ||
558 | def test_static_address(self): | |
559 | self.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'test-static.network') | |
560 | self.start_networkd() | |
561 | ||
562 | self.assertTrue(self.link_exits('dummy98')) | |
e40a58b5 | 563 | |
1f0e3109 SS |
564 | output = subprocess.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8') |
565 | print(output) | |
566 | self.assertRegex(output, '192.168.0.15') | |
567 | self.assertRegex(output, '192.168.0.1') | |
568 | self.assertRegex(output, 'routable') | |
569 | ||
570 | def test_configure_without_carrier(self): | |
571 | self.copy_unit_to_networkd_unit_path('configure-without-carrier.network', '11-dummy.netdev') | |
572 | self.start_networkd() | |
573 | ||
574 | self.assertTrue(self.link_exits('test1')) | |
e40a58b5 | 575 | |
1f0e3109 SS |
576 | output = subprocess.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8') |
577 | print(output) | |
578 | self.assertRegex(output, '192.168.0.15') | |
579 | self.assertRegex(output, '192.168.0.1') | |
580 | self.assertRegex(output, 'routable') | |
581 | ||
582 | def test_bond_active_slave(self): | |
583 | self.copy_unit_to_networkd_unit_path('23-active-slave.network', '23-bond199.network', '25-bond-active-backup-slave.netdev', '12-dummy.netdev') | |
584 | self.start_networkd() | |
585 | ||
586 | self.assertTrue(self.link_exits('dummy98')) | |
587 | self.assertTrue(self.link_exits('bond199')) | |
e40a58b5 | 588 | |
1f0e3109 SS |
589 | output = subprocess.check_output(['ip', '-d', 'link', 'show', 'bond199']).rstrip().decode('utf-8') |
590 | print(output) | |
591 | self.assertRegex(output, 'active_slave dummy98') | |
592 | ||
593 | def test_bond_primary_slave(self): | |
594 | self.copy_unit_to_networkd_unit_path('23-primary-slave.network', '23-test1-bond199.network', '25-bond-active-backup-slave.netdev', '11-dummy.netdev') | |
595 | self.start_networkd() | |
596 | ||
597 | self.assertTrue(self.link_exits('test1')) | |
598 | self.assertTrue(self.link_exits('bond199')) | |
e40a58b5 | 599 | |
1f0e3109 SS |
600 | output = subprocess.check_output(['ip', '-d', 'link', 'show', 'bond199']).rstrip().decode('utf-8') |
601 | print(output) | |
602 | self.assertRegex(output, 'primary test1') | |
603 | ||
604 | def test_routing_policy_rule(self): | |
605 | self.copy_unit_to_networkd_unit_path('routing-policy-rule.network', '11-dummy.netdev') | |
606 | self.start_networkd() | |
607 | ||
608 | self.assertTrue(self.link_exits('test1')) | |
e40a58b5 | 609 | |
1f0e3109 SS |
610 | output = subprocess.check_output(['ip', 'rule']).rstrip().decode('utf-8') |
611 | print(output) | |
612 | self.assertRegex(output, '111') | |
613 | self.assertRegex(output, 'from 192.168.100.18') | |
f7bdd562 | 614 | self.assertRegex(output, r'tos (?:0x08|throughput)\s') |
1f0e3109 SS |
615 | self.assertRegex(output, 'iif test1') |
616 | self.assertRegex(output, 'oif test1') | |
617 | self.assertRegex(output, 'lookup 7') | |
618 | ||
e4eacdb0 YW |
619 | subprocess.call(['ip', 'rule', 'del', 'table', '7']) |
620 | ||
926062f0 SS |
621 | def test_routing_policy_rule_port_range(self): |
622 | self.copy_unit_to_networkd_unit_path('25-fibrule-port-range.network', '11-dummy.netdev') | |
623 | self.start_networkd() | |
624 | ||
625 | self.assertTrue(self.link_exits('test1')) | |
e40a58b5 | 626 | |
926062f0 SS |
627 | output = subprocess.check_output(['ip', 'rule']).rstrip().decode('utf-8') |
628 | print(output) | |
629 | self.assertRegex(output, '111') | |
630 | self.assertRegex(output, 'from 192.168.100.18') | |
631 | self.assertRegex(output, '1123-1150') | |
632 | self.assertRegex(output, '3224-3290') | |
633 | self.assertRegex(output, 'tcp') | |
634 | self.assertRegex(output, 'lookup 7') | |
1f0e3109 | 635 | |
e4eacdb0 YW |
636 | subprocess.call(['ip', 'rule', 'del', 'table', '7']) |
637 | ||
efecf9cd SS |
638 | def test_routing_policy_rule_invert(self): |
639 | self.copy_unit_to_networkd_unit_path('25-fibrule-invert.network', '11-dummy.netdev') | |
640 | self.start_networkd() | |
641 | ||
642 | self.assertTrue(self.link_exits('test1')) | |
e40a58b5 | 643 | |
efecf9cd SS |
644 | output = subprocess.check_output(['ip', 'rule']).rstrip().decode('utf-8') |
645 | print(output) | |
efecf9cd SS |
646 | self.assertRegex(output, '111') |
647 | self.assertRegex(output, 'not.*?from.*?192.168.100.18') | |
648 | self.assertRegex(output, 'tcp') | |
649 | self.assertRegex(output, 'lookup 7') | |
650 | ||
e4eacdb0 YW |
651 | subprocess.call(['ip', 'rule', 'del', 'table', '7']) |
652 | ||
1f0e3109 SS |
653 | def test_address_preferred_lifetime_zero_ipv6(self): |
654 | self.copy_unit_to_networkd_unit_path('25-address-section-miscellaneous.network', '12-dummy.netdev') | |
655 | self.start_networkd() | |
656 | ||
657 | self.assertTrue(self.link_exits('dummy98')) | |
658 | ||
659 | output = subprocess.check_output(['ip', 'address', 'show', 'dummy98']).rstrip().decode('utf-8') | |
660 | print(output) | |
661 | self.assertRegex(output, 'inet 10.2.3.4/16 brd 10.2.255.255 scope link deprecated dummy98') | |
662 | self.assertRegex(output, 'inet6 2001:db8:0:f101::1/64 scope global') | |
663 | ||
664 | def test_ip_route(self): | |
665 | self.copy_unit_to_networkd_unit_path('25-route-section.network', '12-dummy.netdev') | |
666 | self.start_networkd() | |
667 | ||
668 | self.assertTrue(self.link_exits('dummy98')) | |
669 | ||
670 | output = subprocess.check_output(['ip', 'route', 'list', 'dev', 'dummy98']).rstrip().decode('utf-8') | |
671 | print(output) | |
672 | self.assertRegex(output, '192.168.0.1') | |
673 | self.assertRegex(output, 'static') | |
674 | self.assertRegex(output, '192.168.0.0/24') | |
675 | ||
0d34228f SS |
676 | def test_ip_route_reverse(self): |
677 | self.copy_unit_to_networkd_unit_path('25-route-reverse-order.network', '12-dummy.netdev') | |
678 | self.start_networkd() | |
679 | ||
680 | self.assertTrue(self.link_exits('dummy98')) | |
681 | ||
682 | output = subprocess.check_output(['ip', '-6', 'route', 'show', 'dev', 'dummy98']).rstrip().decode('utf-8') | |
683 | print(output) | |
684 | self.assertRegex(output, '2001:1234:5:8fff:ff:ff:ff:ff') | |
685 | self.assertRegex(output, '2001:1234:5:8f63::1') | |
686 | ||
1f0e3109 SS |
687 | def test_ip_route_blackhole_unreachable_prohibit(self): |
688 | self.copy_unit_to_networkd_unit_path('25-route-type.network', '12-dummy.netdev') | |
689 | self.start_networkd() | |
690 | ||
691 | self.assertTrue(self.link_exits('dummy98')) | |
692 | ||
693 | output = subprocess.check_output(['ip', 'route', 'list']).rstrip().decode('utf-8') | |
694 | print(output) | |
695 | self.assertRegex(output, 'blackhole') | |
696 | self.assertRegex(output, 'unreachable') | |
697 | self.assertRegex(output, 'prohibit') | |
698 | ||
699 | subprocess.call(['ip', 'route', 'del', 'blackhole', '202.54.1.2']) | |
700 | subprocess.call(['ip', 'route', 'del', 'unreachable', '202.54.1.3']) | |
701 | subprocess.call(['ip', 'route', 'del', 'prohibit', '202.54.1.4']) | |
702 | ||
703 | def test_ip_route_tcp_window(self): | |
704 | self.copy_unit_to_networkd_unit_path('25-route-tcp-window-settings.network', '11-dummy.netdev') | |
705 | self.start_networkd() | |
706 | ||
707 | self.assertTrue(self.link_exits('test1')) | |
708 | ||
709 | output = subprocess.check_output(['ip', 'route', 'list']).rstrip().decode('utf-8') | |
710 | print(output) | |
711 | self.assertRegex(output, 'initcwnd 20') | |
712 | self.assertRegex(output, 'initrwnd 30') | |
713 | ||
f5050e48 YW |
714 | def test_ip_route_gateway(self): |
715 | self.copy_unit_to_networkd_unit_path('25-route-gateway.network', '12-dummy.netdev') | |
716 | self.start_networkd() | |
717 | ||
718 | self.assertTrue(self.link_exits('dummy98')) | |
719 | ||
720 | output = subprocess.check_output(['ip', 'route', 'list', 'dev', 'dummy98', 'default']).rstrip().decode('utf-8') | |
721 | print(output) | |
722 | self.assertRegex(output, 'default') | |
723 | self.assertRegex(output, 'via') | |
724 | self.assertRegex(output, '149.10.124.64') | |
725 | self.assertRegex(output, 'proto') | |
726 | self.assertRegex(output, 'static') | |
727 | ||
728 | output = subprocess.check_output(['ip', 'route', 'list', 'dev', 'dummy98', 'src', '149.10.124.58']).rstrip().decode('utf-8') | |
729 | print(output) | |
730 | self.assertRegex(output, '149.10.124.48/28') | |
731 | self.assertRegex(output, 'proto') | |
732 | self.assertRegex(output, 'kernel') | |
733 | self.assertRegex(output, 'scope') | |
734 | self.assertRegex(output, 'link') | |
735 | ||
736 | def test_ip_route_gateway_on_link(self): | |
737 | self.copy_unit_to_networkd_unit_path('25-route-gateway-on-link.network', '12-dummy.netdev') | |
738 | self.start_networkd() | |
739 | ||
740 | self.assertTrue(self.link_exits('dummy98')) | |
741 | ||
742 | output = subprocess.check_output(['ip', 'route', 'list', 'dev', 'dummy98', 'default']).rstrip().decode('utf-8') | |
743 | print(output) | |
744 | self.assertRegex(output, 'default') | |
745 | self.assertRegex(output, 'via') | |
746 | self.assertRegex(output, '149.10.125.65') | |
747 | self.assertRegex(output, 'proto') | |
748 | self.assertRegex(output, 'static') | |
749 | self.assertRegex(output, 'onlink') | |
750 | ||
751 | output = subprocess.check_output(['ip', 'route', 'list', 'dev', 'dummy98', 'src', '149.10.124.58']).rstrip().decode('utf-8') | |
752 | print(output) | |
753 | self.assertRegex(output, '149.10.124.48/28') | |
754 | self.assertRegex(output, 'proto') | |
755 | self.assertRegex(output, 'kernel') | |
756 | self.assertRegex(output, 'scope') | |
757 | self.assertRegex(output, 'link') | |
758 | ||
1f0e3109 SS |
759 | def test_ip_link_mac_address(self): |
760 | self.copy_unit_to_networkd_unit_path('25-address-link-section.network', '12-dummy.netdev') | |
761 | self.start_networkd() | |
762 | ||
763 | self.assertTrue(self.link_exits('dummy98')) | |
764 | ||
765 | output = subprocess.check_output(['ip', 'link', 'show', 'dummy98']).rstrip().decode('utf-8') | |
766 | print(output) | |
767 | self.assertRegex(output, '00:01:02:aa:bb:cc') | |
768 | ||
769 | def test_ip_link_unmanaged(self): | |
770 | self.copy_unit_to_networkd_unit_path('25-link-section-unmanaged.network', '12-dummy.netdev') | |
771 | self.start_networkd() | |
772 | ||
773 | self.assertTrue(self.link_exits('dummy98')) | |
774 | ||
775 | output = subprocess.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8') | |
776 | print(output) | |
777 | self.assertRegex(output, 'unmanaged') | |
778 | ||
779 | def test_ipv6_address_label(self): | |
780 | self.copy_unit_to_networkd_unit_path('25-ipv6-address-label-section.network', '12-dummy.netdev') | |
781 | self.start_networkd() | |
782 | ||
783 | self.assertTrue(self.link_exits('dummy98')) | |
784 | ||
785 | output = subprocess.check_output(['ip', 'addrlabel', 'list']).rstrip().decode('utf-8') | |
786 | print(output) | |
787 | self.assertRegex(output, '2004:da8:1::/64') | |
788 | ||
e4a71bf3 WKI |
789 | def test_ipv6_neighbor(self): |
790 | self.copy_unit_to_networkd_unit_path('25-neighbor-section.network', '12-dummy.netdev') | |
791 | self.start_networkd() | |
792 | ||
793 | self.assertTrue(self.link_exits('dummy98')) | |
794 | ||
795 | output = subprocess.check_output(['ip', 'neigh', 'list']).rstrip().decode('utf-8') | |
796 | print(output) | |
797 | self.assertRegex(output, '192.168.10.1.*00:00:5e:00:02:65.*PERMANENT') | |
798 | self.assertRegex(output, '2004:da8:1:0::1.*00:00:5e:00:02:66.*PERMANENT') | |
799 | ||
1f0e3109 SS |
800 | def test_sysctl(self): |
801 | self.copy_unit_to_networkd_unit_path('25-sysctl.network', '12-dummy.netdev') | |
802 | self.start_networkd() | |
803 | ||
804 | self.assertTrue(self.link_exits('dummy98')) | |
805 | ||
806 | self.assertEqual(self.read_ipv6_sysctl_attr('dummy98', 'forwarding'), '1') | |
807 | self.assertEqual(self.read_ipv6_sysctl_attr('dummy98', 'use_tempaddr'), '2') | |
808 | self.assertEqual(self.read_ipv6_sysctl_attr('dummy98', 'dad_transmits'), '3') | |
809 | self.assertEqual(self.read_ipv6_sysctl_attr('dummy98', 'hop_limit'), '5') | |
810 | self.assertEqual(self.read_ipv6_sysctl_attr('dummy98', 'proxy_ndp'), '1') | |
811 | self.assertEqual(self.read_ipv4_sysctl_attr('dummy98', 'forwarding'),'1') | |
812 | self.assertEqual(self.read_ipv4_sysctl_attr('dummy98', 'proxy_arp'), '1') | |
813 | ||
14dc0335 | 814 | class NetworkdNetWorkBridgeTests(unittest.TestCase, Utilities): |
09ea6724 YW |
815 | links = [ |
816 | 'bridge99', | |
817 | 'dummy98', | |
818 | 'test1'] | |
819 | ||
820 | units = [ | |
821 | '11-dummy.netdev', | |
822 | '12-dummy.netdev', | |
823 | '26-bridge.netdev', | |
824 | '26-bridge-slave-interface-1.network', | |
825 | '26-bridge-slave-interface-2.network', | |
826 | 'bridge99.network'] | |
1f0e3109 SS |
827 | |
828 | def setUp(self): | |
829 | self.link_remove(self.links) | |
830 | ||
831 | def tearDown(self): | |
832 | self.link_remove(self.links) | |
833 | self.remove_unit_from_networkd_path(self.units) | |
834 | ||
835 | def test_bridge_property(self): | |
836 | self.copy_unit_to_networkd_unit_path('11-dummy.netdev', '12-dummy.netdev', '26-bridge.netdev', | |
837 | '26-bridge-slave-interface-1.network', '26-bridge-slave-interface-2.network', | |
838 | 'bridge99.network') | |
839 | self.start_networkd() | |
840 | ||
841 | self.assertTrue(self.link_exits('dummy98')) | |
842 | self.assertTrue(self.link_exits('test1')) | |
843 | self.assertTrue(self.link_exits('bridge99')) | |
844 | ||
845 | output = subprocess.check_output(['ip', '-d', 'link', 'show', 'test1']).rstrip().decode('utf-8') | |
846 | print(output) | |
847 | self.assertRegex(output, 'master') | |
848 | self.assertRegex(output, 'bridge') | |
849 | ||
850 | output = subprocess.check_output(['ip', '-d', 'link', 'show', 'dummy98']).rstrip().decode('utf-8') | |
851 | print(output) | |
852 | self.assertRegex(output, 'master') | |
853 | self.assertRegex(output, 'bridge') | |
854 | ||
855 | output = subprocess.check_output(['ip', 'addr', 'show', 'bridge99']).rstrip().decode('utf-8') | |
856 | print(output) | |
857 | self.assertRegex(output, '192.168.0.15') | |
858 | self.assertRegex(output, '192.168.0.1') | |
859 | ||
860 | output = subprocess.check_output(['bridge', '-d', 'link', 'show', 'dummy98']).rstrip().decode('utf-8') | |
861 | print(output) | |
4d7ed14f SS |
862 | self.assertEqual(self.read_bridge_port_attr('bridge99', 'dummy98', 'hairpin_mode'), '1') |
863 | self.assertEqual(self.read_bridge_port_attr('bridge99', 'dummy98', 'path_cost'), '400') | |
864 | self.assertEqual(self.read_bridge_port_attr('bridge99', 'dummy98', 'unicast_flood'), '1') | |
865 | self.assertEqual(self.read_bridge_port_attr('bridge99', 'dummy98', 'multicast_fast_leave'), '1') | |
866 | ||
867 | # CONFIG_BRIDGE_IGMP_SNOOPING=y | |
868 | if (os.path.exists('/sys/devices/virtual/net/bridge00/lower_dummy98/brport/multicast_to_unicast')): | |
869 | self.assertEqual(self.read_bridge_port_attr('bridge99', 'dummy98', 'multicast_to_unicast'), '1') | |
1f0e3109 SS |
870 | |
871 | class NetworkdNetWorkLLDPTests(unittest.TestCase, Utilities): | |
872 | links = ['veth99'] | |
873 | ||
09ea6724 YW |
874 | units = [ |
875 | '23-emit-lldp.network', | |
876 | '24-lldp.network', | |
877 | '25-veth.netdev'] | |
1f0e3109 SS |
878 | |
879 | def setUp(self): | |
880 | self.link_remove(self.links) | |
881 | ||
882 | def tearDown(self): | |
883 | self.link_remove(self.links) | |
884 | self.remove_unit_from_networkd_path(self.units) | |
885 | ||
886 | def test_lldp(self): | |
887 | self.copy_unit_to_networkd_unit_path('23-emit-lldp.network', '24-lldp.network', '25-veth.netdev') | |
888 | self.start_networkd() | |
889 | ||
890 | self.assertTrue(self.link_exits('veth99')) | |
891 | ||
892 | output = subprocess.check_output(['networkctl', 'lldp']).rstrip().decode('utf-8') | |
893 | print(output) | |
894 | self.assertRegex(output, 'veth-peer') | |
895 | self.assertRegex(output, 'veth99') | |
896 | ||
897 | class NetworkdNetworkRATests(unittest.TestCase, Utilities): | |
898 | links = ['veth99'] | |
899 | ||
09ea6724 YW |
900 | units = [ |
901 | '25-veth.netdev', | |
902 | 'ipv6-prefix.network', | |
903 | 'ipv6-prefix-veth.network'] | |
1f0e3109 SS |
904 | |
905 | def setUp(self): | |
906 | self.link_remove(self.links) | |
907 | ||
908 | def tearDown(self): | |
909 | self.link_remove(self.links) | |
910 | self.remove_unit_from_networkd_path(self.units) | |
911 | ||
912 | def test_ipv6_prefix_delegation(self): | |
913 | self.copy_unit_to_networkd_unit_path('25-veth.netdev', 'ipv6-prefix.network', 'ipv6-prefix-veth.network') | |
914 | self.start_networkd() | |
915 | ||
916 | self.assertTrue(self.link_exits('veth99')) | |
917 | ||
918 | output = subprocess.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8') | |
919 | print(output) | |
920 | self.assertRegex(output, '2002:da8:1:0') | |
921 | ||
922 | class NetworkdNetworkDHCPServerTests(unittest.TestCase, Utilities): | |
09ea6724 YW |
923 | links = [ |
924 | 'dummy98', | |
925 | 'veth99'] | |
926 | ||
927 | units = [ | |
928 | '12-dummy.netdev', | |
929 | '24-search-domain.network', | |
930 | '25-veth.netdev', | |
931 | 'dhcp-client.network', | |
932 | 'dhcp-client-timezone-router.network', | |
933 | 'dhcp-server.network', | |
934 | 'dhcp-server-timezone-router.network'] | |
1f0e3109 SS |
935 | |
936 | def setUp(self): | |
937 | self.link_remove(self.links) | |
938 | ||
939 | def tearDown(self): | |
940 | self.link_remove(self.links) | |
941 | self.remove_unit_from_networkd_path(self.units) | |
942 | ||
943 | def test_dhcp_server(self): | |
944 | self.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-client.network', 'dhcp-server.network') | |
945 | self.start_networkd() | |
946 | ||
947 | self.assertTrue(self.link_exits('veth99')) | |
948 | ||
1f0e3109 SS |
949 | output = subprocess.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8') |
950 | print(output) | |
951 | self.assertRegex(output, '192.168.5.*') | |
952 | self.assertRegex(output, 'Gateway: 192.168.5.1') | |
953 | self.assertRegex(output, 'DNS: 192.168.5.1') | |
954 | self.assertRegex(output, 'NTP: 192.168.5.1') | |
955 | ||
956 | def test_domain(self): | |
957 | self.copy_unit_to_networkd_unit_path( '12-dummy.netdev', '24-search-domain.network') | |
958 | self.start_networkd() | |
959 | ||
960 | self.assertTrue(self.link_exits('dummy98')) | |
961 | ||
962 | output = subprocess.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8') | |
963 | print(output) | |
964 | self.assertRegex(output, 'Address: 192.168.42.100') | |
965 | self.assertRegex(output, 'DNS: 192.168.42.1') | |
966 | self.assertRegex(output, 'Search Domains: one') | |
967 | ||
968 | def test_emit_router_timezone(self): | |
969 | self.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-client-timezone-router.network', 'dhcp-server-timezone-router.network') | |
970 | self.start_networkd() | |
971 | ||
972 | self.assertTrue(self.link_exits('veth99')) | |
973 | ||
974 | output = subprocess.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8') | |
975 | print(output) | |
976 | self.assertRegex(output, 'Gateway: 192.168.5.*') | |
977 | self.assertRegex(output, '192.168.5.*') | |
978 | self.assertRegex(output, 'Europe/Berlin') | |
979 | ||
980 | class NetworkdNetworkDHCPClientTests(unittest.TestCase, Utilities): | |
09ea6724 YW |
981 | links = [ |
982 | 'dummy98', | |
983 | 'veth99'] | |
984 | ||
985 | units = [ | |
986 | '25-veth.netdev', | |
987 | 'dhcp-client-anonymize.network', | |
988 | 'dhcp-client-critical-connection.network', | |
989 | 'dhcp-client-ipv4-dhcp-settings.network', | |
990 | 'dhcp-client-ipv4-only-ipv6-disabled.network', | |
991 | 'dhcp-client-ipv4-only.network', | |
992 | 'dhcp-client-ipv6-only.network', | |
993 | 'dhcp-client-ipv6-rapid-commit.network', | |
994 | 'dhcp-client-listen-port.network', | |
995 | 'dhcp-client-route-metric.network', | |
996 | 'dhcp-client-route-table.network', | |
997 | 'dhcp-server-veth-peer.network', | |
998 | 'dhcp-v4-server-veth-peer.network'] | |
1f0e3109 SS |
999 | |
1000 | def setUp(self): | |
1001 | self.link_remove(self.links) | |
1002 | self.stop_dnsmasq(dnsmasq_pid_file) | |
1003 | ||
1004 | def tearDown(self): | |
1005 | self.link_remove(self.links) | |
1006 | self.remove_unit_from_networkd_path(self.units) | |
1007 | self.stop_dnsmasq(dnsmasq_pid_file) | |
1008 | self.remove_lease_file() | |
1009 | self.remove_log_file() | |
1010 | ||
1011 | def test_dhcp_client_ipv6_only(self): | |
1012 | self.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network','dhcp-client-ipv6-only.network') | |
1013 | self.start_networkd() | |
1014 | ||
1015 | self.assertTrue(self.link_exits('veth99')) | |
1016 | ||
1017 | self.start_dnsmasq() | |
1018 | ||
1019 | output = subprocess.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8') | |
1020 | print(output) | |
1021 | self.assertRegex(output, '2600::') | |
1022 | self.assertNotRegex(output, '192.168.5') | |
1023 | ||
1024 | def test_dhcp_client_ipv4_only(self): | |
1025 | self.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network','dhcp-client-ipv4-only-ipv6-disabled.network') | |
1026 | self.start_networkd() | |
1027 | ||
1028 | self.assertTrue(self.link_exits('veth99')) | |
1029 | ||
1030 | self.start_dnsmasq() | |
1031 | ||
1032 | output = subprocess.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8') | |
1033 | print(output) | |
1034 | self.assertNotRegex(output, '2600::') | |
1035 | self.assertRegex(output, '192.168.5') | |
1036 | ||
1037 | def test_dhcp_client_ipv4_ipv6(self): | |
1038 | self.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network', | |
1039 | 'dhcp-client-ipv4-only.network') | |
1040 | self.start_networkd() | |
1041 | ||
1042 | self.assertTrue(self.link_exits('veth99')) | |
1043 | ||
1044 | self.start_dnsmasq() | |
1045 | ||
1046 | output = subprocess.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8') | |
1047 | print(output) | |
1048 | self.assertRegex(output, '2600::') | |
1049 | self.assertRegex(output, '192.168.5') | |
1050 | ||
1051 | def test_dhcp_client_settings(self): | |
1052 | self.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv4-dhcp-settings.network') | |
1053 | self.start_networkd() | |
1054 | ||
1055 | self.assertTrue(self.link_exits('veth99')) | |
1056 | ||
1057 | self.start_dnsmasq() | |
1058 | ||
1059 | output = subprocess.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8') | |
1060 | print(output) | |
1061 | self.assertRegex(output, '12:34:56:78:9a:bc') | |
1062 | self.assertRegex(output, '192.168.5') | |
1063 | self.assertRegex(output, '1492') | |
1064 | ||
1065 | output = subprocess.check_output(['ip', 'route']).rstrip().decode('utf-8') | |
1066 | print(output) | |
1067 | self.assertRegex(output, 'default.*dev veth99 proto dhcp') | |
1068 | ||
131717cb YW |
1069 | self.assertTrue(self.search_words_in_dnsmasq_log('vendor class: SusantVendorTest', True)) |
1070 | self.assertTrue(self.search_words_in_dnsmasq_log('DHCPDISCOVER(veth-peer) 12:34:56:78:9a:bc')) | |
1071 | self.assertTrue(self.search_words_in_dnsmasq_log('client provides name: test-hostname')) | |
1072 | self.assertTrue(self.search_words_in_dnsmasq_log('26:mtu')) | |
1f0e3109 SS |
1073 | |
1074 | def test_dhcp6_client_settings_rapidcommit_true(self): | |
1075 | self.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network') | |
1076 | self.start_networkd() | |
1077 | ||
1078 | self.assertTrue(self.link_exits('veth99')) | |
1079 | ||
1080 | self.start_dnsmasq() | |
1081 | ||
1082 | output = subprocess.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8') | |
1083 | print(output) | |
1084 | self.assertRegex(output, '12:34:56:78:9a:bc') | |
131717cb | 1085 | self.assertTrue(self.search_words_in_dnsmasq_log('14:rapid-commit', True)) |
1f0e3109 SS |
1086 | |
1087 | def test_dhcp6_client_settings_rapidcommit_false(self): | |
1088 | self.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-rapid-commit.network') | |
1089 | self.start_networkd() | |
1090 | ||
1091 | self.assertTrue(self.link_exits('veth99')) | |
1092 | ||
1093 | self.start_dnsmasq() | |
1094 | ||
1095 | output = subprocess.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8') | |
1096 | print(output) | |
1097 | self.assertRegex(output, '12:34:56:78:9a:bc') | |
131717cb | 1098 | self.assertFalse(self.search_words_in_dnsmasq_log('14:rapid-commit', True)) |
1f0e3109 SS |
1099 | |
1100 | def test_dhcp_client_settings_anonymize(self): | |
1101 | self.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-anonymize.network') | |
1102 | self.start_networkd() | |
1103 | ||
1104 | self.assertTrue(self.link_exits('veth99')) | |
1105 | ||
1106 | self.start_dnsmasq() | |
e40a58b5 | 1107 | |
131717cb YW |
1108 | self.assertFalse(self.search_words_in_dnsmasq_log('VendorClassIdentifier=SusantVendorTest', True)) |
1109 | self.assertFalse(self.search_words_in_dnsmasq_log('test-hostname')) | |
1110 | self.assertFalse(self.search_words_in_dnsmasq_log('26:mtu')) | |
1f0e3109 SS |
1111 | |
1112 | def test_dhcp_client_listen_port(self): | |
1113 | self.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-listen-port.network') | |
e40a58b5 | 1114 | |
1f0e3109 SS |
1115 | dh_server = DHCPServer("dhcp_server") |
1116 | dh_server.start() | |
1117 | ||
1118 | self.start_networkd() | |
1119 | ||
1120 | self.assertTrue(self.link_exits('veth99')) | |
1121 | ||
1122 | global port | |
1123 | global ip | |
1124 | ||
1125 | self.assertRegex(str(port), '5555') | |
1126 | self.assertRegex(str(ip), '0.0.0.0') | |
1127 | ||
1128 | dh_server.join() | |
1129 | ||
1130 | def test_dhcp_route_table_id(self): | |
1131 | self.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-route-table.network') | |
1132 | self.start_networkd() | |
1f0e3109 SS |
1133 | |
1134 | self.assertTrue(self.link_exits('veth99')) | |
1135 | ||
e40a58b5 YW |
1136 | self.start_dnsmasq() |
1137 | ||
1f0e3109 SS |
1138 | output = subprocess.check_output(['ip', 'route', 'show', 'table', '12']).rstrip().decode('utf-8') |
1139 | print(output) | |
1f0e3109 SS |
1140 | self.assertRegex(output, 'veth99 proto dhcp') |
1141 | self.assertRegex(output, '192.168.5.1') | |
1142 | ||
1143 | def test_dhcp_route_metric(self): | |
1144 | self.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-route-metric.network') | |
1145 | self.start_networkd() | |
1f0e3109 SS |
1146 | |
1147 | self.assertTrue(self.link_exits('veth99')) | |
1148 | ||
e40a58b5 YW |
1149 | self.start_dnsmasq() |
1150 | ||
1f0e3109 SS |
1151 | output = subprocess.check_output(['ip', 'route', 'show', 'dev', 'veth99']).rstrip().decode('utf-8') |
1152 | print(output) | |
1f0e3109 SS |
1153 | self.assertRegex(output, 'metric 24') |
1154 | ||
1155 | def test_dhcp_route_criticalconnection_true(self): | |
1156 | self.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-critical-connection.network') | |
1157 | self.start_networkd() | |
1f0e3109 SS |
1158 | |
1159 | self.assertTrue(self.link_exits('veth99')) | |
1160 | ||
e40a58b5 YW |
1161 | self.start_dnsmasq() |
1162 | ||
1f0e3109 SS |
1163 | output = subprocess.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8') |
1164 | print(output) | |
1f0e3109 | 1165 | self.assertRegex(output, '192.168.5.*') |
e40a58b5 | 1166 | |
1f0e3109 SS |
1167 | # Stoping dnsmasq as networkd won't be allowed to renew the DHCP lease. |
1168 | self.stop_dnsmasq(dnsmasq_pid_file) | |
1169 | ||
1170 | # Sleep for 120 sec as the dnsmasq minimum lease time can only be set to 120 | |
1171 | time.sleep(125) | |
1172 | ||
1173 | output = subprocess.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8') | |
1174 | print(output) | |
1175 | self.assertRegex(output, '192.168.5.*') | |
1176 | ||
1177 | if __name__ == '__main__': | |
1178 | unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, | |
1179 | verbosity=3)) |