]>
git.ipfire.org Git - thirdparty/systemd.git/blob - test/test-network/systemd-networkd-tests.py
2 # SPDX-License-Identifier: LGPL-2.1+
3 # systemd-networkd tests
15 from shutil
import copytree
17 network_unit_file_path
='/var/run/systemd/network'
18 networkd_ci_path
='/var/run/networkd-ci'
19 network_sysctl_ipv6_path
='/proc/sys/net/ipv6/conf'
20 network_sysctl_ipv4_path
='/proc/sys/net/ipv4/conf'
22 dnsmasq_config_file
='/var/run/networkd-ci/test-dnsmasq.conf'
23 dnsmasq_pid_file
='/var/run/networkd-ci/test-test-dnsmasq.pid'
24 dnsmasq_log_file
='/var/run/networkd-ci/test-dnsmasq-log-file'
26 def is_module_available(module_name
):
27 lsmod_output
= subprocess
.check_output('lsmod', universal_newlines
=True)
28 module_re
= re
.compile(r
'^{0}\b'.format(re
.escape(module_name
)), re
.MULTILINE
)
29 return module_re
.search(lsmod_output
) or not subprocess
.call(["modprobe", module_name
])
31 def expectedFailureIfModuleIsNotAvailable(module_name
):
33 if not is_module_available(module_name
):
34 return unittest
.expectedFailure(func
)
41 os
.makedirs(network_unit_file_path
, exist_ok
=True)
42 os
.makedirs(networkd_ci_path
, exist_ok
=True)
44 shutil
.rmtree(networkd_ci_path
)
45 copytree(os
.path
.join(os
.path
.dirname(os
.path
.abspath(__file__
)), 'conf'), networkd_ci_path
)
48 shutil
.rmtree(networkd_ci_path
)
53 def read_link_attr(self
, link
, dev
, attribute
):
54 with
open(os
.path
.join(os
.path
.join(os
.path
.join('/sys/class/net/', link
), dev
), attribute
)) as f
:
55 return f
.readline().strip()
57 def link_exits(self
, link
):
58 return os
.path
.exists(os
.path
.join('/sys/class/net', link
))
60 def link_remove(self
, links
):
62 if os
.path
.exists(os
.path
.join('/sys/class/net', link
)):
63 subprocess
.call(['ip', 'link', 'del', 'dev', link
])
66 def read_ipv6_sysctl_attr(self
, link
, attribute
):
67 with
open(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, link
), attribute
)) as f
:
68 return f
.readline().strip()
70 def read_ipv4_sysctl_attr(self
, link
, attribute
):
71 with
open(os
.path
.join(os
.path
.join(network_sysctl_ipv4_path
, link
), attribute
)) as f
:
72 return f
.readline().strip()
74 def copy_unit_to_networkd_unit_path(self
, *units
):
76 shutil
.copy(os
.path
.join(networkd_ci_path
, unit
), network_unit_file_path
)
77 if (os
.path
.exists(os
.path
.join(networkd_ci_path
, unit
+ '.d'))):
78 copytree(os
.path
.join(networkd_ci_path
, unit
+ '.d'), os
.path
.join(network_unit_file_path
, unit
+ '.d'))
80 def remove_unit_from_networkd_path(self
, units
):
82 if (os
.path
.exists(os
.path
.join(network_unit_file_path
, unit
))):
83 os
.remove(os
.path
.join(network_unit_file_path
, unit
))
84 if (os
.path
.exists(os
.path
.join(network_unit_file_path
, unit
+ '.d'))):
85 shutil
.rmtree(os
.path
.join(network_unit_file_path
, unit
+ '.d'))
87 def start_dnsmasq(self
):
88 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)
92 def stop_dnsmasq(self
, pid_file
):
93 if os
.path
.exists(pid_file
):
94 with
open(pid_file
, 'r') as f
:
95 pid
= f
.read().rstrip(' \t\r\n\0')
96 os
.kill(int(pid
), signal
.SIGTERM
)
100 def search_words_in_file(self
, word
):
101 if os
.path
.exists(dnsmasq_log_file
):
102 with
open (dnsmasq_log_file
) as in_file
:
103 contents
= in_file
.read()
105 for part
in contents
.split():
108 print("%s, %s" % (word
, part
))
112 def remove_lease_file(self
):
113 if os
.path
.exists(os
.path
.join(networkd_ci_path
, 'lease')):
114 os
.remove(os
.path
.join(networkd_ci_path
, 'lease'))
116 def remove_log_file(self
):
117 if os
.path
.exists(dnsmasq_log_file
):
118 os
.remove(dnsmasq_log_file
)
120 def start_networkd(self
):
121 subprocess
.check_call('systemctl restart systemd-networkd', shell
=True)
127 class DHCPServer(threading
.Thread
):
128 def __init__(self
, name
):
129 threading
.Thread
.__init
__(self
)
133 self
.start_dhcp_server()
135 def start_dhcp_server(self
):
136 sock
= socket
.socket(socket
.AF_INET
, socket
.SOCK_DGRAM
)
138 server_address
= ('0.0.0.0', 67)
139 sock
.bind(server_address
)
141 print('Starting DHCP Server ...\n')
142 data
, addr
= sock
.recvfrom(1024) # buffer size is 1024 bytes
151 class NetworkdNetDevTests(unittest
.TestCase
, Utilities
):
153 links
=['bridge99', 'bond99', 'bond99', 'vlan99', 'test1', 'macvtap99',
154 'macvlan99', 'ipvlan99', 'vxlan99', 'veth99', 'vrf99', 'tun99',
155 'tap99', 'vcan99', 'geneve99', 'dummy98', 'ipiptun99', 'sittun99', '6rdtun99',
156 'gretap99', 'vtitun99', 'vti6tun99','ip6tnl99', 'gretun99', 'ip6gretap99',
157 'wg99', 'dropin-test', 'erspan-test']
159 units
= ['25-bridge.netdev', '25-bond.netdev', '21-vlan.netdev', '11-dummy.netdev', '21-vlan.network',
160 '21-macvtap.netdev', 'macvtap.network', '21-macvlan.netdev', 'macvlan.network', 'vxlan.network',
161 '25-vxlan.netdev', '25-ipvlan.netdev', 'ipvlan.network', '25-veth.netdev', '25-vrf.netdev',
162 '25-tun.netdev', '25-tun.netdev', '25-vcan.netdev', '25-geneve.netdev', '25-ipip-tunnel.netdev',
163 '25-ip6tnl-tunnel.netdev', '25-ip6gre-tunnel.netdev', '25-sit-tunnel.netdev', '25-6rd-tunnel.netdev',
164 '25-erspan-tunnel.netdev', '25-gre-tunnel.netdev', '25-gretap-tunnel.netdev', '25-vti-tunnel.netdev',
165 '25-vti6-tunnel.netdev', '12-dummy.netdev', 'gre.network', 'ipip.network', 'ip6gretap.network',
166 'gretun.network', 'ip6tnl.network', '25-tap.netdev', 'vti6.network', 'vti.network', 'gretap.network',
167 'sit.network', '25-ipip-tunnel-independent.netdev', '25-wireguard.netdev', '6rd.network', '10-dropin-test.netdev']
170 self
.link_remove(self
.links
)
173 self
.link_remove(self
.links
)
174 self
.remove_unit_from_networkd_path(self
.units
)
176 def test_dropin(self
):
177 self
.copy_unit_to_networkd_unit_path('10-dropin-test.netdev')
179 self
.start_networkd()
181 self
.assertTrue(self
.link_exits('dropin-test'))
183 output
= subprocess
.check_output(['ip', 'link', 'show', 'dropin-test']).rstrip().decode('utf-8')
185 self
.assertRegex(output
, '00:50:56:c0:00:28')
187 def test_bridge(self
):
188 self
.copy_unit_to_networkd_unit_path('25-bridge.netdev')
189 self
.start_networkd()
191 self
.assertTrue(self
.link_exits('bridge99'))
193 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge', 'hello_time'))
194 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge', 'max_age'))
195 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge','forward_delay'))
196 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge','ageing_time'))
197 self
.assertEqual('9', self
.read_link_attr('bridge99', 'bridge','priority'))
198 self
.assertEqual('1', self
.read_link_attr('bridge99', 'bridge','multicast_querier'))
199 self
.assertEqual('1', self
.read_link_attr('bridge99', 'bridge','multicast_snooping'))
200 self
.assertEqual('1', self
.read_link_attr('bridge99', 'bridge','stp_state'))
203 self
.copy_unit_to_networkd_unit_path('25-bond.netdev')
204 self
.start_networkd()
206 self
.assertTrue(self
.link_exits('bond99'))
208 self
.assertEqual('802.3ad 4', self
.read_link_attr('bond99', 'bonding', 'mode'))
209 self
.assertEqual('layer3+4 1', self
.read_link_attr('bond99', 'bonding', 'xmit_hash_policy'))
210 self
.assertEqual('1000', self
.read_link_attr('bond99', 'bonding', 'miimon'))
211 self
.assertEqual('fast 1', self
.read_link_attr('bond99', 'bonding', 'lacp_rate'))
212 self
.assertEqual('2000', self
.read_link_attr('bond99', 'bonding', 'updelay'))
213 self
.assertEqual('2000', self
.read_link_attr('bond99', 'bonding', 'downdelay'))
214 self
.assertEqual('4', self
.read_link_attr('bond99', 'bonding', 'resend_igmp'))
215 self
.assertEqual('1', self
.read_link_attr('bond99', 'bonding', 'min_links'))
216 self
.assertEqual('1218', self
.read_link_attr('bond99', 'bonding', 'ad_actor_sys_prio'))
217 self
.assertEqual('811', self
.read_link_attr('bond99', 'bonding', 'ad_user_port_key'))
218 self
.assertEqual('00:11:22:33:44:55', self
.read_link_attr('bond99', 'bonding', 'ad_actor_system'))
221 self
.copy_unit_to_networkd_unit_path('21-vlan.netdev', '11-dummy.netdev', '21-vlan.network')
223 self
.start_networkd()
225 self
.assertTrue(self
.link_exits('vlan99'))
227 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vlan99']).rstrip().decode('utf-8')
228 self
.assertTrue(output
, 'REORDER_HDR')
229 self
.assertTrue(output
, 'LOOSE_BINDING')
230 self
.assertTrue(output
, 'GVRP')
231 self
.assertTrue(output
, 'MVRP')
232 self
.assertTrue(output
, '99')
234 def test_macvtap(self
):
235 self
.copy_unit_to_networkd_unit_path('21-macvtap.netdev', '11-dummy.netdev', 'macvtap.network')
237 self
.start_networkd()
239 self
.assertTrue(self
.link_exits('macvtap99'))
241 def test_macvlan(self
):
242 self
.copy_unit_to_networkd_unit_path('21-macvlan.netdev', '11-dummy.netdev', 'macvlan.network')
244 self
.start_networkd()
246 self
.assertTrue(self
.link_exits('macvlan99'))
248 @expectedFailureIfModuleIsNotAvailable('ipvlan')
249 def test_ipvlan(self
):
250 self
.copy_unit_to_networkd_unit_path('25-ipvlan.netdev', '11-dummy.netdev', 'ipvlan.network')
252 self
.start_networkd()
254 self
.assertTrue(self
.link_exits('ipvlan99'))
257 self
.copy_unit_to_networkd_unit_path('25-veth.netdev')
259 self
.start_networkd()
261 self
.assertTrue(self
.link_exits('veth99'))
263 def test_dummy(self
):
264 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev')
266 self
.start_networkd()
268 self
.assertTrue(self
.link_exits('test1'))
271 self
.copy_unit_to_networkd_unit_path('25-tun.netdev')
273 self
.start_networkd()
275 self
.assertTrue(self
.link_exits('tun99'))
278 self
.copy_unit_to_networkd_unit_path('25-tap.netdev')
280 self
.start_networkd()
282 self
.assertTrue(self
.link_exits('tap99'))
284 @expectedFailureIfModuleIsNotAvailable('vrf')
286 self
.copy_unit_to_networkd_unit_path('25-vrf.netdev')
288 self
.start_networkd()
290 self
.assertTrue(self
.link_exits('vrf99'))
292 @expectedFailureIfModuleIsNotAvailable('vcan')
294 self
.copy_unit_to_networkd_unit_path('25-vcan.netdev')
296 self
.start_networkd()
298 self
.assertTrue(self
.link_exits('vcan99'))
300 @expectedFailureIfModuleIsNotAvailable('wireguard')
301 def test_wireguard(self
):
302 self
.copy_unit_to_networkd_unit_path('25-wireguard.netdev')
304 self
.start_networkd()
306 if shutil
.which('wg'):
307 subprocess
.call('wg')
309 self
.assertTrue(self
.link_exits('wg99'))
311 def test_geneve(self
):
312 self
.copy_unit_to_networkd_unit_path('25-geneve.netdev')
314 self
.start_networkd()
316 self
.assertTrue(self
.link_exits('geneve99'))
318 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'geneve99']).rstrip().decode('utf-8')
319 self
.assertTrue(output
, '192.168.22.1')
320 self
.assertTrue(output
, '6082')
321 self
.assertTrue(output
, 'udpcsum')
322 self
.assertTrue(output
, 'udp6zerocsumrx')
324 def test_ipip_tunnel(self
):
325 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-ipip-tunnel.netdev', 'ipip.network')
326 self
.start_networkd()
328 self
.assertTrue(self
.link_exits('dummy98'))
329 self
.assertTrue(self
.link_exits('ipiptun99'))
331 def test_gre_tunnel(self
):
332 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-gre-tunnel.netdev', 'gretun.network')
333 self
.start_networkd()
335 self
.assertTrue(self
.link_exits('dummy98'))
336 self
.assertTrue(self
.link_exits('gretun99'))
338 def test_gretap_tunnel(self
):
339 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-gretap-tunnel.netdev', 'gretap.network')
340 self
.start_networkd()
342 self
.assertTrue(self
.link_exits('dummy98'))
343 self
.assertTrue(self
.link_exits('gretap99'))
345 def test_ip6gretap_tunnel(self
):
346 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-ip6gre-tunnel.netdev', 'ip6gretap.network')
347 self
.start_networkd()
349 self
.assertTrue(self
.link_exits('dummy98'))
350 self
.assertTrue(self
.link_exits('ip6gretap99'))
352 def test_vti_tunnel(self
):
353 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-vti-tunnel.netdev', 'vti.network')
354 self
.start_networkd()
356 self
.assertTrue(self
.link_exits('dummy98'))
357 self
.assertTrue(self
.link_exits('vtitun99'))
359 def test_vti6_tunnel(self
):
360 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-vti6-tunnel.netdev', 'vti6.network')
361 self
.start_networkd()
363 self
.assertTrue(self
.link_exits('dummy98'))
364 self
.assertTrue(self
.link_exits('vti6tun99'))
366 def test_ip6tnl_tunnel(self
):
367 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-ip6tnl-tunnel.netdev', 'ip6tnl.network')
368 self
.start_networkd()
370 self
.assertTrue(self
.link_exits('dummy98'))
371 self
.assertTrue(self
.link_exits('ip6tnl99'))
373 def test_sit_tunnel(self
):
374 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-sit-tunnel.netdev', 'sit.network')
375 self
.start_networkd()
377 self
.assertTrue(self
.link_exits('dummy98'))
378 self
.assertTrue(self
.link_exits('sittun99'))
380 def test_6rd_tunnel(self
):
381 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-6rd-tunnel.netdev', '6rd.network')
382 self
.start_networkd()
384 self
.assertTrue(self
.link_exits('dummy98'))
385 self
.assertTrue(self
.link_exits('sittun99'))
387 def test_erspan_tunnel(self
):
388 self
.copy_unit_to_networkd_unit_path('25-erspan-tunnel.netdev')
389 self
.start_networkd()
391 self
.assertTrue(self
.link_exits('erspan-test'))
393 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'erspan-test']).rstrip().decode('utf-8')
395 self
.assertTrue(output
, '172.16.1.200')
396 self
.assertTrue(output
, '172.16.1.100')
397 self
.assertTrue(output
, '101')
399 def test_tunnel_independent(self
):
400 self
.copy_unit_to_networkd_unit_path('25-ipip-tunnel-independent.netdev')
402 self
.start_networkd()
403 self
.assertTrue(self
.link_exits('ipiptun99'))
405 def test_vxlan(self
):
406 self
.copy_unit_to_networkd_unit_path('25-vxlan.netdev', 'vxlan.network','11-dummy.netdev')
408 self
.start_networkd()
410 self
.assertTrue(self
.link_exits('vxlan99'))
412 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vxlan99']).rstrip().decode('utf-8')
413 self
.assertRegex(output
, "999")
414 self
.assertRegex(output
, '5555')
415 self
.assertRegex(output
, 'l2miss')
416 self
.assertRegex(output
, 'l3miss')
417 self
.assertRegex(output
, 'udpcsum')
418 self
.assertRegex(output
, 'udp6zerocsumtx')
419 self
.assertRegex(output
, 'udp6zerocsumrx')
420 self
.assertRegex(output
, 'remcsumtx')
421 self
.assertRegex(output
, 'remcsumrx')
422 self
.assertRegex(output
, 'gbp')
424 class NetworkdNetWorkTests(unittest
.TestCase
, Utilities
):
425 links
= ['dummy98', 'test1', 'bond199']
427 units
= ['12-dummy.netdev', 'test-static.network', 'configure-without-carrier.network', '11-dummy.netdev',
428 '23-primary-slave.network', '23-test1-bond199.network', '11-dummy.netdev', '23-bond199.network',
429 '25-bond-active-backup-slave.netdev', '12-dummy.netdev', '23-active-slave.network',
430 'routing-policy-rule.network', '25-fibrule-port-range.network', '25-address-section.network',
431 '25-address-section-miscellaneous.network', '25-route-section.network', '25-route-type.network',
432 '25-route-tcp-window-settings.network', '25-route-gateway.network', '25-route-gateway-on-link.network',
433 '25-address-link-section.network', '25-ipv6-address-label-section.network', '25-link-section-unmanaged.network',
434 '25-sysctl.network', '25-route-reverse-order.network']
437 self
.link_remove(self
.links
)
440 self
.link_remove(self
.links
)
441 self
.remove_unit_from_networkd_path(self
.units
)
443 def test_static_address(self
):
444 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'test-static.network')
445 self
.start_networkd()
447 self
.assertTrue(self
.link_exits('dummy98'))
448 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
450 self
.assertRegex(output
, '192.168.0.15')
451 self
.assertRegex(output
, '192.168.0.1')
452 self
.assertRegex(output
, 'routable')
454 def test_configure_without_carrier(self
):
455 self
.copy_unit_to_networkd_unit_path('configure-without-carrier.network', '11-dummy.netdev')
456 self
.start_networkd()
458 self
.assertTrue(self
.link_exits('test1'))
459 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
461 self
.assertRegex(output
, '192.168.0.15')
462 self
.assertRegex(output
, '192.168.0.1')
463 self
.assertRegex(output
, 'routable')
465 def test_bond_active_slave(self
):
466 self
.copy_unit_to_networkd_unit_path('23-active-slave.network', '23-bond199.network', '25-bond-active-backup-slave.netdev', '12-dummy.netdev')
467 self
.start_networkd()
469 self
.assertTrue(self
.link_exits('dummy98'))
470 self
.assertTrue(self
.link_exits('bond199'))
471 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'bond199']).rstrip().decode('utf-8')
473 self
.assertRegex(output
, 'active_slave dummy98')
475 def test_bond_primary_slave(self
):
476 self
.copy_unit_to_networkd_unit_path('23-primary-slave.network', '23-test1-bond199.network', '25-bond-active-backup-slave.netdev', '11-dummy.netdev')
477 self
.start_networkd()
479 self
.assertTrue(self
.link_exits('test1'))
480 self
.assertTrue(self
.link_exits('bond199'))
481 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'bond199']).rstrip().decode('utf-8')
483 self
.assertRegex(output
, 'primary test1')
485 def test_routing_policy_rule(self
):
486 self
.copy_unit_to_networkd_unit_path('routing-policy-rule.network', '11-dummy.netdev')
487 self
.start_networkd()
489 self
.assertTrue(self
.link_exits('test1'))
490 output
= subprocess
.check_output(['ip', 'rule']).rstrip().decode('utf-8')
492 self
.assertRegex(output
, '111')
493 self
.assertRegex(output
, 'from 192.168.100.18')
494 self
.assertRegex(output
, r
'tos (?:0x08|throughput)\s')
495 self
.assertRegex(output
, 'iif test1')
496 self
.assertRegex(output
, 'oif test1')
497 self
.assertRegex(output
, 'lookup 7')
499 def test_routing_policy_rule_port_range(self
):
500 self
.copy_unit_to_networkd_unit_path('25-fibrule-port-range.network', '11-dummy.netdev')
501 self
.start_networkd()
503 self
.assertTrue(self
.link_exits('test1'))
504 output
= subprocess
.check_output(['ip', 'rule']).rstrip().decode('utf-8')
506 self
.assertRegex(output
, '111')
507 self
.assertRegex(output
, 'from 192.168.100.18')
508 self
.assertRegex(output
, '1123-1150')
509 self
.assertRegex(output
, '3224-3290')
510 self
.assertRegex(output
, 'tcp')
511 self
.assertRegex(output
, 'lookup 7')
513 def test_address_preferred_lifetime_zero_ipv6(self
):
514 self
.copy_unit_to_networkd_unit_path('25-address-section-miscellaneous.network', '12-dummy.netdev')
515 self
.start_networkd()
517 self
.assertTrue(self
.link_exits('dummy98'))
519 output
= subprocess
.check_output(['ip', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
521 self
.assertRegex(output
, 'inet 10.2.3.4/16 brd 10.2.255.255 scope link deprecated dummy98')
522 self
.assertRegex(output
, 'inet6 2001:db8:0:f101::1/64 scope global')
524 def test_ip_route(self
):
525 self
.copy_unit_to_networkd_unit_path('25-route-section.network', '12-dummy.netdev')
526 self
.start_networkd()
528 self
.assertTrue(self
.link_exits('dummy98'))
530 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'dummy98']).rstrip().decode('utf-8')
532 self
.assertRegex(output
, '192.168.0.1')
533 self
.assertRegex(output
, 'static')
534 self
.assertRegex(output
, '192.168.0.0/24')
536 def test_ip_route_reverse(self
):
537 self
.copy_unit_to_networkd_unit_path('25-route-reverse-order.network', '12-dummy.netdev')
538 self
.start_networkd()
540 self
.assertTrue(self
.link_exits('dummy98'))
542 output
= subprocess
.check_output(['ip', '-6', 'route', 'show', 'dev', 'dummy98']).rstrip().decode('utf-8')
544 self
.assertRegex(output
, '2001:1234:5:8fff:ff:ff:ff:ff')
545 self
.assertRegex(output
, '2001:1234:5:8f63::1')
547 def test_ip_route_blackhole_unreachable_prohibit(self
):
548 self
.copy_unit_to_networkd_unit_path('25-route-type.network', '12-dummy.netdev')
549 self
.start_networkd()
551 self
.assertTrue(self
.link_exits('dummy98'))
553 output
= subprocess
.check_output(['ip', 'route', 'list']).rstrip().decode('utf-8')
555 self
.assertRegex(output
, 'blackhole')
556 self
.assertRegex(output
, 'unreachable')
557 self
.assertRegex(output
, 'prohibit')
559 subprocess
.call(['ip', 'route', 'del', 'blackhole', '202.54.1.2'])
560 subprocess
.call(['ip', 'route', 'del', 'unreachable', '202.54.1.3'])
561 subprocess
.call(['ip', 'route', 'del', 'prohibit', '202.54.1.4'])
563 def test_ip_route_tcp_window(self
):
564 self
.copy_unit_to_networkd_unit_path('25-route-tcp-window-settings.network', '11-dummy.netdev')
565 self
.start_networkd()
567 self
.assertTrue(self
.link_exits('test1'))
569 output
= subprocess
.check_output(['ip', 'route', 'list']).rstrip().decode('utf-8')
571 self
.assertRegex(output
, 'initcwnd 20')
572 self
.assertRegex(output
, 'initrwnd 30')
574 def test_ip_route_gateway(self
):
575 self
.copy_unit_to_networkd_unit_path('25-route-gateway.network', '12-dummy.netdev')
576 self
.start_networkd()
578 self
.assertTrue(self
.link_exits('dummy98'))
580 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'dummy98', 'default']).rstrip().decode('utf-8')
582 self
.assertRegex(output
, 'default')
583 self
.assertRegex(output
, 'via')
584 self
.assertRegex(output
, '149.10.124.64')
585 self
.assertRegex(output
, 'proto')
586 self
.assertRegex(output
, 'static')
588 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'dummy98', 'src', '149.10.124.58']).rstrip().decode('utf-8')
590 self
.assertRegex(output
, '149.10.124.48/28')
591 self
.assertRegex(output
, 'proto')
592 self
.assertRegex(output
, 'kernel')
593 self
.assertRegex(output
, 'scope')
594 self
.assertRegex(output
, 'link')
596 def test_ip_route_gateway_on_link(self
):
597 self
.copy_unit_to_networkd_unit_path('25-route-gateway-on-link.network', '12-dummy.netdev')
598 self
.start_networkd()
600 self
.assertTrue(self
.link_exits('dummy98'))
602 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'dummy98', 'default']).rstrip().decode('utf-8')
604 self
.assertRegex(output
, 'default')
605 self
.assertRegex(output
, 'via')
606 self
.assertRegex(output
, '149.10.125.65')
607 self
.assertRegex(output
, 'proto')
608 self
.assertRegex(output
, 'static')
609 self
.assertRegex(output
, 'onlink')
611 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'dummy98', 'src', '149.10.124.58']).rstrip().decode('utf-8')
613 self
.assertRegex(output
, '149.10.124.48/28')
614 self
.assertRegex(output
, 'proto')
615 self
.assertRegex(output
, 'kernel')
616 self
.assertRegex(output
, 'scope')
617 self
.assertRegex(output
, 'link')
619 def test_ip_link_mac_address(self
):
620 self
.copy_unit_to_networkd_unit_path('25-address-link-section.network', '12-dummy.netdev')
621 self
.start_networkd()
623 self
.assertTrue(self
.link_exits('dummy98'))
625 output
= subprocess
.check_output(['ip', 'link', 'show', 'dummy98']).rstrip().decode('utf-8')
627 self
.assertRegex(output
, '00:01:02:aa:bb:cc')
629 def test_ip_link_unmanaged(self
):
630 self
.copy_unit_to_networkd_unit_path('25-link-section-unmanaged.network', '12-dummy.netdev')
631 self
.start_networkd()
633 self
.assertTrue(self
.link_exits('dummy98'))
635 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
637 self
.assertRegex(output
, 'unmanaged')
639 def test_ipv6_address_label(self
):
640 self
.copy_unit_to_networkd_unit_path('25-ipv6-address-label-section.network', '12-dummy.netdev')
641 self
.start_networkd()
643 self
.assertTrue(self
.link_exits('dummy98'))
645 output
= subprocess
.check_output(['ip', 'addrlabel', 'list']).rstrip().decode('utf-8')
647 self
.assertRegex(output
, '2004:da8:1::/64')
649 def test_sysctl(self
):
650 self
.copy_unit_to_networkd_unit_path('25-sysctl.network', '12-dummy.netdev')
651 self
.start_networkd()
653 self
.assertTrue(self
.link_exits('dummy98'))
655 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'forwarding'), '1')
656 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'use_tempaddr'), '2')
657 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'dad_transmits'), '3')
658 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'hop_limit'), '5')
659 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'proxy_ndp'), '1')
660 self
.assertEqual(self
.read_ipv4_sysctl_attr('dummy98', 'forwarding'),'1')
661 self
.assertEqual(self
.read_ipv4_sysctl_attr('dummy98', 'proxy_arp'), '1')
663 class NetworkdNetWorkBrideTests(unittest
.TestCase
, Utilities
):
664 links
= ['dummy98', 'test1', 'bridge99']
666 units
= ['11-dummy.netdev', '12-dummy.netdev', '26-bridge.netdev', '26-bridge-slave-interface-1.network',
667 '26-bridge-slave-interface-2.network', 'bridge99.network']
670 self
.link_remove(self
.links
)
673 self
.link_remove(self
.links
)
674 self
.remove_unit_from_networkd_path(self
.units
)
676 def test_bridge_property(self
):
677 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev', '12-dummy.netdev', '26-bridge.netdev',
678 '26-bridge-slave-interface-1.network', '26-bridge-slave-interface-2.network',
680 self
.start_networkd()
682 self
.assertTrue(self
.link_exits('dummy98'))
683 self
.assertTrue(self
.link_exits('test1'))
684 self
.assertTrue(self
.link_exits('bridge99'))
686 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'test1']).rstrip().decode('utf-8')
688 self
.assertRegex(output
, 'master')
689 self
.assertRegex(output
, 'bridge')
691 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'dummy98']).rstrip().decode('utf-8')
693 self
.assertRegex(output
, 'master')
694 self
.assertRegex(output
, 'bridge')
696 output
= subprocess
.check_output(['ip', 'addr', 'show', 'bridge99']).rstrip().decode('utf-8')
698 self
.assertRegex(output
, '192.168.0.15')
699 self
.assertRegex(output
, '192.168.0.1')
701 output
= subprocess
.check_output(['bridge', '-d', 'link', 'show', 'dummy98']).rstrip().decode('utf-8')
703 self
.assertRegex(output
, 'cost 400')
704 self
.assertRegex(output
, 'hairpin on')
705 self
.assertRegex(output
, 'flood on')
706 self
.assertRegex(output
, 'fastleave on')
708 class NetworkdNetWorkLLDPTests(unittest
.TestCase
, Utilities
):
711 units
= ['23-emit-lldp.network', '24-lldp.network', '25-veth.netdev']
714 self
.link_remove(self
.links
)
717 self
.link_remove(self
.links
)
718 self
.remove_unit_from_networkd_path(self
.units
)
721 self
.copy_unit_to_networkd_unit_path('23-emit-lldp.network', '24-lldp.network', '25-veth.netdev')
722 self
.start_networkd()
724 self
.assertTrue(self
.link_exits('veth99'))
726 output
= subprocess
.check_output(['networkctl', 'lldp']).rstrip().decode('utf-8')
728 self
.assertRegex(output
, 'veth-peer')
729 self
.assertRegex(output
, 'veth99')
731 class NetworkdNetworkRATests(unittest
.TestCase
, Utilities
):
734 units
= ['25-veth.netdev', 'ipv6-prefix.network', 'ipv6-prefix-veth.network']
737 self
.link_remove(self
.links
)
740 self
.link_remove(self
.links
)
741 self
.remove_unit_from_networkd_path(self
.units
)
743 def test_ipv6_prefix_delegation(self
):
744 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'ipv6-prefix.network', 'ipv6-prefix-veth.network')
745 self
.start_networkd()
747 self
.assertTrue(self
.link_exits('veth99'))
749 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
751 self
.assertRegex(output
, '2002:da8:1:0')
753 class NetworkdNetworkDHCPServerTests(unittest
.TestCase
, Utilities
):
754 links
= ['veth99', 'dummy98']
756 units
= ['25-veth.netdev', 'dhcp-client.network', 'dhcp-server.network', '12-dummy.netdev', '24-search-domain.network',
757 'dhcp-client-timezone-router.network', 'dhcp-server-timezone-router.network']
760 self
.link_remove(self
.links
)
763 self
.link_remove(self
.links
)
764 self
.remove_unit_from_networkd_path(self
.units
)
766 def test_dhcp_server(self
):
767 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-client.network', 'dhcp-server.network')
768 self
.start_networkd()
770 self
.assertTrue(self
.link_exits('veth99'))
774 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
776 self
.assertRegex(output
, '192.168.5.*')
777 self
.assertRegex(output
, 'Gateway: 192.168.5.1')
778 self
.assertRegex(output
, 'DNS: 192.168.5.1')
779 self
.assertRegex(output
, 'NTP: 192.168.5.1')
781 def test_domain(self
):
782 self
.copy_unit_to_networkd_unit_path( '12-dummy.netdev', '24-search-domain.network')
783 self
.start_networkd()
785 self
.assertTrue(self
.link_exits('dummy98'))
787 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
789 self
.assertRegex(output
, 'Address: 192.168.42.100')
790 self
.assertRegex(output
, 'DNS: 192.168.42.1')
791 self
.assertRegex(output
, 'Search Domains: one')
793 def test_emit_router_timezone(self
):
794 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-client-timezone-router.network', 'dhcp-server-timezone-router.network')
795 self
.start_networkd()
797 self
.assertTrue(self
.link_exits('veth99'))
799 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
801 self
.assertRegex(output
, 'Gateway: 192.168.5.*')
802 self
.assertRegex(output
, '192.168.5.*')
803 self
.assertRegex(output
, 'Europe/Berlin')
805 class NetworkdNetworkDHCPClientTests(unittest
.TestCase
, Utilities
):
806 links
= ['veth99', 'dummy98']
808 units
= ['25-veth.netdev', 'dhcp-server-veth-peer.network','dhcp-client-ipv6-only.network',
809 'dhcp-client-ipv4-only-ipv6-disabled.network', 'dhcp-client-ipv4-only.network',
810 'dhcp-client-ipv4-dhcp-settings.network', 'dhcp-client-anonymize.network',
811 'dhcp-client-ipv6-rapid-commit.network', 'dhcp-client-route-table.network',
812 'dhcp-v4-server-veth-peer.network', 'dhcp-client-listen-port.network',
813 'dhcp-client-route-metric.network', 'dhcp-client-critical-connection.network']
816 self
.link_remove(self
.links
)
817 self
.stop_dnsmasq(dnsmasq_pid_file
)
820 self
.link_remove(self
.links
)
821 self
.remove_unit_from_networkd_path(self
.units
)
822 self
.stop_dnsmasq(dnsmasq_pid_file
)
823 self
.remove_lease_file()
824 self
.remove_log_file()
826 def test_dhcp_client_ipv6_only(self
):
827 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network','dhcp-client-ipv6-only.network')
828 self
.start_networkd()
830 self
.assertTrue(self
.link_exits('veth99'))
834 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
836 self
.assertRegex(output
, '2600::')
837 self
.assertNotRegex(output
, '192.168.5')
839 def test_dhcp_client_ipv4_only(self
):
840 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network','dhcp-client-ipv4-only-ipv6-disabled.network')
841 self
.start_networkd()
843 self
.assertTrue(self
.link_exits('veth99'))
847 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
849 self
.assertNotRegex(output
, '2600::')
850 self
.assertRegex(output
, '192.168.5')
852 def test_dhcp_client_ipv4_ipv6(self
):
853 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network',
854 'dhcp-client-ipv4-only.network')
855 self
.start_networkd()
857 self
.assertTrue(self
.link_exits('veth99'))
861 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
863 self
.assertRegex(output
, '2600::')
864 self
.assertRegex(output
, '192.168.5')
866 def test_dhcp_client_settings(self
):
867 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv4-dhcp-settings.network')
868 self
.start_networkd()
870 self
.assertTrue(self
.link_exits('veth99'))
874 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
876 self
.assertRegex(output
, '12:34:56:78:9a:bc')
877 self
.assertRegex(output
, '192.168.5')
878 self
.assertRegex(output
, '1492')
880 output
= subprocess
.check_output(['ip', 'route']).rstrip().decode('utf-8')
882 self
.assertRegex(output
, 'default.*dev veth99 proto dhcp')
884 self
.search_words_in_file('vendor class: SusantVendorTest')
885 self
.search_words_in_file('client MAC address: 12:34:56:78:9a:bc')
886 self
.search_words_in_file('client provides name: test-hostname')
887 self
.search_words_in_file('26:mtu')
889 def test_dhcp6_client_settings_rapidcommit_true(self
):
890 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network')
891 self
.start_networkd()
893 self
.assertTrue(self
.link_exits('veth99'))
897 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
899 self
.assertRegex(output
, '12:34:56:78:9a:bc')
901 self
.assertTrue(self
.search_words_in_file('14:rapid-commit'))
903 def test_dhcp6_client_settings_rapidcommit_false(self
):
904 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-rapid-commit.network')
905 self
.start_networkd()
907 self
.assertTrue(self
.link_exits('veth99'))
911 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
913 self
.assertRegex(output
, '12:34:56:78:9a:bc')
915 self
.assertFalse(self
.search_words_in_file('14:rapid-commit'))
917 def test_dhcp_client_settings_anonymize(self
):
918 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-anonymize.network')
919 self
.start_networkd()
921 self
.assertTrue(self
.link_exits('veth99'))
924 self
.assertFalse(self
.search_words_in_file('VendorClassIdentifier=SusantVendorTest'))
925 self
.assertFalse(self
.search_words_in_file('test-hostname'))
926 self
.assertFalse(self
.search_words_in_file('26:mtu'))
928 def test_dhcp_client_listen_port(self
):
929 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-listen-port.network')
930 dh_server
= DHCPServer("dhcp_server")
933 self
.start_networkd()
935 self
.assertTrue(self
.link_exits('veth99'))
940 self
.assertRegex(str(port
), '5555')
941 self
.assertRegex(str(ip
), '0.0.0.0')
945 def test_dhcp_route_table_id(self
):
946 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-route-table.network')
947 self
.start_networkd()
950 self
.assertTrue(self
.link_exits('veth99'))
952 output
= subprocess
.check_output(['ip', 'route', 'show', 'table', '12']).rstrip().decode('utf-8')
955 self
.assertRegex(output
, 'veth99 proto dhcp')
956 self
.assertRegex(output
, '192.168.5.1')
958 def test_dhcp_route_metric(self
):
959 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-route-metric.network')
960 self
.start_networkd()
963 self
.assertTrue(self
.link_exits('veth99'))
965 output
= subprocess
.check_output(['ip', 'route', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
968 self
.assertRegex(output
, 'metric 24')
970 def test_dhcp_route_criticalconnection_true(self
):
971 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-critical-connection.network')
972 self
.start_networkd()
975 self
.assertTrue(self
.link_exits('veth99'))
977 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
980 self
.assertRegex(output
, '192.168.5.*')
981 # Stoping dnsmasq as networkd won't be allowed to renew the DHCP lease.
982 self
.stop_dnsmasq(dnsmasq_pid_file
)
984 # Sleep for 120 sec as the dnsmasq minimum lease time can only be set to 120
987 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
989 self
.assertRegex(output
, '192.168.5.*')
991 if __name__
== '__main__':
992 unittest
.main(testRunner
=unittest
.TextTestRunner(stream
=sys
.stdout
,