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
, remove_state_files
=True):
169 if (remove_state_files
and
170 os
.path
.exists(os
.path
.join(networkd_runtime_directory
, 'state'))):
171 subprocess
.check_call('systemctl stop systemd-networkd', shell
=True)
172 os
.remove(os
.path
.join(networkd_runtime_directory
, 'state'))
173 subprocess
.check_call('systemctl start systemd-networkd', shell
=True)
175 subprocess
.check_call('systemctl restart systemd-networkd', shell
=True)
178 class NetworkdNetDevTests(unittest
.TestCase
, Utilities
):
212 '10-dropin-test.netdev',
217 '21-vlan-test1.network',
220 '25-6rd-tunnel.netdev',
222 '25-bond-balanced-tlb.netdev',
224 '25-erspan-tunnel.netdev',
226 '25-gretap-tunnel.netdev',
227 '25-gre-tunnel.netdev',
228 '25-ip6gre-tunnel.netdev',
229 '25-ip6tnl-tunnel.netdev',
230 '25-ipip-tunnel-independent.netdev',
231 '25-ipip-tunnel.netdev',
233 '25-isatap-tunnel.netdev',
234 '25-sit-tunnel.netdev',
240 '25-vti6-tunnel.netdev',
241 '25-vti-tunnel.netdev',
243 '25-wireguard-23-peers.netdev',
244 '25-wireguard-23-peers.network',
245 '25-wireguard.netdev',
263 self
.link_remove(self
.links
)
266 self
.link_remove(self
.links
)
267 self
.remove_unit_from_networkd_path(self
.units
)
269 def test_dropin(self
):
270 self
.copy_unit_to_networkd_unit_path('10-dropin-test.netdev')
271 self
.start_networkd()
273 self
.assertTrue(self
.link_exits('dropin-test'))
275 output
= subprocess
.check_output(['ip', 'link', 'show', 'dropin-test']).rstrip().decode('utf-8')
277 self
.assertRegex(output
, '00:50:56:c0:00:28')
279 output
= subprocess
.check_output(['networkctl', 'list']).rstrip().decode('utf-8')
280 self
.assertRegex(output
, '1 lo ')
281 self
.assertRegex(output
, 'dropin-test')
283 output
= subprocess
.check_output(['networkctl', 'list', 'dropin-test']).rstrip().decode('utf-8')
284 self
.assertNotRegex(output
, '1 lo ')
285 self
.assertRegex(output
, 'dropin-test')
287 output
= subprocess
.check_output(['networkctl', 'list', 'dropin-*']).rstrip().decode('utf-8')
288 self
.assertNotRegex(output
, '1 lo ')
289 self
.assertRegex(output
, 'dropin-test')
291 output
= subprocess
.check_output(['networkctl', 'status', 'dropin-*']).rstrip().decode('utf-8')
292 self
.assertNotRegex(output
, '1: lo ')
293 self
.assertRegex(output
, 'dropin-test')
295 ret
= subprocess
.run(['ethtool', '--driver', 'dropin-test'], stdout
=subprocess
.PIPE
, stderr
=subprocess
.STDOUT
)
296 print(ret
.stdout
.rstrip().decode('utf-8'))
297 if ret
.returncode
== 0 and re
.search('driver: dummy', ret
.stdout
.rstrip().decode('utf-8')) != None:
298 self
.assertRegex(output
, 'Driver: dummy')
300 print('ethtool does not support driver field at least for dummy interfaces, skipping test for Driver field of networkctl.')
302 def test_bridge(self
):
303 self
.copy_unit_to_networkd_unit_path('25-bridge.netdev')
304 self
.start_networkd()
306 self
.assertTrue(self
.link_exits('bridge99'))
308 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge', 'hello_time'))
309 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge', 'max_age'))
310 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge','forward_delay'))
311 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge','ageing_time'))
312 self
.assertEqual('9', self
.read_link_attr('bridge99', 'bridge','priority'))
313 self
.assertEqual('1', self
.read_link_attr('bridge99', 'bridge','multicast_querier'))
314 self
.assertEqual('1', self
.read_link_attr('bridge99', 'bridge','multicast_snooping'))
315 self
.assertEqual('1', self
.read_link_attr('bridge99', 'bridge','stp_state'))
318 self
.copy_unit_to_networkd_unit_path('25-bond.netdev')
319 self
.start_networkd()
321 self
.assertTrue(self
.link_exits('bond99'))
323 self
.assertEqual('802.3ad 4', self
.read_link_attr('bond99', 'bonding', 'mode'))
324 self
.assertEqual('layer3+4 1', self
.read_link_attr('bond99', 'bonding', 'xmit_hash_policy'))
325 self
.assertEqual('1000', self
.read_link_attr('bond99', 'bonding', 'miimon'))
326 self
.assertEqual('fast 1', self
.read_link_attr('bond99', 'bonding', 'lacp_rate'))
327 self
.assertEqual('2000', self
.read_link_attr('bond99', 'bonding', 'updelay'))
328 self
.assertEqual('2000', self
.read_link_attr('bond99', 'bonding', 'downdelay'))
329 self
.assertEqual('4', self
.read_link_attr('bond99', 'bonding', 'resend_igmp'))
330 self
.assertEqual('1', self
.read_link_attr('bond99', 'bonding', 'min_links'))
331 self
.assertEqual('1218', self
.read_link_attr('bond99', 'bonding', 'ad_actor_sys_prio'))
332 self
.assertEqual('811', self
.read_link_attr('bond99', 'bonding', 'ad_user_port_key'))
333 self
.assertEqual('00:11:22:33:44:55', self
.read_link_attr('bond99', 'bonding', 'ad_actor_system'))
335 def test_bond_balanced_tlb(self
):
336 self
.copy_unit_to_networkd_unit_path('25-bond-balanced-tlb.netdev')
337 self
.start_networkd()
339 self
.assertTrue(self
.link_exits('bond99'))
341 self
.assertEqual('balance-tlb 5', self
.read_link_attr('bond99', 'bonding', 'mode'))
342 self
.assertEqual('1', self
.read_link_attr('bond99', 'bonding', 'tlb_dynamic_lb'))
345 self
.copy_unit_to_networkd_unit_path('21-vlan.netdev', '11-dummy.netdev',
346 '21-vlan.network', '21-vlan-test1.network')
347 self
.start_networkd()
349 self
.assertTrue(self
.link_exits('test1'))
350 self
.assertTrue(self
.link_exits('vlan99'))
352 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'test1']).rstrip().decode('utf-8')
354 self
.assertTrue(output
, ' mtu 2004 ')
356 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vlan99']).rstrip().decode('utf-8')
358 self
.assertTrue(output
, ' mtu 2000 ')
359 self
.assertTrue(output
, 'REORDER_HDR')
360 self
.assertTrue(output
, 'LOOSE_BINDING')
361 self
.assertTrue(output
, 'GVRP')
362 self
.assertTrue(output
, 'MVRP')
363 self
.assertTrue(output
, ' id 99 ')
365 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'test1']).rstrip().decode('utf-8')
367 self
.assertRegex(output
, 'inet 192.168.24.5/24 brd 192.168.24.255 scope global test1')
368 self
.assertRegex(output
, 'inet 192.168.25.5/24 brd 192.168.25.255 scope global test1')
370 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'vlan99']).rstrip().decode('utf-8')
372 self
.assertRegex(output
, 'inet 192.168.23.5/24 brd 192.168.23.255 scope global vlan99')
374 def test_macvtap(self
):
375 self
.copy_unit_to_networkd_unit_path('21-macvtap.netdev', '11-dummy.netdev', 'macvtap.network')
376 self
.start_networkd()
378 self
.assertTrue(self
.link_exits('macvtap99'))
380 def test_macvlan(self
):
381 self
.copy_unit_to_networkd_unit_path('21-macvlan.netdev', '11-dummy.netdev', 'macvlan.network')
382 self
.start_networkd()
384 self
.assertTrue(self
.link_exits('test1'))
385 self
.assertTrue(self
.link_exits('macvlan99'))
387 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'test1']).rstrip().decode('utf-8')
389 self
.assertTrue(output
, ' mtu 2000 ')
391 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'macvlan99']).rstrip().decode('utf-8')
393 self
.assertTrue(output
, ' mtu 2000 ')
395 @expectedFailureIfModuleIsNotAvailable('ipvlan')
396 def test_ipvlan(self
):
397 self
.copy_unit_to_networkd_unit_path('25-ipvlan.netdev', '11-dummy.netdev', 'ipvlan.network')
398 self
.start_networkd()
400 self
.assertTrue(self
.link_exits('ipvlan99'))
403 self
.copy_unit_to_networkd_unit_path('25-veth.netdev')
404 self
.start_networkd()
406 self
.assertTrue(self
.link_exits('veth99'))
408 def test_dummy(self
):
409 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev')
410 self
.start_networkd()
412 self
.assertTrue(self
.link_exits('test1'))
415 self
.copy_unit_to_networkd_unit_path('25-tun.netdev')
416 self
.start_networkd()
418 self
.assertTrue(self
.link_exits('tun99'))
421 self
.copy_unit_to_networkd_unit_path('25-tap.netdev')
422 self
.start_networkd()
424 self
.assertTrue(self
.link_exits('tap99'))
426 @expectedFailureIfModuleIsNotAvailable('vrf')
428 self
.copy_unit_to_networkd_unit_path('25-vrf.netdev')
429 self
.start_networkd()
431 self
.assertTrue(self
.link_exits('vrf99'))
433 @expectedFailureIfModuleIsNotAvailable('vcan')
435 self
.copy_unit_to_networkd_unit_path('25-vcan.netdev')
436 self
.start_networkd()
438 self
.assertTrue(self
.link_exits('vcan99'))
440 @expectedFailureIfModuleIsNotAvailable('wireguard')
441 def test_wireguard(self
):
442 self
.copy_unit_to_networkd_unit_path('25-wireguard.netdev')
443 self
.start_networkd()
445 if shutil
.which('wg'):
446 subprocess
.call('wg')
447 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'listen-port']).rstrip().decode('utf-8')
448 self
.assertTrue(output
, '51820')
449 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'fwmark']).rstrip().decode('utf-8')
450 self
.assertTrue(output
, '0x4d2')
451 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'allowed-ips']).rstrip().decode('utf-8')
452 self
.assertTrue(output
, 'RDf+LSpeEre7YEIKaxg+wbpsNV7du+ktR99uBEtIiCA=\t192.168.26.0/24 fd31:bf08:57cb::/48')
453 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'persistent-keepalive']).rstrip().decode('utf-8')
454 self
.assertTrue(output
, 'RDf+LSpeEre7YEIKaxg+wbpsNV7du+ktR99uBEtIiCA=\t20')
455 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'endpoints']).rstrip().decode('utf-8')
456 self
.assertTrue(output
, 'RDf+LSpeEre7YEIKaxg+wbpsNV7du+ktR99uBEtIiCA=\t192.168.27.3:51820')
458 self
.assertTrue(self
.link_exits('wg99'))
460 @expectedFailureIfModuleIsNotAvailable('wireguard')
461 def test_wireguard_23_peers(self
):
462 self
.copy_unit_to_networkd_unit_path('25-wireguard-23-peers.netdev', '25-wireguard-23-peers.network')
463 self
.start_networkd()
465 if shutil
.which('wg'):
466 subprocess
.call('wg')
468 self
.assertTrue(self
.link_exits('wg98'))
470 def test_geneve(self
):
471 self
.copy_unit_to_networkd_unit_path('25-geneve.netdev')
472 self
.start_networkd()
474 self
.assertTrue(self
.link_exits('geneve99'))
476 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'geneve99']).rstrip().decode('utf-8')
478 self
.assertTrue(output
, '192.168.22.1')
479 self
.assertTrue(output
, '6082')
480 self
.assertTrue(output
, 'udpcsum')
481 self
.assertTrue(output
, 'udp6zerocsumrx')
483 def test_ipip_tunnel(self
):
484 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-ipip-tunnel.netdev', 'ipip.network')
485 self
.start_networkd()
487 self
.assertTrue(self
.link_exits('dummy98'))
488 self
.assertTrue(self
.link_exits('ipiptun99'))
490 def test_gre_tunnel(self
):
491 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-gre-tunnel.netdev', 'gretun.network')
492 self
.start_networkd()
494 self
.assertTrue(self
.link_exits('dummy98'))
495 self
.assertTrue(self
.link_exits('gretun99'))
497 def test_gretap_tunnel(self
):
498 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-gretap-tunnel.netdev', 'gretap.network')
499 self
.start_networkd()
501 self
.assertTrue(self
.link_exits('dummy98'))
502 self
.assertTrue(self
.link_exits('gretap99'))
504 def test_ip6gretap_tunnel(self
):
505 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-ip6gre-tunnel.netdev', 'ip6gretap.network')
506 self
.start_networkd()
508 self
.assertTrue(self
.link_exits('dummy98'))
509 self
.assertTrue(self
.link_exits('ip6gretap99'))
511 def test_vti_tunnel(self
):
512 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-vti-tunnel.netdev', 'vti.network')
513 self
.start_networkd()
515 self
.assertTrue(self
.link_exits('dummy98'))
516 self
.assertTrue(self
.link_exits('vtitun99'))
518 def test_vti6_tunnel(self
):
519 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-vti6-tunnel.netdev', 'vti6.network')
520 self
.start_networkd()
522 self
.assertTrue(self
.link_exits('dummy98'))
523 self
.assertTrue(self
.link_exits('vti6tun99'))
525 def test_ip6tnl_tunnel(self
):
526 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-ip6tnl-tunnel.netdev', 'ip6tnl.network')
527 self
.start_networkd()
529 self
.assertTrue(self
.link_exits('dummy98'))
530 self
.assertTrue(self
.link_exits('ip6tnl99'))
532 def test_sit_tunnel(self
):
533 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-sit-tunnel.netdev', 'sit.network')
534 self
.start_networkd()
536 self
.assertTrue(self
.link_exits('dummy98'))
537 self
.assertTrue(self
.link_exits('sittun99'))
539 def test_isatap_tunnel(self
):
540 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-isatap-tunnel.netdev', 'isatap.network')
541 self
.start_networkd()
543 self
.assertTrue(self
.link_exits('dummy98'))
544 self
.assertTrue(self
.link_exits('isataptun99'))
546 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'isataptun99']).rstrip().decode('utf-8')
548 self
.assertRegex(output
, "isatap ")
550 def test_6rd_tunnel(self
):
551 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-6rd-tunnel.netdev', '6rd.network')
552 self
.start_networkd()
554 self
.assertTrue(self
.link_exits('dummy98'))
555 self
.assertTrue(self
.link_exits('sittun99'))
557 @expectedFailureIfERSPANModuleIsNotAvailable()
558 def test_erspan_tunnel(self
):
559 self
.copy_unit_to_networkd_unit_path('25-erspan-tunnel.netdev')
560 self
.start_networkd()
562 self
.assertTrue(self
.link_exits('erspan-test'))
564 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'erspan-test']).rstrip().decode('utf-8')
566 self
.assertTrue(output
, '172.16.1.200')
567 self
.assertTrue(output
, '172.16.1.100')
568 self
.assertTrue(output
, '101')
570 def test_tunnel_independent(self
):
571 self
.copy_unit_to_networkd_unit_path('25-ipip-tunnel-independent.netdev')
572 self
.start_networkd()
574 self
.assertTrue(self
.link_exits('ipiptun99'))
576 def test_vxlan(self
):
577 self
.copy_unit_to_networkd_unit_path('25-vxlan.netdev', 'vxlan.network','11-dummy.netdev')
578 self
.start_networkd()
580 self
.assertTrue(self
.link_exits('vxlan99'))
582 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vxlan99']).rstrip().decode('utf-8')
584 self
.assertRegex(output
, "999")
585 self
.assertRegex(output
, '5555')
586 self
.assertRegex(output
, 'l2miss')
587 self
.assertRegex(output
, 'l3miss')
588 self
.assertRegex(output
, 'udpcsum')
589 self
.assertRegex(output
, 'udp6zerocsumtx')
590 self
.assertRegex(output
, 'udp6zerocsumrx')
591 self
.assertRegex(output
, 'remcsumtx')
592 self
.assertRegex(output
, 'remcsumrx')
593 self
.assertRegex(output
, 'gbp')
595 class NetworkdNetWorkTests(unittest
.TestCase
, Utilities
):
605 '23-active-slave.network',
606 '23-bond199.network',
607 '23-primary-slave.network',
608 '23-test1-bond199.network',
609 '25-address-link-section.network',
610 '25-address-section-miscellaneous.network',
611 '25-address-section.network',
612 '25-bind-carrier.network',
613 '25-bond-active-backup-slave.netdev',
614 '25-fibrule-invert.network',
615 '25-fibrule-port-range.network',
616 '25-ipv6-address-label-section.network',
617 '25-neighbor-section.network',
618 '25-link-local-addressing-no.network',
619 '25-link-local-addressing-yes.network',
620 '25-link-section-unmanaged.network',
621 '25-route-gateway.network',
622 '25-route-gateway-on-link.network',
623 '25-route-ipv6-src.network',
624 '25-route-reverse-order.network',
625 '25-route-section.network',
626 '25-route-tcp-window-settings.network',
627 '25-route-type.network',
628 '25-sysctl-disable-ipv6.network',
630 'configure-without-carrier.network',
631 'routing-policy-rule-dummy98.network',
632 'routing-policy-rule-test1.network',
633 'test-static.network']
636 self
.link_remove(self
.links
)
639 self
.link_remove(self
.links
)
640 self
.remove_unit_from_networkd_path(self
.units
)
642 def test_static_address(self
):
643 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'test-static.network')
644 self
.start_networkd()
646 self
.assertTrue(self
.link_exits('dummy98'))
648 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
650 self
.assertRegex(output
, '192.168.0.15')
651 self
.assertRegex(output
, '192.168.0.1')
652 self
.assertRegex(output
, 'routable')
654 def test_configure_without_carrier(self
):
655 self
.copy_unit_to_networkd_unit_path('configure-without-carrier.network', '11-dummy.netdev')
656 self
.start_networkd()
658 self
.assertTrue(self
.link_exits('test1'))
660 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
662 self
.assertRegex(output
, '192.168.0.15')
663 self
.assertRegex(output
, '192.168.0.1')
664 self
.assertRegex(output
, 'routable')
666 def test_bond_active_slave(self
):
667 self
.copy_unit_to_networkd_unit_path('23-active-slave.network', '23-bond199.network', '25-bond-active-backup-slave.netdev', '12-dummy.netdev')
668 self
.start_networkd()
670 self
.assertTrue(self
.link_exits('dummy98'))
671 self
.assertTrue(self
.link_exits('bond199'))
673 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'bond199']).rstrip().decode('utf-8')
675 self
.assertRegex(output
, 'active_slave dummy98')
677 def test_bond_primary_slave(self
):
678 self
.copy_unit_to_networkd_unit_path('23-primary-slave.network', '23-test1-bond199.network', '25-bond-active-backup-slave.netdev', '11-dummy.netdev')
679 self
.start_networkd()
681 self
.assertTrue(self
.link_exits('test1'))
682 self
.assertTrue(self
.link_exits('bond199'))
684 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'bond199']).rstrip().decode('utf-8')
686 self
.assertRegex(output
, 'primary test1')
688 def test_routing_policy_rule(self
):
689 self
.copy_unit_to_networkd_unit_path('routing-policy-rule-test1.network', '11-dummy.netdev')
691 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
693 self
.start_networkd()
695 self
.assertTrue(self
.link_exits('test1'))
697 output
= subprocess
.check_output(['ip', 'rule']).rstrip().decode('utf-8')
699 self
.assertRegex(output
, '111')
700 self
.assertRegex(output
, 'from 192.168.100.18')
701 self
.assertRegex(output
, r
'tos (?:0x08|throughput)\s')
702 self
.assertRegex(output
, 'iif test1')
703 self
.assertRegex(output
, 'oif test1')
704 self
.assertRegex(output
, 'lookup 7')
706 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
708 def test_routing_policy_rule_issue_11280(self
):
709 self
.copy_unit_to_networkd_unit_path('routing-policy-rule-test1.network', '11-dummy.netdev',
710 'routing-policy-rule-dummy98.network', '12-dummy.netdev')
712 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
713 subprocess
.call(['ip', 'rule', 'del', 'table', '8'])
715 for trial
in range(3):
716 # Remove state files only first time
717 self
.start_networkd(trial
== 0)
719 self
.assertTrue(self
.link_exits('test1'))
720 self
.assertTrue(self
.link_exits('dummy98'))
722 output
= subprocess
.check_output(['ip', 'rule', 'list', 'table', '7']).rstrip().decode('utf-8')
724 self
.assertRegex(output
, '111: from 192.168.100.18 tos (?:0x08|throughput) iif test1 oif test1 lookup 7')
726 output
= subprocess
.check_output(['ip', 'rule', 'list', 'table', '8']).rstrip().decode('utf-8')
728 self
.assertRegex(output
, '112: from 192.168.101.18 tos (?:0x08|throughput) iif dummy98 oif dummy98 lookup 8')
730 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
731 subprocess
.call(['ip', 'rule', 'del', 'table', '8'])
733 @expectedFailureIfRoutingPolicyPortRangeIsNotAvailable()
734 def test_routing_policy_rule_port_range(self
):
735 self
.copy_unit_to_networkd_unit_path('25-fibrule-port-range.network', '11-dummy.netdev')
737 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
739 self
.start_networkd()
741 self
.assertTrue(self
.link_exits('test1'))
743 output
= subprocess
.check_output(['ip', 'rule']).rstrip().decode('utf-8')
745 self
.assertRegex(output
, '111')
746 self
.assertRegex(output
, 'from 192.168.100.18')
747 self
.assertRegex(output
, '1123-1150')
748 self
.assertRegex(output
, '3224-3290')
749 self
.assertRegex(output
, 'tcp')
750 self
.assertRegex(output
, 'lookup 7')
752 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
754 @expectedFailureIfRoutingPolicyIPProtoIsNotAvailable()
755 def test_routing_policy_rule_invert(self
):
756 self
.copy_unit_to_networkd_unit_path('25-fibrule-invert.network', '11-dummy.netdev')
758 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
760 self
.start_networkd()
762 self
.assertTrue(self
.link_exits('test1'))
764 output
= subprocess
.check_output(['ip', 'rule']).rstrip().decode('utf-8')
766 self
.assertRegex(output
, '111')
767 self
.assertRegex(output
, 'not.*?from.*?192.168.100.18')
768 self
.assertRegex(output
, 'tcp')
769 self
.assertRegex(output
, 'lookup 7')
771 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
773 def test_address_peer(self
):
774 self
.copy_unit_to_networkd_unit_path('25-address-section.network', '12-dummy.netdev')
775 self
.start_networkd()
777 self
.assertTrue(self
.link_exits('dummy98'))
779 # This also tests address pool
781 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'dummy98', 'label', '32']).rstrip().decode('utf-8')
783 self
.assertRegex(output
, 'inet 10.2.3.4 peer 10.2.3.5/16 scope global 32')
785 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'dummy98', 'label', '33']).rstrip().decode('utf-8')
787 self
.assertRegex(output
, 'inet 10.6.7.8/16 brd 10.6.255.255 scope global 33')
789 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'dummy98', 'label', '34']).rstrip().decode('utf-8')
791 self
.assertRegex(output
, 'inet 192.168.[0-9]*.1/24 brd 192.168.[0-9]*.255 scope global 34')
793 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'dummy98', 'label', '35']).rstrip().decode('utf-8')
795 self
.assertRegex(output
, 'inet 172.[0-9]*.0.1/16 brd 172.[0-9]*.255.255 scope global 35')
797 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'dummy98']).rstrip().decode('utf-8')
799 self
.assertRegex(output
, 'inet6 2001:db8::20 peer 2001:db8::10/128 scope global')
800 self
.assertRegex(output
, 'inet6 fd[0-9a-f:]*1/64 scope global')
802 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
804 self
.assertRegex(output
, 'State: routable \(configured\)')
806 def test_address_preferred_lifetime_zero_ipv6(self
):
807 self
.copy_unit_to_networkd_unit_path('25-address-section-miscellaneous.network', '12-dummy.netdev')
808 self
.start_networkd()
810 self
.assertTrue(self
.link_exits('dummy98'))
812 output
= subprocess
.check_output(['ip', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
814 self
.assertRegex(output
, 'inet 10.2.3.4/16 brd 10.2.255.255 scope link deprecated dummy98')
815 self
.assertRegex(output
, 'inet6 2001:db8:0:f101::1/64 scope global')
817 def test_ip_route(self
):
818 self
.copy_unit_to_networkd_unit_path('25-route-section.network', '12-dummy.netdev')
819 self
.start_networkd()
821 self
.assertTrue(self
.link_exits('dummy98'))
823 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'dummy98']).rstrip().decode('utf-8')
825 self
.assertRegex(output
, '192.168.0.1')
826 self
.assertRegex(output
, 'static')
827 self
.assertRegex(output
, '192.168.0.0/24')
829 def test_ip_route_reverse(self
):
830 self
.copy_unit_to_networkd_unit_path('25-route-reverse-order.network', '12-dummy.netdev')
831 self
.start_networkd()
833 self
.assertTrue(self
.link_exits('dummy98'))
835 output
= subprocess
.check_output(['ip', '-6', 'route', 'show', 'dev', 'dummy98']).rstrip().decode('utf-8')
837 self
.assertRegex(output
, '2001:1234:5:8fff:ff:ff:ff:ff')
838 self
.assertRegex(output
, '2001:1234:5:8f63::1')
840 def test_ip_route_blackhole_unreachable_prohibit(self
):
841 self
.copy_unit_to_networkd_unit_path('25-route-type.network', '12-dummy.netdev')
842 self
.start_networkd()
844 self
.assertTrue(self
.link_exits('dummy98'))
846 output
= subprocess
.check_output(['ip', 'route', 'list']).rstrip().decode('utf-8')
848 self
.assertRegex(output
, 'blackhole')
849 self
.assertRegex(output
, 'unreachable')
850 self
.assertRegex(output
, 'prohibit')
852 subprocess
.call(['ip', 'route', 'del', 'blackhole', '202.54.1.2'])
853 subprocess
.call(['ip', 'route', 'del', 'unreachable', '202.54.1.3'])
854 subprocess
.call(['ip', 'route', 'del', 'prohibit', '202.54.1.4'])
856 def test_ip_route_tcp_window(self
):
857 self
.copy_unit_to_networkd_unit_path('25-route-tcp-window-settings.network', '11-dummy.netdev')
858 self
.start_networkd()
860 self
.assertTrue(self
.link_exits('test1'))
862 output
= subprocess
.check_output(['ip', 'route', 'list']).rstrip().decode('utf-8')
864 self
.assertRegex(output
, 'initcwnd 20')
865 self
.assertRegex(output
, 'initrwnd 30')
867 def test_ip_route_gateway(self
):
868 self
.copy_unit_to_networkd_unit_path('25-route-gateway.network', '12-dummy.netdev')
869 self
.start_networkd()
871 self
.assertTrue(self
.link_exits('dummy98'))
873 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'dummy98', 'default']).rstrip().decode('utf-8')
875 self
.assertRegex(output
, 'default')
876 self
.assertRegex(output
, 'via')
877 self
.assertRegex(output
, '149.10.124.64')
878 self
.assertRegex(output
, 'proto')
879 self
.assertRegex(output
, 'static')
881 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'dummy98', 'src', '149.10.124.58']).rstrip().decode('utf-8')
883 self
.assertRegex(output
, '149.10.124.48/28')
884 self
.assertRegex(output
, 'proto')
885 self
.assertRegex(output
, 'kernel')
886 self
.assertRegex(output
, 'scope')
887 self
.assertRegex(output
, 'link')
889 def test_ip_route_gateway_on_link(self
):
890 self
.copy_unit_to_networkd_unit_path('25-route-gateway-on-link.network', '12-dummy.netdev')
891 self
.start_networkd()
893 self
.assertTrue(self
.link_exits('dummy98'))
895 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'dummy98', 'default']).rstrip().decode('utf-8')
897 self
.assertRegex(output
, 'default')
898 self
.assertRegex(output
, 'via')
899 self
.assertRegex(output
, '149.10.125.65')
900 self
.assertRegex(output
, 'proto')
901 self
.assertRegex(output
, 'static')
902 self
.assertRegex(output
, 'onlink')
904 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'dummy98', 'src', '149.10.124.58']).rstrip().decode('utf-8')
906 self
.assertRegex(output
, '149.10.124.48/28')
907 self
.assertRegex(output
, 'proto')
908 self
.assertRegex(output
, 'kernel')
909 self
.assertRegex(output
, 'scope')
910 self
.assertRegex(output
, 'link')
912 def test_ip_route_ipv6_src_route(self
):
913 # a dummy device does not make the addresses go through tentative state, so we
914 # reuse a bond from an earlier test, which does make the addresses go through
915 # tentative state, and do our test on that
916 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')
917 self
.start_networkd()
919 self
.assertTrue(self
.link_exits('dummy98'))
920 self
.assertTrue(self
.link_exits('bond199'))
922 output
= subprocess
.check_output(['ip', '-6', 'route', 'list', 'dev', 'bond199']).rstrip().decode('utf-8')
924 self
.assertRegex(output
, 'abcd::/16')
925 self
.assertRegex(output
, 'src')
926 self
.assertRegex(output
, '2001:1234:56:8f63::2')
928 def test_ip_link_mac_address(self
):
929 self
.copy_unit_to_networkd_unit_path('25-address-link-section.network', '12-dummy.netdev')
930 self
.start_networkd()
932 self
.assertTrue(self
.link_exits('dummy98'))
934 output
= subprocess
.check_output(['ip', 'link', 'show', 'dummy98']).rstrip().decode('utf-8')
936 self
.assertRegex(output
, '00:01:02:aa:bb:cc')
938 def test_ip_link_unmanaged(self
):
939 self
.copy_unit_to_networkd_unit_path('25-link-section-unmanaged.network', '12-dummy.netdev')
940 self
.start_networkd()
942 self
.assertTrue(self
.link_exits('dummy98'))
944 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
946 self
.assertRegex(output
, 'unmanaged')
948 def test_ipv6_address_label(self
):
949 self
.copy_unit_to_networkd_unit_path('25-ipv6-address-label-section.network', '12-dummy.netdev')
950 self
.start_networkd()
952 self
.assertTrue(self
.link_exits('dummy98'))
954 output
= subprocess
.check_output(['ip', 'addrlabel', 'list']).rstrip().decode('utf-8')
956 self
.assertRegex(output
, '2004:da8:1::/64')
958 def test_ipv6_neighbor(self
):
959 self
.copy_unit_to_networkd_unit_path('25-neighbor-section.network', '12-dummy.netdev')
960 self
.start_networkd()
962 self
.assertTrue(self
.link_exits('dummy98'))
964 output
= subprocess
.check_output(['ip', 'neigh', 'list']).rstrip().decode('utf-8')
966 self
.assertRegex(output
, '192.168.10.1.*00:00:5e:00:02:65.*PERMANENT')
967 self
.assertRegex(output
, '2004:da8:1::1.*00:00:5e:00:02:66.*PERMANENT')
969 def test_link_local_addressing(self
):
970 self
.copy_unit_to_networkd_unit_path('25-link-local-addressing-yes.network', '11-dummy.netdev',
971 '25-link-local-addressing-no.network', '12-dummy.netdev')
972 self
.start_networkd()
974 self
.assertTrue(self
.link_exits('test1'))
975 self
.assertTrue(self
.link_exits('dummy98'))
979 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'test1']).rstrip().decode('utf-8')
981 self
.assertRegex(output
, 'inet .* scope link')
982 self
.assertRegex(output
, 'inet6 .* scope link')
984 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'dummy98']).rstrip().decode('utf-8')
986 self
.assertNotRegex(output
, 'inet6* .* scope link')
988 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
990 self
.assertRegex(output
, 'State: degraded \(configured\)')
992 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
994 self
.assertRegex(output
, 'State: carrier \(configured\)')
997 Documentation/networking/ip-sysctl.txt
999 addr_gen_mode - INTEGER
1000 Defines how link-local and autoconf addresses are generated.
1002 0: generate address based on EUI64 (default)
1003 1: do no generate a link-local address, use EUI64 for addresses generated
1005 2: generate stable privacy addresses, using the secret from
1006 stable_secret (RFC7217)
1007 3: generate stable privacy addresses, using a random secret if unset
1010 test1_addr_gen_mode
= ''
1011 if os
.path
.exists(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, 'test1'), 'stable_secret')):
1012 with
open(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, 'test1'), 'stable_secret')) as f
:
1016 # if stable_secret is unset, then EIO is returned
1017 test1_addr_gen_mode
= '0'
1019 test1_addr_gen_mode
= '2'
1021 test1_addr_gen_mode
= '0'
1023 if os
.path
.exists(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, 'test1'), 'addr_gen_mode')):
1024 self
.assertEqual(self
.read_ipv6_sysctl_attr('test1', 'addr_gen_mode'), '0')
1026 if os
.path
.exists(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, 'dummy98'), 'addr_gen_mode')):
1027 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'addr_gen_mode'), '1')
1029 def test_sysctl(self
):
1030 self
.copy_unit_to_networkd_unit_path('25-sysctl.network', '12-dummy.netdev')
1031 self
.start_networkd()
1033 self
.assertTrue(self
.link_exits('dummy98'))
1035 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'forwarding'), '1')
1036 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'use_tempaddr'), '2')
1037 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'dad_transmits'), '3')
1038 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'hop_limit'), '5')
1039 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'proxy_ndp'), '1')
1040 self
.assertEqual(self
.read_ipv4_sysctl_attr('dummy98', 'forwarding'),'1')
1041 self
.assertEqual(self
.read_ipv4_sysctl_attr('dummy98', 'proxy_arp'), '1')
1043 def test_sysctl_disable_ipv6(self
):
1044 self
.copy_unit_to_networkd_unit_path('25-sysctl-disable-ipv6.network', '12-dummy.netdev')
1046 print('## Disable ipv6')
1047 self
.assertEqual(subprocess
.call(['sysctl', 'net.ipv6.conf.all.disable_ipv6=1']), 0)
1048 self
.assertEqual(subprocess
.call(['sysctl', 'net.ipv6.conf.default.disable_ipv6=1']), 0)
1050 self
.start_networkd()
1052 self
.assertTrue(self
.link_exits('dummy98'))
1054 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
1056 self
.assertRegex(output
, 'inet 10.2.3.4/16 brd 10.2.255.255 scope global dummy98')
1057 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
1059 self
.assertEqual(output
, '')
1060 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1061 self
.assertRegex(output
, 'State: routable \(configured\)')
1063 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1065 print('## Enable ipv6')
1066 self
.assertEqual(subprocess
.call(['sysctl', 'net.ipv6.conf.all.disable_ipv6=0']), 0)
1067 self
.assertEqual(subprocess
.call(['sysctl', 'net.ipv6.conf.default.disable_ipv6=0']), 0)
1069 self
.start_networkd()
1071 self
.assertTrue(self
.link_exits('dummy98'))
1073 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
1075 self
.assertRegex(output
, 'inet 10.2.3.4/16 brd 10.2.255.255 scope global dummy98')
1076 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
1078 self
.assertRegex(output
, 'inet6 .* scope link')
1079 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1080 self
.assertRegex(output
, 'State: routable \(configured\)')
1082 def test_bind_carrier(self
):
1083 self
.copy_unit_to_networkd_unit_path('25-bind-carrier.network', '11-dummy.netdev')
1084 self
.start_networkd()
1086 self
.assertTrue(self
.link_exits('test1'))
1088 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1089 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1091 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1']).rstrip().decode('utf-8')
1093 self
.assertRegex(output
, 'UP,LOWER_UP')
1094 self
.assertRegex(output
, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
1095 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1096 self
.assertRegex(output
, 'State: routable \(configured\)')
1098 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy99', 'type', 'dummy']), 0)
1099 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy99', 'up']), 0)
1101 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1']).rstrip().decode('utf-8')
1103 self
.assertRegex(output
, 'UP,LOWER_UP')
1104 self
.assertRegex(output
, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
1105 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1106 self
.assertRegex(output
, 'State: routable \(configured\)')
1108 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1110 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1']).rstrip().decode('utf-8')
1112 self
.assertRegex(output
, 'UP,LOWER_UP')
1113 self
.assertRegex(output
, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
1114 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1115 self
.assertRegex(output
, 'State: routable \(configured\)')
1117 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy99']), 0)
1119 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1']).rstrip().decode('utf-8')
1121 self
.assertNotRegex(output
, 'UP,LOWER_UP')
1122 self
.assertRegex(output
, 'DOWN')
1123 self
.assertNotRegex(output
, '192.168.10')
1124 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1125 self
.assertRegex(output
, 'State: off \(configured\)')
1127 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1128 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1130 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1']).rstrip().decode('utf-8')
1132 self
.assertRegex(output
, 'UP,LOWER_UP')
1133 self
.assertRegex(output
, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
1134 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1135 self
.assertRegex(output
, 'State: routable \(configured\)')
1137 class NetworkdNetWorkBondTests(unittest
.TestCase
, Utilities
):
1148 'bond-slave.network']
1151 self
.link_remove(self
.links
)
1154 self
.link_remove(self
.links
)
1155 self
.remove_unit_from_networkd_path(self
.units
)
1157 def test_bond_operstate(self
):
1158 self
.copy_unit_to_networkd_unit_path('25-bond.netdev', '11-dummy.netdev', '12-dummy.netdev',
1159 'bond99.network','bond-slave.network')
1160 self
.start_networkd()
1162 self
.assertTrue(self
.link_exits('bond99'))
1163 self
.assertTrue(self
.link_exits('dummy98'))
1164 self
.assertTrue(self
.link_exits('test1'))
1166 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'dummy98']).rstrip().decode('utf-8')
1168 self
.assertRegex(output
, 'SLAVE,UP,LOWER_UP')
1170 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'test1']).rstrip().decode('utf-8')
1172 self
.assertRegex(output
, 'SLAVE,UP,LOWER_UP')
1174 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'bond99']).rstrip().decode('utf-8')
1176 self
.assertRegex(output
, 'MASTER,UP,LOWER_UP')
1178 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1180 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1182 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1184 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1186 output
= subprocess
.check_output(['networkctl', 'status', 'bond99']).rstrip().decode('utf-8')
1188 self
.assertRegex(output
, 'State: routable \(configured\)')
1190 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'down']), 0)
1193 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1195 self
.assertRegex(output
, 'State: off \(configured\)')
1197 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1199 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1201 output
= subprocess
.check_output(['networkctl', 'status', 'bond99']).rstrip().decode('utf-8')
1203 self
.assertRegex(output
, 'State: degraded \(configured\)')
1205 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1208 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1210 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1212 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1214 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1216 output
= subprocess
.check_output(['networkctl', 'status', 'bond99']).rstrip().decode('utf-8')
1218 self
.assertRegex(output
, 'State: routable \(configured\)')
1220 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'down']), 0)
1221 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'test1', 'down']), 0)
1224 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1226 self
.assertRegex(output
, 'State: off \(configured\)')
1228 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1230 self
.assertRegex(output
, 'State: off \(configured\)')
1232 output
= subprocess
.check_output(['networkctl', 'status', 'bond99']).rstrip().decode('utf-8')
1234 self
.assertRegex(output
, 'State: degraded \(configured\)')
1236 class NetworkdNetWorkBridgeTests(unittest
.TestCase
, Utilities
):
1246 '26-bridge-slave-interface-1.network',
1247 '26-bridge-slave-interface-2.network',
1248 'bridge99-ignore-carrier-loss.network',
1252 self
.link_remove(self
.links
)
1255 self
.link_remove(self
.links
)
1256 self
.remove_unit_from_networkd_path(self
.units
)
1258 def test_bridge_property(self
):
1259 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev', '12-dummy.netdev', '26-bridge.netdev',
1260 '26-bridge-slave-interface-1.network', '26-bridge-slave-interface-2.network',
1262 self
.start_networkd()
1264 self
.assertTrue(self
.link_exits('dummy98'))
1265 self
.assertTrue(self
.link_exits('test1'))
1266 self
.assertTrue(self
.link_exits('bridge99'))
1268 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'test1']).rstrip().decode('utf-8')
1270 self
.assertRegex(output
, 'master')
1271 self
.assertRegex(output
, 'bridge')
1273 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'dummy98']).rstrip().decode('utf-8')
1275 self
.assertRegex(output
, 'master')
1276 self
.assertRegex(output
, 'bridge')
1278 output
= subprocess
.check_output(['ip', 'addr', 'show', 'bridge99']).rstrip().decode('utf-8')
1280 self
.assertRegex(output
, '192.168.0.15/24')
1282 output
= subprocess
.check_output(['bridge', '-d', 'link', 'show', 'dummy98']).rstrip().decode('utf-8')
1284 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'hairpin_mode'), '1')
1285 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'path_cost'), '400')
1286 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'unicast_flood'), '1')
1287 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'multicast_fast_leave'), '1')
1289 # CONFIG_BRIDGE_IGMP_SNOOPING=y
1290 if (os
.path
.exists('/sys/devices/virtual/net/bridge00/lower_dummy98/brport/multicast_to_unicast')):
1291 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'multicast_to_unicast'), '1')
1293 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1294 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1296 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1297 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1299 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
1300 self
.assertRegex(output
, 'State: routable \(configured\)')
1302 self
.assertEqual(subprocess
.call(['ip', 'address', 'add', '192.168.0.16/24', 'dev', 'bridge99']), 0)
1305 output
= subprocess
.check_output(['ip', 'addr', 'show', 'bridge99']).rstrip().decode('utf-8')
1307 self
.assertRegex(output
, '192.168.0.16/24')
1309 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
1310 self
.assertRegex(output
, 'State: routable \(configured\)')
1312 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'test1']), 0)
1315 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
1316 self
.assertRegex(output
, 'State: degraded \(configured\)')
1318 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1321 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
1322 self
.assertRegex(output
, 'State: no-carrier \(configured\)')
1324 output
= subprocess
.check_output(['ip', 'address', 'show', 'bridge99']).rstrip().decode('utf-8')
1326 self
.assertRegex(output
, 'NO-CARRIER')
1327 self
.assertNotRegex(output
, '192.168.0.15/24')
1328 self
.assertNotRegex(output
, '192.168.0.16/24')
1330 def test_bridge_ignore_carrier_loss(self
):
1331 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev', '12-dummy.netdev', '26-bridge.netdev',
1332 '26-bridge-slave-interface-1.network', '26-bridge-slave-interface-2.network',
1333 'bridge99-ignore-carrier-loss.network')
1335 subprocess
.call(['ip', 'rule', 'del', 'table', '100'])
1337 self
.start_networkd()
1339 self
.assertTrue(self
.link_exits('dummy98'))
1340 self
.assertTrue(self
.link_exits('test1'))
1341 self
.assertTrue(self
.link_exits('bridge99'))
1343 self
.assertEqual(subprocess
.call(['ip', 'address', 'add', '192.168.0.16/24', 'dev', 'bridge99']), 0)
1346 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'test1']), 0)
1347 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1350 output
= subprocess
.check_output(['ip', 'address', 'show', 'bridge99']).rstrip().decode('utf-8')
1352 self
.assertRegex(output
, 'NO-CARRIER')
1353 self
.assertRegex(output
, 'inet 192.168.0.15/24 brd 192.168.0.255 scope global bridge99')
1354 self
.assertRegex(output
, 'inet 192.168.0.16/24 scope global secondary bridge99')
1356 subprocess
.call(['ip', 'rule', 'del', 'table', '100'])
1358 def test_bridge_ignore_carrier_loss_frequent_loss_and_gain(self
):
1359 self
.copy_unit_to_networkd_unit_path('26-bridge.netdev', '26-bridge-slave-interface-1.network',
1360 'bridge99-ignore-carrier-loss.network')
1362 subprocess
.call(['ip', 'rule', 'del', 'table', '100'])
1364 self
.start_networkd()
1366 self
.assertTrue(self
.link_exits('bridge99'))
1368 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1369 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1370 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1372 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1373 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1374 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1376 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1377 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1378 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1380 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1381 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1385 output
= subprocess
.check_output(['ip', 'address', 'show', 'bridge99']).rstrip().decode('utf-8')
1387 self
.assertRegex(output
, 'inet 192.168.0.15/24 brd 192.168.0.255 scope global bridge99')
1389 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
1390 self
.assertRegex(output
, 'State: routable \(configured\)')
1392 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1393 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1395 output
= subprocess
.check_output(['ip', 'rule', 'list', 'table', '100']).rstrip().decode('utf-8')
1397 self
.assertEqual(output
, '0: from all to 8.8.8.8 lookup 100')
1399 subprocess
.call(['ip', 'rule', 'del', 'table', '100'])
1401 class NetworkdNetWorkLLDPTests(unittest
.TestCase
, Utilities
):
1405 '23-emit-lldp.network',
1410 self
.link_remove(self
.links
)
1413 self
.link_remove(self
.links
)
1414 self
.remove_unit_from_networkd_path(self
.units
)
1416 def test_lldp(self
):
1417 self
.copy_unit_to_networkd_unit_path('23-emit-lldp.network', '24-lldp.network', '25-veth.netdev')
1418 self
.start_networkd()
1420 self
.assertTrue(self
.link_exits('veth99'))
1422 output
= subprocess
.check_output(['networkctl', 'lldp']).rstrip().decode('utf-8')
1424 self
.assertRegex(output
, 'veth-peer')
1425 self
.assertRegex(output
, 'veth99')
1427 class NetworkdNetworkRATests(unittest
.TestCase
, Utilities
):
1432 'ipv6-prefix.network',
1433 'ipv6-prefix-veth.network']
1436 self
.link_remove(self
.links
)
1439 self
.link_remove(self
.links
)
1440 self
.remove_unit_from_networkd_path(self
.units
)
1442 def test_ipv6_prefix_delegation(self
):
1443 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'ipv6-prefix.network', 'ipv6-prefix-veth.network')
1444 self
.start_networkd()
1446 self
.assertTrue(self
.link_exits('veth99'))
1448 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1450 self
.assertRegex(output
, '2002:da8:1:0')
1452 class NetworkdNetworkDHCPServerTests(unittest
.TestCase
, Utilities
):
1459 '24-search-domain.network',
1461 'dhcp-client.network',
1462 'dhcp-client-timezone-router.network',
1463 'dhcp-server.network',
1464 'dhcp-server-timezone-router.network']
1467 self
.link_remove(self
.links
)
1470 self
.link_remove(self
.links
)
1471 self
.remove_unit_from_networkd_path(self
.units
)
1473 def test_dhcp_server(self
):
1474 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-client.network', 'dhcp-server.network')
1475 self
.start_networkd()
1477 self
.assertTrue(self
.link_exits('veth99'))
1479 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1481 self
.assertRegex(output
, '192.168.5.*')
1482 self
.assertRegex(output
, 'Gateway: 192.168.5.1')
1483 self
.assertRegex(output
, 'DNS: 192.168.5.1')
1484 self
.assertRegex(output
, 'NTP: 192.168.5.1')
1486 def test_domain(self
):
1487 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '24-search-domain.network')
1488 self
.start_networkd()
1490 self
.assertTrue(self
.link_exits('dummy98'))
1492 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1494 self
.assertRegex(output
, 'Address: 192.168.42.100')
1495 self
.assertRegex(output
, 'DNS: 192.168.42.1')
1496 self
.assertRegex(output
, 'Search Domains: one')
1498 def test_emit_router_timezone(self
):
1499 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-client-timezone-router.network', 'dhcp-server-timezone-router.network')
1500 self
.start_networkd()
1502 self
.assertTrue(self
.link_exits('veth99'))
1504 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1506 self
.assertRegex(output
, 'Gateway: 192.168.5.*')
1507 self
.assertRegex(output
, '192.168.5.*')
1508 self
.assertRegex(output
, 'Europe/Berlin')
1510 class NetworkdNetworkDHCPClientTests(unittest
.TestCase
, Utilities
):
1520 'dhcp-client-anonymize.network',
1521 'dhcp-client-critical-connection.network',
1522 'dhcp-client-gateway-onlink-implicit.network',
1523 'dhcp-client-ipv4-dhcp-settings.network',
1524 'dhcp-client-ipv4-only-ipv6-disabled.network',
1525 'dhcp-client-ipv4-only.network',
1526 'dhcp-client-ipv6-only.network',
1527 'dhcp-client-ipv6-rapid-commit.network',
1528 'dhcp-client-listen-port.network',
1529 'dhcp-client-route-metric.network',
1530 'dhcp-client-route-table.network',
1531 'dhcp-client-vrf.network',
1532 'dhcp-client.network',
1533 'dhcp-server-veth-peer.network',
1534 'dhcp-v4-server-veth-peer.network',
1538 self
.link_remove(self
.links
)
1539 self
.stop_dnsmasq(dnsmasq_pid_file
)
1542 self
.link_remove(self
.links
)
1543 self
.remove_unit_from_networkd_path(self
.units
)
1544 self
.stop_dnsmasq(dnsmasq_pid_file
)
1545 self
.remove_lease_file()
1546 self
.remove_log_file()
1548 def test_dhcp_client_ipv6_only(self
):
1549 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network')
1550 self
.start_networkd()
1552 self
.assertTrue(self
.link_exits('veth99'))
1554 self
.start_dnsmasq()
1556 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1558 self
.assertRegex(output
, '2600::')
1559 self
.assertNotRegex(output
, '192.168.5')
1561 def test_dhcp_client_ipv4_only(self
):
1562 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv4-only-ipv6-disabled.network')
1563 self
.start_networkd()
1565 self
.assertTrue(self
.link_exits('veth99'))
1567 self
.start_dnsmasq()
1569 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1571 self
.assertNotRegex(output
, '2600::')
1572 self
.assertRegex(output
, '192.168.5')
1574 def test_dhcp_client_ipv4_ipv6(self
):
1575 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network',
1576 'dhcp-client-ipv4-only.network')
1577 self
.start_networkd()
1579 self
.assertTrue(self
.link_exits('veth99'))
1581 self
.start_dnsmasq()
1583 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1585 self
.assertRegex(output
, '2600::')
1586 self
.assertRegex(output
, '192.168.5')
1588 def test_dhcp_client_settings(self
):
1589 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv4-dhcp-settings.network')
1590 self
.start_networkd()
1592 self
.assertTrue(self
.link_exits('veth99'))
1594 self
.start_dnsmasq()
1596 print('## ip address show dev veth99')
1597 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
1599 self
.assertRegex(output
, '12:34:56:78:9a:bc')
1600 self
.assertRegex(output
, '192.168.5')
1601 self
.assertRegex(output
, '1492')
1604 print('## ip route show table main dev veth99')
1605 output
= subprocess
.check_output(['ip', 'route', 'show', 'table', 'main', 'dev', 'veth99']).rstrip().decode('utf-8')
1607 self
.assertNotRegex(output
, 'proto dhcp')
1609 print('## ip route show table 211 dev veth99')
1610 output
= subprocess
.check_output(['ip', 'route', 'show', 'table', '211', 'dev', 'veth99']).rstrip().decode('utf-8')
1612 self
.assertRegex(output
, 'default via 192.168.5.1 proto dhcp')
1613 self
.assertRegex(output
, '192.168.5.0/24 via 192.168.5.5 proto dhcp')
1614 self
.assertRegex(output
, '192.168.5.1 proto dhcp scope link')
1616 print('## dnsmasq log')
1617 self
.assertTrue(self
.search_words_in_dnsmasq_log('vendor class: SusantVendorTest', True))
1618 self
.assertTrue(self
.search_words_in_dnsmasq_log('DHCPDISCOVER(veth-peer) 12:34:56:78:9a:bc'))
1619 self
.assertTrue(self
.search_words_in_dnsmasq_log('client provides name: test-hostname'))
1620 self
.assertTrue(self
.search_words_in_dnsmasq_log('26:mtu'))
1622 def test_dhcp6_client_settings_rapidcommit_true(self
):
1623 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network')
1624 self
.start_networkd()
1626 self
.assertTrue(self
.link_exits('veth99'))
1628 self
.start_dnsmasq()
1630 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
1632 self
.assertRegex(output
, '12:34:56:78:9a:bc')
1633 self
.assertTrue(self
.search_words_in_dnsmasq_log('14:rapid-commit', True))
1635 def test_dhcp6_client_settings_rapidcommit_false(self
):
1636 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-rapid-commit.network')
1637 self
.start_networkd()
1639 self
.assertTrue(self
.link_exits('veth99'))
1641 self
.start_dnsmasq()
1643 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
1645 self
.assertRegex(output
, '12:34:56:78:9a:bc')
1646 self
.assertFalse(self
.search_words_in_dnsmasq_log('14:rapid-commit', True))
1648 def test_dhcp_client_settings_anonymize(self
):
1649 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-anonymize.network')
1650 self
.start_networkd()
1652 self
.assertTrue(self
.link_exits('veth99'))
1654 self
.start_dnsmasq()
1656 self
.assertFalse(self
.search_words_in_dnsmasq_log('VendorClassIdentifier=SusantVendorTest', True))
1657 self
.assertFalse(self
.search_words_in_dnsmasq_log('test-hostname'))
1658 self
.assertFalse(self
.search_words_in_dnsmasq_log('26:mtu'))
1660 def test_dhcp_client_listen_port(self
):
1661 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-listen-port.network')
1662 self
.start_networkd()
1664 self
.assertTrue(self
.link_exits('veth99'))
1666 self
.start_dnsmasq('--dhcp-alternate-port=67,5555')
1668 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
1670 self
.assertRegex(output
, '192.168.5.* dynamic')
1672 def test_dhcp_route_table_id(self
):
1673 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-route-table.network')
1674 self
.start_networkd()
1676 self
.assertTrue(self
.link_exits('veth99'))
1678 self
.start_dnsmasq()
1680 output
= subprocess
.check_output(['ip', 'route', 'show', 'table', '12']).rstrip().decode('utf-8')
1682 self
.assertRegex(output
, 'veth99 proto dhcp')
1683 self
.assertRegex(output
, '192.168.5.1')
1685 def test_dhcp_route_metric(self
):
1686 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-route-metric.network')
1687 self
.start_networkd()
1689 self
.assertTrue(self
.link_exits('veth99'))
1691 self
.start_dnsmasq()
1693 output
= subprocess
.check_output(['ip', 'route', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
1695 self
.assertRegex(output
, 'metric 24')
1697 def test_dhcp_route_criticalconnection_true(self
):
1698 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-critical-connection.network')
1699 self
.start_networkd()
1701 self
.assertTrue(self
.link_exits('veth99'))
1703 self
.start_dnsmasq()
1705 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1707 self
.assertRegex(output
, '192.168.5.*')
1709 # Stoping dnsmasq as networkd won't be allowed to renew the DHCP lease.
1710 self
.stop_dnsmasq(dnsmasq_pid_file
)
1712 # Sleep for 120 sec as the dnsmasq minimum lease time can only be set to 120
1715 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1717 self
.assertRegex(output
, '192.168.5.*')
1719 def test_dhcp_client_reuse_address_as_static(self
):
1720 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client.network')
1721 self
.start_networkd()
1723 self
.assertTrue(self
.link_exits('veth99'))
1725 self
.start_dnsmasq()
1727 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99', 'scope', 'global']).rstrip().decode('utf-8')
1729 self
.assertRegex(output
, '192.168.5')
1730 self
.assertRegex(output
, '2600::')
1732 ipv4_address
= re
.search('192\.168\.5\.[0-9]*/24', output
)
1733 ipv6_address
= re
.search('2600::[0-9a-f:]*/128', output
)
1734 static_network
= '\n'.join(['[Match]', 'Name=veth99', '[Network]', 'IPv6AcceptRA=no', 'Address=' + ipv4_address
.group(), 'Address=' + ipv6_address
.group()])
1735 print(static_network
)
1737 self
.remove_unit_from_networkd_path(['dhcp-client.network'])
1739 with
open(os
.path
.join(network_unit_file_path
, 'static.network'), mode
='w') as f
:
1740 f
.write(static_network
)
1742 self
.start_networkd()
1744 self
.assertTrue(self
.link_exits('veth99'))
1746 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99', 'scope', 'global']).rstrip().decode('utf-8')
1748 self
.assertRegex(output
, '192.168.5')
1749 self
.assertRegex(output
, 'valid_lft forever preferred_lft forever')
1751 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'veth99', 'scope', 'global']).rstrip().decode('utf-8')
1753 self
.assertRegex(output
, '2600::')
1754 self
.assertRegex(output
, 'valid_lft forever preferred_lft forever')
1756 @expectedFailureIfModuleIsNotAvailable('vrf')
1757 def test_dhcp_client_vrf(self
):
1758 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-vrf.network',
1759 '25-vrf.netdev', '25-vrf.network')
1760 self
.start_networkd()
1762 self
.assertTrue(self
.link_exits('veth99'))
1763 self
.assertTrue(self
.link_exits('vrf99'))
1765 self
.start_dnsmasq()
1767 print('## ip -d link show dev vrf99')
1768 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'dev', 'vrf99']).rstrip().decode('utf-8')
1770 self
.assertRegex(output
, 'vrf table 42')
1772 print('## ip address show vrf vrf99')
1773 output_ip_vrf
= subprocess
.check_output(['ip', 'address', 'show', 'vrf', 'vrf99']).rstrip().decode('utf-8')
1774 print(output_ip_vrf
)
1776 print('## ip address show dev veth99')
1777 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
1779 self
.assertEqual(output
, output_ip_vrf
)
1780 self
.assertRegex(output
, 'inet 169.254.[0-9]*.[0-9]*/16 brd 169.254.255.255 scope link veth99')
1781 self
.assertRegex(output
, 'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99')
1782 self
.assertRegex(output
, 'inet6 2600::[0-9a-f]*/128 scope global dynamic noprefixroute')
1783 self
.assertRegex(output
, 'inet6 .* scope link')
1785 print('## ip route show vrf vrf99')
1786 output
= subprocess
.check_output(['ip', 'route', 'show', 'vrf', 'vrf99']).rstrip().decode('utf-8')
1788 self
.assertRegex(output
, 'default via 192.168.5.1 dev veth99 proto dhcp src 192.168.5.')
1789 self
.assertRegex(output
, 'default dev veth99 proto static scope link')
1790 self
.assertRegex(output
, '169.254.0.0/16 dev veth99 proto kernel scope link src 169.254')
1791 self
.assertRegex(output
, '192.168.5.0/24 dev veth99 proto kernel scope link src 192.168.5')
1792 self
.assertRegex(output
, '192.168.5.0/24 via 192.168.5.5 dev veth99 proto dhcp')
1793 self
.assertRegex(output
, '192.168.5.1 dev veth99 proto dhcp scope link src 192.168.5')
1795 print('## ip route show table main dev veth99')
1796 output
= subprocess
.check_output(['ip', 'route', 'show', 'table', 'main', 'dev', 'veth99']).rstrip().decode('utf-8')
1798 self
.assertEqual(output
, '')
1800 output
= subprocess
.check_output(['networkctl', 'status', 'vrf99']).rstrip().decode('utf-8')
1802 self
.assertRegex(output
, 'State: carrier \(configured\)')
1804 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1806 self
.assertRegex(output
, 'State: routable \(configured\)')
1808 def test_dhcp_client_gateway_onlink_implicit(self
):
1809 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network',
1810 'dhcp-client-gateway-onlink-implicit.network')
1811 self
.start_networkd()
1813 self
.assertTrue(self
.link_exits('veth99'))
1815 self
.start_dnsmasq()
1817 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1819 self
.assertRegex(output
, '192.168.5')
1821 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'veth99', '10.0.0.0/8']).rstrip().decode('utf-8')
1823 self
.assertRegex(output
, 'onlink')
1824 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'veth99', '192.168.100.0/24']).rstrip().decode('utf-8')
1826 self
.assertRegex(output
, 'onlink')
1828 if __name__
== '__main__':
1829 unittest
.main(testRunner
=unittest
.TextTestRunner(stream
=sys
.stdout
,