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 wait_online_bin
='/usr/lib/systemd/systemd-networkd-wait-online'
27 def is_module_available(module_name
):
28 lsmod_output
= subprocess
.check_output('lsmod', universal_newlines
=True)
29 module_re
= re
.compile(r
'^{0}\b'.format(re
.escape(module_name
)), re
.MULTILINE
)
30 return module_re
.search(lsmod_output
) or not subprocess
.call(["modprobe", module_name
])
32 def expectedFailureIfModuleIsNotAvailable(module_name
):
34 if not is_module_available(module_name
):
35 return unittest
.expectedFailure(func
)
40 def expectedFailureIfERSPANModuleIsNotAvailable():
42 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'])
44 subprocess
.call(['ip', 'link', 'del', 'erspan99'])
47 return unittest
.expectedFailure(func
)
51 def expectedFailureIfRoutingPolicyPortRangeIsNotAvailable():
53 rc
= subprocess
.call(['ip', 'rule', 'add', 'from', '192.168.100.19', 'sport', '1123-1150', 'dport', '3224-3290', 'table', '7'])
55 subprocess
.call(['ip', 'rule', 'del', 'from', '192.168.100.19', 'sport', '1123-1150', 'dport', '3224-3290', 'table', '7'])
58 return unittest
.expectedFailure(func
)
62 def expectedFailureIfRoutingPolicyIPProtoIsNotAvailable():
64 rc
= subprocess
.call(['ip', 'rule', 'add', 'not', 'from', '192.168.100.19', 'ipproto', 'tcp', 'table', '7'])
66 subprocess
.call(['ip', 'rule', 'del', 'not', 'from', '192.168.100.19', 'ipproto', 'tcp', 'table', '7'])
69 return unittest
.expectedFailure(func
)
74 os
.makedirs(network_unit_file_path
, exist_ok
=True)
75 os
.makedirs(networkd_ci_path
, exist_ok
=True)
77 shutil
.rmtree(networkd_ci_path
)
78 copytree(os
.path
.join(os
.path
.dirname(os
.path
.abspath(__file__
)), 'conf'), networkd_ci_path
)
80 subprocess
.check_call('systemctl stop systemd-networkd.socket', shell
=True)
83 shutil
.rmtree(networkd_ci_path
)
85 subprocess
.check_call('systemctl stop systemd-networkd.service', shell
=True)
86 subprocess
.check_call('systemctl start systemd-networkd.socket', shell
=True)
87 subprocess
.check_call('systemctl start systemd-networkd.service', shell
=True)
90 def read_link_attr(self
, link
, dev
, attribute
):
91 with
open(os
.path
.join(os
.path
.join(os
.path
.join('/sys/class/net/', link
), dev
), attribute
)) as f
:
92 return f
.readline().strip()
94 def read_bridge_port_attr(self
, bridge
, link
, attribute
):
96 path_bridge
= os
.path
.join('/sys/devices/virtual/net', bridge
)
97 path_port
= 'lower_' + link
+ '/brport'
98 path
= os
.path
.join(path_bridge
, path_port
)
100 with
open(os
.path
.join(path
, attribute
)) as f
:
101 return f
.readline().strip()
103 def link_exits(self
, link
):
104 return os
.path
.exists(os
.path
.join('/sys/class/net', link
))
106 def link_remove(self
, links
):
108 if os
.path
.exists(os
.path
.join('/sys/class/net', link
)):
109 subprocess
.call(['ip', 'link', 'del', 'dev', link
])
112 def l2tp_tunnel_remove(self
, tunnel_ids
):
113 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'tunnel']).rstrip().decode('utf-8')
114 for tid
in tunnel_ids
:
115 words
='Tunnel ' + tid
+ ', encap'
117 subprocess
.call(['ip', 'l2tp', 'del', 'tunnel', 'tid', tid
])
120 def read_ipv6_sysctl_attr(self
, link
, attribute
):
121 with
open(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, link
), attribute
)) as f
:
122 return f
.readline().strip()
124 def read_ipv4_sysctl_attr(self
, link
, attribute
):
125 with
open(os
.path
.join(os
.path
.join(network_sysctl_ipv4_path
, link
), attribute
)) as f
:
126 return f
.readline().strip()
128 def copy_unit_to_networkd_unit_path(self
, *units
):
131 shutil
.copy(os
.path
.join(networkd_ci_path
, unit
), network_unit_file_path
)
132 if (os
.path
.exists(os
.path
.join(networkd_ci_path
, unit
+ '.d'))):
133 copytree(os
.path
.join(networkd_ci_path
, unit
+ '.d'), os
.path
.join(network_unit_file_path
, unit
+ '.d'))
135 def remove_unit_from_networkd_path(self
, units
):
137 if (os
.path
.exists(os
.path
.join(network_unit_file_path
, unit
))):
138 os
.remove(os
.path
.join(network_unit_file_path
, unit
))
139 if (os
.path
.exists(os
.path
.join(network_unit_file_path
, unit
+ '.d'))):
140 shutil
.rmtree(os
.path
.join(network_unit_file_path
, unit
+ '.d'))
142 def start_dnsmasq(self
, additional_options
=''):
143 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
144 subprocess
.check_call(dnsmasq_command
, shell
=True)
148 def stop_dnsmasq(self
, pid_file
):
149 if os
.path
.exists(pid_file
):
150 with
open(pid_file
, 'r') as f
:
151 pid
= f
.read().rstrip(' \t\r\n\0')
152 os
.kill(int(pid
), signal
.SIGTERM
)
156 def search_words_in_dnsmasq_log(self
, words
, show_all
=False):
157 if os
.path
.exists(dnsmasq_log_file
):
158 with
open (dnsmasq_log_file
) as in_file
:
159 contents
= in_file
.read()
162 for line
in contents
.split('\n'):
165 print("%s, %s" % (words
, line
))
169 def remove_lease_file(self
):
170 if os
.path
.exists(os
.path
.join(networkd_ci_path
, 'lease')):
171 os
.remove(os
.path
.join(networkd_ci_path
, 'lease'))
173 def remove_log_file(self
):
174 if os
.path
.exists(dnsmasq_log_file
):
175 os
.remove(dnsmasq_log_file
)
177 def start_networkd(self
, sleep_sec
=5, remove_state_files
=True):
178 if (remove_state_files
and
179 os
.path
.exists(os
.path
.join(networkd_runtime_directory
, 'state'))):
180 subprocess
.check_call('systemctl stop systemd-networkd', shell
=True)
181 os
.remove(os
.path
.join(networkd_runtime_directory
, 'state'))
182 subprocess
.check_call('systemctl start systemd-networkd', shell
=True)
184 subprocess
.check_call('systemctl restart systemd-networkd', shell
=True)
186 time
.sleep(sleep_sec
)
188 def wait_online(self
, links_with_operstate
, timeout
='20s', bool_any
=False):
189 args
= [wait_online_bin
, f
'--timeout={timeout}'] + [f
'--interface={link}' for link
in links_with_operstate
]
192 subprocess
.check_call(args
)
194 class NetworkdNetDevTests(unittest
.TestCase
, Utilities
):
250 '10-dropin-test.netdev',
254 '15-name-conflict-test.netdev',
257 '21-vlan-test1.network',
260 '25-6rd-tunnel.netdev',
262 '25-bond-balanced-tlb.netdev',
265 '25-erspan-tunnel-local-any.netdev',
266 '25-erspan-tunnel.netdev',
267 '25-fou-gretap.netdev',
269 '25-fou-ipip.netdev',
270 '25-fou-ipproto-gre.netdev',
271 '25-fou-ipproto-ipip.netdev',
274 '25-gretap-tunnel-local-any.netdev',
275 '25-gretap-tunnel.netdev',
276 '25-gre-tunnel-local-any.netdev',
277 '25-gre-tunnel-remote-any.netdev',
278 '25-gre-tunnel.netdev',
279 '25-ip6gretap-tunnel-local-any.netdev',
280 '25-ip6gretap-tunnel.netdev',
281 '25-ip6gre-tunnel-local-any.netdev',
282 '25-ip6gre-tunnel-remote-any.netdev',
283 '25-ip6gre-tunnel.netdev',
284 '25-ip6tnl-tunnel-remote-any.netdev',
285 '25-ip6tnl-tunnel-local-any.netdev',
286 '25-ip6tnl-tunnel.netdev',
287 '25-ipip-tunnel-independent.netdev',
288 '25-ipip-tunnel-local-any.netdev',
289 '25-ipip-tunnel-remote-any.netdev',
290 '25-ipip-tunnel.netdev',
292 '25-isatap-tunnel.netdev',
293 '25-sit-tunnel-local-any.netdev',
294 '25-sit-tunnel-remote-any.netdev',
295 '25-sit-tunnel.netdev',
301 '25-vti6-tunnel-local-any.netdev',
302 '25-vti6-tunnel-remote-any.netdev',
303 '25-vti6-tunnel.netdev',
304 '25-vti-tunnel-local-any.netdev',
305 '25-vti-tunnel-remote-any.netdev',
306 '25-vti-tunnel.netdev',
308 '25-wireguard-23-peers.netdev',
309 '25-wireguard-23-peers.network',
310 '25-wireguard-preshared-key.txt',
311 '25-wireguard-private-key.txt',
312 '25-wireguard.netdev',
313 '25-wireguard.network',
333 self
.link_remove(self
.links
)
336 self
.link_remove(self
.links
)
337 self
.remove_unit_from_networkd_path(self
.units
)
339 def test_dropin(self
):
340 self
.copy_unit_to_networkd_unit_path('10-dropin-test.netdev', '15-name-conflict-test.netdev')
341 self
.start_networkd()
343 self
.assertTrue(self
.link_exits('dropin-test'))
345 # This also tests NetDev.Name= conflict and basic networkctl functionalities
347 output
= subprocess
.check_output(['ip', 'link', 'show', 'dropin-test']).rstrip().decode('utf-8')
349 self
.assertRegex(output
, '00:50:56:c0:00:28')
351 output
= subprocess
.check_output(['networkctl', 'list']).rstrip().decode('utf-8')
352 self
.assertRegex(output
, '1 lo ')
353 self
.assertRegex(output
, 'dropin-test')
355 output
= subprocess
.check_output(['networkctl', 'list', 'dropin-test']).rstrip().decode('utf-8')
356 self
.assertNotRegex(output
, '1 lo ')
357 self
.assertRegex(output
, 'dropin-test')
359 output
= subprocess
.check_output(['networkctl', 'list', 'dropin-*']).rstrip().decode('utf-8')
360 self
.assertNotRegex(output
, '1 lo ')
361 self
.assertRegex(output
, 'dropin-test')
363 output
= subprocess
.check_output(['networkctl', 'status', 'dropin-*']).rstrip().decode('utf-8')
364 self
.assertNotRegex(output
, '1: lo ')
365 self
.assertRegex(output
, 'dropin-test')
367 ret
= subprocess
.run(['ethtool', '--driver', 'dropin-test'], stdout
=subprocess
.PIPE
, stderr
=subprocess
.STDOUT
)
368 print(ret
.stdout
.rstrip().decode('utf-8'))
369 if ret
.returncode
== 0 and re
.search('driver: dummy', ret
.stdout
.rstrip().decode('utf-8')) != None:
370 self
.assertRegex(output
, 'Driver: dummy')
372 print('ethtool does not support driver field at least for dummy interfaces, skipping test for Driver field of networkctl.')
374 def test_wait_online_any(self
):
375 self
.copy_unit_to_networkd_unit_path('25-bridge.netdev', '25-bridge.network', '11-dummy.netdev', '11-dummy.network')
376 self
.start_networkd(0)
378 self
.wait_online(['bridge99', 'test1:degraded'], bool_any
=True)
379 self
.assertTrue(self
.link_exits('bridge99'))
380 self
.assertTrue(self
.link_exits('test1'))
382 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
384 self
.assertRegex(output
, 'State: (?:off|no-carrier) \(configuring\)')
386 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
388 self
.assertRegex(output
, 'State: degraded \(configured\)')
390 def test_bridge(self
):
391 self
.copy_unit_to_networkd_unit_path('25-bridge.netdev')
392 self
.start_networkd()
394 self
.assertTrue(self
.link_exits('bridge99'))
396 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge', 'hello_time'))
397 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge', 'max_age'))
398 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge','forward_delay'))
399 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge','ageing_time'))
400 self
.assertEqual('9', self
.read_link_attr('bridge99', 'bridge','priority'))
401 self
.assertEqual('1', self
.read_link_attr('bridge99', 'bridge','multicast_querier'))
402 self
.assertEqual('1', self
.read_link_attr('bridge99', 'bridge','multicast_snooping'))
403 self
.assertEqual('1', self
.read_link_attr('bridge99', 'bridge','stp_state'))
406 self
.copy_unit_to_networkd_unit_path('25-bond.netdev')
407 self
.start_networkd()
409 self
.assertTrue(self
.link_exits('bond99'))
411 self
.assertEqual('802.3ad 4', self
.read_link_attr('bond99', 'bonding', 'mode'))
412 self
.assertEqual('layer3+4 1', self
.read_link_attr('bond99', 'bonding', 'xmit_hash_policy'))
413 self
.assertEqual('1000', self
.read_link_attr('bond99', 'bonding', 'miimon'))
414 self
.assertEqual('fast 1', self
.read_link_attr('bond99', 'bonding', 'lacp_rate'))
415 self
.assertEqual('2000', self
.read_link_attr('bond99', 'bonding', 'updelay'))
416 self
.assertEqual('2000', self
.read_link_attr('bond99', 'bonding', 'downdelay'))
417 self
.assertEqual('4', self
.read_link_attr('bond99', 'bonding', 'resend_igmp'))
418 self
.assertEqual('1', self
.read_link_attr('bond99', 'bonding', 'min_links'))
419 self
.assertEqual('1218', self
.read_link_attr('bond99', 'bonding', 'ad_actor_sys_prio'))
420 self
.assertEqual('811', self
.read_link_attr('bond99', 'bonding', 'ad_user_port_key'))
421 self
.assertEqual('00:11:22:33:44:55', self
.read_link_attr('bond99', 'bonding', 'ad_actor_system'))
423 def test_bond_balanced_tlb(self
):
424 self
.copy_unit_to_networkd_unit_path('25-bond-balanced-tlb.netdev')
425 self
.start_networkd()
427 self
.assertTrue(self
.link_exits('bond99'))
429 self
.assertEqual('balance-tlb 5', self
.read_link_attr('bond99', 'bonding', 'mode'))
430 self
.assertEqual('1', self
.read_link_attr('bond99', 'bonding', 'tlb_dynamic_lb'))
433 self
.copy_unit_to_networkd_unit_path('21-vlan.netdev', '11-dummy.netdev',
434 '21-vlan.network', '21-vlan-test1.network')
435 self
.start_networkd()
437 self
.assertTrue(self
.link_exits('test1'))
438 self
.assertTrue(self
.link_exits('vlan99'))
440 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'test1']).rstrip().decode('utf-8')
442 self
.assertTrue(output
, ' mtu 2004 ')
444 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vlan99']).rstrip().decode('utf-8')
446 self
.assertTrue(output
, ' mtu 2000 ')
447 self
.assertTrue(output
, 'REORDER_HDR')
448 self
.assertTrue(output
, 'LOOSE_BINDING')
449 self
.assertTrue(output
, 'GVRP')
450 self
.assertTrue(output
, 'MVRP')
451 self
.assertTrue(output
, ' id 99 ')
453 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'test1']).rstrip().decode('utf-8')
455 self
.assertRegex(output
, 'inet 192.168.24.5/24 brd 192.168.24.255 scope global test1')
456 self
.assertRegex(output
, 'inet 192.168.25.5/24 brd 192.168.25.255 scope global test1')
458 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'vlan99']).rstrip().decode('utf-8')
460 self
.assertRegex(output
, 'inet 192.168.23.5/24 brd 192.168.23.255 scope global vlan99')
462 def test_macvtap(self
):
463 self
.copy_unit_to_networkd_unit_path('21-macvtap.netdev', '11-dummy.netdev', 'macvtap.network')
464 self
.start_networkd()
466 self
.assertTrue(self
.link_exits('macvtap99'))
468 def test_macvlan(self
):
469 self
.copy_unit_to_networkd_unit_path('21-macvlan.netdev', '11-dummy.netdev', 'macvlan.network')
470 self
.start_networkd()
472 self
.assertTrue(self
.link_exits('test1'))
473 self
.assertTrue(self
.link_exits('macvlan99'))
475 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'test1']).rstrip().decode('utf-8')
477 self
.assertTrue(output
, ' mtu 2000 ')
479 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'macvlan99']).rstrip().decode('utf-8')
481 self
.assertTrue(output
, ' mtu 2000 ')
483 @expectedFailureIfModuleIsNotAvailable('ipvlan')
484 def test_ipvlan(self
):
485 self
.copy_unit_to_networkd_unit_path('25-ipvlan.netdev', '11-dummy.netdev', 'ipvlan.network')
486 self
.start_networkd()
488 self
.assertTrue(self
.link_exits('ipvlan99'))
491 self
.copy_unit_to_networkd_unit_path('25-veth.netdev')
492 self
.start_networkd()
494 self
.assertTrue(self
.link_exits('veth99'))
496 def test_dummy(self
):
497 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev')
498 self
.start_networkd()
500 self
.assertTrue(self
.link_exits('test1'))
503 self
.copy_unit_to_networkd_unit_path('25-tun.netdev')
504 self
.start_networkd()
506 self
.assertTrue(self
.link_exits('tun99'))
509 self
.copy_unit_to_networkd_unit_path('25-tap.netdev')
510 self
.start_networkd()
512 self
.assertTrue(self
.link_exits('tap99'))
514 @expectedFailureIfModuleIsNotAvailable('vrf')
516 self
.copy_unit_to_networkd_unit_path('25-vrf.netdev')
517 self
.start_networkd()
519 self
.assertTrue(self
.link_exits('vrf99'))
521 @expectedFailureIfModuleIsNotAvailable('vcan')
523 self
.copy_unit_to_networkd_unit_path('25-vcan.netdev')
524 self
.start_networkd()
526 self
.assertTrue(self
.link_exits('vcan99'))
528 @expectedFailureIfModuleIsNotAvailable('wireguard')
529 def test_wireguard(self
):
530 self
.copy_unit_to_networkd_unit_path('25-wireguard.netdev', '25-wireguard.network',
531 '25-wireguard-23-peers.netdev', '25-wireguard-23-peers.network',
532 '25-wireguard-preshared-key.txt', '25-wireguard-private-key.txt')
533 self
.start_networkd(0)
534 self
.wait_online(['wg99:carrier', 'wg98:routable'])
536 self
.assertTrue(self
.link_exits('wg99'))
537 self
.assertTrue(self
.link_exits('wg98'))
539 if shutil
.which('wg'):
540 subprocess
.call('wg')
542 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'listen-port']).rstrip().decode('utf-8')
543 self
.assertTrue(output
, '51820')
544 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'fwmark']).rstrip().decode('utf-8')
545 self
.assertTrue(output
, '0x4d2')
546 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'allowed-ips']).rstrip().decode('utf-8')
547 self
.assertTrue(output
, 'RDf+LSpeEre7YEIKaxg+wbpsNV7du+ktR99uBEtIiCA=\t192.168.26.0/24 fd31:bf08:57cb::/48')
548 self
.assertTrue(output
, 'lsDtM3AbjxNlauRKzHEPfgS1Zp7cp/VX5Use/P4PQSc=\tfdbc:bae2:7871:e1fe:793:8636::/96 fdbc:bae2:7871:500:e1fe:793:8636:dad1/128')
549 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'persistent-keepalive']).rstrip().decode('utf-8')
550 self
.assertTrue(output
, 'RDf+LSpeEre7YEIKaxg+wbpsNV7du+ktR99uBEtIiCA=\t20')
551 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'endpoints']).rstrip().decode('utf-8')
552 self
.assertTrue(output
, 'RDf+LSpeEre7YEIKaxg+wbpsNV7du+ktR99uBEtIiCA=\t192.168.27.3:51820')
553 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'private-key']).rstrip().decode('utf-8')
554 self
.assertTrue(output
, 'EEGlnEPYJV//kbvvIqxKkQwOiS+UENyPncC4bF46ong=')
555 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'preshared-keys']).rstrip().decode('utf-8')
556 self
.assertTrue(output
, 'RDf+LSpeEre7YEIKaxg+wbpsNV7du+ktR99uBEtIiCA= IIWIV17wutHv7t4cR6pOT91z6NSz/T8Arh0yaywhw3M=')
557 self
.assertTrue(output
, 'lsDtM3AbjxNlauRKzHEPfgS1Zp7cp/VX5Use/P4PQSc= cPLOy1YUrEI0EMMIycPJmOo0aTu3RZnw8bL5meVD6m0=')
559 output
= subprocess
.check_output(['wg', 'show', 'wg98', 'private-key']).rstrip().decode('utf-8')
560 self
.assertTrue(output
, 'CJQUtcS9emY2fLYqDlpSZiE/QJyHkPWr+WHtZLZ90FU=')
562 def test_geneve(self
):
563 self
.copy_unit_to_networkd_unit_path('25-geneve.netdev')
564 self
.start_networkd()
566 self
.assertTrue(self
.link_exits('geneve99'))
568 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'geneve99']).rstrip().decode('utf-8')
570 self
.assertTrue(output
, '192.168.22.1')
571 self
.assertTrue(output
, '6082')
572 self
.assertTrue(output
, 'udpcsum')
573 self
.assertTrue(output
, 'udp6zerocsumrx')
575 def test_ipip_tunnel(self
):
576 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-ipip-tunnel.netdev', 'ipip.network',
577 '25-ipip-tunnel-local-any.netdev', '25-ipip-tunnel-remote-any.netdev')
578 self
.start_networkd()
580 self
.assertTrue(self
.link_exits('dummy98'))
581 self
.assertTrue(self
.link_exits('ipiptun99'))
582 self
.assertTrue(self
.link_exits('ipiptun98'))
583 self
.assertTrue(self
.link_exits('ipiptun97'))
585 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ipiptun99']).rstrip().decode('utf-8')
587 self
.assertRegex(output
, 'ipip (?:ipip |)remote 192.169.224.239 local 192.168.223.238 dev dummy98')
588 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ipiptun98']).rstrip().decode('utf-8')
590 self
.assertRegex(output
, 'ipip (?:ipip |)remote 192.169.224.239 local any dev dummy98')
591 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ipiptun97']).rstrip().decode('utf-8')
593 self
.assertRegex(output
, 'ipip (?:ipip |)remote any local 192.168.223.238 dev dummy98')
595 def test_gre_tunnel(self
):
596 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-gre-tunnel.netdev', 'gretun.network',
597 '25-gre-tunnel-local-any.netdev', '25-gre-tunnel-remote-any.netdev')
598 self
.start_networkd()
600 self
.assertTrue(self
.link_exits('dummy98'))
601 self
.assertTrue(self
.link_exits('gretun99'))
602 self
.assertTrue(self
.link_exits('gretun98'))
603 self
.assertTrue(self
.link_exits('gretun97'))
605 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretun99']).rstrip().decode('utf-8')
607 self
.assertRegex(output
, 'gre remote 10.65.223.239 local 10.65.223.238 dev dummy98')
608 self
.assertRegex(output
, 'ikey 1.2.3.103')
609 self
.assertRegex(output
, 'okey 1.2.4.103')
610 self
.assertRegex(output
, 'iseq')
611 self
.assertRegex(output
, 'oseq')
612 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretun98']).rstrip().decode('utf-8')
614 self
.assertRegex(output
, 'gre remote 10.65.223.239 local any dev dummy98')
615 self
.assertRegex(output
, 'ikey 0.0.0.104')
616 self
.assertRegex(output
, 'okey 0.0.0.104')
617 self
.assertNotRegex(output
, 'iseq')
618 self
.assertNotRegex(output
, 'oseq')
619 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretun97']).rstrip().decode('utf-8')
621 self
.assertRegex(output
, 'gre remote any local 10.65.223.238 dev dummy98')
622 self
.assertRegex(output
, 'ikey 0.0.0.105')
623 self
.assertRegex(output
, 'okey 0.0.0.105')
624 self
.assertNotRegex(output
, 'iseq')
625 self
.assertNotRegex(output
, 'oseq')
627 def test_ip6gre_tunnel(self
):
628 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-ip6gre-tunnel.netdev', 'ip6gretun.network',
629 '25-ip6gre-tunnel-local-any.netdev', '25-ip6gre-tunnel-remote-any.netdev')
630 self
.start_networkd()
632 self
.assertTrue(self
.link_exits('dummy98'))
633 self
.assertTrue(self
.link_exits('ip6gretun99'))
634 self
.assertTrue(self
.link_exits('ip6gretun98'))
635 self
.assertTrue(self
.link_exits('ip6gretun97'))
637 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6gretun99']).rstrip().decode('utf-8')
639 self
.assertRegex(output
, 'ip6gre remote 2001:473:fece:cafe::5179 local 2a00:ffde:4567:edde::4987 dev dummy98')
640 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6gretun98']).rstrip().decode('utf-8')
642 self
.assertRegex(output
, 'ip6gre remote 2001:473:fece:cafe::5179 local any dev dummy98')
643 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6gretun97']).rstrip().decode('utf-8')
645 self
.assertRegex(output
, 'ip6gre remote any local 2a00:ffde:4567:edde::4987 dev dummy98')
647 def test_gretap_tunnel(self
):
648 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-gretap-tunnel.netdev', 'gretap.network',
649 '25-gretap-tunnel-local-any.netdev')
650 self
.start_networkd()
652 self
.assertTrue(self
.link_exits('dummy98'))
653 self
.assertTrue(self
.link_exits('gretap99'))
654 self
.assertTrue(self
.link_exits('gretap98'))
656 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretap99']).rstrip().decode('utf-8')
658 self
.assertRegex(output
, 'gretap remote 10.65.223.239 local 10.65.223.238 dev dummy98')
659 self
.assertRegex(output
, 'ikey 0.0.0.106')
660 self
.assertRegex(output
, 'okey 0.0.0.106')
661 self
.assertRegex(output
, 'iseq')
662 self
.assertRegex(output
, 'oseq')
663 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretap98']).rstrip().decode('utf-8')
665 self
.assertRegex(output
, 'gretap remote 10.65.223.239 local any dev dummy98')
666 self
.assertRegex(output
, 'ikey 0.0.0.107')
667 self
.assertRegex(output
, 'okey 0.0.0.107')
668 self
.assertRegex(output
, 'iseq')
669 self
.assertRegex(output
, 'oseq')
671 def test_ip6gretap_tunnel(self
):
672 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-ip6gretap-tunnel.netdev', 'ip6gretap.network',
673 '25-ip6gretap-tunnel-local-any.netdev')
674 self
.start_networkd()
676 self
.assertTrue(self
.link_exits('dummy98'))
677 self
.assertTrue(self
.link_exits('ip6gretap99'))
678 self
.assertTrue(self
.link_exits('ip6gretap98'))
680 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6gretap99']).rstrip().decode('utf-8')
682 self
.assertRegex(output
, 'ip6gretap remote 2001:473:fece:cafe::5179 local 2a00:ffde:4567:edde::4987 dev dummy98')
683 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6gretap98']).rstrip().decode('utf-8')
685 self
.assertRegex(output
, 'ip6gretap remote 2001:473:fece:cafe::5179 local any dev dummy98')
687 def test_vti_tunnel(self
):
688 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-vti-tunnel.netdev', 'vti.network',
689 '25-vti-tunnel-local-any.netdev', '25-vti-tunnel-remote-any.netdev')
690 self
.start_networkd()
692 self
.assertTrue(self
.link_exits('dummy98'))
693 self
.assertTrue(self
.link_exits('vtitun99'))
694 self
.assertTrue(self
.link_exits('vtitun98'))
695 self
.assertTrue(self
.link_exits('vtitun97'))
697 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vtitun99']).rstrip().decode('utf-8')
699 self
.assertRegex(output
, 'vti remote 10.65.223.239 local 10.65.223.238 dev dummy98')
700 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vtitun98']).rstrip().decode('utf-8')
702 self
.assertRegex(output
, 'vti remote 10.65.223.239 local any dev dummy98')
703 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vtitun97']).rstrip().decode('utf-8')
705 self
.assertRegex(output
, 'vti remote any local 10.65.223.238 dev dummy98')
707 def test_vti6_tunnel(self
):
708 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-vti6-tunnel.netdev', 'vti6.network',
709 '25-vti6-tunnel-local-any.netdev', '25-vti6-tunnel-remote-any.netdev')
710 self
.start_networkd()
712 self
.assertTrue(self
.link_exits('dummy98'))
713 self
.assertTrue(self
.link_exits('vti6tun99'))
714 self
.assertTrue(self
.link_exits('vti6tun98'))
715 self
.assertTrue(self
.link_exits('vti6tun97'))
717 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vti6tun99']).rstrip().decode('utf-8')
719 self
.assertRegex(output
, 'vti6 remote 2001:473:fece:cafe::5179 local 2a00:ffde:4567:edde::4987 dev dummy98')
720 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vti6tun98']).rstrip().decode('utf-8')
722 self
.assertRegex(output
, 'vti6 remote 2001:473:fece:cafe::5179 local (?:any|::) dev dummy98')
723 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vti6tun97']).rstrip().decode('utf-8')
725 self
.assertRegex(output
, 'vti6 remote (?:any|::) local 2a00:ffde:4567:edde::4987 dev dummy98')
727 def test_ip6tnl_tunnel(self
):
728 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-ip6tnl-tunnel.netdev', 'ip6tnl.network',
729 '25-ip6tnl-tunnel-local-any.netdev', '25-ip6tnl-tunnel-remote-any.netdev')
730 self
.start_networkd()
732 self
.assertTrue(self
.link_exits('dummy98'))
733 self
.assertTrue(self
.link_exits('ip6tnl99'))
734 self
.assertTrue(self
.link_exits('ip6tnl98'))
735 self
.assertTrue(self
.link_exits('ip6tnl97'))
737 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6tnl99']).rstrip().decode('utf-8')
739 self
.assertRegex(output
, 'ip6tnl ip6ip6 remote 2001:473:fece:cafe::5179 local 2a00:ffde:4567:edde::4987 dev dummy98')
740 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6tnl98']).rstrip().decode('utf-8')
742 self
.assertRegex(output
, 'ip6tnl ip6ip6 remote 2001:473:fece:cafe::5179 local (?:any|::) dev dummy98')
743 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6tnl97']).rstrip().decode('utf-8')
745 self
.assertRegex(output
, 'ip6tnl ip6ip6 remote (?:any|::) local 2a00:ffde:4567:edde::4987 dev dummy98')
747 def test_sit_tunnel(self
):
748 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-sit-tunnel.netdev', 'sit.network',
749 '25-sit-tunnel-local-any.netdev',
750 '25-sit-tunnel-remote-any.netdev')
751 self
.start_networkd()
753 self
.assertTrue(self
.link_exits('dummy98'))
754 self
.assertTrue(self
.link_exits('sittun99'))
755 self
.assertTrue(self
.link_exits('sittun98'))
756 self
.assertTrue(self
.link_exits('sittun97'))
758 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'sittun99']).rstrip().decode('utf-8')
760 self
.assertRegex(output
, "sit (?:ip6ip |)remote 10.65.223.239 local 10.65.223.238 dev dummy98")
761 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'sittun98']).rstrip().decode('utf-8')
763 self
.assertRegex(output
, "sit (?:ip6ip |)remote 10.65.223.239 local any dev dummy98")
764 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'sittun97']).rstrip().decode('utf-8')
766 self
.assertRegex(output
, "sit (?:ip6ip |)remote any local 10.65.223.238 dev dummy98")
768 def test_isatap_tunnel(self
):
769 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-isatap-tunnel.netdev', 'isatap.network')
770 self
.start_networkd()
772 self
.assertTrue(self
.link_exits('dummy98'))
773 self
.assertTrue(self
.link_exits('isataptun99'))
775 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'isataptun99']).rstrip().decode('utf-8')
777 self
.assertRegex(output
, "isatap ")
779 def test_6rd_tunnel(self
):
780 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-6rd-tunnel.netdev', '6rd.network')
781 self
.start_networkd()
783 self
.assertTrue(self
.link_exits('dummy98'))
784 self
.assertTrue(self
.link_exits('sittun99'))
786 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'sittun99']).rstrip().decode('utf-8')
788 self
.assertRegex(output
, '6rd-prefix 2602::/24')
790 @expectedFailureIfERSPANModuleIsNotAvailable()
791 def test_erspan_tunnel(self
):
792 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'erspan.network',
793 '25-erspan-tunnel.netdev', '25-erspan-tunnel-local-any.netdev')
794 self
.start_networkd()
796 self
.assertTrue(self
.link_exits('dummy98'))
797 self
.assertTrue(self
.link_exits('erspan99'))
798 self
.assertTrue(self
.link_exits('erspan98'))
800 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'erspan99']).rstrip().decode('utf-8')
802 self
.assertRegex(output
, 'erspan remote 172.16.1.100 local 172.16.1.200')
803 self
.assertRegex(output
, 'ikey 0.0.0.101')
804 self
.assertRegex(output
, 'okey 0.0.0.101')
805 self
.assertRegex(output
, 'iseq')
806 self
.assertRegex(output
, 'oseq')
807 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'erspan98']).rstrip().decode('utf-8')
809 self
.assertRegex(output
, 'erspan remote 172.16.1.100 local any')
810 self
.assertRegex(output
, '102')
811 self
.assertRegex(output
, 'ikey 0.0.0.102')
812 self
.assertRegex(output
, 'okey 0.0.0.102')
813 self
.assertRegex(output
, 'iseq')
814 self
.assertRegex(output
, 'oseq')
816 def test_tunnel_independent(self
):
817 self
.copy_unit_to_networkd_unit_path('25-ipip-tunnel-independent.netdev')
818 self
.start_networkd()
820 self
.assertTrue(self
.link_exits('ipiptun99'))
822 @expectedFailureIfModuleIsNotAvailable('fou')
824 # The following redundant check is necessary for CentOS CI.
825 # Maybe, error handling in lookup_id() in sd-netlink/generic-netlink.c needs to be updated.
826 self
.assertTrue(is_module_available('fou'))
828 self
.copy_unit_to_networkd_unit_path('25-fou-ipproto-ipip.netdev', '25-fou-ipproto-gre.netdev',
829 '25-fou-ipip.netdev', '25-fou-sit.netdev',
830 '25-fou-gre.netdev', '25-fou-gretap.netdev')
831 self
.start_networkd()
833 self
.assertTrue(self
.link_exits('ipiptun96'))
834 self
.assertTrue(self
.link_exits('sittun96'))
835 self
.assertTrue(self
.link_exits('gretun96'))
836 self
.assertTrue(self
.link_exits('gretap96'))
838 output
= subprocess
.check_output(['ip', 'fou', 'show']).rstrip().decode('utf-8')
840 self
.assertRegex(output
, 'port 55555 ipproto 4')
841 self
.assertRegex(output
, 'port 55556 ipproto 47')
843 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ipiptun96']).rstrip().decode('utf-8')
845 self
.assertRegex(output
, 'encap fou encap-sport auto encap-dport 55555')
846 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'sittun96']).rstrip().decode('utf-8')
848 self
.assertRegex(output
, 'encap fou encap-sport auto encap-dport 55555')
849 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretun96']).rstrip().decode('utf-8')
851 self
.assertRegex(output
, 'encap fou encap-sport 1001 encap-dport 55556')
852 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretap96']).rstrip().decode('utf-8')
854 self
.assertRegex(output
, 'encap fou encap-sport auto encap-dport 55556')
856 subprocess
.call(['ip', 'fou', 'del', 'port', '55555'])
857 subprocess
.call(['ip', 'fou', 'del', 'port', '55556'])
859 def test_vxlan(self
):
860 self
.copy_unit_to_networkd_unit_path('25-vxlan.netdev', 'vxlan.network', '11-dummy.netdev')
861 self
.start_networkd()
863 self
.assertTrue(self
.link_exits('vxlan99'))
865 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vxlan99']).rstrip().decode('utf-8')
867 self
.assertRegex(output
, "999")
868 self
.assertRegex(output
, '5555')
869 self
.assertRegex(output
, 'l2miss')
870 self
.assertRegex(output
, 'l3miss')
871 self
.assertRegex(output
, 'udpcsum')
872 self
.assertRegex(output
, 'udp6zerocsumtx')
873 self
.assertRegex(output
, 'udp6zerocsumrx')
874 self
.assertRegex(output
, 'remcsumtx')
875 self
.assertRegex(output
, 'remcsumrx')
876 self
.assertRegex(output
, 'gbp')
878 class NetworkdL2TPTests(unittest
.TestCase
, Utilities
):
889 '25-l2tp-dummy.network',
891 '25-l2tp-udp.netdev']
893 l2tp_tunnel_ids
= [ '10' ]
896 self
.l2tp_tunnel_remove(self
.l2tp_tunnel_ids
)
897 self
.link_remove(self
.links
)
900 self
.l2tp_tunnel_remove(self
.l2tp_tunnel_ids
)
901 self
.link_remove(self
.links
)
902 self
.remove_unit_from_networkd_path(self
.units
)
904 @expectedFailureIfModuleIsNotAvailable('l2tp_eth')
905 def test_l2tp_udp(self
):
906 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev', '25-l2tp-dummy.network', '25-l2tp-udp.netdev')
907 self
.start_networkd()
909 self
.assertTrue(self
.link_exits('test1'))
910 self
.assertTrue(self
.link_exits('l2tp-ses1'))
911 self
.assertTrue(self
.link_exits('l2tp-ses2'))
913 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'tunnel', 'tunnel_id', '10']).rstrip().decode('utf-8')
915 self
.assertRegex(output
, "Tunnel 10, encap UDP")
916 self
.assertRegex(output
, "From 192.168.30.100 to 192.168.30.101")
917 self
.assertRegex(output
, "Peer tunnel 11")
918 self
.assertRegex(output
, "UDP source / dest ports: 3000/4000")
919 self
.assertRegex(output
, "UDP checksum: enabled")
921 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'session', 'tid', '10', 'session_id', '15']).rstrip().decode('utf-8')
923 self
.assertRegex(output
, "Session 15 in tunnel 10")
924 self
.assertRegex(output
, "Peer session 16, tunnel 11")
925 self
.assertRegex(output
, "interface name: l2tp-ses1")
927 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'session', 'tid', '10', 'session_id', '17']).rstrip().decode('utf-8')
929 self
.assertRegex(output
, "Session 17 in tunnel 10")
930 self
.assertRegex(output
, "Peer session 18, tunnel 11")
931 self
.assertRegex(output
, "interface name: l2tp-ses2")
933 @expectedFailureIfModuleIsNotAvailable('l2tp_ip')
934 def test_l2tp_ip(self
):
935 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev', '25-l2tp-dummy.network', '25-l2tp-ip.netdev')
936 self
.start_networkd()
938 self
.assertTrue(self
.link_exits('test1'))
939 self
.assertTrue(self
.link_exits('l2tp-ses3'))
940 self
.assertTrue(self
.link_exits('l2tp-ses4'))
942 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'tunnel', 'tunnel_id', '10']).rstrip().decode('utf-8')
944 self
.assertRegex(output
, "Tunnel 10, encap IP")
945 self
.assertRegex(output
, "From 192.168.30.100 to 192.168.30.101")
946 self
.assertRegex(output
, "Peer tunnel 12")
948 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'session', 'tid', '10', 'session_id', '25']).rstrip().decode('utf-8')
950 self
.assertRegex(output
, "Session 25 in tunnel 10")
951 self
.assertRegex(output
, "Peer session 26, tunnel 12")
952 self
.assertRegex(output
, "interface name: l2tp-ses3")
954 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'session', 'tid', '10', 'session_id', '27']).rstrip().decode('utf-8')
956 self
.assertRegex(output
, "Session 27 in tunnel 10")
957 self
.assertRegex(output
, "Peer session 28, tunnel 12")
958 self
.assertRegex(output
, "interface name: l2tp-ses4")
960 class NetworkdNetWorkTests(unittest
.TestCase
, Utilities
):
970 '23-active-slave.network',
971 '25-address-link-section.network',
972 '25-address-preferred-lifetime-zero-ipv6.network',
973 '25-address-static.network',
974 '25-bind-carrier.network',
975 '25-bond-active-backup-slave.netdev',
976 '25-fibrule-invert.network',
977 '25-fibrule-port-range.network',
978 '25-ipv6-address-label-section.network',
979 '25-neighbor-section.network',
980 '25-link-local-addressing-no.network',
981 '25-link-local-addressing-yes.network',
982 '25-link-section-unmanaged.network',
983 '25-route-ipv6-src.network',
984 '25-route-static.network',
985 '25-sysctl-disable-ipv6.network',
987 'configure-without-carrier.network',
988 'routing-policy-rule-dummy98.network',
989 'routing-policy-rule-test1.network']
992 self
.link_remove(self
.links
)
995 self
.link_remove(self
.links
)
996 self
.remove_unit_from_networkd_path(self
.units
)
998 def test_address_static(self
):
999 self
.copy_unit_to_networkd_unit_path('25-address-static.network', '12-dummy.netdev')
1000 self
.start_networkd(0)
1002 self
.wait_online(['dummy98:routable'])
1004 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'dummy98']).rstrip().decode('utf-8')
1006 self
.assertRegex(output
, 'inet 10.1.2.3/16 brd 10.1.255.255 scope global dummy98')
1007 self
.assertRegex(output
, 'inet 10.1.2.4/16 brd 10.1.255.255 scope global secondary dummy98')
1008 self
.assertRegex(output
, 'inet 10.2.2.4/16 brd 10.2.255.255 scope global dummy98')
1011 self
.assertNotRegex(output
, '10.10.0.1/16')
1012 self
.assertNotRegex(output
, '10.10.0.2/16')
1014 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'dummy98', 'label', '32']).rstrip().decode('utf-8')
1015 self
.assertRegex(output
, 'inet 10.3.2.3/16 brd 10.3.255.255 scope global 32')
1017 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'dummy98', 'label', '33']).rstrip().decode('utf-8')
1018 self
.assertRegex(output
, 'inet 10.4.2.3 peer 10.4.2.4/16 scope global 33')
1020 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'dummy98', 'label', '34']).rstrip().decode('utf-8')
1021 self
.assertRegex(output
, 'inet 192.168.[0-9]*.1/24 brd 192.168.[0-9]*.255 scope global 34')
1023 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'dummy98', 'label', '35']).rstrip().decode('utf-8')
1024 self
.assertRegex(output
, 'inet 172.[0-9]*.0.1/16 brd 172.[0-9]*.255.255 scope global 35')
1026 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'dummy98']).rstrip().decode('utf-8')
1028 self
.assertRegex(output
, 'inet6 2001:db8:0:f101::15/64 scope global')
1029 self
.assertRegex(output
, 'inet6 2001:db8:0:f101::16/64 scope global')
1030 self
.assertRegex(output
, 'inet6 2001:db8:0:f102::15/64 scope global')
1031 self
.assertRegex(output
, 'inet6 2001:db8:0:f102::16/64 scope global')
1032 self
.assertRegex(output
, 'inet6 2001:db8:0:f103::20 peer 2001:db8:0:f103::10/128 scope global')
1033 self
.assertRegex(output
, 'inet6 fd[0-9a-f:]*1/64 scope global')
1035 def test_address_preferred_lifetime_zero_ipv6(self
):
1036 self
.copy_unit_to_networkd_unit_path('25-address-preferred-lifetime-zero-ipv6.network', '12-dummy.netdev')
1037 self
.start_networkd()
1039 self
.assertTrue(self
.link_exits('dummy98'))
1041 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1043 self
.assertRegex(output
, 'State: routable \(configuring\)')
1045 output
= subprocess
.check_output(['ip', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
1047 self
.assertRegex(output
, 'inet 10.2.3.4/16 brd 10.2.255.255 scope link deprecated dummy98')
1048 self
.assertRegex(output
, 'inet6 2001:db8:0:f101::1/64 scope global')
1050 def test_configure_without_carrier(self
):
1051 self
.copy_unit_to_networkd_unit_path('configure-without-carrier.network', '11-dummy.netdev')
1052 self
.start_networkd()
1054 self
.assertTrue(self
.link_exits('test1'))
1056 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1058 self
.assertRegex(output
, '192.168.0.15')
1059 self
.assertRegex(output
, '192.168.0.1')
1060 self
.assertRegex(output
, 'routable')
1062 def test_routing_policy_rule(self
):
1063 self
.copy_unit_to_networkd_unit_path('routing-policy-rule-test1.network', '11-dummy.netdev')
1065 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1067 self
.start_networkd()
1069 self
.assertTrue(self
.link_exits('test1'))
1071 output
= subprocess
.check_output(['ip', 'rule']).rstrip().decode('utf-8')
1073 self
.assertRegex(output
, '111')
1074 self
.assertRegex(output
, 'from 192.168.100.18')
1075 self
.assertRegex(output
, r
'tos (?:0x08|throughput)\s')
1076 self
.assertRegex(output
, 'iif test1')
1077 self
.assertRegex(output
, 'oif test1')
1078 self
.assertRegex(output
, 'lookup 7')
1080 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1082 def test_routing_policy_rule_issue_11280(self
):
1083 self
.copy_unit_to_networkd_unit_path('routing-policy-rule-test1.network', '11-dummy.netdev',
1084 'routing-policy-rule-dummy98.network', '12-dummy.netdev')
1086 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1087 subprocess
.call(['ip', 'rule', 'del', 'table', '8'])
1089 for trial
in range(3):
1090 # Remove state files only first time
1091 self
.start_networkd(remove_state_files
=(trial
== 0))
1093 self
.assertTrue(self
.link_exits('test1'))
1094 self
.assertTrue(self
.link_exits('dummy98'))
1096 output
= subprocess
.check_output(['ip', 'rule', 'list', 'table', '7']).rstrip().decode('utf-8')
1098 self
.assertRegex(output
, '111: from 192.168.100.18 tos (?:0x08|throughput) iif test1 oif test1 lookup 7')
1100 output
= subprocess
.check_output(['ip', 'rule', 'list', 'table', '8']).rstrip().decode('utf-8')
1102 self
.assertRegex(output
, '112: from 192.168.101.18 tos (?:0x08|throughput) iif dummy98 oif dummy98 lookup 8')
1104 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1105 subprocess
.call(['ip', 'rule', 'del', 'table', '8'])
1107 @expectedFailureIfRoutingPolicyPortRangeIsNotAvailable()
1108 def test_routing_policy_rule_port_range(self
):
1109 self
.copy_unit_to_networkd_unit_path('25-fibrule-port-range.network', '11-dummy.netdev')
1111 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1113 self
.start_networkd()
1115 self
.assertTrue(self
.link_exits('test1'))
1117 output
= subprocess
.check_output(['ip', 'rule']).rstrip().decode('utf-8')
1119 self
.assertRegex(output
, '111')
1120 self
.assertRegex(output
, 'from 192.168.100.18')
1121 self
.assertRegex(output
, '1123-1150')
1122 self
.assertRegex(output
, '3224-3290')
1123 self
.assertRegex(output
, 'tcp')
1124 self
.assertRegex(output
, 'lookup 7')
1126 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1128 @expectedFailureIfRoutingPolicyIPProtoIsNotAvailable()
1129 def test_routing_policy_rule_invert(self
):
1130 self
.copy_unit_to_networkd_unit_path('25-fibrule-invert.network', '11-dummy.netdev')
1132 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1134 self
.start_networkd()
1136 self
.assertTrue(self
.link_exits('test1'))
1138 output
= subprocess
.check_output(['ip', 'rule']).rstrip().decode('utf-8')
1140 self
.assertRegex(output
, '111')
1141 self
.assertRegex(output
, 'not.*?from.*?192.168.100.18')
1142 self
.assertRegex(output
, 'tcp')
1143 self
.assertRegex(output
, 'lookup 7')
1145 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1147 def test_route_static(self
):
1148 self
.copy_unit_to_networkd_unit_path('25-route-static.network', '12-dummy.netdev')
1149 self
.start_networkd(0)
1151 self
.wait_online(['dummy98:routable'])
1153 output
= subprocess
.check_output(['ip', '-6', 'route', 'show', 'dev', 'dummy98']).rstrip().decode('utf-8')
1155 self
.assertRegex(output
, '2001:1234:5:8fff:ff:ff:ff:ff proto static')
1156 self
.assertRegex(output
, '2001:1234:5:8f63::1 proto kernel')
1158 output
= subprocess
.check_output(['ip', '-6', 'route', 'show', 'dev', 'dummy98', 'default']).rstrip().decode('utf-8')
1159 self
.assertRegex(output
, 'default via 2001:1234:5:8fff:ff:ff:ff:ff proto static metric 1024 pref medium')
1161 output
= subprocess
.check_output(['ip', '-4', 'route', 'show', 'dev', 'dummy98']).rstrip().decode('utf-8')
1163 self
.assertRegex(output
, '149.10.124.48/28 proto kernel scope link src 149.10.124.58')
1164 self
.assertRegex(output
, '149.10.124.64 proto static scope link')
1165 self
.assertRegex(output
, '192.168.1.1 proto static initcwnd 20')
1166 self
.assertRegex(output
, '192.168.1.2 proto static initrwnd 30')
1168 output
= subprocess
.check_output(['ip', '-4', 'route', 'show', 'dev', 'dummy98', 'default']).rstrip().decode('utf-8')
1169 self
.assertRegex(output
, 'default via 149.10.125.65 proto static onlink')
1170 self
.assertRegex(output
, 'default via 149.10.124.64 proto static')
1172 output
= subprocess
.check_output(['ip', 'route', 'show', 'type', 'blackhole']).rstrip().decode('utf-8')
1174 self
.assertRegex(output
, 'blackhole 202.54.1.2 proto static')
1176 output
= subprocess
.check_output(['ip', 'route', 'show', 'type', 'unreachable']).rstrip().decode('utf-8')
1178 self
.assertRegex(output
, 'unreachable 202.54.1.3 proto static')
1180 output
= subprocess
.check_output(['ip', 'route', 'show', 'type', 'prohibit']).rstrip().decode('utf-8')
1182 self
.assertRegex(output
, 'prohibit 202.54.1.4 proto static')
1184 subprocess
.call(['ip', 'route', 'del', 'blackhole', '202.54.1.2'])
1185 subprocess
.call(['ip', 'route', 'del', 'unreachable', '202.54.1.3'])
1186 subprocess
.call(['ip', 'route', 'del', 'prohibit', '202.54.1.4'])
1188 def test_ip_route_ipv6_src_route(self
):
1189 # a dummy device does not make the addresses go through tentative state, so we
1190 # reuse a bond from an earlier test, which does make the addresses go through
1191 # tentative state, and do our test on that
1192 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')
1193 self
.start_networkd()
1195 self
.assertTrue(self
.link_exits('dummy98'))
1196 self
.assertTrue(self
.link_exits('bond199'))
1198 output
= subprocess
.check_output(['ip', '-6', 'route', 'list', 'dev', 'bond199']).rstrip().decode('utf-8')
1200 self
.assertRegex(output
, 'abcd::/16')
1201 self
.assertRegex(output
, 'src')
1202 self
.assertRegex(output
, '2001:1234:56:8f63::2')
1204 def test_ip_link_mac_address(self
):
1205 self
.copy_unit_to_networkd_unit_path('25-address-link-section.network', '12-dummy.netdev')
1206 self
.start_networkd()
1208 self
.assertTrue(self
.link_exits('dummy98'))
1210 output
= subprocess
.check_output(['ip', 'link', 'show', 'dummy98']).rstrip().decode('utf-8')
1212 self
.assertRegex(output
, '00:01:02:aa:bb:cc')
1214 def test_ip_link_unmanaged(self
):
1215 self
.copy_unit_to_networkd_unit_path('25-link-section-unmanaged.network', '12-dummy.netdev')
1216 self
.start_networkd()
1218 self
.assertTrue(self
.link_exits('dummy98'))
1220 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1222 self
.assertRegex(output
, 'unmanaged')
1224 def test_ipv6_address_label(self
):
1225 self
.copy_unit_to_networkd_unit_path('25-ipv6-address-label-section.network', '12-dummy.netdev')
1226 self
.start_networkd()
1228 self
.assertTrue(self
.link_exits('dummy98'))
1230 output
= subprocess
.check_output(['ip', 'addrlabel', 'list']).rstrip().decode('utf-8')
1232 self
.assertRegex(output
, '2004:da8:1::/64')
1234 def test_ipv6_neighbor(self
):
1235 self
.copy_unit_to_networkd_unit_path('25-neighbor-section.network', '12-dummy.netdev')
1236 self
.start_networkd()
1238 self
.assertTrue(self
.link_exits('dummy98'))
1240 output
= subprocess
.check_output(['ip', 'neigh', 'list']).rstrip().decode('utf-8')
1242 self
.assertRegex(output
, '192.168.10.1.*00:00:5e:00:02:65.*PERMANENT')
1243 self
.assertRegex(output
, '2004:da8:1::1.*00:00:5e:00:02:66.*PERMANENT')
1245 def test_link_local_addressing(self
):
1246 self
.copy_unit_to_networkd_unit_path('25-link-local-addressing-yes.network', '11-dummy.netdev',
1247 '25-link-local-addressing-no.network', '12-dummy.netdev')
1248 self
.start_networkd(0)
1249 self
.wait_online(['test1:degraded', 'dummy98:carrier'])
1251 self
.assertTrue(self
.link_exits('test1'))
1252 self
.assertTrue(self
.link_exits('dummy98'))
1254 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'test1']).rstrip().decode('utf-8')
1256 self
.assertRegex(output
, 'inet .* scope link')
1257 self
.assertRegex(output
, 'inet6 .* scope link')
1259 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'dummy98']).rstrip().decode('utf-8')
1261 self
.assertNotRegex(output
, 'inet6* .* scope link')
1263 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1265 self
.assertRegex(output
, 'State: degraded \(configured\)')
1267 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1269 self
.assertRegex(output
, 'State: carrier \(configured\)')
1272 Documentation/networking/ip-sysctl.txt
1274 addr_gen_mode - INTEGER
1275 Defines how link-local and autoconf addresses are generated.
1277 0: generate address based on EUI64 (default)
1278 1: do no generate a link-local address, use EUI64 for addresses generated
1280 2: generate stable privacy addresses, using the secret from
1281 stable_secret (RFC7217)
1282 3: generate stable privacy addresses, using a random secret if unset
1285 test1_addr_gen_mode
= ''
1286 if os
.path
.exists(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, 'test1'), 'stable_secret')):
1287 with
open(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, 'test1'), 'stable_secret')) as f
:
1291 # if stable_secret is unset, then EIO is returned
1292 test1_addr_gen_mode
= '0'
1294 test1_addr_gen_mode
= '2'
1296 test1_addr_gen_mode
= '0'
1298 if os
.path
.exists(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, 'test1'), 'addr_gen_mode')):
1299 self
.assertEqual(self
.read_ipv6_sysctl_attr('test1', 'addr_gen_mode'), test1_addr_gen_mode
)
1301 if os
.path
.exists(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, 'dummy98'), 'addr_gen_mode')):
1302 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'addr_gen_mode'), '1')
1304 def test_sysctl(self
):
1305 self
.copy_unit_to_networkd_unit_path('25-sysctl.network', '12-dummy.netdev')
1306 self
.start_networkd(0)
1307 self
.wait_online(['dummy98:degraded'])
1309 self
.assertTrue(self
.link_exits('dummy98'))
1311 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'forwarding'), '1')
1312 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'use_tempaddr'), '2')
1313 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'dad_transmits'), '3')
1314 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'hop_limit'), '5')
1315 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'proxy_ndp'), '1')
1316 self
.assertEqual(self
.read_ipv4_sysctl_attr('dummy98', 'forwarding'),'1')
1317 self
.assertEqual(self
.read_ipv4_sysctl_attr('dummy98', 'proxy_arp'), '1')
1319 def test_sysctl_disable_ipv6(self
):
1320 self
.copy_unit_to_networkd_unit_path('25-sysctl-disable-ipv6.network', '12-dummy.netdev')
1322 print('## Disable ipv6')
1323 self
.assertEqual(subprocess
.call(['sysctl', 'net.ipv6.conf.all.disable_ipv6=1']), 0)
1324 self
.assertEqual(subprocess
.call(['sysctl', 'net.ipv6.conf.default.disable_ipv6=1']), 0)
1326 self
.start_networkd(0)
1327 self
.wait_online(['dummy98:routable'])
1329 self
.assertTrue(self
.link_exits('dummy98'))
1331 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
1333 self
.assertRegex(output
, 'inet 10.2.3.4/16 brd 10.2.255.255 scope global dummy98')
1334 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
1336 self
.assertEqual(output
, '')
1337 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1338 self
.assertRegex(output
, 'State: routable \(configured\)')
1340 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1342 print('## Enable ipv6')
1343 self
.assertEqual(subprocess
.call(['sysctl', 'net.ipv6.conf.all.disable_ipv6=0']), 0)
1344 self
.assertEqual(subprocess
.call(['sysctl', 'net.ipv6.conf.default.disable_ipv6=0']), 0)
1346 self
.start_networkd(0)
1347 self
.wait_online(['dummy98:routable'])
1349 self
.assertTrue(self
.link_exits('dummy98'))
1351 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
1353 self
.assertRegex(output
, 'inet 10.2.3.4/16 brd 10.2.255.255 scope global dummy98')
1354 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
1356 self
.assertRegex(output
, 'inet6 .* scope link')
1357 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1358 self
.assertRegex(output
, 'State: routable \(configured\)')
1360 def test_bind_carrier(self
):
1361 self
.copy_unit_to_networkd_unit_path('25-bind-carrier.network', '11-dummy.netdev')
1362 self
.start_networkd()
1364 self
.assertTrue(self
.link_exits('test1'))
1366 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1367 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1369 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1']).rstrip().decode('utf-8')
1371 self
.assertRegex(output
, 'UP,LOWER_UP')
1372 self
.assertRegex(output
, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
1373 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1374 self
.assertRegex(output
, 'State: routable \(configured\)')
1376 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy99', 'type', 'dummy']), 0)
1377 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy99', 'up']), 0)
1379 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1']).rstrip().decode('utf-8')
1381 self
.assertRegex(output
, 'UP,LOWER_UP')
1382 self
.assertRegex(output
, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
1383 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1384 self
.assertRegex(output
, 'State: routable \(configured\)')
1386 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1388 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1']).rstrip().decode('utf-8')
1390 self
.assertRegex(output
, 'UP,LOWER_UP')
1391 self
.assertRegex(output
, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
1392 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1393 self
.assertRegex(output
, 'State: routable \(configured\)')
1395 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy99']), 0)
1397 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1']).rstrip().decode('utf-8')
1399 self
.assertNotRegex(output
, 'UP,LOWER_UP')
1400 self
.assertRegex(output
, 'DOWN')
1401 self
.assertNotRegex(output
, '192.168.10')
1402 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1403 self
.assertRegex(output
, 'State: off \(configured\)')
1405 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1406 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1408 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1']).rstrip().decode('utf-8')
1410 self
.assertRegex(output
, 'UP,LOWER_UP')
1411 self
.assertRegex(output
, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
1412 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1413 self
.assertRegex(output
, 'State: routable \(configured\)')
1415 class NetworkdNetWorkBondTests(unittest
.TestCase
, Utilities
):
1425 '23-active-slave.network',
1426 '23-bond199.network',
1427 '23-primary-slave.network',
1428 '23-test1-bond199.network',
1429 '25-bond-active-backup-slave.netdev',
1432 'bond-slave.network']
1435 self
.link_remove(self
.links
)
1438 self
.link_remove(self
.links
)
1439 self
.remove_unit_from_networkd_path(self
.units
)
1441 def test_bond_active_slave(self
):
1442 self
.copy_unit_to_networkd_unit_path('23-active-slave.network', '23-bond199.network', '25-bond-active-backup-slave.netdev', '12-dummy.netdev')
1443 self
.start_networkd()
1445 self
.assertTrue(self
.link_exits('dummy98'))
1446 self
.assertTrue(self
.link_exits('bond199'))
1448 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'bond199']).rstrip().decode('utf-8')
1450 self
.assertRegex(output
, 'active_slave dummy98')
1452 def test_bond_primary_slave(self
):
1453 self
.copy_unit_to_networkd_unit_path('23-primary-slave.network', '23-test1-bond199.network', '25-bond-active-backup-slave.netdev', '11-dummy.netdev')
1454 self
.start_networkd()
1456 self
.assertTrue(self
.link_exits('test1'))
1457 self
.assertTrue(self
.link_exits('bond199'))
1459 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'bond199']).rstrip().decode('utf-8')
1461 self
.assertRegex(output
, 'primary test1')
1463 def test_bond_operstate(self
):
1464 self
.copy_unit_to_networkd_unit_path('25-bond.netdev', '11-dummy.netdev', '12-dummy.netdev',
1465 'bond99.network','bond-slave.network')
1466 self
.start_networkd()
1468 self
.assertTrue(self
.link_exits('bond99'))
1469 self
.assertTrue(self
.link_exits('dummy98'))
1470 self
.assertTrue(self
.link_exits('test1'))
1472 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'dummy98']).rstrip().decode('utf-8')
1474 self
.assertRegex(output
, 'SLAVE,UP,LOWER_UP')
1476 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'test1']).rstrip().decode('utf-8')
1478 self
.assertRegex(output
, 'SLAVE,UP,LOWER_UP')
1480 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'bond99']).rstrip().decode('utf-8')
1482 self
.assertRegex(output
, 'MASTER,UP,LOWER_UP')
1484 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1486 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1488 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1490 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1492 output
= subprocess
.check_output(['networkctl', 'status', 'bond99']).rstrip().decode('utf-8')
1494 self
.assertRegex(output
, 'State: routable \(configured\)')
1496 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'down']), 0)
1499 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1501 self
.assertRegex(output
, 'State: off \(configured\)')
1503 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1505 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1507 output
= subprocess
.check_output(['networkctl', 'status', 'bond99']).rstrip().decode('utf-8')
1509 self
.assertRegex(output
, 'State: degraded-carrier \(configured\)')
1511 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1514 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1516 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1518 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1520 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1522 output
= subprocess
.check_output(['networkctl', 'status', 'bond99']).rstrip().decode('utf-8')
1524 self
.assertRegex(output
, 'State: routable \(configured\)')
1526 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'down']), 0)
1527 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'test1', 'down']), 0)
1530 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1532 self
.assertRegex(output
, 'State: off \(configured\)')
1534 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1536 self
.assertRegex(output
, 'State: off \(configured\)')
1538 output
= subprocess
.check_output(['networkctl', 'status', 'bond99']).rstrip().decode('utf-8')
1540 self
.assertRegex(output
, 'State: no-carrier \(configured\)')
1542 class NetworkdNetWorkBridgeTests(unittest
.TestCase
, Utilities
):
1552 '26-bridge-slave-interface-1.network',
1553 '26-bridge-slave-interface-2.network',
1554 'bridge99-ignore-carrier-loss.network',
1558 self
.link_remove(self
.links
)
1561 self
.link_remove(self
.links
)
1562 self
.remove_unit_from_networkd_path(self
.units
)
1564 def test_bridge_property(self
):
1565 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev', '12-dummy.netdev', '26-bridge.netdev',
1566 '26-bridge-slave-interface-1.network', '26-bridge-slave-interface-2.network',
1568 self
.start_networkd()
1570 self
.assertTrue(self
.link_exits('dummy98'))
1571 self
.assertTrue(self
.link_exits('test1'))
1572 self
.assertTrue(self
.link_exits('bridge99'))
1574 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'test1']).rstrip().decode('utf-8')
1576 self
.assertRegex(output
, 'master')
1577 self
.assertRegex(output
, 'bridge')
1579 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'dummy98']).rstrip().decode('utf-8')
1581 self
.assertRegex(output
, 'master')
1582 self
.assertRegex(output
, 'bridge')
1584 output
= subprocess
.check_output(['ip', 'addr', 'show', 'bridge99']).rstrip().decode('utf-8')
1586 self
.assertRegex(output
, '192.168.0.15/24')
1588 output
= subprocess
.check_output(['bridge', '-d', 'link', 'show', 'dummy98']).rstrip().decode('utf-8')
1590 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'hairpin_mode'), '1')
1591 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'path_cost'), '400')
1592 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'unicast_flood'), '1')
1593 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'multicast_flood'), '0')
1594 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'multicast_fast_leave'), '1')
1595 if (os
.path
.exists('/sys/devices/virtual/net/bridge99/lower_dummy98/brport/neigh_suppress')):
1596 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'neigh_suppress'), '1')
1597 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'learning'), '0')
1599 # CONFIG_BRIDGE_IGMP_SNOOPING=y
1600 if (os
.path
.exists('/sys/devices/virtual/net/bridge00/lower_dummy98/brport/multicast_to_unicast')):
1601 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'multicast_to_unicast'), '1')
1603 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1604 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1606 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1607 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1609 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
1610 self
.assertRegex(output
, 'State: routable \(configured\)')
1612 self
.assertEqual(subprocess
.call(['ip', 'address', 'add', '192.168.0.16/24', 'dev', 'bridge99']), 0)
1615 output
= subprocess
.check_output(['ip', 'addr', 'show', 'bridge99']).rstrip().decode('utf-8')
1617 self
.assertRegex(output
, '192.168.0.16/24')
1619 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
1620 self
.assertRegex(output
, 'State: routable \(configured\)')
1622 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'test1']), 0)
1625 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
1626 self
.assertRegex(output
, 'State: degraded-carrier \(configured\)')
1628 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1631 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
1632 self
.assertRegex(output
, 'State: no-carrier \(configured\)')
1634 output
= subprocess
.check_output(['ip', 'address', 'show', 'bridge99']).rstrip().decode('utf-8')
1636 self
.assertRegex(output
, 'NO-CARRIER')
1637 self
.assertNotRegex(output
, '192.168.0.15/24')
1638 self
.assertNotRegex(output
, '192.168.0.16/24')
1640 def test_bridge_ignore_carrier_loss(self
):
1641 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev', '12-dummy.netdev', '26-bridge.netdev',
1642 '26-bridge-slave-interface-1.network', '26-bridge-slave-interface-2.network',
1643 'bridge99-ignore-carrier-loss.network')
1645 subprocess
.call(['ip', 'rule', 'del', 'table', '100'])
1647 self
.start_networkd()
1649 self
.assertTrue(self
.link_exits('dummy98'))
1650 self
.assertTrue(self
.link_exits('test1'))
1651 self
.assertTrue(self
.link_exits('bridge99'))
1653 self
.assertEqual(subprocess
.call(['ip', 'address', 'add', '192.168.0.16/24', 'dev', 'bridge99']), 0)
1656 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'test1']), 0)
1657 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1660 output
= subprocess
.check_output(['ip', 'address', 'show', 'bridge99']).rstrip().decode('utf-8')
1662 self
.assertRegex(output
, 'NO-CARRIER')
1663 self
.assertRegex(output
, 'inet 192.168.0.15/24 brd 192.168.0.255 scope global bridge99')
1664 self
.assertRegex(output
, 'inet 192.168.0.16/24 scope global secondary bridge99')
1666 subprocess
.call(['ip', 'rule', 'del', 'table', '100'])
1668 def test_bridge_ignore_carrier_loss_frequent_loss_and_gain(self
):
1669 self
.copy_unit_to_networkd_unit_path('26-bridge.netdev', '26-bridge-slave-interface-1.network',
1670 'bridge99-ignore-carrier-loss.network')
1672 subprocess
.call(['ip', 'rule', 'del', 'table', '100'])
1674 self
.start_networkd()
1676 self
.assertTrue(self
.link_exits('bridge99'))
1678 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1679 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1680 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1682 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1683 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1684 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1686 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1687 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1688 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1690 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1691 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1695 output
= subprocess
.check_output(['ip', 'address', 'show', 'bridge99']).rstrip().decode('utf-8')
1697 self
.assertRegex(output
, 'inet 192.168.0.15/24 brd 192.168.0.255 scope global bridge99')
1699 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
1700 self
.assertRegex(output
, 'State: routable \(configured\)')
1702 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1703 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1705 output
= subprocess
.check_output(['ip', 'rule', 'list', 'table', '100']).rstrip().decode('utf-8')
1707 self
.assertEqual(output
, '0: from all to 8.8.8.8 lookup 100')
1709 subprocess
.call(['ip', 'rule', 'del', 'table', '100'])
1711 class NetworkdNetWorkLLDPTests(unittest
.TestCase
, Utilities
):
1715 '23-emit-lldp.network',
1720 self
.link_remove(self
.links
)
1723 self
.link_remove(self
.links
)
1724 self
.remove_unit_from_networkd_path(self
.units
)
1726 def test_lldp(self
):
1727 self
.copy_unit_to_networkd_unit_path('23-emit-lldp.network', '24-lldp.network', '25-veth.netdev')
1728 self
.start_networkd()
1730 self
.assertTrue(self
.link_exits('veth99'))
1732 output
= subprocess
.check_output(['networkctl', 'lldp']).rstrip().decode('utf-8')
1734 self
.assertRegex(output
, 'veth-peer')
1735 self
.assertRegex(output
, 'veth99')
1737 class NetworkdNetworkRATests(unittest
.TestCase
, Utilities
):
1742 'ipv6-prefix.network',
1743 'ipv6-prefix-veth.network']
1746 self
.link_remove(self
.links
)
1749 self
.link_remove(self
.links
)
1750 self
.remove_unit_from_networkd_path(self
.units
)
1752 def test_ipv6_prefix_delegation(self
):
1753 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'ipv6-prefix.network', 'ipv6-prefix-veth.network')
1754 self
.start_networkd()
1756 self
.assertTrue(self
.link_exits('veth99'))
1758 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1760 self
.assertRegex(output
, '2002:da8:1:0')
1762 class NetworkdNetworkDHCPServerTests(unittest
.TestCase
, Utilities
):
1769 '24-search-domain.network',
1771 'dhcp-client.network',
1772 'dhcp-client-timezone-router.network',
1773 'dhcp-server.network',
1774 'dhcp-server-timezone-router.network']
1777 self
.link_remove(self
.links
)
1780 self
.link_remove(self
.links
)
1781 self
.remove_unit_from_networkd_path(self
.units
)
1783 def test_dhcp_server(self
):
1784 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-client.network', 'dhcp-server.network')
1785 self
.start_networkd()
1787 self
.assertTrue(self
.link_exits('veth99'))
1789 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1791 self
.assertRegex(output
, '192.168.5.*')
1792 self
.assertRegex(output
, 'Gateway: 192.168.5.1')
1793 self
.assertRegex(output
, 'DNS: 192.168.5.1')
1794 self
.assertRegex(output
, 'NTP: 192.168.5.1')
1796 def test_domain(self
):
1797 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '24-search-domain.network')
1798 self
.start_networkd()
1800 self
.assertTrue(self
.link_exits('dummy98'))
1802 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1804 self
.assertRegex(output
, 'Address: 192.168.42.100')
1805 self
.assertRegex(output
, 'DNS: 192.168.42.1')
1806 self
.assertRegex(output
, 'Search Domains: one')
1808 def test_emit_router_timezone(self
):
1809 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-client-timezone-router.network', 'dhcp-server-timezone-router.network')
1810 self
.start_networkd()
1812 self
.assertTrue(self
.link_exits('veth99'))
1814 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1816 self
.assertRegex(output
, 'Gateway: 192.168.5.*')
1817 self
.assertRegex(output
, '192.168.5.*')
1818 self
.assertRegex(output
, 'Europe/Berlin')
1820 class NetworkdNetworkDHCPClientTests(unittest
.TestCase
, Utilities
):
1830 'dhcp-client-anonymize.network',
1831 'dhcp-client-critical-connection.network',
1832 'dhcp-client-gateway-onlink-implicit.network',
1833 'dhcp-client-ipv4-dhcp-settings.network',
1834 'dhcp-client-ipv4-only-ipv6-disabled.network',
1835 'dhcp-client-ipv4-only.network',
1836 'dhcp-client-ipv6-only.network',
1837 'dhcp-client-ipv6-rapid-commit.network',
1838 'dhcp-client-listen-port.network',
1839 'dhcp-client-route-metric.network',
1840 'dhcp-client-route-table.network',
1841 'dhcp-client-vrf.network',
1842 'dhcp-client.network',
1843 'dhcp-server-veth-peer.network',
1844 'dhcp-v4-server-veth-peer.network',
1848 self
.link_remove(self
.links
)
1849 self
.stop_dnsmasq(dnsmasq_pid_file
)
1852 self
.link_remove(self
.links
)
1853 self
.remove_unit_from_networkd_path(self
.units
)
1854 self
.stop_dnsmasq(dnsmasq_pid_file
)
1855 self
.remove_lease_file()
1856 self
.remove_log_file()
1858 def test_dhcp_client_ipv6_only(self
):
1859 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network')
1860 self
.start_networkd()
1862 self
.assertTrue(self
.link_exits('veth99'))
1864 self
.start_dnsmasq()
1866 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1868 self
.assertRegex(output
, '2600::')
1869 self
.assertNotRegex(output
, '192.168.5')
1871 def test_dhcp_client_ipv4_only(self
):
1872 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv4-only-ipv6-disabled.network')
1873 self
.start_networkd()
1875 self
.assertTrue(self
.link_exits('veth99'))
1877 self
.start_dnsmasq()
1879 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1881 self
.assertNotRegex(output
, '2600::')
1882 self
.assertRegex(output
, '192.168.5')
1884 def test_dhcp_client_ipv4_ipv6(self
):
1885 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network',
1886 'dhcp-client-ipv4-only.network')
1887 self
.start_networkd()
1889 self
.assertTrue(self
.link_exits('veth99'))
1891 self
.start_dnsmasq()
1893 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1895 self
.assertRegex(output
, '2600::')
1896 self
.assertRegex(output
, '192.168.5')
1898 def test_dhcp_client_settings(self
):
1899 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv4-dhcp-settings.network')
1900 self
.start_networkd()
1902 self
.assertTrue(self
.link_exits('veth99'))
1904 self
.start_dnsmasq()
1906 print('## ip address show dev veth99')
1907 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
1909 self
.assertRegex(output
, '12:34:56:78:9a:bc')
1910 self
.assertRegex(output
, '192.168.5')
1911 self
.assertRegex(output
, '1492')
1914 print('## ip route show table main dev veth99')
1915 output
= subprocess
.check_output(['ip', 'route', 'show', 'table', 'main', 'dev', 'veth99']).rstrip().decode('utf-8')
1917 self
.assertNotRegex(output
, 'proto dhcp')
1919 print('## ip route show table 211 dev veth99')
1920 output
= subprocess
.check_output(['ip', 'route', 'show', 'table', '211', 'dev', 'veth99']).rstrip().decode('utf-8')
1922 self
.assertRegex(output
, 'default via 192.168.5.1 proto dhcp')
1923 self
.assertRegex(output
, '192.168.5.0/24 via 192.168.5.5 proto dhcp')
1924 self
.assertRegex(output
, '192.168.5.1 proto dhcp scope link')
1926 print('## dnsmasq log')
1927 self
.assertTrue(self
.search_words_in_dnsmasq_log('vendor class: SusantVendorTest', True))
1928 self
.assertTrue(self
.search_words_in_dnsmasq_log('DHCPDISCOVER(veth-peer) 12:34:56:78:9a:bc'))
1929 self
.assertTrue(self
.search_words_in_dnsmasq_log('client provides name: test-hostname'))
1930 self
.assertTrue(self
.search_words_in_dnsmasq_log('26:mtu'))
1932 def test_dhcp6_client_settings_rapidcommit_true(self
):
1933 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network')
1934 self
.start_networkd()
1936 self
.assertTrue(self
.link_exits('veth99'))
1938 self
.start_dnsmasq()
1940 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
1942 self
.assertRegex(output
, '12:34:56:78:9a:bc')
1943 self
.assertTrue(self
.search_words_in_dnsmasq_log('14:rapid-commit', True))
1945 def test_dhcp6_client_settings_rapidcommit_false(self
):
1946 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-rapid-commit.network')
1947 self
.start_networkd()
1949 self
.assertTrue(self
.link_exits('veth99'))
1951 self
.start_dnsmasq()
1953 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
1955 self
.assertRegex(output
, '12:34:56:78:9a:bc')
1956 self
.assertFalse(self
.search_words_in_dnsmasq_log('14:rapid-commit', True))
1958 def test_dhcp_client_settings_anonymize(self
):
1959 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-anonymize.network')
1960 self
.start_networkd()
1962 self
.assertTrue(self
.link_exits('veth99'))
1964 self
.start_dnsmasq()
1966 self
.assertFalse(self
.search_words_in_dnsmasq_log('VendorClassIdentifier=SusantVendorTest', True))
1967 self
.assertFalse(self
.search_words_in_dnsmasq_log('test-hostname'))
1968 self
.assertFalse(self
.search_words_in_dnsmasq_log('26:mtu'))
1970 def test_dhcp_client_listen_port(self
):
1971 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-listen-port.network')
1972 self
.start_networkd()
1974 self
.assertTrue(self
.link_exits('veth99'))
1976 self
.start_dnsmasq('--dhcp-alternate-port=67,5555')
1978 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
1980 self
.assertRegex(output
, '192.168.5.* dynamic')
1982 def test_dhcp_route_table_id(self
):
1983 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-route-table.network')
1984 self
.start_networkd()
1986 self
.assertTrue(self
.link_exits('veth99'))
1988 self
.start_dnsmasq()
1990 output
= subprocess
.check_output(['ip', 'route', 'show', 'table', '12']).rstrip().decode('utf-8')
1992 self
.assertRegex(output
, 'veth99 proto dhcp')
1993 self
.assertRegex(output
, '192.168.5.1')
1995 def test_dhcp_route_metric(self
):
1996 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-route-metric.network')
1997 self
.start_networkd()
1999 self
.assertTrue(self
.link_exits('veth99'))
2001 self
.start_dnsmasq()
2003 output
= subprocess
.check_output(['ip', 'route', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
2005 self
.assertRegex(output
, 'metric 24')
2007 def test_dhcp_route_criticalconnection_true(self
):
2008 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-critical-connection.network')
2009 self
.start_networkd()
2011 self
.assertTrue(self
.link_exits('veth99'))
2013 self
.start_dnsmasq()
2015 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
2017 self
.assertRegex(output
, '192.168.5.*')
2019 # Stoping dnsmasq as networkd won't be allowed to renew the DHCP lease.
2020 self
.stop_dnsmasq(dnsmasq_pid_file
)
2022 # Sleep for 120 sec as the dnsmasq minimum lease time can only be set to 120
2025 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
2027 self
.assertRegex(output
, '192.168.5.*')
2029 def test_dhcp_client_reuse_address_as_static(self
):
2030 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client.network')
2031 self
.start_networkd()
2033 self
.assertTrue(self
.link_exits('veth99'))
2035 self
.start_dnsmasq()
2037 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99', 'scope', 'global']).rstrip().decode('utf-8')
2039 self
.assertRegex(output
, '192.168.5')
2040 self
.assertRegex(output
, '2600::')
2042 ipv4_address
= re
.search('192\.168\.5\.[0-9]*/24', output
)
2043 ipv6_address
= re
.search('2600::[0-9a-f:]*/128', output
)
2044 static_network
= '\n'.join(['[Match]', 'Name=veth99', '[Network]', 'IPv6AcceptRA=no', 'Address=' + ipv4_address
.group(), 'Address=' + ipv6_address
.group()])
2045 print(static_network
)
2047 self
.remove_unit_from_networkd_path(['dhcp-client.network'])
2049 with
open(os
.path
.join(network_unit_file_path
, 'static.network'), mode
='w') as f
:
2050 f
.write(static_network
)
2052 self
.start_networkd()
2054 self
.assertTrue(self
.link_exits('veth99'))
2056 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99', 'scope', 'global']).rstrip().decode('utf-8')
2058 self
.assertRegex(output
, '192.168.5')
2059 self
.assertRegex(output
, 'valid_lft forever preferred_lft forever')
2061 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'veth99', 'scope', 'global']).rstrip().decode('utf-8')
2063 self
.assertRegex(output
, '2600::')
2064 self
.assertRegex(output
, 'valid_lft forever preferred_lft forever')
2066 @expectedFailureIfModuleIsNotAvailable('vrf')
2067 def test_dhcp_client_vrf(self
):
2068 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-vrf.network',
2069 '25-vrf.netdev', '25-vrf.network')
2070 self
.start_networkd()
2072 self
.assertTrue(self
.link_exits('veth99'))
2073 self
.assertTrue(self
.link_exits('vrf99'))
2075 self
.start_dnsmasq()
2077 print('## ip -d link show dev vrf99')
2078 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'dev', 'vrf99']).rstrip().decode('utf-8')
2080 self
.assertRegex(output
, 'vrf table 42')
2082 print('## ip address show vrf vrf99')
2083 output_ip_vrf
= subprocess
.check_output(['ip', 'address', 'show', 'vrf', 'vrf99']).rstrip().decode('utf-8')
2084 print(output_ip_vrf
)
2086 print('## ip address show dev veth99')
2087 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
2089 self
.assertEqual(output
, output_ip_vrf
)
2090 self
.assertRegex(output
, 'inet 169.254.[0-9]*.[0-9]*/16 brd 169.254.255.255 scope link veth99')
2091 self
.assertRegex(output
, 'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99')
2092 self
.assertRegex(output
, 'inet6 2600::[0-9a-f]*/128 scope global dynamic noprefixroute')
2093 self
.assertRegex(output
, 'inet6 .* scope link')
2095 print('## ip route show vrf vrf99')
2096 output
= subprocess
.check_output(['ip', 'route', 'show', 'vrf', 'vrf99']).rstrip().decode('utf-8')
2098 self
.assertRegex(output
, 'default via 192.168.5.1 dev veth99 proto dhcp src 192.168.5.')
2099 self
.assertRegex(output
, 'default dev veth99 proto static scope link')
2100 self
.assertRegex(output
, '169.254.0.0/16 dev veth99 proto kernel scope link src 169.254')
2101 self
.assertRegex(output
, '192.168.5.0/24 dev veth99 proto kernel scope link src 192.168.5')
2102 self
.assertRegex(output
, '192.168.5.0/24 via 192.168.5.5 dev veth99 proto dhcp')
2103 self
.assertRegex(output
, '192.168.5.1 dev veth99 proto dhcp scope link src 192.168.5')
2105 print('## ip route show table main dev veth99')
2106 output
= subprocess
.check_output(['ip', 'route', 'show', 'table', 'main', 'dev', 'veth99']).rstrip().decode('utf-8')
2108 self
.assertEqual(output
, '')
2110 output
= subprocess
.check_output(['networkctl', 'status', 'vrf99']).rstrip().decode('utf-8')
2112 self
.assertRegex(output
, 'State: carrier \(configured\)')
2114 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
2116 self
.assertRegex(output
, 'State: routable \(configured\)')
2118 def test_dhcp_client_gateway_onlink_implicit(self
):
2119 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network',
2120 'dhcp-client-gateway-onlink-implicit.network')
2121 self
.start_networkd()
2123 self
.assertTrue(self
.link_exits('veth99'))
2125 self
.start_dnsmasq()
2127 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
2129 self
.assertRegex(output
, '192.168.5')
2131 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'veth99', '10.0.0.0/8']).rstrip().decode('utf-8')
2133 self
.assertRegex(output
, 'onlink')
2134 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'veth99', '192.168.100.0/24']).rstrip().decode('utf-8')
2136 self
.assertRegex(output
, 'onlink')
2138 if __name__
== '__main__':
2139 unittest
.main(testRunner
=unittest
.TextTestRunner(stream
=sys
.stdout
,