2 # SPDX-License-Identifier: LGPL-2.1+
3 # systemd-networkd tests
14 from shutil
import copytree
16 network_unit_file_path
='/run/systemd/network'
17 networkd_runtime_directory
='/run/systemd/netif'
18 networkd_ci_path
='/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_pid_file
='/run/networkd-ci/test-test-dnsmasq.pid'
23 dnsmasq_log_file
='/run/networkd-ci/test-dnsmasq-log-file'
25 def is_module_available(module_name
):
26 lsmod_output
= subprocess
.check_output('lsmod', universal_newlines
=True)
27 module_re
= re
.compile(r
'^{0}\b'.format(re
.escape(module_name
)), re
.MULTILINE
)
28 return module_re
.search(lsmod_output
) or not subprocess
.call(["modprobe", module_name
])
30 def expectedFailureIfModuleIsNotAvailable(module_name
):
32 if not is_module_available(module_name
):
33 return unittest
.expectedFailure(func
)
38 def expectedFailureIfERSPANModuleIsNotAvailable():
40 rc
= subprocess
.call(['ip', 'link', 'add', 'dev', 'erspan99', 'type', 'erspan', 'seq', 'key', '30', 'local', '192.168.1.4', 'remote', '192.168.1.1', 'erspan_ver', '1', 'erspan', '123'])
42 subprocess
.call(['ip', 'link', 'del', 'erspan99'])
45 return unittest
.expectedFailure(func
)
49 def expectedFailureIfRoutingPolicyPortRangeIsNotAvailable():
51 rc
= subprocess
.call(['ip', 'rule', 'add', 'from', '192.168.100.19', 'sport', '1123-1150', 'dport', '3224-3290', 'table', '7'])
53 subprocess
.call(['ip', 'rule', 'del', 'from', '192.168.100.19', 'sport', '1123-1150', 'dport', '3224-3290', 'table', '7'])
56 return unittest
.expectedFailure(func
)
60 def expectedFailureIfRoutingPolicyIPProtoIsNotAvailable():
62 rc
= subprocess
.call(['ip', 'rule', 'add', 'not', 'from', '192.168.100.19', 'ipproto', 'tcp', 'table', '7'])
64 subprocess
.call(['ip', 'rule', 'del', 'not', 'from', '192.168.100.19', 'ipproto', 'tcp', 'table', '7'])
67 return unittest
.expectedFailure(func
)
73 os
.makedirs(network_unit_file_path
, exist_ok
=True)
74 os
.makedirs(networkd_ci_path
, exist_ok
=True)
76 shutil
.rmtree(networkd_ci_path
)
77 copytree(os
.path
.join(os
.path
.dirname(os
.path
.abspath(__file__
)), 'conf'), networkd_ci_path
)
79 subprocess
.check_call('systemctl stop systemd-networkd.socket', shell
=True)
82 shutil
.rmtree(networkd_ci_path
)
84 subprocess
.check_call('systemctl stop systemd-networkd.service', shell
=True)
85 subprocess
.check_call('systemctl start systemd-networkd.socket', shell
=True)
86 subprocess
.check_call('systemctl start systemd-networkd.service', shell
=True)
89 def read_link_attr(self
, link
, dev
, attribute
):
90 with
open(os
.path
.join(os
.path
.join(os
.path
.join('/sys/class/net/', link
), dev
), attribute
)) as f
:
91 return f
.readline().strip()
93 def read_bridge_port_attr(self
, bridge
, link
, attribute
):
95 path_bridge
= os
.path
.join('/sys/devices/virtual/net', bridge
)
96 path_port
= 'lower_' + link
+ '/brport'
97 path
= os
.path
.join(path_bridge
, path_port
)
99 with
open(os
.path
.join(path
, attribute
)) as f
:
100 return f
.readline().strip()
102 def link_exits(self
, link
):
103 return os
.path
.exists(os
.path
.join('/sys/class/net', link
))
105 def link_remove(self
, links
):
107 if os
.path
.exists(os
.path
.join('/sys/class/net', link
)):
108 subprocess
.call(['ip', 'link', 'del', 'dev', link
])
111 def read_ipv6_sysctl_attr(self
, link
, attribute
):
112 with
open(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, link
), attribute
)) as f
:
113 return f
.readline().strip()
115 def read_ipv4_sysctl_attr(self
, link
, attribute
):
116 with
open(os
.path
.join(os
.path
.join(network_sysctl_ipv4_path
, link
), attribute
)) as f
:
117 return f
.readline().strip()
119 def copy_unit_to_networkd_unit_path(self
, *units
):
122 shutil
.copy(os
.path
.join(networkd_ci_path
, unit
), network_unit_file_path
)
123 if (os
.path
.exists(os
.path
.join(networkd_ci_path
, unit
+ '.d'))):
124 copytree(os
.path
.join(networkd_ci_path
, unit
+ '.d'), os
.path
.join(network_unit_file_path
, unit
+ '.d'))
126 def remove_unit_from_networkd_path(self
, units
):
128 if (os
.path
.exists(os
.path
.join(network_unit_file_path
, unit
))):
129 os
.remove(os
.path
.join(network_unit_file_path
, unit
))
130 if (os
.path
.exists(os
.path
.join(network_unit_file_path
, unit
+ '.d'))):
131 shutil
.rmtree(os
.path
.join(network_unit_file_path
, unit
+ '.d'))
133 def start_dnsmasq(self
, additional_options
=''):
134 dnsmasq_command
= '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 ' + additional_options
135 subprocess
.check_call(dnsmasq_command
, shell
=True)
139 def stop_dnsmasq(self
, pid_file
):
140 if os
.path
.exists(pid_file
):
141 with
open(pid_file
, 'r') as f
:
142 pid
= f
.read().rstrip(' \t\r\n\0')
143 os
.kill(int(pid
), signal
.SIGTERM
)
147 def search_words_in_dnsmasq_log(self
, words
, show_all
=False):
148 if os
.path
.exists(dnsmasq_log_file
):
149 with
open (dnsmasq_log_file
) as in_file
:
150 contents
= in_file
.read()
153 for line
in contents
.split('\n'):
156 print("%s, %s" % (words
, line
))
160 def remove_lease_file(self
):
161 if os
.path
.exists(os
.path
.join(networkd_ci_path
, 'lease')):
162 os
.remove(os
.path
.join(networkd_ci_path
, 'lease'))
164 def remove_log_file(self
):
165 if os
.path
.exists(dnsmasq_log_file
):
166 os
.remove(dnsmasq_log_file
)
168 def start_networkd(self
):
169 if (os
.path
.exists(os
.path
.join(networkd_runtime_directory
, 'state'))):
170 subprocess
.check_call('systemctl stop systemd-networkd', shell
=True)
171 os
.remove(os
.path
.join(networkd_runtime_directory
, 'state'))
172 subprocess
.check_call('systemctl start systemd-networkd', shell
=True)
174 subprocess
.check_call('systemctl restart systemd-networkd', shell
=True)
177 class NetworkdNetDevTests(unittest
.TestCase
, Utilities
):
211 '10-dropin-test.netdev',
218 '25-6rd-tunnel.netdev',
220 '25-bond-balanced-tlb.netdev',
222 '25-erspan-tunnel.netdev',
224 '25-gretap-tunnel.netdev',
225 '25-gre-tunnel.netdev',
226 '25-ip6gre-tunnel.netdev',
227 '25-ip6tnl-tunnel.netdev',
228 '25-ipip-tunnel-independent.netdev',
229 '25-ipip-tunnel.netdev',
231 '25-isatap-tunnel.netdev',
232 '25-sit-tunnel.netdev',
238 '25-vti6-tunnel.netdev',
239 '25-vti-tunnel.netdev',
241 '25-wireguard-23-peers.netdev',
242 '25-wireguard-23-peers.network',
243 '25-wireguard.netdev',
261 self
.link_remove(self
.links
)
264 self
.link_remove(self
.links
)
265 self
.remove_unit_from_networkd_path(self
.units
)
267 def test_dropin(self
):
268 self
.copy_unit_to_networkd_unit_path('10-dropin-test.netdev')
269 self
.start_networkd()
271 self
.assertTrue(self
.link_exits('dropin-test'))
273 output
= subprocess
.check_output(['ip', 'link', 'show', 'dropin-test']).rstrip().decode('utf-8')
275 self
.assertRegex(output
, '00:50:56:c0:00:28')
277 output
= subprocess
.check_output(['networkctl', 'list']).rstrip().decode('utf-8')
278 self
.assertRegex(output
, '1 lo ')
279 self
.assertRegex(output
, 'dropin-test')
281 output
= subprocess
.check_output(['networkctl', 'list', 'dropin-test']).rstrip().decode('utf-8')
282 self
.assertNotRegex(output
, '1 lo ')
283 self
.assertRegex(output
, 'dropin-test')
285 output
= subprocess
.check_output(['networkctl', 'list', 'dropin-*']).rstrip().decode('utf-8')
286 self
.assertNotRegex(output
, '1 lo ')
287 self
.assertRegex(output
, 'dropin-test')
289 output
= subprocess
.check_output(['networkctl', 'status', 'dropin-*']).rstrip().decode('utf-8')
290 self
.assertNotRegex(output
, '1: lo ')
291 self
.assertRegex(output
, 'dropin-test')
293 ret
= subprocess
.run(['ethtool', '--driver', 'dropin-test'], stdout
=subprocess
.PIPE
, stderr
=subprocess
.STDOUT
)
294 print(ret
.stdout
.rstrip().decode('utf-8'))
295 if ret
.returncode
== 0 and re
.search('driver: dummy', ret
.stdout
.rstrip().decode('utf-8')) != None:
296 self
.assertRegex(output
, 'Driver: dummy')
298 print('ethtool does not support driver field at least for dummy interfaces, skipping test for Driver field of networkctl.')
300 def test_bridge(self
):
301 self
.copy_unit_to_networkd_unit_path('25-bridge.netdev')
302 self
.start_networkd()
304 self
.assertTrue(self
.link_exits('bridge99'))
306 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge', 'hello_time'))
307 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge', 'max_age'))
308 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge','forward_delay'))
309 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge','ageing_time'))
310 self
.assertEqual('9', self
.read_link_attr('bridge99', 'bridge','priority'))
311 self
.assertEqual('1', self
.read_link_attr('bridge99', 'bridge','multicast_querier'))
312 self
.assertEqual('1', self
.read_link_attr('bridge99', 'bridge','multicast_snooping'))
313 self
.assertEqual('1', self
.read_link_attr('bridge99', 'bridge','stp_state'))
316 self
.copy_unit_to_networkd_unit_path('25-bond.netdev')
317 self
.start_networkd()
319 self
.assertTrue(self
.link_exits('bond99'))
321 self
.assertEqual('802.3ad 4', self
.read_link_attr('bond99', 'bonding', 'mode'))
322 self
.assertEqual('layer3+4 1', self
.read_link_attr('bond99', 'bonding', 'xmit_hash_policy'))
323 self
.assertEqual('1000', self
.read_link_attr('bond99', 'bonding', 'miimon'))
324 self
.assertEqual('fast 1', self
.read_link_attr('bond99', 'bonding', 'lacp_rate'))
325 self
.assertEqual('2000', self
.read_link_attr('bond99', 'bonding', 'updelay'))
326 self
.assertEqual('2000', self
.read_link_attr('bond99', 'bonding', 'downdelay'))
327 self
.assertEqual('4', self
.read_link_attr('bond99', 'bonding', 'resend_igmp'))
328 self
.assertEqual('1', self
.read_link_attr('bond99', 'bonding', 'min_links'))
329 self
.assertEqual('1218', self
.read_link_attr('bond99', 'bonding', 'ad_actor_sys_prio'))
330 self
.assertEqual('811', self
.read_link_attr('bond99', 'bonding', 'ad_user_port_key'))
331 self
.assertEqual('00:11:22:33:44:55', self
.read_link_attr('bond99', 'bonding', 'ad_actor_system'))
333 def test_bond_balanced_tlb(self
):
334 self
.copy_unit_to_networkd_unit_path('25-bond-balanced-tlb.netdev')
335 self
.start_networkd()
337 self
.assertTrue(self
.link_exits('bond99'))
339 self
.assertEqual('balance-tlb 5', self
.read_link_attr('bond99', 'bonding', 'mode'))
340 self
.assertEqual('1', self
.read_link_attr('bond99', 'bonding', 'tlb_dynamic_lb'))
343 self
.copy_unit_to_networkd_unit_path('21-vlan.netdev', '11-dummy.netdev', '21-vlan.network')
344 self
.start_networkd()
346 self
.assertTrue(self
.link_exits('test1'))
347 self
.assertTrue(self
.link_exits('vlan99'))
349 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'test1']).rstrip().decode('utf-8')
351 self
.assertTrue(output
, ' mtu 2004 ')
353 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vlan99']).rstrip().decode('utf-8')
355 self
.assertTrue(output
, ' mtu 2000 ')
356 self
.assertTrue(output
, 'REORDER_HDR')
357 self
.assertTrue(output
, 'LOOSE_BINDING')
358 self
.assertTrue(output
, 'GVRP')
359 self
.assertTrue(output
, 'MVRP')
360 self
.assertTrue(output
, ' id 99 ')
362 def test_macvtap(self
):
363 self
.copy_unit_to_networkd_unit_path('21-macvtap.netdev', '11-dummy.netdev', 'macvtap.network')
364 self
.start_networkd()
366 self
.assertTrue(self
.link_exits('macvtap99'))
368 def test_macvlan(self
):
369 self
.copy_unit_to_networkd_unit_path('21-macvlan.netdev', '11-dummy.netdev', 'macvlan.network')
370 self
.start_networkd()
372 self
.assertTrue(self
.link_exits('test1'))
373 self
.assertTrue(self
.link_exits('macvlan99'))
375 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'test1']).rstrip().decode('utf-8')
377 self
.assertTrue(output
, ' mtu 2000 ')
379 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'macvlan99']).rstrip().decode('utf-8')
381 self
.assertTrue(output
, ' mtu 2000 ')
383 @expectedFailureIfModuleIsNotAvailable('ipvlan')
384 def test_ipvlan(self
):
385 self
.copy_unit_to_networkd_unit_path('25-ipvlan.netdev', '11-dummy.netdev', 'ipvlan.network')
386 self
.start_networkd()
388 self
.assertTrue(self
.link_exits('ipvlan99'))
391 self
.copy_unit_to_networkd_unit_path('25-veth.netdev')
392 self
.start_networkd()
394 self
.assertTrue(self
.link_exits('veth99'))
396 def test_dummy(self
):
397 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev')
398 self
.start_networkd()
400 self
.assertTrue(self
.link_exits('test1'))
403 self
.copy_unit_to_networkd_unit_path('25-tun.netdev')
404 self
.start_networkd()
406 self
.assertTrue(self
.link_exits('tun99'))
409 self
.copy_unit_to_networkd_unit_path('25-tap.netdev')
410 self
.start_networkd()
412 self
.assertTrue(self
.link_exits('tap99'))
414 @expectedFailureIfModuleIsNotAvailable('vrf')
416 self
.copy_unit_to_networkd_unit_path('25-vrf.netdev')
417 self
.start_networkd()
419 self
.assertTrue(self
.link_exits('vrf99'))
421 @expectedFailureIfModuleIsNotAvailable('vcan')
423 self
.copy_unit_to_networkd_unit_path('25-vcan.netdev')
424 self
.start_networkd()
426 self
.assertTrue(self
.link_exits('vcan99'))
428 @expectedFailureIfModuleIsNotAvailable('wireguard')
429 def test_wireguard(self
):
430 self
.copy_unit_to_networkd_unit_path('25-wireguard.netdev')
431 self
.start_networkd()
433 if shutil
.which('wg'):
434 subprocess
.call('wg')
435 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'listen-port']).rstrip().decode('utf-8')
436 self
.assertTrue(output
, '51820')
437 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'fwmark']).rstrip().decode('utf-8')
438 self
.assertTrue(output
, '0x4d2')
439 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'allowed-ips']).rstrip().decode('utf-8')
440 self
.assertTrue(output
, 'RDf+LSpeEre7YEIKaxg+wbpsNV7du+ktR99uBEtIiCA=\t192.168.26.0/24 fd31:bf08:57cb::/48')
441 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'persistent-keepalive']).rstrip().decode('utf-8')
442 self
.assertTrue(output
, 'RDf+LSpeEre7YEIKaxg+wbpsNV7du+ktR99uBEtIiCA=\t20')
443 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'endpoints']).rstrip().decode('utf-8')
444 self
.assertTrue(output
, 'RDf+LSpeEre7YEIKaxg+wbpsNV7du+ktR99uBEtIiCA=\t192.168.27.3:51820')
446 self
.assertTrue(self
.link_exits('wg99'))
448 @expectedFailureIfModuleIsNotAvailable('wireguard')
449 def test_wireguard_23_peers(self
):
450 self
.copy_unit_to_networkd_unit_path('25-wireguard-23-peers.netdev', '25-wireguard-23-peers.network')
451 self
.start_networkd()
453 if shutil
.which('wg'):
454 subprocess
.call('wg')
456 self
.assertTrue(self
.link_exits('wg98'))
458 def test_geneve(self
):
459 self
.copy_unit_to_networkd_unit_path('25-geneve.netdev')
460 self
.start_networkd()
462 self
.assertTrue(self
.link_exits('geneve99'))
464 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'geneve99']).rstrip().decode('utf-8')
466 self
.assertTrue(output
, '192.168.22.1')
467 self
.assertTrue(output
, '6082')
468 self
.assertTrue(output
, 'udpcsum')
469 self
.assertTrue(output
, 'udp6zerocsumrx')
471 def test_ipip_tunnel(self
):
472 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-ipip-tunnel.netdev', 'ipip.network')
473 self
.start_networkd()
475 self
.assertTrue(self
.link_exits('dummy98'))
476 self
.assertTrue(self
.link_exits('ipiptun99'))
478 def test_gre_tunnel(self
):
479 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-gre-tunnel.netdev', 'gretun.network')
480 self
.start_networkd()
482 self
.assertTrue(self
.link_exits('dummy98'))
483 self
.assertTrue(self
.link_exits('gretun99'))
485 def test_gretap_tunnel(self
):
486 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-gretap-tunnel.netdev', 'gretap.network')
487 self
.start_networkd()
489 self
.assertTrue(self
.link_exits('dummy98'))
490 self
.assertTrue(self
.link_exits('gretap99'))
492 def test_ip6gretap_tunnel(self
):
493 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-ip6gre-tunnel.netdev', 'ip6gretap.network')
494 self
.start_networkd()
496 self
.assertTrue(self
.link_exits('dummy98'))
497 self
.assertTrue(self
.link_exits('ip6gretap99'))
499 def test_vti_tunnel(self
):
500 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-vti-tunnel.netdev', 'vti.network')
501 self
.start_networkd()
503 self
.assertTrue(self
.link_exits('dummy98'))
504 self
.assertTrue(self
.link_exits('vtitun99'))
506 def test_vti6_tunnel(self
):
507 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-vti6-tunnel.netdev', 'vti6.network')
508 self
.start_networkd()
510 self
.assertTrue(self
.link_exits('dummy98'))
511 self
.assertTrue(self
.link_exits('vti6tun99'))
513 def test_ip6tnl_tunnel(self
):
514 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-ip6tnl-tunnel.netdev', 'ip6tnl.network')
515 self
.start_networkd()
517 self
.assertTrue(self
.link_exits('dummy98'))
518 self
.assertTrue(self
.link_exits('ip6tnl99'))
520 def test_sit_tunnel(self
):
521 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-sit-tunnel.netdev', 'sit.network')
522 self
.start_networkd()
524 self
.assertTrue(self
.link_exits('dummy98'))
525 self
.assertTrue(self
.link_exits('sittun99'))
527 def test_isatap_tunnel(self
):
528 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-isatap-tunnel.netdev', 'isatap.network')
529 self
.start_networkd()
531 self
.assertTrue(self
.link_exits('dummy98'))
532 self
.assertTrue(self
.link_exits('isataptun99'))
534 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'isataptun99']).rstrip().decode('utf-8')
536 self
.assertRegex(output
, "isatap ")
538 def test_6rd_tunnel(self
):
539 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-6rd-tunnel.netdev', '6rd.network')
540 self
.start_networkd()
542 self
.assertTrue(self
.link_exits('dummy98'))
543 self
.assertTrue(self
.link_exits('sittun99'))
545 @expectedFailureIfERSPANModuleIsNotAvailable()
546 def test_erspan_tunnel(self
):
547 self
.copy_unit_to_networkd_unit_path('25-erspan-tunnel.netdev')
548 self
.start_networkd()
550 self
.assertTrue(self
.link_exits('erspan-test'))
552 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'erspan-test']).rstrip().decode('utf-8')
554 self
.assertTrue(output
, '172.16.1.200')
555 self
.assertTrue(output
, '172.16.1.100')
556 self
.assertTrue(output
, '101')
558 def test_tunnel_independent(self
):
559 self
.copy_unit_to_networkd_unit_path('25-ipip-tunnel-independent.netdev')
560 self
.start_networkd()
562 self
.assertTrue(self
.link_exits('ipiptun99'))
564 def test_vxlan(self
):
565 self
.copy_unit_to_networkd_unit_path('25-vxlan.netdev', 'vxlan.network','11-dummy.netdev')
566 self
.start_networkd()
568 self
.assertTrue(self
.link_exits('vxlan99'))
570 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vxlan99']).rstrip().decode('utf-8')
572 self
.assertRegex(output
, "999")
573 self
.assertRegex(output
, '5555')
574 self
.assertRegex(output
, 'l2miss')
575 self
.assertRegex(output
, 'l3miss')
576 self
.assertRegex(output
, 'udpcsum')
577 self
.assertRegex(output
, 'udp6zerocsumtx')
578 self
.assertRegex(output
, 'udp6zerocsumrx')
579 self
.assertRegex(output
, 'remcsumtx')
580 self
.assertRegex(output
, 'remcsumrx')
581 self
.assertRegex(output
, 'gbp')
583 class NetworkdNetWorkTests(unittest
.TestCase
, Utilities
):
593 '23-active-slave.network',
594 '23-bond199.network',
595 '23-primary-slave.network',
596 '23-test1-bond199.network',
597 '25-address-link-section.network',
598 '25-address-section-miscellaneous.network',
599 '25-address-section.network',
600 '25-bind-carrier.network',
601 '25-bond-active-backup-slave.netdev',
602 '25-fibrule-invert.network',
603 '25-fibrule-port-range.network',
604 '25-ipv6-address-label-section.network',
605 '25-neighbor-section.network',
606 '25-link-local-addressing-no.network',
607 '25-link-local-addressing-yes.network',
608 '25-link-section-unmanaged.network',
609 '25-route-gateway.network',
610 '25-route-gateway-on-link.network',
611 '25-route-ipv6-src.network',
612 '25-route-reverse-order.network',
613 '25-route-section.network',
614 '25-route-tcp-window-settings.network',
615 '25-route-type.network',
616 '25-sysctl-disable-ipv6.network',
618 'configure-without-carrier.network',
619 'routing-policy-rule.network',
620 'test-static.network']
623 self
.link_remove(self
.links
)
626 self
.link_remove(self
.links
)
627 self
.remove_unit_from_networkd_path(self
.units
)
629 def test_static_address(self
):
630 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'test-static.network')
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
, '192.168.0.15')
638 self
.assertRegex(output
, '192.168.0.1')
639 self
.assertRegex(output
, 'routable')
641 def test_configure_without_carrier(self
):
642 self
.copy_unit_to_networkd_unit_path('configure-without-carrier.network', '11-dummy.netdev')
643 self
.start_networkd()
645 self
.assertTrue(self
.link_exits('test1'))
647 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
649 self
.assertRegex(output
, '192.168.0.15')
650 self
.assertRegex(output
, '192.168.0.1')
651 self
.assertRegex(output
, 'routable')
653 def test_bond_active_slave(self
):
654 self
.copy_unit_to_networkd_unit_path('23-active-slave.network', '23-bond199.network', '25-bond-active-backup-slave.netdev', '12-dummy.netdev')
655 self
.start_networkd()
657 self
.assertTrue(self
.link_exits('dummy98'))
658 self
.assertTrue(self
.link_exits('bond199'))
660 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'bond199']).rstrip().decode('utf-8')
662 self
.assertRegex(output
, 'active_slave dummy98')
664 def test_bond_primary_slave(self
):
665 self
.copy_unit_to_networkd_unit_path('23-primary-slave.network', '23-test1-bond199.network', '25-bond-active-backup-slave.netdev', '11-dummy.netdev')
666 self
.start_networkd()
668 self
.assertTrue(self
.link_exits('test1'))
669 self
.assertTrue(self
.link_exits('bond199'))
671 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'bond199']).rstrip().decode('utf-8')
673 self
.assertRegex(output
, 'primary test1')
675 def test_routing_policy_rule(self
):
676 self
.copy_unit_to_networkd_unit_path('routing-policy-rule.network', '11-dummy.netdev')
677 self
.start_networkd()
679 self
.assertTrue(self
.link_exits('test1'))
681 output
= subprocess
.check_output(['ip', 'rule']).rstrip().decode('utf-8')
683 self
.assertRegex(output
, '111')
684 self
.assertRegex(output
, 'from 192.168.100.18')
685 self
.assertRegex(output
, r
'tos (?:0x08|throughput)\s')
686 self
.assertRegex(output
, 'iif test1')
687 self
.assertRegex(output
, 'oif test1')
688 self
.assertRegex(output
, 'lookup 7')
690 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
692 @expectedFailureIfRoutingPolicyPortRangeIsNotAvailable()
693 def test_routing_policy_rule_port_range(self
):
694 self
.copy_unit_to_networkd_unit_path('25-fibrule-port-range.network', '11-dummy.netdev')
695 self
.start_networkd()
697 self
.assertTrue(self
.link_exits('test1'))
699 output
= subprocess
.check_output(['ip', 'rule']).rstrip().decode('utf-8')
701 self
.assertRegex(output
, '111')
702 self
.assertRegex(output
, 'from 192.168.100.18')
703 self
.assertRegex(output
, '1123-1150')
704 self
.assertRegex(output
, '3224-3290')
705 self
.assertRegex(output
, 'tcp')
706 self
.assertRegex(output
, 'lookup 7')
708 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
710 @expectedFailureIfRoutingPolicyIPProtoIsNotAvailable()
711 def test_routing_policy_rule_invert(self
):
712 self
.copy_unit_to_networkd_unit_path('25-fibrule-invert.network', '11-dummy.netdev')
713 self
.start_networkd()
715 self
.assertTrue(self
.link_exits('test1'))
717 output
= subprocess
.check_output(['ip', 'rule']).rstrip().decode('utf-8')
719 self
.assertRegex(output
, '111')
720 self
.assertRegex(output
, 'not.*?from.*?192.168.100.18')
721 self
.assertRegex(output
, 'tcp')
722 self
.assertRegex(output
, 'lookup 7')
724 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
726 def test_address_peer(self
):
727 self
.copy_unit_to_networkd_unit_path('25-address-section.network', '12-dummy.netdev')
728 self
.start_networkd()
730 self
.assertTrue(self
.link_exits('dummy98'))
732 output
= subprocess
.check_output(['ip', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
734 self
.assertRegex(output
, 'inet 10.2.3.4 peer 10.2.3.5/16 scope global 32')
735 self
.assertRegex(output
, 'inet 10.6.7.8/16 brd 10.6.255.255 scope global 33')
736 self
.assertRegex(output
, 'inet6 2001:db8::20 peer 2001:db8::10/128 scope global')
738 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
740 self
.assertRegex(output
, 'State: routable \(configured\)')
742 def test_address_preferred_lifetime_zero_ipv6(self
):
743 self
.copy_unit_to_networkd_unit_path('25-address-section-miscellaneous.network', '12-dummy.netdev')
744 self
.start_networkd()
746 self
.assertTrue(self
.link_exits('dummy98'))
748 output
= subprocess
.check_output(['ip', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
750 self
.assertRegex(output
, 'inet 10.2.3.4/16 brd 10.2.255.255 scope link deprecated dummy98')
751 self
.assertRegex(output
, 'inet6 2001:db8:0:f101::1/64 scope global')
753 def test_ip_route(self
):
754 self
.copy_unit_to_networkd_unit_path('25-route-section.network', '12-dummy.netdev')
755 self
.start_networkd()
757 self
.assertTrue(self
.link_exits('dummy98'))
759 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'dummy98']).rstrip().decode('utf-8')
761 self
.assertRegex(output
, '192.168.0.1')
762 self
.assertRegex(output
, 'static')
763 self
.assertRegex(output
, '192.168.0.0/24')
765 def test_ip_route_reverse(self
):
766 self
.copy_unit_to_networkd_unit_path('25-route-reverse-order.network', '12-dummy.netdev')
767 self
.start_networkd()
769 self
.assertTrue(self
.link_exits('dummy98'))
771 output
= subprocess
.check_output(['ip', '-6', 'route', 'show', 'dev', 'dummy98']).rstrip().decode('utf-8')
773 self
.assertRegex(output
, '2001:1234:5:8fff:ff:ff:ff:ff')
774 self
.assertRegex(output
, '2001:1234:5:8f63::1')
776 def test_ip_route_blackhole_unreachable_prohibit(self
):
777 self
.copy_unit_to_networkd_unit_path('25-route-type.network', '12-dummy.netdev')
778 self
.start_networkd()
780 self
.assertTrue(self
.link_exits('dummy98'))
782 output
= subprocess
.check_output(['ip', 'route', 'list']).rstrip().decode('utf-8')
784 self
.assertRegex(output
, 'blackhole')
785 self
.assertRegex(output
, 'unreachable')
786 self
.assertRegex(output
, 'prohibit')
788 subprocess
.call(['ip', 'route', 'del', 'blackhole', '202.54.1.2'])
789 subprocess
.call(['ip', 'route', 'del', 'unreachable', '202.54.1.3'])
790 subprocess
.call(['ip', 'route', 'del', 'prohibit', '202.54.1.4'])
792 def test_ip_route_tcp_window(self
):
793 self
.copy_unit_to_networkd_unit_path('25-route-tcp-window-settings.network', '11-dummy.netdev')
794 self
.start_networkd()
796 self
.assertTrue(self
.link_exits('test1'))
798 output
= subprocess
.check_output(['ip', 'route', 'list']).rstrip().decode('utf-8')
800 self
.assertRegex(output
, 'initcwnd 20')
801 self
.assertRegex(output
, 'initrwnd 30')
803 def test_ip_route_gateway(self
):
804 self
.copy_unit_to_networkd_unit_path('25-route-gateway.network', '12-dummy.netdev')
805 self
.start_networkd()
807 self
.assertTrue(self
.link_exits('dummy98'))
809 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'dummy98', 'default']).rstrip().decode('utf-8')
811 self
.assertRegex(output
, 'default')
812 self
.assertRegex(output
, 'via')
813 self
.assertRegex(output
, '149.10.124.64')
814 self
.assertRegex(output
, 'proto')
815 self
.assertRegex(output
, 'static')
817 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'dummy98', 'src', '149.10.124.58']).rstrip().decode('utf-8')
819 self
.assertRegex(output
, '149.10.124.48/28')
820 self
.assertRegex(output
, 'proto')
821 self
.assertRegex(output
, 'kernel')
822 self
.assertRegex(output
, 'scope')
823 self
.assertRegex(output
, 'link')
825 def test_ip_route_gateway_on_link(self
):
826 self
.copy_unit_to_networkd_unit_path('25-route-gateway-on-link.network', '12-dummy.netdev')
827 self
.start_networkd()
829 self
.assertTrue(self
.link_exits('dummy98'))
831 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'dummy98', 'default']).rstrip().decode('utf-8')
833 self
.assertRegex(output
, 'default')
834 self
.assertRegex(output
, 'via')
835 self
.assertRegex(output
, '149.10.125.65')
836 self
.assertRegex(output
, 'proto')
837 self
.assertRegex(output
, 'static')
838 self
.assertRegex(output
, 'onlink')
840 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'dummy98', 'src', '149.10.124.58']).rstrip().decode('utf-8')
842 self
.assertRegex(output
, '149.10.124.48/28')
843 self
.assertRegex(output
, 'proto')
844 self
.assertRegex(output
, 'kernel')
845 self
.assertRegex(output
, 'scope')
846 self
.assertRegex(output
, 'link')
848 def test_ip_route_ipv6_src_route(self
):
849 # a dummy device does not make the addresses go through tentative state, so we
850 # reuse a bond from an earlier test, which does make the addresses go through
851 # tentative state, and do our test on that
852 self
.copy_unit_to_networkd_unit_path('23-active-slave.network', '25-route-ipv6-src.network', '25-bond-active-backup-slave.netdev', '12-dummy.netdev')
853 self
.start_networkd()
855 self
.assertTrue(self
.link_exits('dummy98'))
856 self
.assertTrue(self
.link_exits('bond199'))
858 output
= subprocess
.check_output(['ip', '-6', 'route', 'list', 'dev', 'bond199']).rstrip().decode('utf-8')
860 self
.assertRegex(output
, 'abcd::/16')
861 self
.assertRegex(output
, 'src')
862 self
.assertRegex(output
, '2001:1234:56:8f63::2')
864 def test_ip_link_mac_address(self
):
865 self
.copy_unit_to_networkd_unit_path('25-address-link-section.network', '12-dummy.netdev')
866 self
.start_networkd()
868 self
.assertTrue(self
.link_exits('dummy98'))
870 output
= subprocess
.check_output(['ip', 'link', 'show', 'dummy98']).rstrip().decode('utf-8')
872 self
.assertRegex(output
, '00:01:02:aa:bb:cc')
874 def test_ip_link_unmanaged(self
):
875 self
.copy_unit_to_networkd_unit_path('25-link-section-unmanaged.network', '12-dummy.netdev')
876 self
.start_networkd()
878 self
.assertTrue(self
.link_exits('dummy98'))
880 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
882 self
.assertRegex(output
, 'unmanaged')
884 def test_ipv6_address_label(self
):
885 self
.copy_unit_to_networkd_unit_path('25-ipv6-address-label-section.network', '12-dummy.netdev')
886 self
.start_networkd()
888 self
.assertTrue(self
.link_exits('dummy98'))
890 output
= subprocess
.check_output(['ip', 'addrlabel', 'list']).rstrip().decode('utf-8')
892 self
.assertRegex(output
, '2004:da8:1::/64')
894 def test_ipv6_neighbor(self
):
895 self
.copy_unit_to_networkd_unit_path('25-neighbor-section.network', '12-dummy.netdev')
896 self
.start_networkd()
898 self
.assertTrue(self
.link_exits('dummy98'))
900 output
= subprocess
.check_output(['ip', 'neigh', 'list']).rstrip().decode('utf-8')
902 self
.assertRegex(output
, '192.168.10.1.*00:00:5e:00:02:65.*PERMANENT')
903 self
.assertRegex(output
, '2004:da8:1::1.*00:00:5e:00:02:66.*PERMANENT')
905 def test_link_local_addressing(self
):
906 self
.copy_unit_to_networkd_unit_path('25-link-local-addressing-yes.network', '11-dummy.netdev',
907 '25-link-local-addressing-no.network', '12-dummy.netdev')
908 self
.start_networkd()
910 self
.assertTrue(self
.link_exits('test1'))
911 self
.assertTrue(self
.link_exits('dummy98'))
915 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'test1']).rstrip().decode('utf-8')
917 self
.assertRegex(output
, 'inet .* scope link')
918 self
.assertRegex(output
, 'inet6 .* scope link')
920 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'dummy98']).rstrip().decode('utf-8')
922 self
.assertNotRegex(output
, 'inet6* .* scope link')
924 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
926 self
.assertRegex(output
, 'State: degraded \(configured\)')
928 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
930 self
.assertRegex(output
, 'State: carrier \(configured\)')
933 Documentation/networking/ip-sysctl.txt
935 addr_gen_mode - INTEGER
936 Defines how link-local and autoconf addresses are generated.
938 0: generate address based on EUI64 (default)
939 1: do no generate a link-local address, use EUI64 for addresses generated
941 2: generate stable privacy addresses, using the secret from
942 stable_secret (RFC7217)
943 3: generate stable privacy addresses, using a random secret if unset
946 test1_addr_gen_mode
= ''
947 if os
.path
.exists(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, 'test1'), 'stable_secret')):
948 with
open(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, 'test1'), 'stable_secret')) as f
:
952 # if stable_secret is unset, then EIO is returned
953 test1_addr_gen_mode
= '0'
955 test1_addr_gen_mode
= '2'
957 test1_addr_gen_mode
= '0'
959 if os
.path
.exists(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, 'test1'), 'addr_gen_mode')):
960 self
.assertEqual(self
.read_ipv6_sysctl_attr('test1', 'addr_gen_mode'), '0')
962 if os
.path
.exists(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, 'dummy98'), 'addr_gen_mode')):
963 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'addr_gen_mode'), '1')
965 def test_sysctl(self
):
966 self
.copy_unit_to_networkd_unit_path('25-sysctl.network', '12-dummy.netdev')
967 self
.start_networkd()
969 self
.assertTrue(self
.link_exits('dummy98'))
971 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'forwarding'), '1')
972 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'use_tempaddr'), '2')
973 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'dad_transmits'), '3')
974 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'hop_limit'), '5')
975 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'proxy_ndp'), '1')
976 self
.assertEqual(self
.read_ipv4_sysctl_attr('dummy98', 'forwarding'),'1')
977 self
.assertEqual(self
.read_ipv4_sysctl_attr('dummy98', 'proxy_arp'), '1')
979 def test_sysctl_disable_ipv6(self
):
980 self
.copy_unit_to_networkd_unit_path('25-sysctl-disable-ipv6.network', '12-dummy.netdev')
982 print('## Disable ipv6')
983 self
.assertEqual(subprocess
.call(['sysctl', 'net.ipv6.conf.all.disable_ipv6=1']), 0)
984 self
.assertEqual(subprocess
.call(['sysctl', 'net.ipv6.conf.default.disable_ipv6=1']), 0)
986 self
.start_networkd()
988 self
.assertTrue(self
.link_exits('dummy98'))
990 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
992 self
.assertRegex(output
, 'inet 10.2.3.4/16 brd 10.2.255.255 scope global dummy98')
993 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
995 self
.assertEqual(output
, '')
996 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
997 self
.assertRegex(output
, 'State: routable \(configured\)')
999 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1001 print('## Enable ipv6')
1002 self
.assertEqual(subprocess
.call(['sysctl', 'net.ipv6.conf.all.disable_ipv6=0']), 0)
1003 self
.assertEqual(subprocess
.call(['sysctl', 'net.ipv6.conf.default.disable_ipv6=0']), 0)
1005 self
.start_networkd()
1007 self
.assertTrue(self
.link_exits('dummy98'))
1009 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
1011 self
.assertRegex(output
, 'inet 10.2.3.4/16 brd 10.2.255.255 scope global dummy98')
1012 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
1014 self
.assertRegex(output
, 'inet6 .* scope link')
1015 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1016 self
.assertRegex(output
, 'State: routable \(configured\)')
1018 def test_bind_carrier(self
):
1019 self
.copy_unit_to_networkd_unit_path('25-bind-carrier.network', '11-dummy.netdev')
1020 self
.start_networkd()
1022 self
.assertTrue(self
.link_exits('test1'))
1024 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1025 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1027 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1']).rstrip().decode('utf-8')
1029 self
.assertRegex(output
, 'UP,LOWER_UP')
1030 self
.assertRegex(output
, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
1031 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1032 self
.assertRegex(output
, 'State: routable \(configured\)')
1034 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy99', 'type', 'dummy']), 0)
1035 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy99', 'up']), 0)
1037 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1']).rstrip().decode('utf-8')
1039 self
.assertRegex(output
, 'UP,LOWER_UP')
1040 self
.assertRegex(output
, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
1041 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1042 self
.assertRegex(output
, 'State: routable \(configured\)')
1044 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1046 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1']).rstrip().decode('utf-8')
1048 self
.assertRegex(output
, 'UP,LOWER_UP')
1049 self
.assertRegex(output
, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
1050 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1051 self
.assertRegex(output
, 'State: routable \(configured\)')
1053 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy99']), 0)
1055 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1']).rstrip().decode('utf-8')
1057 self
.assertNotRegex(output
, 'UP,LOWER_UP')
1058 self
.assertRegex(output
, 'DOWN')
1059 self
.assertNotRegex(output
, '192.168.10')
1060 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1061 self
.assertRegex(output
, 'State: off \(configured\)')
1063 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1064 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1066 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1']).rstrip().decode('utf-8')
1068 self
.assertRegex(output
, 'UP,LOWER_UP')
1069 self
.assertRegex(output
, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
1070 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1071 self
.assertRegex(output
, 'State: routable \(configured\)')
1073 class NetworkdNetWorkBondTests(unittest
.TestCase
, Utilities
):
1084 'bond-slave.network']
1087 self
.link_remove(self
.links
)
1090 self
.link_remove(self
.links
)
1091 self
.remove_unit_from_networkd_path(self
.units
)
1093 def test_bond_operstate(self
):
1094 self
.copy_unit_to_networkd_unit_path('25-bond.netdev', '11-dummy.netdev', '12-dummy.netdev',
1095 'bond99.network','bond-slave.network')
1096 self
.start_networkd()
1098 self
.assertTrue(self
.link_exits('bond99'))
1099 self
.assertTrue(self
.link_exits('dummy98'))
1100 self
.assertTrue(self
.link_exits('test1'))
1102 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'dummy98']).rstrip().decode('utf-8')
1104 self
.assertRegex(output
, 'SLAVE,UP,LOWER_UP')
1106 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'test1']).rstrip().decode('utf-8')
1108 self
.assertRegex(output
, 'SLAVE,UP,LOWER_UP')
1110 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'bond99']).rstrip().decode('utf-8')
1112 self
.assertRegex(output
, 'MASTER,UP,LOWER_UP')
1114 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1116 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1118 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1120 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1122 output
= subprocess
.check_output(['networkctl', 'status', 'bond99']).rstrip().decode('utf-8')
1124 self
.assertRegex(output
, 'State: routable \(configured\)')
1126 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'down']), 0)
1129 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1131 self
.assertRegex(output
, 'State: off \(configured\)')
1133 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1135 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1137 output
= subprocess
.check_output(['networkctl', 'status', 'bond99']).rstrip().decode('utf-8')
1139 self
.assertRegex(output
, 'State: degraded \(configured\)')
1141 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1144 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1146 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1148 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1150 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1152 output
= subprocess
.check_output(['networkctl', 'status', 'bond99']).rstrip().decode('utf-8')
1154 self
.assertRegex(output
, 'State: routable \(configured\)')
1156 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'down']), 0)
1157 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'test1', 'down']), 0)
1160 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1162 self
.assertRegex(output
, 'State: off \(configured\)')
1164 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1166 self
.assertRegex(output
, 'State: off \(configured\)')
1168 output
= subprocess
.check_output(['networkctl', 'status', 'bond99']).rstrip().decode('utf-8')
1170 self
.assertRegex(output
, 'State: degraded \(configured\)')
1172 class NetworkdNetWorkBridgeTests(unittest
.TestCase
, Utilities
):
1182 '26-bridge-slave-interface-1.network',
1183 '26-bridge-slave-interface-2.network',
1184 'bridge99-ignore-carrier-loss.network',
1188 self
.link_remove(self
.links
)
1191 self
.link_remove(self
.links
)
1192 self
.remove_unit_from_networkd_path(self
.units
)
1194 def test_bridge_property(self
):
1195 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev', '12-dummy.netdev', '26-bridge.netdev',
1196 '26-bridge-slave-interface-1.network', '26-bridge-slave-interface-2.network',
1198 self
.start_networkd()
1200 self
.assertTrue(self
.link_exits('dummy98'))
1201 self
.assertTrue(self
.link_exits('test1'))
1202 self
.assertTrue(self
.link_exits('bridge99'))
1204 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'test1']).rstrip().decode('utf-8')
1206 self
.assertRegex(output
, 'master')
1207 self
.assertRegex(output
, 'bridge')
1209 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'dummy98']).rstrip().decode('utf-8')
1211 self
.assertRegex(output
, 'master')
1212 self
.assertRegex(output
, 'bridge')
1214 output
= subprocess
.check_output(['ip', 'addr', 'show', 'bridge99']).rstrip().decode('utf-8')
1216 self
.assertRegex(output
, '192.168.0.15/24')
1218 output
= subprocess
.check_output(['bridge', '-d', 'link', 'show', 'dummy98']).rstrip().decode('utf-8')
1220 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'hairpin_mode'), '1')
1221 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'path_cost'), '400')
1222 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'unicast_flood'), '1')
1223 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'multicast_fast_leave'), '1')
1225 # CONFIG_BRIDGE_IGMP_SNOOPING=y
1226 if (os
.path
.exists('/sys/devices/virtual/net/bridge00/lower_dummy98/brport/multicast_to_unicast')):
1227 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'multicast_to_unicast'), '1')
1229 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1230 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1232 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1233 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1235 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
1236 self
.assertRegex(output
, 'State: routable \(configured\)')
1238 self
.assertEqual(subprocess
.call(['ip', 'address', 'add', '192.168.0.16/24', 'dev', 'bridge99']), 0)
1241 output
= subprocess
.check_output(['ip', 'addr', 'show', 'bridge99']).rstrip().decode('utf-8')
1243 self
.assertRegex(output
, '192.168.0.16/24')
1245 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
1246 self
.assertRegex(output
, 'State: routable \(configured\)')
1248 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'test1']), 0)
1251 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
1252 self
.assertRegex(output
, 'State: degraded \(configured\)')
1254 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1257 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
1258 self
.assertRegex(output
, 'State: no-carrier \(configured\)')
1260 output
= subprocess
.check_output(['ip', 'address', 'show', 'bridge99']).rstrip().decode('utf-8')
1262 self
.assertRegex(output
, 'NO-CARRIER')
1263 self
.assertNotRegex(output
, '192.168.0.15/24')
1264 self
.assertNotRegex(output
, '192.168.0.16/24')
1266 def test_bridge_ignore_carrier_loss(self
):
1267 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev', '12-dummy.netdev', '26-bridge.netdev',
1268 '26-bridge-slave-interface-1.network', '26-bridge-slave-interface-2.network',
1269 'bridge99-ignore-carrier-loss.network')
1270 self
.start_networkd()
1272 self
.assertTrue(self
.link_exits('dummy98'))
1273 self
.assertTrue(self
.link_exits('test1'))
1274 self
.assertTrue(self
.link_exits('bridge99'))
1276 self
.assertEqual(subprocess
.call(['ip', 'address', 'add', '192.168.0.16/24', 'dev', 'bridge99']), 0)
1279 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'test1']), 0)
1280 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1283 output
= subprocess
.check_output(['ip', 'address', 'show', 'bridge99']).rstrip().decode('utf-8')
1285 self
.assertRegex(output
, 'NO-CARRIER')
1286 self
.assertRegex(output
, 'inet 192.168.0.15/24 brd 192.168.0.255 scope global bridge99')
1287 self
.assertRegex(output
, 'inet 192.168.0.16/24 scope global secondary bridge99')
1289 subprocess
.call(['ip', 'rule', 'del', 'table', '100'])
1291 def test_bridge_ignore_carrier_loss_frequent_loss_and_gain(self
):
1292 self
.copy_unit_to_networkd_unit_path('26-bridge.netdev', '26-bridge-slave-interface-1.network',
1293 'bridge99-ignore-carrier-loss.network')
1294 self
.start_networkd()
1296 self
.assertTrue(self
.link_exits('bridge99'))
1298 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1299 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1300 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1302 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1303 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1304 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1306 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1307 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1308 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1310 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1311 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1315 output
= subprocess
.check_output(['ip', 'address', 'show', 'bridge99']).rstrip().decode('utf-8')
1317 self
.assertRegex(output
, 'inet 192.168.0.15/24 brd 192.168.0.255 scope global bridge99')
1319 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
1320 self
.assertRegex(output
, 'State: routable \(configured\)')
1322 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1323 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1325 output
= subprocess
.check_output(['ip', 'rule', 'list', 'table', '100']).rstrip().decode('utf-8')
1327 self
.assertEqual(output
, '0: from all to 8.8.8.8 lookup 100')
1329 subprocess
.call(['ip', 'rule', 'del', 'table', '100'])
1331 class NetworkdNetWorkLLDPTests(unittest
.TestCase
, Utilities
):
1335 '23-emit-lldp.network',
1340 self
.link_remove(self
.links
)
1343 self
.link_remove(self
.links
)
1344 self
.remove_unit_from_networkd_path(self
.units
)
1346 def test_lldp(self
):
1347 self
.copy_unit_to_networkd_unit_path('23-emit-lldp.network', '24-lldp.network', '25-veth.netdev')
1348 self
.start_networkd()
1350 self
.assertTrue(self
.link_exits('veth99'))
1352 output
= subprocess
.check_output(['networkctl', 'lldp']).rstrip().decode('utf-8')
1354 self
.assertRegex(output
, 'veth-peer')
1355 self
.assertRegex(output
, 'veth99')
1357 class NetworkdNetworkRATests(unittest
.TestCase
, Utilities
):
1362 'ipv6-prefix.network',
1363 'ipv6-prefix-veth.network']
1366 self
.link_remove(self
.links
)
1369 self
.link_remove(self
.links
)
1370 self
.remove_unit_from_networkd_path(self
.units
)
1372 def test_ipv6_prefix_delegation(self
):
1373 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'ipv6-prefix.network', 'ipv6-prefix-veth.network')
1374 self
.start_networkd()
1376 self
.assertTrue(self
.link_exits('veth99'))
1378 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1380 self
.assertRegex(output
, '2002:da8:1:0')
1382 class NetworkdNetworkDHCPServerTests(unittest
.TestCase
, Utilities
):
1389 '24-search-domain.network',
1391 'dhcp-client.network',
1392 'dhcp-client-timezone-router.network',
1393 'dhcp-server.network',
1394 'dhcp-server-timezone-router.network']
1397 self
.link_remove(self
.links
)
1400 self
.link_remove(self
.links
)
1401 self
.remove_unit_from_networkd_path(self
.units
)
1403 def test_dhcp_server(self
):
1404 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-client.network', 'dhcp-server.network')
1405 self
.start_networkd()
1407 self
.assertTrue(self
.link_exits('veth99'))
1409 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1411 self
.assertRegex(output
, '192.168.5.*')
1412 self
.assertRegex(output
, 'Gateway: 192.168.5.1')
1413 self
.assertRegex(output
, 'DNS: 192.168.5.1')
1414 self
.assertRegex(output
, 'NTP: 192.168.5.1')
1416 def test_domain(self
):
1417 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '24-search-domain.network')
1418 self
.start_networkd()
1420 self
.assertTrue(self
.link_exits('dummy98'))
1422 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1424 self
.assertRegex(output
, 'Address: 192.168.42.100')
1425 self
.assertRegex(output
, 'DNS: 192.168.42.1')
1426 self
.assertRegex(output
, 'Search Domains: one')
1428 def test_emit_router_timezone(self
):
1429 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-client-timezone-router.network', 'dhcp-server-timezone-router.network')
1430 self
.start_networkd()
1432 self
.assertTrue(self
.link_exits('veth99'))
1434 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1436 self
.assertRegex(output
, 'Gateway: 192.168.5.*')
1437 self
.assertRegex(output
, '192.168.5.*')
1438 self
.assertRegex(output
, 'Europe/Berlin')
1440 class NetworkdNetworkDHCPClientTests(unittest
.TestCase
, Utilities
):
1450 'dhcp-client-anonymize.network',
1451 'dhcp-client-critical-connection.network',
1452 'dhcp-client-ipv4-dhcp-settings.network',
1453 'dhcp-client-ipv4-only-ipv6-disabled.network',
1454 'dhcp-client-ipv4-only.network',
1455 'dhcp-client-ipv6-only.network',
1456 'dhcp-client-ipv6-rapid-commit.network',
1457 'dhcp-client-listen-port.network',
1458 'dhcp-client-route-metric.network',
1459 'dhcp-client-route-table.network',
1460 'dhcp-client-vrf.network',
1461 'dhcp-client.network',
1462 'dhcp-server-veth-peer.network',
1463 'dhcp-v4-server-veth-peer.network',
1467 self
.link_remove(self
.links
)
1468 self
.stop_dnsmasq(dnsmasq_pid_file
)
1471 self
.link_remove(self
.links
)
1472 self
.remove_unit_from_networkd_path(self
.units
)
1473 self
.stop_dnsmasq(dnsmasq_pid_file
)
1474 self
.remove_lease_file()
1475 self
.remove_log_file()
1477 def test_dhcp_client_ipv6_only(self
):
1478 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network')
1479 self
.start_networkd()
1481 self
.assertTrue(self
.link_exits('veth99'))
1483 self
.start_dnsmasq()
1485 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1487 self
.assertRegex(output
, '2600::')
1488 self
.assertNotRegex(output
, '192.168.5')
1490 def test_dhcp_client_ipv4_only(self
):
1491 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv4-only-ipv6-disabled.network')
1492 self
.start_networkd()
1494 self
.assertTrue(self
.link_exits('veth99'))
1496 self
.start_dnsmasq()
1498 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1500 self
.assertNotRegex(output
, '2600::')
1501 self
.assertRegex(output
, '192.168.5')
1503 def test_dhcp_client_ipv4_ipv6(self
):
1504 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network',
1505 'dhcp-client-ipv4-only.network')
1506 self
.start_networkd()
1508 self
.assertTrue(self
.link_exits('veth99'))
1510 self
.start_dnsmasq()
1512 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1514 self
.assertRegex(output
, '2600::')
1515 self
.assertRegex(output
, '192.168.5')
1517 def test_dhcp_client_settings(self
):
1518 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv4-dhcp-settings.network')
1519 self
.start_networkd()
1521 self
.assertTrue(self
.link_exits('veth99'))
1523 self
.start_dnsmasq()
1525 print('## ip address show dev veth99')
1526 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
1528 self
.assertRegex(output
, '12:34:56:78:9a:bc')
1529 self
.assertRegex(output
, '192.168.5')
1530 self
.assertRegex(output
, '1492')
1533 print('## ip route show table main dev veth99')
1534 output
= subprocess
.check_output(['ip', 'route', 'show', 'table', 'main', 'dev', 'veth99']).rstrip().decode('utf-8')
1536 self
.assertNotRegex(output
, 'proto dhcp')
1538 print('## ip route show table 211 dev veth99')
1539 output
= subprocess
.check_output(['ip', 'route', 'show', 'table', '211', 'dev', 'veth99']).rstrip().decode('utf-8')
1541 self
.assertRegex(output
, 'default via 192.168.5.1 proto dhcp')
1542 self
.assertRegex(output
, '192.168.5.0/24 via 192.168.5.5 proto dhcp')
1543 self
.assertRegex(output
, '192.168.5.1 proto dhcp scope link')
1545 print('## dnsmasq log')
1546 self
.assertTrue(self
.search_words_in_dnsmasq_log('vendor class: SusantVendorTest', True))
1547 self
.assertTrue(self
.search_words_in_dnsmasq_log('DHCPDISCOVER(veth-peer) 12:34:56:78:9a:bc'))
1548 self
.assertTrue(self
.search_words_in_dnsmasq_log('client provides name: test-hostname'))
1549 self
.assertTrue(self
.search_words_in_dnsmasq_log('26:mtu'))
1551 def test_dhcp6_client_settings_rapidcommit_true(self
):
1552 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network')
1553 self
.start_networkd()
1555 self
.assertTrue(self
.link_exits('veth99'))
1557 self
.start_dnsmasq()
1559 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
1561 self
.assertRegex(output
, '12:34:56:78:9a:bc')
1562 self
.assertTrue(self
.search_words_in_dnsmasq_log('14:rapid-commit', True))
1564 def test_dhcp6_client_settings_rapidcommit_false(self
):
1565 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-rapid-commit.network')
1566 self
.start_networkd()
1568 self
.assertTrue(self
.link_exits('veth99'))
1570 self
.start_dnsmasq()
1572 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
1574 self
.assertRegex(output
, '12:34:56:78:9a:bc')
1575 self
.assertFalse(self
.search_words_in_dnsmasq_log('14:rapid-commit', True))
1577 def test_dhcp_client_settings_anonymize(self
):
1578 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-anonymize.network')
1579 self
.start_networkd()
1581 self
.assertTrue(self
.link_exits('veth99'))
1583 self
.start_dnsmasq()
1585 self
.assertFalse(self
.search_words_in_dnsmasq_log('VendorClassIdentifier=SusantVendorTest', True))
1586 self
.assertFalse(self
.search_words_in_dnsmasq_log('test-hostname'))
1587 self
.assertFalse(self
.search_words_in_dnsmasq_log('26:mtu'))
1589 def test_dhcp_client_listen_port(self
):
1590 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-listen-port.network')
1591 self
.start_networkd()
1593 self
.assertTrue(self
.link_exits('veth99'))
1595 self
.start_dnsmasq('--dhcp-alternate-port=67,5555')
1597 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
1599 self
.assertRegex(output
, '192.168.5.* dynamic')
1601 def test_dhcp_route_table_id(self
):
1602 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-route-table.network')
1603 self
.start_networkd()
1605 self
.assertTrue(self
.link_exits('veth99'))
1607 self
.start_dnsmasq()
1609 output
= subprocess
.check_output(['ip', 'route', 'show', 'table', '12']).rstrip().decode('utf-8')
1611 self
.assertRegex(output
, 'veth99 proto dhcp')
1612 self
.assertRegex(output
, '192.168.5.1')
1614 def test_dhcp_route_metric(self
):
1615 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-route-metric.network')
1616 self
.start_networkd()
1618 self
.assertTrue(self
.link_exits('veth99'))
1620 self
.start_dnsmasq()
1622 output
= subprocess
.check_output(['ip', 'route', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
1624 self
.assertRegex(output
, 'metric 24')
1626 def test_dhcp_route_criticalconnection_true(self
):
1627 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-critical-connection.network')
1628 self
.start_networkd()
1630 self
.assertTrue(self
.link_exits('veth99'))
1632 self
.start_dnsmasq()
1634 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1636 self
.assertRegex(output
, '192.168.5.*')
1638 # Stoping dnsmasq as networkd won't be allowed to renew the DHCP lease.
1639 self
.stop_dnsmasq(dnsmasq_pid_file
)
1641 # Sleep for 120 sec as the dnsmasq minimum lease time can only be set to 120
1644 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1646 self
.assertRegex(output
, '192.168.5.*')
1648 def test_dhcp_client_reuse_address_as_static(self
):
1649 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client.network')
1650 self
.start_networkd()
1652 self
.assertTrue(self
.link_exits('veth99'))
1654 self
.start_dnsmasq()
1656 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99', 'scope', 'global']).rstrip().decode('utf-8')
1658 self
.assertRegex(output
, '192.168.5')
1659 self
.assertRegex(output
, '2600::')
1661 ipv4_address
= re
.search('192\.168\.5\.[0-9]*/24', output
)
1662 ipv6_address
= re
.search('2600::[0-9a-f:]*/128', output
)
1663 static_network
= '\n'.join(['[Match]', 'Name=veth99', '[Network]', 'IPv6AcceptRA=no', 'Address=' + ipv4_address
.group(), 'Address=' + ipv6_address
.group()])
1664 print(static_network
)
1666 self
.remove_unit_from_networkd_path(['dhcp-client.network'])
1668 with
open(os
.path
.join(network_unit_file_path
, 'static.network'), mode
='w') as f
:
1669 f
.write(static_network
)
1671 self
.start_networkd()
1673 self
.assertTrue(self
.link_exits('veth99'))
1675 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99', 'scope', 'global']).rstrip().decode('utf-8')
1677 self
.assertRegex(output
, '192.168.5')
1678 self
.assertRegex(output
, 'valid_lft forever preferred_lft forever')
1680 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'veth99', 'scope', 'global']).rstrip().decode('utf-8')
1682 self
.assertRegex(output
, '2600::')
1683 self
.assertRegex(output
, 'valid_lft forever preferred_lft forever')
1685 @expectedFailureIfModuleIsNotAvailable('vrf')
1686 def test_dhcp_client_vrf(self
):
1687 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-vrf.network',
1688 '25-vrf.netdev', '25-vrf.network')
1689 self
.start_networkd()
1691 self
.assertTrue(self
.link_exits('veth99'))
1692 self
.assertTrue(self
.link_exits('vrf99'))
1694 self
.start_dnsmasq()
1696 print('## ip -d link show dev vrf99')
1697 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'dev', 'vrf99']).rstrip().decode('utf-8')
1699 self
.assertRegex(output
, 'vrf table 42')
1701 print('## ip address show vrf vrf99')
1702 output_ip_vrf
= subprocess
.check_output(['ip', 'address', 'show', 'vrf', 'vrf99']).rstrip().decode('utf-8')
1703 print(output_ip_vrf
)
1705 print('## ip address show dev veth99')
1706 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
1708 self
.assertEqual(output
, output_ip_vrf
)
1709 self
.assertRegex(output
, 'inet 169.254.[0-9]*.[0-9]*/16 brd 169.254.255.255 scope link veth99')
1710 self
.assertRegex(output
, 'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99')
1711 self
.assertRegex(output
, 'inet6 2600::[0-9a-f]*/128 scope global dynamic noprefixroute')
1712 self
.assertRegex(output
, 'inet6 .* scope link')
1714 print('## ip route show vrf vrf99')
1715 output
= subprocess
.check_output(['ip', 'route', 'show', 'vrf', 'vrf99']).rstrip().decode('utf-8')
1717 self
.assertRegex(output
, 'default via 192.168.5.1 dev veth99 proto dhcp src 192.168.5.')
1718 self
.assertRegex(output
, 'default dev veth99 proto static scope link')
1719 self
.assertRegex(output
, '169.254.0.0/16 dev veth99 proto kernel scope link src 169.254')
1720 self
.assertRegex(output
, '192.168.5.0/24 dev veth99 proto kernel scope link src 192.168.5')
1721 self
.assertRegex(output
, '192.168.5.0/24 via 192.168.5.5 dev veth99 proto dhcp')
1722 self
.assertRegex(output
, '192.168.5.1 dev veth99 proto dhcp scope link src 192.168.5')
1724 print('## ip route show table main dev veth99')
1725 output
= subprocess
.check_output(['ip', 'route', 'show', 'table', 'main', 'dev', 'veth99']).rstrip().decode('utf-8')
1727 self
.assertEqual(output
, '')
1729 output
= subprocess
.check_output(['networkctl', 'status', 'vrf99']).rstrip().decode('utf-8')
1731 self
.assertRegex(output
, 'State: carrier \(configured\)')
1733 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1735 self
.assertRegex(output
, 'State: routable \(configured\)')
1737 if __name__
== '__main__':
1738 unittest
.main(testRunner
=unittest
.TextTestRunner(stream
=sys
.stdout
,