2 # SPDX-License-Identifier: LGPL-2.1+
3 # systemd-networkd tests
15 from shutil
import copytree
17 network_unit_file_path
='/run/systemd/network'
18 networkd_runtime_directory
='/run/systemd/netif'
19 networkd_ci_path
='/run/networkd-ci'
20 network_sysctl_ipv6_path
='/proc/sys/net/ipv6/conf'
21 network_sysctl_ipv4_path
='/proc/sys/net/ipv4/conf'
23 dnsmasq_pid_file
='/run/networkd-ci/test-test-dnsmasq.pid'
24 dnsmasq_log_file
='/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
)
47 subprocess
.check_call('systemctl stop systemd-networkd.socket', shell
=True)
50 shutil
.rmtree(networkd_ci_path
)
52 subprocess
.check_call('systemctl stop systemd-networkd.service', shell
=True)
53 subprocess
.check_call('systemctl start systemd-networkd.socket', shell
=True)
54 subprocess
.check_call('systemctl start systemd-networkd.service', shell
=True)
59 def read_link_attr(self
, link
, dev
, attribute
):
60 with
open(os
.path
.join(os
.path
.join(os
.path
.join('/sys/class/net/', link
), dev
), attribute
)) as f
:
61 return f
.readline().strip()
63 def read_bridge_port_attr(self
, bridge
, link
, attribute
):
65 path_bridge
= os
.path
.join('/sys/devices/virtual/net', bridge
)
66 path_port
= 'lower_' + link
+ '/brport'
67 path
= os
.path
.join(path_bridge
, path_port
)
69 with
open(os
.path
.join(path
, attribute
)) as f
:
70 return f
.readline().strip()
72 def link_exits(self
, link
):
73 return os
.path
.exists(os
.path
.join('/sys/class/net', link
))
75 def link_remove(self
, links
):
77 if os
.path
.exists(os
.path
.join('/sys/class/net', link
)):
78 subprocess
.call(['ip', 'link', 'del', 'dev', link
])
81 def read_ipv6_sysctl_attr(self
, link
, attribute
):
82 with
open(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, link
), attribute
)) as f
:
83 return f
.readline().strip()
85 def read_ipv4_sysctl_attr(self
, link
, attribute
):
86 with
open(os
.path
.join(os
.path
.join(network_sysctl_ipv4_path
, link
), attribute
)) as f
:
87 return f
.readline().strip()
89 def copy_unit_to_networkd_unit_path(self
, *units
):
91 shutil
.copy(os
.path
.join(networkd_ci_path
, unit
), network_unit_file_path
)
92 if (os
.path
.exists(os
.path
.join(networkd_ci_path
, unit
+ '.d'))):
93 copytree(os
.path
.join(networkd_ci_path
, unit
+ '.d'), os
.path
.join(network_unit_file_path
, unit
+ '.d'))
95 def remove_unit_from_networkd_path(self
, units
):
97 if (os
.path
.exists(os
.path
.join(network_unit_file_path
, unit
))):
98 os
.remove(os
.path
.join(network_unit_file_path
, unit
))
99 if (os
.path
.exists(os
.path
.join(network_unit_file_path
, unit
+ '.d'))):
100 shutil
.rmtree(os
.path
.join(network_unit_file_path
, unit
+ '.d'))
102 def start_dnsmasq(self
):
103 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 --port=0', shell
=True)
107 def stop_dnsmasq(self
, pid_file
):
108 if os
.path
.exists(pid_file
):
109 with
open(pid_file
, 'r') as f
:
110 pid
= f
.read().rstrip(' \t\r\n\0')
111 os
.kill(int(pid
), signal
.SIGTERM
)
115 def search_words_in_dnsmasq_log(self
, words
, show_all
=False):
116 if os
.path
.exists(dnsmasq_log_file
):
117 with
open (dnsmasq_log_file
) as in_file
:
118 contents
= in_file
.read()
121 for line
in contents
.split('\n'):
124 print("%s, %s" % (words
, line
))
128 def remove_lease_file(self
):
129 if os
.path
.exists(os
.path
.join(networkd_ci_path
, 'lease')):
130 os
.remove(os
.path
.join(networkd_ci_path
, 'lease'))
132 def remove_log_file(self
):
133 if os
.path
.exists(dnsmasq_log_file
):
134 os
.remove(dnsmasq_log_file
)
136 def start_networkd(self
):
137 if (os
.path
.exists(os
.path
.join(networkd_runtime_directory
, 'state'))):
138 subprocess
.check_call('systemctl stop systemd-networkd', shell
=True)
139 os
.remove(os
.path
.join(networkd_runtime_directory
, 'state'))
140 subprocess
.check_call('systemctl start systemd-networkd', shell
=True)
142 subprocess
.check_call('systemctl restart systemd-networkd', shell
=True)
149 class DHCPServer(threading
.Thread
):
150 def __init__(self
, name
):
151 threading
.Thread
.__init
__(self
)
155 self
.start_dhcp_server()
157 def start_dhcp_server(self
):
158 sock
= socket
.socket(socket
.AF_INET
, socket
.SOCK_DGRAM
)
160 server_address
= ('0.0.0.0', 67)
161 sock
.bind(server_address
)
163 print('Starting DHCP Server ...\n')
164 data
, addr
= sock
.recvfrom(1024) # buffer size is 1024 bytes
173 class NetworkdNetDevTests(unittest
.TestCase
, Utilities
):
207 '10-dropin-test.netdev',
214 '25-6rd-tunnel.netdev',
216 '25-bond-balanced-tlb.netdev',
218 '25-erspan-tunnel.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',
227 '25-isatap-tunnel.netdev',
228 '25-sit-tunnel.netdev',
234 '25-vti6-tunnel.netdev',
235 '25-vti-tunnel.netdev',
237 '25-wireguard-23-peers.netdev',
238 '25-wireguard-23-peers.network',
239 '25-wireguard.netdev',
257 self
.link_remove(self
.links
)
260 self
.link_remove(self
.links
)
261 self
.remove_unit_from_networkd_path(self
.units
)
263 def test_dropin(self
):
264 self
.copy_unit_to_networkd_unit_path('10-dropin-test.netdev')
265 self
.start_networkd()
267 self
.assertTrue(self
.link_exits('dropin-test'))
269 output
= subprocess
.check_output(['ip', 'link', 'show', 'dropin-test']).rstrip().decode('utf-8')
271 self
.assertRegex(output
, '00:50:56:c0:00:28')
273 def test_bridge(self
):
274 self
.copy_unit_to_networkd_unit_path('25-bridge.netdev')
275 self
.start_networkd()
277 self
.assertTrue(self
.link_exits('bridge99'))
279 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge', 'hello_time'))
280 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge', 'max_age'))
281 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge','forward_delay'))
282 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge','ageing_time'))
283 self
.assertEqual('9', self
.read_link_attr('bridge99', 'bridge','priority'))
284 self
.assertEqual('1', self
.read_link_attr('bridge99', 'bridge','multicast_querier'))
285 self
.assertEqual('1', self
.read_link_attr('bridge99', 'bridge','multicast_snooping'))
286 self
.assertEqual('1', self
.read_link_attr('bridge99', 'bridge','stp_state'))
289 self
.copy_unit_to_networkd_unit_path('25-bond.netdev')
290 self
.start_networkd()
292 self
.assertTrue(self
.link_exits('bond99'))
294 self
.assertEqual('802.3ad 4', self
.read_link_attr('bond99', 'bonding', 'mode'))
295 self
.assertEqual('layer3+4 1', self
.read_link_attr('bond99', 'bonding', 'xmit_hash_policy'))
296 self
.assertEqual('1000', self
.read_link_attr('bond99', 'bonding', 'miimon'))
297 self
.assertEqual('fast 1', self
.read_link_attr('bond99', 'bonding', 'lacp_rate'))
298 self
.assertEqual('2000', self
.read_link_attr('bond99', 'bonding', 'updelay'))
299 self
.assertEqual('2000', self
.read_link_attr('bond99', 'bonding', 'downdelay'))
300 self
.assertEqual('4', self
.read_link_attr('bond99', 'bonding', 'resend_igmp'))
301 self
.assertEqual('1', self
.read_link_attr('bond99', 'bonding', 'min_links'))
302 self
.assertEqual('1218', self
.read_link_attr('bond99', 'bonding', 'ad_actor_sys_prio'))
303 self
.assertEqual('811', self
.read_link_attr('bond99', 'bonding', 'ad_user_port_key'))
304 self
.assertEqual('00:11:22:33:44:55', self
.read_link_attr('bond99', 'bonding', 'ad_actor_system'))
306 def test_bond_balanced_tlb(self
):
307 self
.copy_unit_to_networkd_unit_path('25-bond-balanced-tlb.netdev')
308 self
.start_networkd()
310 self
.assertTrue(self
.link_exits('bond99'))
312 self
.assertEqual('balance-tlb 5', self
.read_link_attr('bond99', 'bonding', 'mode'))
313 self
.assertEqual('1', self
.read_link_attr('bond99', 'bonding', 'tlb_dynamic_lb'))
316 self
.copy_unit_to_networkd_unit_path('21-vlan.netdev', '11-dummy.netdev', '21-vlan.network')
317 self
.start_networkd()
319 self
.assertTrue(self
.link_exits('vlan99'))
321 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vlan99']).rstrip().decode('utf-8')
323 self
.assertTrue(output
, 'REORDER_HDR')
324 self
.assertTrue(output
, 'LOOSE_BINDING')
325 self
.assertTrue(output
, 'GVRP')
326 self
.assertTrue(output
, 'MVRP')
327 self
.assertTrue(output
, '99')
329 def test_macvtap(self
):
330 self
.copy_unit_to_networkd_unit_path('21-macvtap.netdev', '11-dummy.netdev', 'macvtap.network')
331 self
.start_networkd()
333 self
.assertTrue(self
.link_exits('macvtap99'))
335 def test_macvlan(self
):
336 self
.copy_unit_to_networkd_unit_path('21-macvlan.netdev', '11-dummy.netdev', 'macvlan.network')
337 self
.start_networkd()
339 self
.assertTrue(self
.link_exits('macvlan99'))
341 @expectedFailureIfModuleIsNotAvailable('ipvlan')
342 def test_ipvlan(self
):
343 self
.copy_unit_to_networkd_unit_path('25-ipvlan.netdev', '11-dummy.netdev', 'ipvlan.network')
344 self
.start_networkd()
346 self
.assertTrue(self
.link_exits('ipvlan99'))
349 self
.copy_unit_to_networkd_unit_path('25-veth.netdev')
350 self
.start_networkd()
352 self
.assertTrue(self
.link_exits('veth99'))
354 def test_dummy(self
):
355 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev')
356 self
.start_networkd()
358 self
.assertTrue(self
.link_exits('test1'))
361 self
.copy_unit_to_networkd_unit_path('25-tun.netdev')
362 self
.start_networkd()
364 self
.assertTrue(self
.link_exits('tun99'))
367 self
.copy_unit_to_networkd_unit_path('25-tap.netdev')
368 self
.start_networkd()
370 self
.assertTrue(self
.link_exits('tap99'))
372 @expectedFailureIfModuleIsNotAvailable('vrf')
374 self
.copy_unit_to_networkd_unit_path('25-vrf.netdev')
375 self
.start_networkd()
377 self
.assertTrue(self
.link_exits('vrf99'))
379 @expectedFailureIfModuleIsNotAvailable('vcan')
381 self
.copy_unit_to_networkd_unit_path('25-vcan.netdev')
382 self
.start_networkd()
384 self
.assertTrue(self
.link_exits('vcan99'))
386 @expectedFailureIfModuleIsNotAvailable('wireguard')
387 def test_wireguard(self
):
388 self
.copy_unit_to_networkd_unit_path('25-wireguard.netdev')
389 self
.start_networkd()
391 if shutil
.which('wg'):
392 subprocess
.call('wg')
394 self
.assertTrue(self
.link_exits('wg99'))
396 @expectedFailureIfModuleIsNotAvailable('wireguard')
397 def test_wireguard_23_peers(self
):
398 self
.copy_unit_to_networkd_unit_path('25-wireguard-23-peers.netdev', '25-wireguard-23-peers.network')
399 self
.start_networkd()
401 if shutil
.which('wg'):
402 subprocess
.call('wg')
404 self
.assertTrue(self
.link_exits('wg98'))
406 def test_geneve(self
):
407 self
.copy_unit_to_networkd_unit_path('25-geneve.netdev')
408 self
.start_networkd()
410 self
.assertTrue(self
.link_exits('geneve99'))
412 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'geneve99']).rstrip().decode('utf-8')
414 self
.assertTrue(output
, '192.168.22.1')
415 self
.assertTrue(output
, '6082')
416 self
.assertTrue(output
, 'udpcsum')
417 self
.assertTrue(output
, 'udp6zerocsumrx')
419 def test_ipip_tunnel(self
):
420 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-ipip-tunnel.netdev', 'ipip.network')
421 self
.start_networkd()
423 self
.assertTrue(self
.link_exits('dummy98'))
424 self
.assertTrue(self
.link_exits('ipiptun99'))
426 def test_gre_tunnel(self
):
427 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-gre-tunnel.netdev', 'gretun.network')
428 self
.start_networkd()
430 self
.assertTrue(self
.link_exits('dummy98'))
431 self
.assertTrue(self
.link_exits('gretun99'))
433 def test_gretap_tunnel(self
):
434 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-gretap-tunnel.netdev', 'gretap.network')
435 self
.start_networkd()
437 self
.assertTrue(self
.link_exits('dummy98'))
438 self
.assertTrue(self
.link_exits('gretap99'))
440 def test_ip6gretap_tunnel(self
):
441 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-ip6gre-tunnel.netdev', 'ip6gretap.network')
442 self
.start_networkd()
444 self
.assertTrue(self
.link_exits('dummy98'))
445 self
.assertTrue(self
.link_exits('ip6gretap99'))
447 def test_vti_tunnel(self
):
448 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-vti-tunnel.netdev', 'vti.network')
449 self
.start_networkd()
451 self
.assertTrue(self
.link_exits('dummy98'))
452 self
.assertTrue(self
.link_exits('vtitun99'))
454 def test_vti6_tunnel(self
):
455 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-vti6-tunnel.netdev', 'vti6.network')
456 self
.start_networkd()
458 self
.assertTrue(self
.link_exits('dummy98'))
459 self
.assertTrue(self
.link_exits('vti6tun99'))
461 def test_ip6tnl_tunnel(self
):
462 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-ip6tnl-tunnel.netdev', 'ip6tnl.network')
463 self
.start_networkd()
465 self
.assertTrue(self
.link_exits('dummy98'))
466 self
.assertTrue(self
.link_exits('ip6tnl99'))
468 def test_sit_tunnel(self
):
469 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-sit-tunnel.netdev', 'sit.network')
470 self
.start_networkd()
472 self
.assertTrue(self
.link_exits('dummy98'))
473 self
.assertTrue(self
.link_exits('sittun99'))
475 def test_isatap_tunnel(self
):
476 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-isatap-tunnel.netdev', 'isatap.network')
477 self
.start_networkd()
479 self
.assertTrue(self
.link_exits('dummy98'))
480 self
.assertTrue(self
.link_exits('isataptun99'))
482 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'isataptun99']).rstrip().decode('utf-8')
484 self
.assertRegex(output
, "isatap ")
486 def test_6rd_tunnel(self
):
487 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-6rd-tunnel.netdev', '6rd.network')
488 self
.start_networkd()
490 self
.assertTrue(self
.link_exits('dummy98'))
491 self
.assertTrue(self
.link_exits('sittun99'))
493 def test_erspan_tunnel(self
):
494 self
.copy_unit_to_networkd_unit_path('25-erspan-tunnel.netdev')
495 self
.start_networkd()
497 self
.assertTrue(self
.link_exits('erspan-test'))
499 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'erspan-test']).rstrip().decode('utf-8')
501 self
.assertTrue(output
, '172.16.1.200')
502 self
.assertTrue(output
, '172.16.1.100')
503 self
.assertTrue(output
, '101')
505 def test_tunnel_independent(self
):
506 self
.copy_unit_to_networkd_unit_path('25-ipip-tunnel-independent.netdev')
507 self
.start_networkd()
509 self
.assertTrue(self
.link_exits('ipiptun99'))
511 def test_vxlan(self
):
512 self
.copy_unit_to_networkd_unit_path('25-vxlan.netdev', 'vxlan.network','11-dummy.netdev')
513 self
.start_networkd()
515 self
.assertTrue(self
.link_exits('vxlan99'))
517 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vxlan99']).rstrip().decode('utf-8')
519 self
.assertRegex(output
, "999")
520 self
.assertRegex(output
, '5555')
521 self
.assertRegex(output
, 'l2miss')
522 self
.assertRegex(output
, 'l3miss')
523 self
.assertRegex(output
, 'udpcsum')
524 self
.assertRegex(output
, 'udp6zerocsumtx')
525 self
.assertRegex(output
, 'udp6zerocsumrx')
526 self
.assertRegex(output
, 'remcsumtx')
527 self
.assertRegex(output
, 'remcsumrx')
528 self
.assertRegex(output
, 'gbp')
530 class NetworkdNetWorkTests(unittest
.TestCase
, Utilities
):
539 '23-active-slave.network',
540 '23-bond199.network',
541 '23-primary-slave.network',
542 '23-test1-bond199.network',
543 '25-address-link-section.network',
544 '25-address-section-miscellaneous.network',
545 '25-address-section.network',
546 '25-bond-active-backup-slave.netdev',
547 '25-fibrule-invert.network',
548 '25-fibrule-port-range.network',
549 '25-ipv6-address-label-section.network',
550 '25-neighbor-section.network',
551 '25-link-section-unmanaged.network',
552 '25-route-gateway.network',
553 '25-route-gateway-on-link.network',
554 '25-route-reverse-order.network',
555 '25-route-section.network',
556 '25-route-tcp-window-settings.network',
557 '25-route-type.network',
559 'configure-without-carrier.network',
560 'routing-policy-rule.network',
561 'test-static.network']
564 self
.link_remove(self
.links
)
567 self
.link_remove(self
.links
)
568 self
.remove_unit_from_networkd_path(self
.units
)
570 def test_static_address(self
):
571 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'test-static.network')
572 self
.start_networkd()
574 self
.assertTrue(self
.link_exits('dummy98'))
576 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
578 self
.assertRegex(output
, '192.168.0.15')
579 self
.assertRegex(output
, '192.168.0.1')
580 self
.assertRegex(output
, 'routable')
582 def test_configure_without_carrier(self
):
583 self
.copy_unit_to_networkd_unit_path('configure-without-carrier.network', '11-dummy.netdev')
584 self
.start_networkd()
586 self
.assertTrue(self
.link_exits('test1'))
588 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
590 self
.assertRegex(output
, '192.168.0.15')
591 self
.assertRegex(output
, '192.168.0.1')
592 self
.assertRegex(output
, 'routable')
594 def test_bond_active_slave(self
):
595 self
.copy_unit_to_networkd_unit_path('23-active-slave.network', '23-bond199.network', '25-bond-active-backup-slave.netdev', '12-dummy.netdev')
596 self
.start_networkd()
598 self
.assertTrue(self
.link_exits('dummy98'))
599 self
.assertTrue(self
.link_exits('bond199'))
601 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'bond199']).rstrip().decode('utf-8')
603 self
.assertRegex(output
, 'active_slave dummy98')
605 def test_bond_primary_slave(self
):
606 self
.copy_unit_to_networkd_unit_path('23-primary-slave.network', '23-test1-bond199.network', '25-bond-active-backup-slave.netdev', '11-dummy.netdev')
607 self
.start_networkd()
609 self
.assertTrue(self
.link_exits('test1'))
610 self
.assertTrue(self
.link_exits('bond199'))
612 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'bond199']).rstrip().decode('utf-8')
614 self
.assertRegex(output
, 'primary test1')
616 def test_routing_policy_rule(self
):
617 self
.copy_unit_to_networkd_unit_path('routing-policy-rule.network', '11-dummy.netdev')
618 self
.start_networkd()
620 self
.assertTrue(self
.link_exits('test1'))
622 output
= subprocess
.check_output(['ip', 'rule']).rstrip().decode('utf-8')
624 self
.assertRegex(output
, '111')
625 self
.assertRegex(output
, 'from 192.168.100.18')
626 self
.assertRegex(output
, r
'tos (?:0x08|throughput)\s')
627 self
.assertRegex(output
, 'iif test1')
628 self
.assertRegex(output
, 'oif test1')
629 self
.assertRegex(output
, 'lookup 7')
631 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
633 def test_routing_policy_rule_port_range(self
):
634 self
.copy_unit_to_networkd_unit_path('25-fibrule-port-range.network', '11-dummy.netdev')
635 self
.start_networkd()
637 self
.assertTrue(self
.link_exits('test1'))
639 output
= subprocess
.check_output(['ip', 'rule']).rstrip().decode('utf-8')
641 self
.assertRegex(output
, '111')
642 self
.assertRegex(output
, 'from 192.168.100.18')
643 self
.assertRegex(output
, '1123-1150')
644 self
.assertRegex(output
, '3224-3290')
645 self
.assertRegex(output
, 'tcp')
646 self
.assertRegex(output
, 'lookup 7')
648 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
650 def test_routing_policy_rule_invert(self
):
651 self
.copy_unit_to_networkd_unit_path('25-fibrule-invert.network', '11-dummy.netdev')
652 self
.start_networkd()
654 self
.assertTrue(self
.link_exits('test1'))
656 output
= subprocess
.check_output(['ip', 'rule']).rstrip().decode('utf-8')
658 self
.assertRegex(output
, '111')
659 self
.assertRegex(output
, 'not.*?from.*?192.168.100.18')
660 self
.assertRegex(output
, 'tcp')
661 self
.assertRegex(output
, 'lookup 7')
663 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
665 def test_address_peer(self
):
666 self
.copy_unit_to_networkd_unit_path('25-address-section.network', '12-dummy.netdev')
667 self
.start_networkd()
669 self
.assertTrue(self
.link_exits('dummy98'))
671 output
= subprocess
.check_output(['ip', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
673 self
.assertRegex(output
, 'inet 10.2.3.4 peer 10.2.3.5/16 scope global 32')
674 self
.assertRegex(output
, 'inet 10.6.7.8/16 brd 10.6.255.255 scope global 33')
675 self
.assertRegex(output
, 'inet6 2001:db8::20 peer 2001:db8::10/128 scope global')
677 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
679 self
.assertRegex(output
, 'State: routable \(configured\)')
681 def test_address_preferred_lifetime_zero_ipv6(self
):
682 self
.copy_unit_to_networkd_unit_path('25-address-section-miscellaneous.network', '12-dummy.netdev')
683 self
.start_networkd()
685 self
.assertTrue(self
.link_exits('dummy98'))
687 output
= subprocess
.check_output(['ip', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
689 self
.assertRegex(output
, 'inet 10.2.3.4/16 brd 10.2.255.255 scope link deprecated dummy98')
690 self
.assertRegex(output
, 'inet6 2001:db8:0:f101::1/64 scope global')
692 def test_ip_route(self
):
693 self
.copy_unit_to_networkd_unit_path('25-route-section.network', '12-dummy.netdev')
694 self
.start_networkd()
696 self
.assertTrue(self
.link_exits('dummy98'))
698 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'dummy98']).rstrip().decode('utf-8')
700 self
.assertRegex(output
, '192.168.0.1')
701 self
.assertRegex(output
, 'static')
702 self
.assertRegex(output
, '192.168.0.0/24')
704 def test_ip_route_reverse(self
):
705 self
.copy_unit_to_networkd_unit_path('25-route-reverse-order.network', '12-dummy.netdev')
706 self
.start_networkd()
708 self
.assertTrue(self
.link_exits('dummy98'))
710 output
= subprocess
.check_output(['ip', '-6', 'route', 'show', 'dev', 'dummy98']).rstrip().decode('utf-8')
712 self
.assertRegex(output
, '2001:1234:5:8fff:ff:ff:ff:ff')
713 self
.assertRegex(output
, '2001:1234:5:8f63::1')
715 def test_ip_route_blackhole_unreachable_prohibit(self
):
716 self
.copy_unit_to_networkd_unit_path('25-route-type.network', '12-dummy.netdev')
717 self
.start_networkd()
719 self
.assertTrue(self
.link_exits('dummy98'))
721 output
= subprocess
.check_output(['ip', 'route', 'list']).rstrip().decode('utf-8')
723 self
.assertRegex(output
, 'blackhole')
724 self
.assertRegex(output
, 'unreachable')
725 self
.assertRegex(output
, 'prohibit')
727 subprocess
.call(['ip', 'route', 'del', 'blackhole', '202.54.1.2'])
728 subprocess
.call(['ip', 'route', 'del', 'unreachable', '202.54.1.3'])
729 subprocess
.call(['ip', 'route', 'del', 'prohibit', '202.54.1.4'])
731 def test_ip_route_tcp_window(self
):
732 self
.copy_unit_to_networkd_unit_path('25-route-tcp-window-settings.network', '11-dummy.netdev')
733 self
.start_networkd()
735 self
.assertTrue(self
.link_exits('test1'))
737 output
= subprocess
.check_output(['ip', 'route', 'list']).rstrip().decode('utf-8')
739 self
.assertRegex(output
, 'initcwnd 20')
740 self
.assertRegex(output
, 'initrwnd 30')
742 def test_ip_route_gateway(self
):
743 self
.copy_unit_to_networkd_unit_path('25-route-gateway.network', '12-dummy.netdev')
744 self
.start_networkd()
746 self
.assertTrue(self
.link_exits('dummy98'))
748 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'dummy98', 'default']).rstrip().decode('utf-8')
750 self
.assertRegex(output
, 'default')
751 self
.assertRegex(output
, 'via')
752 self
.assertRegex(output
, '149.10.124.64')
753 self
.assertRegex(output
, 'proto')
754 self
.assertRegex(output
, 'static')
756 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'dummy98', 'src', '149.10.124.58']).rstrip().decode('utf-8')
758 self
.assertRegex(output
, '149.10.124.48/28')
759 self
.assertRegex(output
, 'proto')
760 self
.assertRegex(output
, 'kernel')
761 self
.assertRegex(output
, 'scope')
762 self
.assertRegex(output
, 'link')
764 def test_ip_route_gateway_on_link(self
):
765 self
.copy_unit_to_networkd_unit_path('25-route-gateway-on-link.network', '12-dummy.netdev')
766 self
.start_networkd()
768 self
.assertTrue(self
.link_exits('dummy98'))
770 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'dummy98', 'default']).rstrip().decode('utf-8')
772 self
.assertRegex(output
, 'default')
773 self
.assertRegex(output
, 'via')
774 self
.assertRegex(output
, '149.10.125.65')
775 self
.assertRegex(output
, 'proto')
776 self
.assertRegex(output
, 'static')
777 self
.assertRegex(output
, 'onlink')
779 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'dummy98', 'src', '149.10.124.58']).rstrip().decode('utf-8')
781 self
.assertRegex(output
, '149.10.124.48/28')
782 self
.assertRegex(output
, 'proto')
783 self
.assertRegex(output
, 'kernel')
784 self
.assertRegex(output
, 'scope')
785 self
.assertRegex(output
, 'link')
787 def test_ip_link_mac_address(self
):
788 self
.copy_unit_to_networkd_unit_path('25-address-link-section.network', '12-dummy.netdev')
789 self
.start_networkd()
791 self
.assertTrue(self
.link_exits('dummy98'))
793 output
= subprocess
.check_output(['ip', 'link', 'show', 'dummy98']).rstrip().decode('utf-8')
795 self
.assertRegex(output
, '00:01:02:aa:bb:cc')
797 def test_ip_link_unmanaged(self
):
798 self
.copy_unit_to_networkd_unit_path('25-link-section-unmanaged.network', '12-dummy.netdev')
799 self
.start_networkd()
801 self
.assertTrue(self
.link_exits('dummy98'))
803 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
805 self
.assertRegex(output
, 'unmanaged')
807 def test_ipv6_address_label(self
):
808 self
.copy_unit_to_networkd_unit_path('25-ipv6-address-label-section.network', '12-dummy.netdev')
809 self
.start_networkd()
811 self
.assertTrue(self
.link_exits('dummy98'))
813 output
= subprocess
.check_output(['ip', 'addrlabel', 'list']).rstrip().decode('utf-8')
815 self
.assertRegex(output
, '2004:da8:1::/64')
817 def test_ipv6_neighbor(self
):
818 self
.copy_unit_to_networkd_unit_path('25-neighbor-section.network', '12-dummy.netdev')
819 self
.start_networkd()
821 self
.assertTrue(self
.link_exits('dummy98'))
823 output
= subprocess
.check_output(['ip', 'neigh', 'list']).rstrip().decode('utf-8')
825 self
.assertRegex(output
, '192.168.10.1.*00:00:5e:00:02:65.*PERMANENT')
826 self
.assertRegex(output
, '2004:da8:1::1.*00:00:5e:00:02:66.*PERMANENT')
828 def test_sysctl(self
):
829 self
.copy_unit_to_networkd_unit_path('25-sysctl.network', '12-dummy.netdev')
830 self
.start_networkd()
832 self
.assertTrue(self
.link_exits('dummy98'))
834 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'forwarding'), '1')
835 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'use_tempaddr'), '2')
836 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'dad_transmits'), '3')
837 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'hop_limit'), '5')
838 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'proxy_ndp'), '1')
839 self
.assertEqual(self
.read_ipv4_sysctl_attr('dummy98', 'forwarding'),'1')
840 self
.assertEqual(self
.read_ipv4_sysctl_attr('dummy98', 'proxy_arp'), '1')
842 class NetworkdNetWorkBridgeTests(unittest
.TestCase
, Utilities
):
852 '26-bridge-slave-interface-1.network',
853 '26-bridge-slave-interface-2.network',
857 self
.link_remove(self
.links
)
860 self
.link_remove(self
.links
)
861 self
.remove_unit_from_networkd_path(self
.units
)
863 def test_bridge_property(self
):
864 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev', '12-dummy.netdev', '26-bridge.netdev',
865 '26-bridge-slave-interface-1.network', '26-bridge-slave-interface-2.network',
867 self
.start_networkd()
869 self
.assertTrue(self
.link_exits('dummy98'))
870 self
.assertTrue(self
.link_exits('test1'))
871 self
.assertTrue(self
.link_exits('bridge99'))
873 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'test1']).rstrip().decode('utf-8')
875 self
.assertRegex(output
, 'master')
876 self
.assertRegex(output
, 'bridge')
878 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'dummy98']).rstrip().decode('utf-8')
880 self
.assertRegex(output
, 'master')
881 self
.assertRegex(output
, 'bridge')
883 output
= subprocess
.check_output(['ip', 'addr', 'show', 'bridge99']).rstrip().decode('utf-8')
885 self
.assertRegex(output
, '192.168.0.15')
886 self
.assertRegex(output
, '192.168.0.1')
888 output
= subprocess
.check_output(['bridge', '-d', 'link', 'show', 'dummy98']).rstrip().decode('utf-8')
890 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'hairpin_mode'), '1')
891 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'path_cost'), '400')
892 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'unicast_flood'), '1')
893 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'multicast_fast_leave'), '1')
895 # CONFIG_BRIDGE_IGMP_SNOOPING=y
896 if (os
.path
.exists('/sys/devices/virtual/net/bridge00/lower_dummy98/brport/multicast_to_unicast')):
897 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'multicast_to_unicast'), '1')
899 class NetworkdNetWorkLLDPTests(unittest
.TestCase
, Utilities
):
903 '23-emit-lldp.network',
908 self
.link_remove(self
.links
)
911 self
.link_remove(self
.links
)
912 self
.remove_unit_from_networkd_path(self
.units
)
915 self
.copy_unit_to_networkd_unit_path('23-emit-lldp.network', '24-lldp.network', '25-veth.netdev')
916 self
.start_networkd()
918 self
.assertTrue(self
.link_exits('veth99'))
920 output
= subprocess
.check_output(['networkctl', 'lldp']).rstrip().decode('utf-8')
922 self
.assertRegex(output
, 'veth-peer')
923 self
.assertRegex(output
, 'veth99')
925 class NetworkdNetworkRATests(unittest
.TestCase
, Utilities
):
930 'ipv6-prefix.network',
931 'ipv6-prefix-veth.network']
934 self
.link_remove(self
.links
)
937 self
.link_remove(self
.links
)
938 self
.remove_unit_from_networkd_path(self
.units
)
940 def test_ipv6_prefix_delegation(self
):
941 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'ipv6-prefix.network', 'ipv6-prefix-veth.network')
942 self
.start_networkd()
944 self
.assertTrue(self
.link_exits('veth99'))
946 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
948 self
.assertRegex(output
, '2002:da8:1:0')
950 class NetworkdNetworkDHCPServerTests(unittest
.TestCase
, Utilities
):
957 '24-search-domain.network',
959 'dhcp-client.network',
960 'dhcp-client-timezone-router.network',
961 'dhcp-server.network',
962 'dhcp-server-timezone-router.network']
965 self
.link_remove(self
.links
)
968 self
.link_remove(self
.links
)
969 self
.remove_unit_from_networkd_path(self
.units
)
971 def test_dhcp_server(self
):
972 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-client.network', 'dhcp-server.network')
973 self
.start_networkd()
975 self
.assertTrue(self
.link_exits('veth99'))
977 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
979 self
.assertRegex(output
, '192.168.5.*')
980 self
.assertRegex(output
, 'Gateway: 192.168.5.1')
981 self
.assertRegex(output
, 'DNS: 192.168.5.1')
982 self
.assertRegex(output
, 'NTP: 192.168.5.1')
984 def test_domain(self
):
985 self
.copy_unit_to_networkd_unit_path( '12-dummy.netdev', '24-search-domain.network')
986 self
.start_networkd()
988 self
.assertTrue(self
.link_exits('dummy98'))
990 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
992 self
.assertRegex(output
, 'Address: 192.168.42.100')
993 self
.assertRegex(output
, 'DNS: 192.168.42.1')
994 self
.assertRegex(output
, 'Search Domains: one')
996 def test_emit_router_timezone(self
):
997 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-client-timezone-router.network', 'dhcp-server-timezone-router.network')
998 self
.start_networkd()
1000 self
.assertTrue(self
.link_exits('veth99'))
1002 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1004 self
.assertRegex(output
, 'Gateway: 192.168.5.*')
1005 self
.assertRegex(output
, '192.168.5.*')
1006 self
.assertRegex(output
, 'Europe/Berlin')
1008 class NetworkdNetworkDHCPClientTests(unittest
.TestCase
, Utilities
):
1015 'dhcp-client-anonymize.network',
1016 'dhcp-client-critical-connection.network',
1017 'dhcp-client-ipv4-dhcp-settings.network',
1018 'dhcp-client-ipv4-only-ipv6-disabled.network',
1019 'dhcp-client-ipv4-only.network',
1020 'dhcp-client-ipv6-only.network',
1021 'dhcp-client-ipv6-rapid-commit.network',
1022 'dhcp-client-listen-port.network',
1023 'dhcp-client-route-metric.network',
1024 'dhcp-client-route-table.network',
1025 'dhcp-client.network'
1026 'dhcp-server-veth-peer.network',
1027 'dhcp-v4-server-veth-peer.network',
1031 self
.link_remove(self
.links
)
1032 self
.stop_dnsmasq(dnsmasq_pid_file
)
1035 self
.link_remove(self
.links
)
1036 self
.remove_unit_from_networkd_path(self
.units
)
1037 self
.stop_dnsmasq(dnsmasq_pid_file
)
1038 self
.remove_lease_file()
1039 self
.remove_log_file()
1041 def test_dhcp_client_ipv6_only(self
):
1042 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network','dhcp-client-ipv6-only.network')
1043 self
.start_networkd()
1045 self
.assertTrue(self
.link_exits('veth99'))
1047 self
.start_dnsmasq()
1049 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1051 self
.assertRegex(output
, '2600::')
1052 self
.assertNotRegex(output
, '192.168.5')
1054 def test_dhcp_client_ipv4_only(self
):
1055 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network','dhcp-client-ipv4-only-ipv6-disabled.network')
1056 self
.start_networkd()
1058 self
.assertTrue(self
.link_exits('veth99'))
1060 self
.start_dnsmasq()
1062 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1064 self
.assertNotRegex(output
, '2600::')
1065 self
.assertRegex(output
, '192.168.5')
1067 def test_dhcp_client_ipv4_ipv6(self
):
1068 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network',
1069 'dhcp-client-ipv4-only.network')
1070 self
.start_networkd()
1072 self
.assertTrue(self
.link_exits('veth99'))
1074 self
.start_dnsmasq()
1076 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1078 self
.assertRegex(output
, '2600::')
1079 self
.assertRegex(output
, '192.168.5')
1081 def test_dhcp_client_settings(self
):
1082 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv4-dhcp-settings.network')
1083 self
.start_networkd()
1085 self
.assertTrue(self
.link_exits('veth99'))
1087 self
.start_dnsmasq()
1089 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
1091 self
.assertRegex(output
, '12:34:56:78:9a:bc')
1092 self
.assertRegex(output
, '192.168.5')
1093 self
.assertRegex(output
, '1492')
1095 output
= subprocess
.check_output(['ip', 'route']).rstrip().decode('utf-8')
1097 self
.assertRegex(output
, 'default.*dev veth99 proto dhcp')
1099 self
.assertTrue(self
.search_words_in_dnsmasq_log('vendor class: SusantVendorTest', True))
1100 self
.assertTrue(self
.search_words_in_dnsmasq_log('DHCPDISCOVER(veth-peer) 12:34:56:78:9a:bc'))
1101 self
.assertTrue(self
.search_words_in_dnsmasq_log('client provides name: test-hostname'))
1102 self
.assertTrue(self
.search_words_in_dnsmasq_log('26:mtu'))
1104 def test_dhcp6_client_settings_rapidcommit_true(self
):
1105 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network')
1106 self
.start_networkd()
1108 self
.assertTrue(self
.link_exits('veth99'))
1110 self
.start_dnsmasq()
1112 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
1114 self
.assertRegex(output
, '12:34:56:78:9a:bc')
1115 self
.assertTrue(self
.search_words_in_dnsmasq_log('14:rapid-commit', True))
1117 def test_dhcp6_client_settings_rapidcommit_false(self
):
1118 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-rapid-commit.network')
1119 self
.start_networkd()
1121 self
.assertTrue(self
.link_exits('veth99'))
1123 self
.start_dnsmasq()
1125 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
1127 self
.assertRegex(output
, '12:34:56:78:9a:bc')
1128 self
.assertFalse(self
.search_words_in_dnsmasq_log('14:rapid-commit', True))
1130 def test_dhcp_client_settings_anonymize(self
):
1131 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-anonymize.network')
1132 self
.start_networkd()
1134 self
.assertTrue(self
.link_exits('veth99'))
1136 self
.start_dnsmasq()
1138 self
.assertFalse(self
.search_words_in_dnsmasq_log('VendorClassIdentifier=SusantVendorTest', True))
1139 self
.assertFalse(self
.search_words_in_dnsmasq_log('test-hostname'))
1140 self
.assertFalse(self
.search_words_in_dnsmasq_log('26:mtu'))
1142 def test_dhcp_client_listen_port(self
):
1143 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-listen-port.network')
1145 dh_server
= DHCPServer("dhcp_server")
1148 self
.start_networkd()
1150 self
.assertTrue(self
.link_exits('veth99'))
1155 self
.assertRegex(str(port
), '5555')
1156 self
.assertRegex(str(ip
), '0.0.0.0')
1160 def test_dhcp_route_table_id(self
):
1161 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-route-table.network')
1162 self
.start_networkd()
1164 self
.assertTrue(self
.link_exits('veth99'))
1166 self
.start_dnsmasq()
1168 output
= subprocess
.check_output(['ip', 'route', 'show', 'table', '12']).rstrip().decode('utf-8')
1170 self
.assertRegex(output
, 'veth99 proto dhcp')
1171 self
.assertRegex(output
, '192.168.5.1')
1173 def test_dhcp_route_metric(self
):
1174 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-route-metric.network')
1175 self
.start_networkd()
1177 self
.assertTrue(self
.link_exits('veth99'))
1179 self
.start_dnsmasq()
1181 output
= subprocess
.check_output(['ip', 'route', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
1183 self
.assertRegex(output
, 'metric 24')
1185 def test_dhcp_route_criticalconnection_true(self
):
1186 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-critical-connection.network')
1187 self
.start_networkd()
1189 self
.assertTrue(self
.link_exits('veth99'))
1191 self
.start_dnsmasq()
1193 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1195 self
.assertRegex(output
, '192.168.5.*')
1197 # Stoping dnsmasq as networkd won't be allowed to renew the DHCP lease.
1198 self
.stop_dnsmasq(dnsmasq_pid_file
)
1200 # Sleep for 120 sec as the dnsmasq minimum lease time can only be set to 120
1203 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1205 self
.assertRegex(output
, '192.168.5.*')
1207 def test_dhcp_client_reuse_address_as_static(self
):
1208 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client.network')
1209 self
.start_networkd()
1211 self
.assertTrue(self
.link_exits('veth99'))
1213 self
.start_dnsmasq()
1215 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99', 'scope', 'global']).rstrip().decode('utf-8')
1217 self
.assertRegex(output
, '192.168.5')
1218 self
.assertRegex(output
, '2600::')
1220 ipv4_address
= re
.search('192\.168\.5\.[0-9]*/24', output
)
1221 ipv6_address
= re
.search('2600::[0-9a-f:]*/128', output
)
1222 static_network
= '\n'.join(['[Match]', 'Name=veth99', '[Network]', 'IPv6AcceptRA=no', 'Address=' + ipv4_address
.group(), 'Address=' + ipv6_address
.group()])
1223 print(static_network
)
1225 self
.remove_unit_from_networkd_path(['dhcp-client.network'])
1227 with
open(os
.path
.join(network_unit_file_path
, 'static.network'), mode
='w') as f
:
1228 f
.write(static_network
)
1230 self
.start_networkd()
1232 self
.assertTrue(self
.link_exits('veth99'))
1234 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99', 'scope', 'global']).rstrip().decode('utf-8')
1236 self
.assertRegex(output
, '192.168.5')
1237 self
.assertRegex(output
, 'valid_lft forever preferred_lft forever')
1239 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'veth99', 'scope', 'global']).rstrip().decode('utf-8')
1241 self
.assertRegex(output
, '2600::')
1242 self
.assertRegex(output
, 'valid_lft forever preferred_lft forever')
1244 if __name__
== '__main__':
1245 unittest
.main(testRunner
=unittest
.TextTestRunner(stream
=sys
.stdout
,