]>
Commit | Line | Data |
---|---|---|
1f0e3109 SS |
1 | #!/usr/bin/env python3 |
2 | # SPDX-License-Identifier: LGPL-2.1+ | |
3 | # systemd-networkd tests | |
4 | ||
9c1ae484 | 5 | import argparse |
1f0e3109 | 6 | import os |
201bf07f | 7 | import re |
1f0e3109 SS |
8 | import shutil |
9 | import signal | |
a9bc5e37 YW |
10 | import subprocess |
11 | import sys | |
a9bc5e37 YW |
12 | import time |
13 | import unittest | |
1f0e3109 SS |
14 | from shutil import copytree |
15 | ||
d486a2d0 | 16 | network_unit_file_path='/run/systemd/network' |
bad4969b | 17 | networkd_runtime_directory='/run/systemd/netif' |
d486a2d0 | 18 | networkd_ci_path='/run/networkd-ci' |
1f0e3109 SS |
19 | network_sysctl_ipv6_path='/proc/sys/net/ipv6/conf' |
20 | network_sysctl_ipv4_path='/proc/sys/net/ipv4/conf' | |
21 | ||
d486a2d0 YW |
22 | dnsmasq_pid_file='/run/networkd-ci/test-test-dnsmasq.pid' |
23 | dnsmasq_log_file='/run/networkd-ci/test-dnsmasq-log-file' | |
1f0e3109 | 24 | |
9c1ae484 | 25 | networkd_bin='/usr/lib/systemd/systemd-networkd' |
b6d587d1 | 26 | resolved_bin='/usr/lib/systemd/systemd-resolved' |
5aa58329 | 27 | wait_online_bin='/usr/lib/systemd/systemd-networkd-wait-online' |
9c1ae484 | 28 | networkctl_bin='/usr/bin/networkctl' |
b6d587d1 YW |
29 | resolvectl_bin='/usr/bin/resolvectl' |
30 | timedatectl_bin='/usr/bin/timedatectl' | |
9c1ae484 | 31 | use_valgrind=False |
aaae5713 | 32 | enable_debug=True |
9c1ae484 | 33 | env = {} |
94c03122 | 34 | asan_options=None |
fa4c6095 | 35 | lsan_options=None |
94c03122 | 36 | ubsan_options=None |
5aa58329 | 37 | |
371810d1 ZJS |
38 | def check_output(*command, **kwargs): |
39 | # This replaces both check_output and check_call (output can be ignored) | |
40 | command = command[0].split() + list(command[1:]) | |
41 | return subprocess.check_output(command, universal_newlines=True, **kwargs).rstrip() | |
42 | ||
43 | def call(*command, **kwargs): | |
44 | command = command[0].split() + list(command[1:]) | |
45 | return subprocess.call(command, universal_newlines=True, **kwargs) | |
46 | ||
47 | def run(*command, **kwargs): | |
48 | command = command[0].split() + list(command[1:]) | |
49 | return subprocess.run(command, universal_newlines=True, **kwargs) | |
50 | ||
7a0a37b2 | 51 | def is_module_available(module_name): |
371810d1 ZJS |
52 | lsmod_output = check_output('lsmod') |
53 | module_re = re.compile(rf'^{re.escape(module_name)}\b', re.MULTILINE) | |
54 | return module_re.search(lsmod_output) or not call('modprobe', module_name) | |
7a0a37b2 EV |
55 | |
56 | def expectedFailureIfModuleIsNotAvailable(module_name): | |
57 | def f(func): | |
58 | if not is_module_available(module_name): | |
59 | return unittest.expectedFailure(func) | |
60 | return func | |
61 | ||
62 | return f | |
63 | ||
7bea7f9b SS |
64 | def expectedFailureIfERSPANModuleIsNotAvailable(): |
65 | def f(func): | |
371810d1 | 66 | rc = 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') |
7bea7f9b | 67 | if rc == 0: |
371810d1 | 68 | call('ip link del erspan99') |
7bea7f9b SS |
69 | return func |
70 | else: | |
71 | return unittest.expectedFailure(func) | |
72 | ||
73 | return f | |
74 | ||
d586a2c3 YW |
75 | def expectedFailureIfRoutingPolicyPortRangeIsNotAvailable(): |
76 | def f(func): | |
371810d1 | 77 | rc = call('ip rule add from 192.168.100.19 sport 1123-1150 dport 3224-3290 table 7') |
d586a2c3 | 78 | if rc == 0: |
371810d1 | 79 | call('ip rule del from 192.168.100.19 sport 1123-1150 dport 3224-3290 table 7') |
d586a2c3 YW |
80 | return func |
81 | else: | |
82 | return unittest.expectedFailure(func) | |
83 | ||
84 | return f | |
85 | ||
86 | def expectedFailureIfRoutingPolicyIPProtoIsNotAvailable(): | |
87 | def f(func): | |
371810d1 | 88 | rc = call('ip rule add not from 192.168.100.19 ipproto tcp table 7') |
d586a2c3 | 89 | if rc == 0: |
371810d1 | 90 | call('ip rule del not from 192.168.100.19 ipproto tcp table 7') |
d586a2c3 YW |
91 | return func |
92 | else: | |
93 | return unittest.expectedFailure(func) | |
94 | ||
95 | return f | |
96 | ||
e28fd95f YW |
97 | def expectedFailureIfLinkFileFieldIsNotSet(): |
98 | def f(func): | |
99 | support = False | |
100 | rc = call('ip link add name dummy99 type dummy') | |
101 | if rc == 0: | |
102 | ret = run('udevadm info -w10s /sys/class/net/dummy99', stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
103 | if ret.returncode == 0 and 'E: ID_NET_LINK_FILE=' in ret.stdout.rstrip(): | |
104 | support = True | |
105 | call('ip link del dummy99') | |
106 | ||
107 | if support: | |
108 | return func | |
109 | else: | |
110 | return unittest.expectedFailure(func) | |
111 | ||
112 | return f | |
113 | ||
1f0e3109 | 114 | def setUpModule(): |
1f0e3109 SS |
115 | os.makedirs(network_unit_file_path, exist_ok=True) |
116 | os.makedirs(networkd_ci_path, exist_ok=True) | |
117 | ||
118 | shutil.rmtree(networkd_ci_path) | |
6aea9276 | 119 | copytree(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'conf'), networkd_ci_path) |
1f0e3109 | 120 | |
371810d1 ZJS |
121 | check_output('systemctl stop systemd-networkd.socket') |
122 | check_output('systemctl stop systemd-networkd.service') | |
b6d587d1 | 123 | check_output('systemctl stop systemd-resolved.service') |
c0bf6733 | 124 | |
9c1ae484 YW |
125 | drop_in = [ |
126 | '[Service]', | |
127 | 'Restart=no', | |
128 | 'ExecStart=', | |
129 | ] | |
130 | if use_valgrind: | |
131 | drop_in += [ | |
132 | 'ExecStart=!!valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all ' + networkd_bin, | |
94c03122 | 133 | 'PrivateTmp=yes' |
9c1ae484 YW |
134 | ] |
135 | else: | |
136 | drop_in += ['ExecStart=!!' + networkd_bin] | |
137 | if enable_debug: | |
138 | drop_in += ['Environment=SYSTEMD_LOG_LEVEL=debug'] | |
94c03122 YW |
139 | if asan_options: |
140 | drop_in += ['Environment=ASAN_OPTIONS="' + asan_options + '"'] | |
fa4c6095 YW |
141 | if lsan_options: |
142 | drop_in += ['Environment=LSAN_OPTIONS="' + lsan_options + '"'] | |
94c03122 YW |
143 | if ubsan_options: |
144 | drop_in += ['Environment=UBSAN_OPTIONS="' + ubsan_options + '"'] | |
78690bb5 YW |
145 | if asan_options or lsan_options or ubsan_options: |
146 | drop_in += ['SystemCallFilter='] | |
fa4c6095 | 147 | if use_valgrind or asan_options or lsan_options or ubsan_options: |
94c03122 | 148 | drop_in += ['MemoryDenyWriteExecute=no'] |
9c1ae484 | 149 | |
9c1ae484 YW |
150 | os.makedirs('/run/systemd/system/systemd-networkd.service.d', exist_ok=True) |
151 | with open('/run/systemd/system/systemd-networkd.service.d/00-override.conf', mode='w') as f: | |
72917fcc | 152 | f.write('\n'.join(drop_in)) |
9c1ae484 | 153 | |
b6d587d1 YW |
154 | drop_in = [ |
155 | '[Service]', | |
156 | 'Restart=no', | |
157 | 'ExecStart=', | |
158 | ] | |
159 | if use_valgrind: | |
160 | drop_in += ['ExecStart=!!valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all ' + resolved_bin] | |
161 | else: | |
162 | drop_in += ['ExecStart=!!' + resolved_bin] | |
163 | if enable_debug: | |
164 | drop_in += ['Environment=SYSTEMD_LOG_LEVEL=debug'] | |
165 | if asan_options: | |
166 | drop_in += ['Environment=ASAN_OPTIONS="' + asan_options + '"'] | |
167 | if lsan_options: | |
168 | drop_in += ['Environment=LSAN_OPTIONS="' + lsan_options + '"'] | |
169 | if ubsan_options: | |
170 | drop_in += ['Environment=UBSAN_OPTIONS="' + ubsan_options + '"'] | |
171 | if asan_options or lsan_options or ubsan_options: | |
172 | drop_in += ['SystemCallFilter='] | |
173 | if use_valgrind or asan_options or lsan_options or ubsan_options: | |
174 | drop_in += ['MemoryDenyWriteExecute=no'] | |
175 | ||
176 | os.makedirs('/run/systemd/system/systemd-resolved.service.d', exist_ok=True) | |
177 | with open('/run/systemd/system/systemd-resolved.service.d/00-override.conf', mode='w') as f: | |
178 | f.write('\n'.join(drop_in)) | |
179 | ||
371810d1 ZJS |
180 | check_output('systemctl daemon-reload') |
181 | print(check_output('systemctl cat systemd-networkd.service')) | |
b6d587d1 YW |
182 | print(check_output('systemctl cat systemd-resolved.service')) |
183 | check_output('systemctl restart systemd-resolved') | |
9c1ae484 | 184 | |
1f0e3109 SS |
185 | def tearDownModule(): |
186 | shutil.rmtree(networkd_ci_path) | |
d4fda2a5 | 187 | |
371810d1 | 188 | check_output('systemctl stop systemd-networkd.service') |
b6d587d1 | 189 | check_output('systemctl stop systemd-resolved.service') |
d4fda2a5 | 190 | |
9c1ae484 | 191 | shutil.rmtree('/run/systemd/system/systemd-networkd.service.d') |
b6d587d1 | 192 | shutil.rmtree('/run/systemd/system/systemd-resolved.service.d') |
371810d1 | 193 | check_output('systemctl daemon-reload') |
1f0e3109 | 194 | |
371810d1 | 195 | check_output('systemctl start systemd-networkd.socket') |
b6d587d1 | 196 | check_output('systemctl start systemd-resolved.service') |
c0bf6733 | 197 | |
ec38833c ZJS |
198 | def read_link_attr(link, dev, attribute): |
199 | with open(os.path.join(os.path.join(os.path.join('/sys/class/net/', link), dev), attribute)) as f: | |
200 | return f.readline().strip() | |
201 | ||
202 | def read_bridge_port_attr(bridge, link, attribute): | |
203 | path_bridge = os.path.join('/sys/devices/virtual/net', bridge) | |
204 | path_port = 'lower_' + link + '/brport' | |
205 | path = os.path.join(path_bridge, path_port) | |
206 | ||
207 | with open(os.path.join(path, attribute)) as f: | |
208 | return f.readline().strip() | |
209 | ||
210 | def link_exists(link): | |
211 | return os.path.exists(os.path.join('/sys/class/net', link)) | |
212 | ||
213 | def remove_links(links): | |
214 | for link in links: | |
215 | if link_exists(link): | |
216 | call('ip link del dev', link) | |
217 | time.sleep(1) | |
218 | ||
219 | def remove_fou_ports(ports): | |
220 | for port in ports: | |
5239d7b3 | 221 | call('ip fou del port', port, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
ec38833c ZJS |
222 | |
223 | def remove_routing_policy_rule_tables(tables): | |
224 | for table in tables: | |
4ef39b49 YW |
225 | rc = 0 |
226 | while rc == 0: | |
227 | rc = call('ip rule del table', table, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) | |
ec38833c ZJS |
228 | |
229 | def remove_routes(routes): | |
230 | for route_type, addr in routes: | |
5239d7b3 | 231 | call('ip route del', route_type, addr, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
ec38833c | 232 | |
ad78d7b0 | 233 | def remove_l2tp_tunnels(tunnel_ids): |
ec38833c ZJS |
234 | output = check_output('ip l2tp show tunnel') |
235 | for tid in tunnel_ids: | |
236 | words='Tunnel ' + tid + ', encap' | |
237 | if words in output: | |
238 | call('ip l2tp del tunnel tid', tid) | |
239 | time.sleep(1) | |
240 | ||
241 | def read_ipv6_sysctl_attr(link, attribute): | |
242 | with open(os.path.join(os.path.join(network_sysctl_ipv6_path, link), attribute)) as f: | |
243 | return f.readline().strip() | |
244 | ||
245 | def read_ipv4_sysctl_attr(link, attribute): | |
246 | with open(os.path.join(os.path.join(network_sysctl_ipv4_path, link), attribute)) as f: | |
247 | return f.readline().strip() | |
248 | ||
249 | def copy_unit_to_networkd_unit_path(*units): | |
250 | print() | |
251 | for unit in units: | |
252 | shutil.copy(os.path.join(networkd_ci_path, unit), network_unit_file_path) | |
253 | if (os.path.exists(os.path.join(networkd_ci_path, unit + '.d'))): | |
254 | copytree(os.path.join(networkd_ci_path, unit + '.d'), os.path.join(network_unit_file_path, unit + '.d')) | |
255 | ||
256 | def remove_unit_from_networkd_path(units): | |
257 | for unit in units: | |
258 | if (os.path.exists(os.path.join(network_unit_file_path, unit))): | |
259 | os.remove(os.path.join(network_unit_file_path, unit)) | |
260 | if (os.path.exists(os.path.join(network_unit_file_path, unit + '.d'))): | |
261 | shutil.rmtree(os.path.join(network_unit_file_path, unit + '.d')) | |
262 | ||
263 | def warn_about_firewalld(): | |
264 | rc = call('systemctl -q is-active firewalld.service') | |
265 | if rc == 0: | |
266 | print('\nWARNING: firewalld.service is active. The test may fail.') | |
267 | ||
268 | def start_dnsmasq(additional_options='', ipv4_range='192.168.5.10,192.168.5.200', ipv6_range='2600::10,2600::20', lease_time='1h'): | |
269 | warn_about_firewalld() | |
270 | dnsmasq_command = f'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={ipv6_range},{lease_time} --dhcp-range={ipv4_range},{lease_time} -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 | |
271 | check_output(dnsmasq_command) | |
272 | ||
273 | def stop_dnsmasq(pid_file): | |
274 | if os.path.exists(pid_file): | |
275 | with open(pid_file, 'r') as f: | |
276 | pid = f.read().rstrip(' \t\r\n\0') | |
277 | os.kill(int(pid), signal.SIGTERM) | |
278 | ||
279 | os.remove(pid_file) | |
280 | ||
281 | def search_words_in_dnsmasq_log(words, show_all=False): | |
282 | if os.path.exists(dnsmasq_log_file): | |
283 | with open (dnsmasq_log_file) as in_file: | |
284 | contents = in_file.read() | |
285 | if show_all: | |
286 | print(contents) | |
287 | for line in contents.splitlines(): | |
288 | if words in line: | |
289 | in_file.close() | |
290 | print("%s, %s" % (words, line)) | |
291 | return True | |
292 | return False | |
293 | ||
294 | def remove_lease_file(): | |
295 | if os.path.exists(os.path.join(networkd_ci_path, 'lease')): | |
296 | os.remove(os.path.join(networkd_ci_path, 'lease')) | |
297 | ||
298 | def remove_log_file(): | |
299 | if os.path.exists(dnsmasq_log_file): | |
300 | os.remove(dnsmasq_log_file) | |
301 | ||
aaae5713 YW |
302 | def remove_networkd_state_files(): |
303 | if os.path.exists(os.path.join(networkd_runtime_directory, 'state')): | |
ec38833c | 304 | os.remove(os.path.join(networkd_runtime_directory, 'state')) |
aaae5713 YW |
305 | |
306 | def stop_networkd(show_logs=True, remove_state_files=True): | |
307 | if show_logs: | |
308 | invocation_id = check_output('systemctl show systemd-networkd -p InvocationID --value') | |
309 | check_output('systemctl stop systemd-networkd') | |
310 | if show_logs: | |
311 | print(check_output('journalctl _SYSTEMD_INVOCATION_ID=' + invocation_id)) | |
312 | if remove_state_files: | |
313 | remove_networkd_state_files() | |
314 | ||
315 | def start_networkd(sleep_sec=0): | |
316 | check_output('systemctl start systemd-networkd') | |
ec38833c ZJS |
317 | if sleep_sec > 0: |
318 | time.sleep(sleep_sec) | |
319 | ||
aaae5713 YW |
320 | def restart_networkd(sleep_sec=0, show_logs=True, remove_state_files=True): |
321 | stop_networkd(show_logs, remove_state_files) | |
322 | start_networkd(sleep_sec) | |
323 | ||
ec38833c ZJS |
324 | def get_operstate(link, show_status=True, setup_state='configured'): |
325 | output = check_output(*networkctl_cmd, 'status', link, env=env) | |
326 | if show_status: | |
327 | print(output) | |
328 | for line in output.splitlines(): | |
329 | if 'State:' in line and (not setup_state or setup_state in line): | |
330 | return line.split()[1] | |
331 | return None | |
1f0e3109 | 332 | |
ec38833c | 333 | class Utilities(): |
e39cc445 | 334 | def check_link_exists(self, link): |
ec38833c | 335 | self.assertTrue(link_exists(link)) |
2be0b6fc YW |
336 | |
337 | def check_operstate(self, link, expected, show_status=True, setup_state='configured'): | |
ec38833c | 338 | self.assertRegex(get_operstate(link, show_status, setup_state), expected) |
2be0b6fc | 339 | |
e2aea43f YW |
340 | def wait_online(self, links_with_operstate, timeout='20s', bool_any=False, setup_state='configured'): |
341 | args = wait_online_cmd + [f'--timeout={timeout}'] + [f'--interface={link}' for link in links_with_operstate] | |
342 | if bool_any: | |
343 | args += ['--any'] | |
344 | try: | |
345 | check_output(*args, env=env) | |
346 | except subprocess.CalledProcessError: | |
347 | for link in links_with_operstate: | |
348 | output = check_output(*networkctl_cmd, 'status', link.split(':')[0], env=env) | |
349 | print(output) | |
350 | raise | |
351 | if not bool_any: | |
352 | for link in links_with_operstate: | |
353 | output = check_output(*networkctl_cmd, 'status', link.split(':')[0]) | |
354 | print(output) | |
355 | for line in output.splitlines(): | |
356 | if 'State:' in line: | |
357 | self.assertRegex(line, setup_state) | |
358 | ||
53c32c2b | 359 | def wait_address(self, link, address_regex, scope='global', ipv='', timeout_sec=100): |
2629df47 YW |
360 | for i in range(timeout_sec): |
361 | if i > 0: | |
362 | time.sleep(1) | |
371810d1 | 363 | output = check_output(f'ip {ipv} address show dev {link} scope {scope}') |
2629df47 YW |
364 | if re.search(address_regex, output): |
365 | break | |
366 | else: | |
367 | self.assertRegex(output, address_regex) | |
368 | ||
1ca44d7d YW |
369 | class NetworkctlTests(unittest.TestCase, Utilities): |
370 | ||
371 | links = [ | |
372 | 'test1', | |
373 | 'veth99', | |
374 | ] | |
375 | ||
376 | units = [ | |
377 | '11-dummy.netdev', | |
6d5b4efe | 378 | '11-dummy-mtu.netdev', |
1ca44d7d YW |
379 | '11-dummy.network', |
380 | '25-veth.netdev', | |
381 | 'netdev-link-local-addressing-yes.network', | |
382 | ] | |
383 | ||
384 | def setUp(self): | |
ec38833c | 385 | remove_links(self.links) |
aaae5713 | 386 | stop_networkd(show_logs=False) |
1ca44d7d YW |
387 | |
388 | def tearDown(self): | |
ec38833c ZJS |
389 | remove_links(self.links) |
390 | remove_unit_from_networkd_path(self.units) | |
aaae5713 | 391 | stop_networkd(show_logs=True) |
1ca44d7d YW |
392 | |
393 | def test_glob(self): | |
ec38833c | 394 | copy_unit_to_networkd_unit_path('11-dummy.netdev', '11-dummy.network') |
2cf6fdff | 395 | start_networkd() |
1ca44d7d | 396 | |
e2aea43f | 397 | self.wait_online(['test1:degraded']) |
1ca44d7d | 398 | |
371810d1 | 399 | output = check_output(*networkctl_cmd, 'list', env=env) |
1ca44d7d YW |
400 | self.assertRegex(output, '1 lo ') |
401 | self.assertRegex(output, 'test1') | |
402 | ||
371810d1 | 403 | output = check_output(*networkctl_cmd, 'list', 'test1', env=env) |
1ca44d7d YW |
404 | self.assertNotRegex(output, '1 lo ') |
405 | self.assertRegex(output, 'test1') | |
406 | ||
371810d1 | 407 | output = check_output(*networkctl_cmd, 'list', 'te*', env=env) |
1ca44d7d YW |
408 | self.assertNotRegex(output, '1 lo ') |
409 | self.assertRegex(output, 'test1') | |
410 | ||
371810d1 | 411 | output = check_output(*networkctl_cmd, 'status', 'te*', env=env) |
1ca44d7d YW |
412 | self.assertNotRegex(output, '1: lo ') |
413 | self.assertRegex(output, 'test1') | |
414 | ||
371810d1 | 415 | output = check_output(*networkctl_cmd, 'status', 'tes[a-z][0-9]', env=env) |
1ca44d7d YW |
416 | self.assertNotRegex(output, '1: lo ') |
417 | self.assertRegex(output, 'test1') | |
418 | ||
6d5b4efe | 419 | def test_mtu(self): |
ec38833c | 420 | copy_unit_to_networkd_unit_path('11-dummy-mtu.netdev', '11-dummy.network') |
2cf6fdff | 421 | start_networkd() |
6d5b4efe | 422 | |
e2aea43f | 423 | self.wait_online(['test1:degraded']) |
6d5b4efe | 424 | |
371810d1 | 425 | output = check_output(*networkctl_cmd, 'status', 'test1', env=env) |
6d5b4efe YW |
426 | self.assertRegex(output, 'MTU: 1600') |
427 | ||
e28fd95f YW |
428 | def test_type(self): |
429 | copy_unit_to_networkd_unit_path('11-dummy.netdev', '11-dummy.network') | |
430 | start_networkd() | |
e2aea43f | 431 | self.wait_online(['test1:degraded']) |
e28fd95f YW |
432 | |
433 | output = check_output(*networkctl_cmd, 'status', 'test1') | |
434 | print(output) | |
435 | self.assertRegex(output, 'Type: ether') | |
436 | ||
437 | output = check_output(*networkctl_cmd, 'status', 'lo') | |
438 | print(output) | |
439 | self.assertRegex(output, 'Type: loopback') | |
440 | ||
441 | @expectedFailureIfLinkFileFieldIsNotSet() | |
442 | def test_udev_link_file(self): | |
443 | copy_unit_to_networkd_unit_path('11-dummy.netdev', '11-dummy.network') | |
444 | start_networkd() | |
e2aea43f | 445 | self.wait_online(['test1:degraded']) |
e28fd95f YW |
446 | |
447 | output = check_output(*networkctl_cmd, 'status', 'test1') | |
448 | print(output) | |
449 | self.assertRegex(output, r'Link File: (?:/usr)/lib/systemd/network/99-default.link') | |
450 | self.assertRegex(output, r'Network File: /run/systemd/network/11-dummy.network') | |
451 | ||
452 | output = check_output(*networkctl_cmd, 'status', 'lo') | |
453 | print(output) | |
454 | self.assertRegex(output, r'Link File: (?:/usr)/lib/systemd/network/99-default.link') | |
455 | self.assertRegex(output, r'Network File: n/a') | |
456 | ||
bee692fd | 457 | def test_delete_links(self): |
ec38833c ZJS |
458 | copy_unit_to_networkd_unit_path('11-dummy.netdev', '11-dummy.network', |
459 | '25-veth.netdev', 'netdev-link-local-addressing-yes.network') | |
2cf6fdff | 460 | start_networkd() |
bee692fd | 461 | |
e2aea43f | 462 | self.wait_online(['test1:degraded', 'veth99:degraded', 'veth-peer:degraded']) |
bee692fd | 463 | |
371810d1 | 464 | check_output(*networkctl_cmd, 'delete', 'test1', 'veth99') |
ec38833c ZJS |
465 | self.assertFalse(link_exists('test1')) |
466 | self.assertFalse(link_exists('veth99')) | |
467 | self.assertFalse(link_exists('veth-peer')) | |
bee692fd | 468 | |
1f0e3109 SS |
469 | class NetworkdNetDevTests(unittest.TestCase, Utilities): |
470 | ||
e64dc406 YW |
471 | links_remove_earlier = [ |
472 | 'xfrm99', | |
473 | ] | |
474 | ||
475 | links = [ | |
09ea6724 YW |
476 | '6rdtun99', |
477 | 'bond99', | |
478 | 'bridge99', | |
479 | 'dropin-test', | |
480 | 'dummy98', | |
6a97a864 YW |
481 | 'erspan98', |
482 | 'erspan99', | |
09ea6724 | 483 | 'geneve99', |
4b6a6d1e | 484 | 'gretap96', |
6a97a864 | 485 | 'gretap98', |
09ea6724 | 486 | 'gretap99', |
4b6a6d1e | 487 | 'gretun96', |
6a97a864 YW |
488 | 'gretun97', |
489 | 'gretun98', | |
09ea6724 | 490 | 'gretun99', |
6a97a864 | 491 | 'ip6gretap98', |
09ea6724 | 492 | 'ip6gretap99', |
42a29fcb | 493 | 'ip6gretun96', |
6a97a864 YW |
494 | 'ip6gretun97', |
495 | 'ip6gretun98', | |
496 | 'ip6gretun99', | |
497 | 'ip6tnl97', | |
498 | 'ip6tnl98', | |
09ea6724 | 499 | 'ip6tnl99', |
4b6a6d1e | 500 | 'ipiptun96', |
6a97a864 YW |
501 | 'ipiptun97', |
502 | 'ipiptun98', | |
09ea6724 YW |
503 | 'ipiptun99', |
504 | 'ipvlan99', | |
956c8fec | 505 | 'ipvtap99', |
09ea6724 YW |
506 | 'isataptun99', |
507 | 'macvlan99', | |
508 | 'macvtap99', | |
811f33d0 | 509 | 'nlmon99', |
4b6a6d1e | 510 | 'sittun96', |
6a97a864 YW |
511 | 'sittun97', |
512 | 'sittun98', | |
09ea6724 YW |
513 | 'sittun99', |
514 | 'tap99', | |
515 | 'test1', | |
516 | 'tun99', | |
517 | 'vcan99', | |
518 | 'veth99', | |
519 | 'vlan99', | |
520 | 'vrf99', | |
6a97a864 YW |
521 | 'vti6tun97', |
522 | 'vti6tun98', | |
09ea6724 | 523 | 'vti6tun99', |
42a29fcb | 524 | 'vtitun96', |
6a97a864 YW |
525 | 'vtitun97', |
526 | 'vtitun98', | |
09ea6724 | 527 | 'vtitun99', |
f63b14d3 | 528 | 'vxcan99', |
09ea6724 | 529 | 'vxlan99', |
da44fb8a | 530 | 'wg98', |
e64dc406 YW |
531 | 'wg99', |
532 | ] | |
09ea6724 YW |
533 | |
534 | units = [ | |
535 | '10-dropin-test.netdev', | |
536 | '11-dummy.netdev', | |
03db80b2 | 537 | '11-dummy.network', |
09ea6724 | 538 | '12-dummy.netdev', |
6b9518a0 YW |
539 | '13-not-match-udev-property.network', |
540 | '14-match-udev-property.network', | |
753e0a24 | 541 | '15-name-conflict-test.netdev', |
09ea6724 YW |
542 | '21-macvlan.netdev', |
543 | '21-macvtap.netdev', | |
7f45d738 | 544 | '21-vlan-test1.network', |
09ea6724 YW |
545 | '21-vlan.netdev', |
546 | '21-vlan.network', | |
547 | '25-6rd-tunnel.netdev', | |
548 | '25-bond.netdev', | |
fde60a42 | 549 | '25-bond-balanced-tlb.netdev', |
09ea6724 | 550 | '25-bridge.netdev', |
1285edf3 | 551 | '25-bridge-configure-without-carrier.network', |
03db80b2 | 552 | '25-bridge.network', |
6a97a864 | 553 | '25-erspan-tunnel-local-any.netdev', |
09ea6724 | 554 | '25-erspan-tunnel.netdev', |
4b6a6d1e YW |
555 | '25-fou-gretap.netdev', |
556 | '25-fou-gre.netdev', | |
557 | '25-fou-ipip.netdev', | |
558 | '25-fou-ipproto-gre.netdev', | |
559 | '25-fou-ipproto-ipip.netdev', | |
560 | '25-fou-sit.netdev', | |
09ea6724 | 561 | '25-geneve.netdev', |
6a97a864 | 562 | '25-gretap-tunnel-local-any.netdev', |
09ea6724 | 563 | '25-gretap-tunnel.netdev', |
42a29fcb | 564 | '25-gre-tunnel-any-any.netdev', |
6a97a864 YW |
565 | '25-gre-tunnel-local-any.netdev', |
566 | '25-gre-tunnel-remote-any.netdev', | |
09ea6724 | 567 | '25-gre-tunnel.netdev', |
6a97a864 YW |
568 | '25-ip6gretap-tunnel-local-any.netdev', |
569 | '25-ip6gretap-tunnel.netdev', | |
42a29fcb | 570 | '25-ip6gre-tunnel-any-any.netdev', |
6a97a864 YW |
571 | '25-ip6gre-tunnel-local-any.netdev', |
572 | '25-ip6gre-tunnel-remote-any.netdev', | |
09ea6724 | 573 | '25-ip6gre-tunnel.netdev', |
42a29fcb | 574 | '25-ip6tnl-tunnel-any-any.netdev', |
6a97a864 | 575 | '25-ip6tnl-tunnel-local-any.netdev', |
42a29fcb | 576 | '25-ip6tnl-tunnel-remote-any.netdev', |
09ea6724 | 577 | '25-ip6tnl-tunnel.netdev', |
42a29fcb | 578 | '25-ipip-tunnel-any-any.netdev', |
09ea6724 | 579 | '25-ipip-tunnel-independent.netdev', |
95082dbe | 580 | '25-ipip-tunnel-independent-loopback.netdev', |
6a97a864 YW |
581 | '25-ipip-tunnel-local-any.netdev', |
582 | '25-ipip-tunnel-remote-any.netdev', | |
09ea6724 YW |
583 | '25-ipip-tunnel.netdev', |
584 | '25-ipvlan.netdev', | |
956c8fec | 585 | '25-ipvtap.netdev', |
09ea6724 | 586 | '25-isatap-tunnel.netdev', |
02849d8b YW |
587 | '25-macsec.key', |
588 | '25-macsec.netdev', | |
589 | '25-macsec.network', | |
811f33d0 | 590 | '25-nlmon.netdev', |
42a29fcb | 591 | '25-sit-tunnel-any-any.netdev', |
6a97a864 YW |
592 | '25-sit-tunnel-local-any.netdev', |
593 | '25-sit-tunnel-remote-any.netdev', | |
09ea6724 YW |
594 | '25-sit-tunnel.netdev', |
595 | '25-tap.netdev', | |
596 | '25-tun.netdev', | |
11309591 YW |
597 | '25-tunnel-local-any.network', |
598 | '25-tunnel-remote-any.network', | |
599 | '25-tunnel.network', | |
09ea6724 YW |
600 | '25-vcan.netdev', |
601 | '25-veth.netdev', | |
602 | '25-vrf.netdev', | |
42a29fcb | 603 | '25-vti6-tunnel-any-any.netdev', |
6a97a864 YW |
604 | '25-vti6-tunnel-local-any.netdev', |
605 | '25-vti6-tunnel-remote-any.netdev', | |
09ea6724 | 606 | '25-vti6-tunnel.netdev', |
42a29fcb | 607 | '25-vti-tunnel-any-any.netdev', |
6a97a864 YW |
608 | '25-vti-tunnel-local-any.netdev', |
609 | '25-vti-tunnel-remote-any.netdev', | |
09ea6724 | 610 | '25-vti-tunnel.netdev', |
f63b14d3 | 611 | '25-vxcan.netdev', |
09ea6724 | 612 | '25-vxlan.netdev', |
da44fb8a YW |
613 | '25-wireguard-23-peers.netdev', |
614 | '25-wireguard-23-peers.network', | |
9e5d79e7 | 615 | '25-wireguard-preshared-key.txt', |
39bcff3b | 616 | '25-wireguard-private-key.txt', |
09ea6724 | 617 | '25-wireguard.netdev', |
5a0bd90b | 618 | '25-wireguard.network', |
e64dc406 YW |
619 | '25-xfrm.netdev', |
620 | '25-xfrm-independent.netdev', | |
09ea6724 | 621 | '6rd.network', |
6730a1f3 | 622 | 'erspan.network', |
09ea6724 YW |
623 | 'gre.network', |
624 | 'gretap.network', | |
625 | 'gretun.network', | |
626 | 'ip6gretap.network', | |
6a97a864 | 627 | 'ip6gretun.network', |
09ea6724 YW |
628 | 'ip6tnl.network', |
629 | 'ipip.network', | |
630 | 'ipvlan.network', | |
956c8fec | 631 | 'ipvtap.network', |
09ea6724 | 632 | 'isatap.network', |
02849d8b | 633 | 'macsec.network', |
09ea6724 YW |
634 | 'macvlan.network', |
635 | 'macvtap.network', | |
077f9abc | 636 | 'netdev-link-local-addressing-yes.network', |
09ea6724 YW |
637 | 'sit.network', |
638 | 'vti6.network', | |
639 | 'vti.network', | |
1c862fe0 | 640 | 'vxlan-test1.network', |
e64dc406 YW |
641 | 'vxlan.network', |
642 | 'xfrm.network', | |
643 | ] | |
1f0e3109 | 644 | |
def9fc0d YW |
645 | fou_ports = [ |
646 | '55555', | |
647 | '55556'] | |
648 | ||
1f0e3109 | 649 | def setUp(self): |
ec38833c | 650 | remove_fou_ports(self.fou_ports) |
e64dc406 | 651 | remove_links(self.links_remove_earlier) |
ec38833c | 652 | remove_links(self.links) |
aaae5713 | 653 | stop_networkd(show_logs=False) |
1f0e3109 SS |
654 | |
655 | def tearDown(self): | |
ec38833c | 656 | remove_fou_ports(self.fou_ports) |
e64dc406 | 657 | remove_links(self.links_remove_earlier) |
ec38833c ZJS |
658 | remove_links(self.links) |
659 | remove_unit_from_networkd_path(self.units) | |
aaae5713 | 660 | stop_networkd(show_logs=True) |
1f0e3109 | 661 | |
1ca44d7d | 662 | def test_dropin_and_name_conflict(self): |
ec38833c | 663 | copy_unit_to_networkd_unit_path('10-dropin-test.netdev', '15-name-conflict-test.netdev') |
2cf6fdff | 664 | start_networkd() |
d80734f7 | 665 | |
e2aea43f | 666 | self.wait_online(['dropin-test:off'], setup_state='unmanaged') |
d80734f7 | 667 | |
371810d1 | 668 | output = check_output('ip link show dropin-test') |
d80734f7 YW |
669 | print(output) |
670 | self.assertRegex(output, '00:50:56:c0:00:28') | |
671 | ||
6b9518a0 YW |
672 | def test_match_udev_property(self): |
673 | copy_unit_to_networkd_unit_path('12-dummy.netdev', '13-not-match-udev-property.network', '14-match-udev-property.network') | |
674 | start_networkd() | |
e2aea43f | 675 | self.wait_online(['dummy98:routable']) |
6b9518a0 YW |
676 | |
677 | output = check_output('networkctl status dummy98') | |
678 | print(output) | |
679 | self.assertRegex(output, 'Network File: /run/systemd/network/14-match-udev-property') | |
680 | ||
03db80b2 | 681 | def test_wait_online_any(self): |
ec38833c | 682 | copy_unit_to_networkd_unit_path('25-bridge.netdev', '25-bridge.network', '11-dummy.netdev', '11-dummy.network') |
2cf6fdff | 683 | start_networkd() |
03db80b2 | 684 | |
e2aea43f | 685 | self.wait_online(['bridge99', 'test1:degraded'], bool_any=True) |
03db80b2 | 686 | |
791c1140 YW |
687 | self.check_operstate('bridge99', '(?:off|no-carrier)', setup_state='configuring') |
688 | self.check_operstate('test1', 'degraded') | |
03db80b2 | 689 | |
1f0e3109 | 690 | def test_bridge(self): |
1285edf3 | 691 | copy_unit_to_networkd_unit_path('25-bridge.netdev', '25-bridge-configure-without-carrier.network') |
2cf6fdff | 692 | start_networkd() |
1f0e3109 | 693 | |
e2aea43f | 694 | self.wait_online(['bridge99:no-carrier']) |
1f0e3109 | 695 | |
3d165124 | 696 | tick = os.sysconf('SC_CLK_TCK') |
ec38833c ZJS |
697 | self.assertEqual(9, round(float(read_link_attr('bridge99', 'bridge', 'hello_time')) / tick)) |
698 | self.assertEqual(9, round(float(read_link_attr('bridge99', 'bridge', 'max_age')) / tick)) | |
699 | self.assertEqual(9, round(float(read_link_attr('bridge99', 'bridge','forward_delay')) / tick)) | |
700 | self.assertEqual(9, round(float(read_link_attr('bridge99', 'bridge','ageing_time')) / tick)) | |
701 | self.assertEqual(9, int(read_link_attr('bridge99', 'bridge','priority'))) | |
702 | self.assertEqual(1, int(read_link_attr('bridge99', 'bridge','multicast_querier'))) | |
703 | self.assertEqual(1, int(read_link_attr('bridge99', 'bridge','multicast_snooping'))) | |
704 | self.assertEqual(1, int(read_link_attr('bridge99', 'bridge','stp_state'))) | |
1f0e3109 SS |
705 | |
706 | def test_bond(self): | |
ec38833c | 707 | copy_unit_to_networkd_unit_path('25-bond.netdev', '25-bond-balanced-tlb.netdev') |
2cf6fdff | 708 | start_networkd() |
ec38833c | 709 | |
e2aea43f | 710 | self.wait_online(['bond99:off', 'bond98:off'], setup_state='unmanaged') |
ec38833c ZJS |
711 | |
712 | self.assertEqual('802.3ad 4', read_link_attr('bond99', 'bonding', 'mode')) | |
713 | self.assertEqual('layer3+4 1', read_link_attr('bond99', 'bonding', 'xmit_hash_policy')) | |
714 | self.assertEqual('1000', read_link_attr('bond99', 'bonding', 'miimon')) | |
715 | self.assertEqual('fast 1', read_link_attr('bond99', 'bonding', 'lacp_rate')) | |
716 | self.assertEqual('2000', read_link_attr('bond99', 'bonding', 'updelay')) | |
717 | self.assertEqual('2000', read_link_attr('bond99', 'bonding', 'downdelay')) | |
718 | self.assertEqual('4', read_link_attr('bond99', 'bonding', 'resend_igmp')) | |
719 | self.assertEqual('1', read_link_attr('bond99', 'bonding', 'min_links')) | |
720 | self.assertEqual('1218', read_link_attr('bond99', 'bonding', 'ad_actor_sys_prio')) | |
721 | self.assertEqual('811', read_link_attr('bond99', 'bonding', 'ad_user_port_key')) | |
722 | self.assertEqual('00:11:22:33:44:55', read_link_attr('bond99', 'bonding', 'ad_actor_system')) | |
723 | ||
724 | self.assertEqual('balance-tlb 5', read_link_attr('bond98', 'bonding', 'mode')) | |
725 | self.assertEqual('1', read_link_attr('bond98', 'bonding', 'tlb_dynamic_lb')) | |
fde60a42 | 726 | |
1f0e3109 | 727 | def test_vlan(self): |
ec38833c ZJS |
728 | copy_unit_to_networkd_unit_path('21-vlan.netdev', '11-dummy.netdev', |
729 | '21-vlan.network', '21-vlan-test1.network') | |
2cf6fdff | 730 | start_networkd() |
1f0e3109 | 731 | |
e2aea43f | 732 | self.wait_online(['test1:degraded', 'vlan99:routable']) |
1f0e3109 | 733 | |
371810d1 | 734 | output = check_output('ip -d link show test1') |
72b7f1b9 | 735 | print(output) |
7d7be1b9 | 736 | self.assertRegex(output, ' mtu 2000 ') |
72b7f1b9 | 737 | |
371810d1 | 738 | output = check_output('ip -d link show vlan99') |
14ecd604 | 739 | print(output) |
06895a1d YW |
740 | self.assertRegex(output, ' mtu 2000 ') |
741 | self.assertRegex(output, 'REORDER_HDR') | |
742 | self.assertRegex(output, 'LOOSE_BINDING') | |
743 | self.assertRegex(output, 'GVRP') | |
744 | self.assertRegex(output, 'MVRP') | |
745 | self.assertRegex(output, ' id 99 ') | |
1f0e3109 | 746 | |
371810d1 | 747 | output = check_output('ip -4 address show dev test1') |
7f45d738 YW |
748 | print(output) |
749 | self.assertRegex(output, 'inet 192.168.24.5/24 brd 192.168.24.255 scope global test1') | |
750 | self.assertRegex(output, 'inet 192.168.25.5/24 brd 192.168.25.255 scope global test1') | |
751 | ||
371810d1 | 752 | output = check_output('ip -4 address show dev vlan99') |
7f45d738 YW |
753 | print(output) |
754 | self.assertRegex(output, 'inet 192.168.23.5/24 brd 192.168.23.255 scope global vlan99') | |
755 | ||
1f0e3109 | 756 | def test_macvtap(self): |
460feb61 YW |
757 | for mode in ['private', 'vepa', 'bridge', 'passthru']: |
758 | with self.subTest(mode=mode): | |
759 | if mode != 'private': | |
760 | self.tearDown() | |
ec38833c ZJS |
761 | copy_unit_to_networkd_unit_path('21-macvtap.netdev', 'netdev-link-local-addressing-yes.network', |
762 | '11-dummy.netdev', 'macvtap.network') | |
460feb61 YW |
763 | with open(os.path.join(network_unit_file_path, '21-macvtap.netdev'), mode='a') as f: |
764 | f.write('[MACVTAP]\nMode=' + mode) | |
2cf6fdff | 765 | start_networkd() |
1f0e3109 | 766 | |
e2aea43f | 767 | self.wait_online(['macvtap99:degraded', 'test1:degraded']) |
460feb61 | 768 | |
371810d1 | 769 | output = check_output('ip -d link show macvtap99') |
460feb61 YW |
770 | print(output) |
771 | self.assertRegex(output, 'macvtap mode ' + mode + ' ') | |
1f0e3109 SS |
772 | |
773 | def test_macvlan(self): | |
dff9792b YW |
774 | for mode in ['private', 'vepa', 'bridge', 'passthru']: |
775 | with self.subTest(mode=mode): | |
776 | if mode != 'private': | |
777 | self.tearDown() | |
ec38833c ZJS |
778 | copy_unit_to_networkd_unit_path('21-macvlan.netdev', 'netdev-link-local-addressing-yes.network', |
779 | '11-dummy.netdev', 'macvlan.network') | |
dff9792b YW |
780 | with open(os.path.join(network_unit_file_path, '21-macvlan.netdev'), mode='a') as f: |
781 | f.write('[MACVLAN]\nMode=' + mode) | |
2cf6fdff | 782 | start_networkd() |
dff9792b | 783 | |
e2aea43f | 784 | self.wait_online(['macvlan99:degraded', 'test1:degraded']) |
dff9792b | 785 | |
371810d1 | 786 | output = check_output('ip -d link show test1') |
dff9792b YW |
787 | print(output) |
788 | self.assertRegex(output, ' mtu 2000 ') | |
72b7f1b9 | 789 | |
371810d1 | 790 | output = check_output('ip -d link show macvlan99') |
dff9792b YW |
791 | print(output) |
792 | self.assertRegex(output, ' mtu 2000 ') | |
793 | self.assertRegex(output, 'macvlan mode ' + mode + ' ') | |
72b7f1b9 | 794 | |
7a0a37b2 | 795 | @expectedFailureIfModuleIsNotAvailable('ipvlan') |
1f0e3109 | 796 | def test_ipvlan(self): |
bc6dff6e YW |
797 | for mode, flag in [['L2', 'private'], ['L3', 'vepa'], ['L3S', 'bridge']]: |
798 | with self.subTest(mode=mode, flag=flag): | |
799 | if mode != 'L2': | |
800 | self.tearDown() | |
ec38833c ZJS |
801 | copy_unit_to_networkd_unit_path('25-ipvlan.netdev', 'netdev-link-local-addressing-yes.network', |
802 | '11-dummy.netdev', 'ipvlan.network') | |
bc6dff6e YW |
803 | with open(os.path.join(network_unit_file_path, '25-ipvlan.netdev'), mode='a') as f: |
804 | f.write('[IPVLAN]\nMode=' + mode + '\nFlags=' + flag) | |
1f0e3109 | 805 | |
2cf6fdff | 806 | start_networkd() |
e2aea43f | 807 | self.wait_online(['ipvlan99:degraded', 'test1:degraded']) |
bc6dff6e | 808 | |
371810d1 | 809 | output = check_output('ip -d link show ipvlan99') |
bc6dff6e YW |
810 | print(output) |
811 | self.assertRegex(output, 'ipvlan *mode ' + mode.lower() + ' ' + flag) | |
1f0e3109 | 812 | |
956c8fec YW |
813 | @expectedFailureIfModuleIsNotAvailable('ipvtap') |
814 | def test_ipvtap(self): | |
40921f08 YW |
815 | for mode, flag in [['L2', 'private'], ['L3', 'vepa'], ['L3S', 'bridge']]: |
816 | with self.subTest(mode=mode, flag=flag): | |
817 | if mode != 'L2': | |
818 | self.tearDown() | |
ec38833c ZJS |
819 | copy_unit_to_networkd_unit_path('25-ipvtap.netdev', 'netdev-link-local-addressing-yes.network', |
820 | '11-dummy.netdev', 'ipvtap.network') | |
40921f08 YW |
821 | with open(os.path.join(network_unit_file_path, '25-ipvtap.netdev'), mode='a') as f: |
822 | f.write('[IPVTAP]\nMode=' + mode + '\nFlags=' + flag) | |
823 | ||
2cf6fdff | 824 | start_networkd() |
e2aea43f | 825 | self.wait_online(['ipvtap99:degraded', 'test1:degraded']) |
956c8fec | 826 | |
371810d1 | 827 | output = check_output('ip -d link show ipvtap99') |
40921f08 YW |
828 | print(output) |
829 | self.assertRegex(output, 'ipvtap *mode ' + mode.lower() + ' ' + flag) | |
956c8fec | 830 | |
1f0e3109 | 831 | def test_veth(self): |
ec38833c | 832 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'netdev-link-local-addressing-yes.network') |
2cf6fdff | 833 | start_networkd() |
1f0e3109 | 834 | |
e2aea43f | 835 | self.wait_online(['veth99:degraded', 'veth-peer:degraded']) |
671dacdf | 836 | |
371810d1 | 837 | output = check_output('ip -d link show veth99') |
671dacdf YW |
838 | print(output) |
839 | self.assertRegex(output, 'link/ether 12:34:56:78:9a:bc') | |
371810d1 | 840 | output = check_output('ip -d link show veth-peer') |
671dacdf YW |
841 | print(output) |
842 | self.assertRegex(output, 'link/ether 12:34:56:78:9a:bd') | |
1f0e3109 | 843 | |
1f0e3109 | 844 | def test_tun(self): |
ec38833c | 845 | copy_unit_to_networkd_unit_path('25-tun.netdev') |
2cf6fdff | 846 | start_networkd() |
1f0e3109 | 847 | |
e2aea43f | 848 | self.wait_online(['tun99:off'], setup_state='unmanaged') |
1f0e3109 | 849 | |
371810d1 | 850 | output = check_output('ip -d link show tun99') |
2746d307 YW |
851 | print(output) |
852 | # Old ip command does not support IFF_ flags | |
853 | self.assertRegex(output, 'tun (?:type tun pi on vnet_hdr on multi_queue|addrgenmode) ') | |
854 | ||
1f0e3109 | 855 | def test_tap(self): |
ec38833c | 856 | copy_unit_to_networkd_unit_path('25-tap.netdev') |
2cf6fdff | 857 | start_networkd() |
1f0e3109 | 858 | |
e2aea43f | 859 | self.wait_online(['tap99:off'], setup_state='unmanaged') |
1f0e3109 | 860 | |
371810d1 | 861 | output = check_output('ip -d link show tap99') |
2746d307 YW |
862 | print(output) |
863 | # Old ip command does not support IFF_ flags | |
864 | self.assertRegex(output, 'tun (?:type tap pi on vnet_hdr on multi_queue|addrgenmode) ') | |
865 | ||
7a0a37b2 | 866 | @expectedFailureIfModuleIsNotAvailable('vrf') |
1f0e3109 | 867 | def test_vrf(self): |
ec38833c | 868 | copy_unit_to_networkd_unit_path('25-vrf.netdev', 'netdev-link-local-addressing-yes.network') |
2cf6fdff | 869 | start_networkd() |
1f0e3109 | 870 | |
e2aea43f | 871 | self.wait_online(['vrf99:carrier']) |
1f0e3109 | 872 | |
7a0a37b2 | 873 | @expectedFailureIfModuleIsNotAvailable('vcan') |
1f0e3109 | 874 | def test_vcan(self): |
ec38833c | 875 | copy_unit_to_networkd_unit_path('25-vcan.netdev', 'netdev-link-local-addressing-yes.network') |
2cf6fdff | 876 | start_networkd() |
1f0e3109 | 877 | |
e2aea43f | 878 | self.wait_online(['vcan99:carrier']) |
1f0e3109 | 879 | |
f63b14d3 YW |
880 | @expectedFailureIfModuleIsNotAvailable('vxcan') |
881 | def test_vxcan(self): | |
ec38833c | 882 | copy_unit_to_networkd_unit_path('25-vxcan.netdev', 'netdev-link-local-addressing-yes.network') |
2cf6fdff | 883 | start_networkd() |
f63b14d3 | 884 | |
e2aea43f | 885 | self.wait_online(['vxcan99:carrier', 'vxcan-peer:carrier']) |
f63b14d3 | 886 | |
7a3bc5a8 EV |
887 | @expectedFailureIfModuleIsNotAvailable('wireguard') |
888 | def test_wireguard(self): | |
ec38833c ZJS |
889 | copy_unit_to_networkd_unit_path('25-wireguard.netdev', '25-wireguard.network', |
890 | '25-wireguard-23-peers.netdev', '25-wireguard-23-peers.network', | |
891 | '25-wireguard-preshared-key.txt', '25-wireguard-private-key.txt') | |
2cf6fdff | 892 | start_networkd() |
e2aea43f | 893 | self.wait_online(['wg99:carrier', 'wg98:routable']) |
5a0bd90b | 894 | |
7a3bc5a8 | 895 | if shutil.which('wg'): |
371810d1 | 896 | call('wg') |
5a0bd90b | 897 | |
371810d1 | 898 | output = check_output('wg show wg99 listen-port') |
06895a1d | 899 | self.assertRegex(output, '51820') |
371810d1 | 900 | output = check_output('wg show wg99 fwmark') |
06895a1d | 901 | self.assertRegex(output, '0x4d2') |
371810d1 | 902 | output = check_output('wg show wg99 allowed-ips') |
88aaf89e ZJS |
903 | self.assertRegex(output, r'RDf\+LSpeEre7YEIKaxg\+wbpsNV7du\+ktR99uBEtIiCA=\t192.168.26.0/24 fd31:bf08:57cb::/48') |
904 | self.assertRegex(output, r'lsDtM3AbjxNlauRKzHEPfgS1Zp7cp/VX5Use/P4PQSc=\tfdbc:bae2:7871:e1fe:793:8636::/96 fdbc:bae2:7871:500:e1fe:793:8636:dad1/128') | |
371810d1 | 905 | output = check_output('wg show wg99 persistent-keepalive') |
88aaf89e | 906 | self.assertRegex(output, r'RDf\+LSpeEre7YEIKaxg\+wbpsNV7du\+ktR99uBEtIiCA=\t20') |
371810d1 | 907 | output = check_output('wg show wg99 endpoints') |
88aaf89e | 908 | self.assertRegex(output, r'RDf\+LSpeEre7YEIKaxg\+wbpsNV7du\+ktR99uBEtIiCA=\t192.168.27.3:51820') |
371810d1 | 909 | output = check_output('wg show wg99 private-key') |
88aaf89e | 910 | self.assertRegex(output, r'EEGlnEPYJV//kbvvIqxKkQwOiS\+UENyPncC4bF46ong=') |
371810d1 | 911 | output = check_output('wg show wg99 preshared-keys') |
88aaf89e ZJS |
912 | self.assertRegex(output, r'RDf\+LSpeEre7YEIKaxg\+wbpsNV7du\+ktR99uBEtIiCA= IIWIV17wutHv7t4cR6pOT91z6NSz/T8Arh0yaywhw3M=') |
913 | self.assertRegex(output, r'lsDtM3AbjxNlauRKzHEPfgS1Zp7cp/VX5Use/P4PQSc= cPLOy1YUrEI0EMMIycPJmOo0aTu3RZnw8bL5meVD6m0=') | |
7a3bc5a8 | 914 | |
371810d1 | 915 | output = check_output('wg show wg98 private-key') |
88aaf89e | 916 | self.assertRegex(output, r'CJQUtcS9emY2fLYqDlpSZiE/QJyHkPWr\+WHtZLZ90FU=') |
da44fb8a | 917 | |
1f0e3109 | 918 | def test_geneve(self): |
ec38833c | 919 | copy_unit_to_networkd_unit_path('25-geneve.netdev', 'netdev-link-local-addressing-yes.network') |
2cf6fdff | 920 | start_networkd() |
1f0e3109 | 921 | |
e2aea43f | 922 | self.wait_online(['geneve99:degraded']) |
1f0e3109 | 923 | |
371810d1 | 924 | output = check_output('ip -d link show geneve99') |
14ecd604 | 925 | print(output) |
06895a1d YW |
926 | self.assertRegex(output, '192.168.22.1') |
927 | self.assertRegex(output, '6082') | |
928 | self.assertRegex(output, 'udpcsum') | |
929 | self.assertRegex(output, 'udp6zerocsumrx') | |
1f0e3109 SS |
930 | |
931 | def test_ipip_tunnel(self): | |
ec38833c ZJS |
932 | copy_unit_to_networkd_unit_path('12-dummy.netdev', 'ipip.network', |
933 | '25-ipip-tunnel.netdev', '25-tunnel.network', | |
934 | '25-ipip-tunnel-local-any.netdev', '25-tunnel-local-any.network', | |
42a29fcb YW |
935 | '25-ipip-tunnel-remote-any.netdev', '25-tunnel-remote-any.network', |
936 | '25-ipip-tunnel-any-any.netdev', '25-tunnel-any-any.network') | |
2cf6fdff | 937 | start_networkd() |
e2aea43f | 938 | self.wait_online(['ipiptun99:routable', 'ipiptun98:routable', 'ipiptun97:routable', 'ipiptun96:routable', 'dummy98:degraded']) |
6a97a864 | 939 | |
371810d1 | 940 | output = check_output('ip -d link show ipiptun99') |
6a97a864 YW |
941 | print(output) |
942 | self.assertRegex(output, 'ipip (?:ipip |)remote 192.169.224.239 local 192.168.223.238 dev dummy98') | |
371810d1 | 943 | output = check_output('ip -d link show ipiptun98') |
6a97a864 YW |
944 | print(output) |
945 | self.assertRegex(output, 'ipip (?:ipip |)remote 192.169.224.239 local any dev dummy98') | |
371810d1 | 946 | output = check_output('ip -d link show ipiptun97') |
6a97a864 YW |
947 | print(output) |
948 | self.assertRegex(output, 'ipip (?:ipip |)remote any local 192.168.223.238 dev dummy98') | |
42a29fcb YW |
949 | output = check_output('ip -d link show ipiptun96') |
950 | print(output) | |
951 | self.assertRegex(output, 'ipip (?:ipip |)remote any local any dev dummy98') | |
1f0e3109 SS |
952 | |
953 | def test_gre_tunnel(self): | |
ec38833c ZJS |
954 | copy_unit_to_networkd_unit_path('12-dummy.netdev', 'gretun.network', |
955 | '25-gre-tunnel.netdev', '25-tunnel.network', | |
956 | '25-gre-tunnel-local-any.netdev', '25-tunnel-local-any.network', | |
42a29fcb YW |
957 | '25-gre-tunnel-remote-any.netdev', '25-tunnel-remote-any.network', |
958 | '25-gre-tunnel-any-any.netdev', '25-tunnel-any-any.network') | |
2cf6fdff | 959 | start_networkd() |
e2aea43f | 960 | self.wait_online(['gretun99:routable', 'gretun98:routable', 'gretun97:routable', 'gretun96:routable', 'dummy98:degraded']) |
6a97a864 | 961 | |
371810d1 | 962 | output = check_output('ip -d link show gretun99') |
6a97a864 YW |
963 | print(output) |
964 | self.assertRegex(output, 'gre remote 10.65.223.239 local 10.65.223.238 dev dummy98') | |
38f4bb44 YW |
965 | self.assertRegex(output, 'ikey 1.2.3.103') |
966 | self.assertRegex(output, 'okey 1.2.4.103') | |
967 | self.assertRegex(output, 'iseq') | |
968 | self.assertRegex(output, 'oseq') | |
371810d1 | 969 | output = check_output('ip -d link show gretun98') |
6a97a864 YW |
970 | print(output) |
971 | self.assertRegex(output, 'gre remote 10.65.223.239 local any dev dummy98') | |
38f4bb44 YW |
972 | self.assertRegex(output, 'ikey 0.0.0.104') |
973 | self.assertRegex(output, 'okey 0.0.0.104') | |
974 | self.assertNotRegex(output, 'iseq') | |
975 | self.assertNotRegex(output, 'oseq') | |
371810d1 | 976 | output = check_output('ip -d link show gretun97') |
6a97a864 YW |
977 | print(output) |
978 | self.assertRegex(output, 'gre remote any local 10.65.223.238 dev dummy98') | |
38f4bb44 YW |
979 | self.assertRegex(output, 'ikey 0.0.0.105') |
980 | self.assertRegex(output, 'okey 0.0.0.105') | |
981 | self.assertNotRegex(output, 'iseq') | |
982 | self.assertNotRegex(output, 'oseq') | |
42a29fcb YW |
983 | output = check_output('ip -d link show gretun96') |
984 | print(output) | |
985 | self.assertRegex(output, 'gre remote any local any dev dummy98') | |
986 | self.assertRegex(output, 'ikey 0.0.0.106') | |
987 | self.assertRegex(output, 'okey 0.0.0.106') | |
988 | self.assertNotRegex(output, 'iseq') | |
989 | self.assertNotRegex(output, 'oseq') | |
6a97a864 YW |
990 | |
991 | def test_ip6gre_tunnel(self): | |
ec38833c ZJS |
992 | copy_unit_to_networkd_unit_path('12-dummy.netdev', 'ip6gretun.network', |
993 | '25-ip6gre-tunnel.netdev', '25-tunnel.network', | |
994 | '25-ip6gre-tunnel-local-any.netdev', '25-tunnel-local-any.network', | |
42a29fcb YW |
995 | '25-ip6gre-tunnel-remote-any.netdev', '25-tunnel-remote-any.network', |
996 | '25-ip6gre-tunnel-any-any.netdev', '25-tunnel-any-any.network') | |
01943d43 | 997 | start_networkd(5) |
6a97a864 | 998 | |
17bcf0a0 YW |
999 | # Old kernels seem not to support IPv6LL address on ip6gre tunnel, So please do not use wait_online() here. |
1000 | ||
e39cc445 YW |
1001 | self.check_link_exists('dummy98') |
1002 | self.check_link_exists('ip6gretun99') | |
1003 | self.check_link_exists('ip6gretun98') | |
1004 | self.check_link_exists('ip6gretun97') | |
42a29fcb | 1005 | self.check_link_exists('ip6gretun96') |
6a97a864 | 1006 | |
371810d1 | 1007 | output = check_output('ip -d link show ip6gretun99') |
6a97a864 YW |
1008 | print(output) |
1009 | self.assertRegex(output, 'ip6gre remote 2001:473:fece:cafe::5179 local 2a00:ffde:4567:edde::4987 dev dummy98') | |
371810d1 | 1010 | output = check_output('ip -d link show ip6gretun98') |
6a97a864 YW |
1011 | print(output) |
1012 | self.assertRegex(output, 'ip6gre remote 2001:473:fece:cafe::5179 local any dev dummy98') | |
371810d1 | 1013 | output = check_output('ip -d link show ip6gretun97') |
6a97a864 YW |
1014 | print(output) |
1015 | self.assertRegex(output, 'ip6gre remote any local 2a00:ffde:4567:edde::4987 dev dummy98') | |
42a29fcb YW |
1016 | output = check_output('ip -d link show ip6gretun96') |
1017 | print(output) | |
1018 | self.assertRegex(output, 'ip6gre remote any local any dev dummy98') | |
1f0e3109 | 1019 | |
11309591 | 1020 | def test_gretap_tunnel(self): |
ec38833c ZJS |
1021 | copy_unit_to_networkd_unit_path('12-dummy.netdev', 'gretap.network', |
1022 | '25-gretap-tunnel.netdev', '25-tunnel.network', | |
1023 | '25-gretap-tunnel-local-any.netdev', '25-tunnel-local-any.network') | |
2cf6fdff | 1024 | start_networkd() |
e2aea43f | 1025 | self.wait_online(['gretap99:routable', 'gretap98:routable', 'dummy98:degraded']) |
6a97a864 | 1026 | |
371810d1 | 1027 | output = check_output('ip -d link show gretap99') |
6a97a864 YW |
1028 | print(output) |
1029 | self.assertRegex(output, 'gretap remote 10.65.223.239 local 10.65.223.238 dev dummy98') | |
38f4bb44 YW |
1030 | self.assertRegex(output, 'ikey 0.0.0.106') |
1031 | self.assertRegex(output, 'okey 0.0.0.106') | |
1032 | self.assertRegex(output, 'iseq') | |
1033 | self.assertRegex(output, 'oseq') | |
371810d1 | 1034 | output = check_output('ip -d link show gretap98') |
6a97a864 YW |
1035 | print(output) |
1036 | self.assertRegex(output, 'gretap remote 10.65.223.239 local any dev dummy98') | |
38f4bb44 YW |
1037 | self.assertRegex(output, 'ikey 0.0.0.107') |
1038 | self.assertRegex(output, 'okey 0.0.0.107') | |
1039 | self.assertRegex(output, 'iseq') | |
1040 | self.assertRegex(output, 'oseq') | |
1f0e3109 SS |
1041 | |
1042 | def test_ip6gretap_tunnel(self): | |
ec38833c ZJS |
1043 | copy_unit_to_networkd_unit_path('12-dummy.netdev', 'ip6gretap.network', |
1044 | '25-ip6gretap-tunnel.netdev', '25-tunnel.network', | |
1045 | '25-ip6gretap-tunnel-local-any.netdev', '25-tunnel-local-any.network') | |
2cf6fdff | 1046 | start_networkd() |
e2aea43f | 1047 | self.wait_online(['ip6gretap99:routable', 'ip6gretap98:routable', 'dummy98:degraded']) |
6a97a864 | 1048 | |
371810d1 | 1049 | output = check_output('ip -d link show ip6gretap99') |
6a97a864 YW |
1050 | print(output) |
1051 | self.assertRegex(output, 'ip6gretap remote 2001:473:fece:cafe::5179 local 2a00:ffde:4567:edde::4987 dev dummy98') | |
371810d1 | 1052 | output = check_output('ip -d link show ip6gretap98') |
6a97a864 YW |
1053 | print(output) |
1054 | self.assertRegex(output, 'ip6gretap remote 2001:473:fece:cafe::5179 local any dev dummy98') | |
1f0e3109 SS |
1055 | |
1056 | def test_vti_tunnel(self): | |
ec38833c ZJS |
1057 | copy_unit_to_networkd_unit_path('12-dummy.netdev', 'vti.network', |
1058 | '25-vti-tunnel.netdev', '25-tunnel.network', | |
1059 | '25-vti-tunnel-local-any.netdev', '25-tunnel-local-any.network', | |
42a29fcb YW |
1060 | '25-vti-tunnel-remote-any.netdev', '25-tunnel-remote-any.network', |
1061 | '25-vti-tunnel-any-any.netdev', '25-tunnel-any-any.network') | |
2cf6fdff | 1062 | start_networkd() |
e2aea43f | 1063 | self.wait_online(['vtitun99:routable', 'vtitun98:routable', 'vtitun97:routable', 'vtitun96:routable', 'dummy98:degraded']) |
6a97a864 | 1064 | |
371810d1 | 1065 | output = check_output('ip -d link show vtitun99') |
6a97a864 YW |
1066 | print(output) |
1067 | self.assertRegex(output, 'vti remote 10.65.223.239 local 10.65.223.238 dev dummy98') | |
371810d1 | 1068 | output = check_output('ip -d link show vtitun98') |
6a97a864 YW |
1069 | print(output) |
1070 | self.assertRegex(output, 'vti remote 10.65.223.239 local any dev dummy98') | |
371810d1 | 1071 | output = check_output('ip -d link show vtitun97') |
6a97a864 YW |
1072 | print(output) |
1073 | self.assertRegex(output, 'vti remote any local 10.65.223.238 dev dummy98') | |
42a29fcb YW |
1074 | output = check_output('ip -d link show vtitun96') |
1075 | print(output) | |
1076 | self.assertRegex(output, 'vti remote any local any dev dummy98') | |
1f0e3109 SS |
1077 | |
1078 | def test_vti6_tunnel(self): | |
ec38833c ZJS |
1079 | copy_unit_to_networkd_unit_path('12-dummy.netdev', 'vti6.network', |
1080 | '25-vti6-tunnel.netdev', '25-tunnel.network', | |
1081 | '25-vti6-tunnel-local-any.netdev', '25-tunnel-local-any.network', | |
1082 | '25-vti6-tunnel-remote-any.netdev', '25-tunnel-remote-any.network') | |
2cf6fdff | 1083 | start_networkd() |
e2aea43f | 1084 | self.wait_online(['vti6tun99:routable', 'vti6tun98:routable', 'vti6tun97:routable', 'dummy98:degraded']) |
6a97a864 | 1085 | |
371810d1 | 1086 | output = check_output('ip -d link show vti6tun99') |
6a97a864 YW |
1087 | print(output) |
1088 | self.assertRegex(output, 'vti6 remote 2001:473:fece:cafe::5179 local 2a00:ffde:4567:edde::4987 dev dummy98') | |
371810d1 | 1089 | output = check_output('ip -d link show vti6tun98') |
6a97a864 YW |
1090 | print(output) |
1091 | self.assertRegex(output, 'vti6 remote 2001:473:fece:cafe::5179 local (?:any|::) dev dummy98') | |
371810d1 | 1092 | output = check_output('ip -d link show vti6tun97') |
6a97a864 YW |
1093 | print(output) |
1094 | self.assertRegex(output, 'vti6 remote (?:any|::) local 2a00:ffde:4567:edde::4987 dev dummy98') | |
1f0e3109 SS |
1095 | |
1096 | def test_ip6tnl_tunnel(self): | |
ec38833c ZJS |
1097 | copy_unit_to_networkd_unit_path('12-dummy.netdev', 'ip6tnl.network', |
1098 | '25-ip6tnl-tunnel.netdev', '25-tunnel.network', | |
1099 | '25-ip6tnl-tunnel-local-any.netdev', '25-tunnel-local-any.network', | |
1100 | '25-ip6tnl-tunnel-remote-any.netdev', '25-tunnel-remote-any.network') | |
2cf6fdff | 1101 | start_networkd() |
e2aea43f | 1102 | self.wait_online(['ip6tnl99:routable', 'ip6tnl98:routable', 'ip6tnl97:routable', 'dummy98:degraded']) |
6a97a864 | 1103 | |
371810d1 | 1104 | output = check_output('ip -d link show ip6tnl99') |
6a97a864 YW |
1105 | print(output) |
1106 | self.assertRegex(output, 'ip6tnl ip6ip6 remote 2001:473:fece:cafe::5179 local 2a00:ffde:4567:edde::4987 dev dummy98') | |
371810d1 | 1107 | output = check_output('ip -d link show ip6tnl98') |
6a97a864 YW |
1108 | print(output) |
1109 | self.assertRegex(output, 'ip6tnl ip6ip6 remote 2001:473:fece:cafe::5179 local (?:any|::) dev dummy98') | |
371810d1 | 1110 | output = check_output('ip -d link show ip6tnl97') |
6a97a864 YW |
1111 | print(output) |
1112 | self.assertRegex(output, 'ip6tnl ip6ip6 remote (?:any|::) local 2a00:ffde:4567:edde::4987 dev dummy98') | |
1f0e3109 SS |
1113 | |
1114 | def test_sit_tunnel(self): | |
ec38833c ZJS |
1115 | copy_unit_to_networkd_unit_path('12-dummy.netdev', 'sit.network', |
1116 | '25-sit-tunnel.netdev', '25-tunnel.network', | |
1117 | '25-sit-tunnel-local-any.netdev', '25-tunnel-local-any.network', | |
42a29fcb YW |
1118 | '25-sit-tunnel-remote-any.netdev', '25-tunnel-remote-any.network', |
1119 | '25-sit-tunnel-any-any.netdev', '25-tunnel-any-any.network') | |
2cf6fdff | 1120 | start_networkd() |
e2aea43f | 1121 | self.wait_online(['sittun99:routable', 'sittun98:routable', 'sittun97:routable', 'sittun96:routable', 'dummy98:degraded']) |
6a97a864 | 1122 | |
371810d1 | 1123 | output = check_output('ip -d link show sittun99') |
6a97a864 YW |
1124 | print(output) |
1125 | self.assertRegex(output, "sit (?:ip6ip |)remote 10.65.223.239 local 10.65.223.238 dev dummy98") | |
371810d1 | 1126 | output = check_output('ip -d link show sittun98') |
6a97a864 YW |
1127 | print(output) |
1128 | self.assertRegex(output, "sit (?:ip6ip |)remote 10.65.223.239 local any dev dummy98") | |
371810d1 | 1129 | output = check_output('ip -d link show sittun97') |
6a97a864 YW |
1130 | print(output) |
1131 | self.assertRegex(output, "sit (?:ip6ip |)remote any local 10.65.223.238 dev dummy98") | |
42a29fcb YW |
1132 | output = check_output('ip -d link show sittun96') |
1133 | print(output) | |
1134 | self.assertRegex(output, "sit (?:ip6ip |)remote any local any dev dummy98") | |
1f0e3109 | 1135 | |
d0e728b6 | 1136 | def test_isatap_tunnel(self): |
ec38833c ZJS |
1137 | copy_unit_to_networkd_unit_path('12-dummy.netdev', 'isatap.network', |
1138 | '25-isatap-tunnel.netdev', '25-tunnel.network') | |
2cf6fdff | 1139 | start_networkd() |
e2aea43f | 1140 | self.wait_online(['isataptun99:routable', 'dummy98:degraded']) |
d0e728b6 | 1141 | |
371810d1 | 1142 | output = check_output('ip -d link show isataptun99') |
14ecd604 | 1143 | print(output) |
d0e728b6 SS |
1144 | self.assertRegex(output, "isatap ") |
1145 | ||
d29dc4f1 | 1146 | def test_6rd_tunnel(self): |
ec38833c ZJS |
1147 | copy_unit_to_networkd_unit_path('12-dummy.netdev', '6rd.network', |
1148 | '25-6rd-tunnel.netdev', '25-tunnel.network') | |
2cf6fdff | 1149 | start_networkd() |
e2aea43f | 1150 | self.wait_online(['sittun99:routable', 'dummy98:degraded']) |
d29dc4f1 | 1151 | |
371810d1 | 1152 | output = check_output('ip -d link show sittun99') |
6a97a864 YW |
1153 | print(output) |
1154 | self.assertRegex(output, '6rd-prefix 2602::/24') | |
1155 | ||
7bea7f9b | 1156 | @expectedFailureIfERSPANModuleIsNotAvailable() |
2266864b | 1157 | def test_erspan_tunnel(self): |
ec38833c ZJS |
1158 | copy_unit_to_networkd_unit_path('12-dummy.netdev', 'erspan.network', |
1159 | '25-erspan-tunnel.netdev', '25-tunnel.network', | |
1160 | '25-erspan-tunnel-local-any.netdev', '25-tunnel-local-any.network') | |
2cf6fdff | 1161 | start_networkd() |
e2aea43f | 1162 | self.wait_online(['erspan99:routable', 'erspan98:routable', 'dummy98:degraded']) |
2266864b | 1163 | |
371810d1 | 1164 | output = check_output('ip -d link show erspan99') |
6a97a864 YW |
1165 | print(output) |
1166 | self.assertRegex(output, 'erspan remote 172.16.1.100 local 172.16.1.200') | |
38f4bb44 YW |
1167 | self.assertRegex(output, 'ikey 0.0.0.101') |
1168 | self.assertRegex(output, 'okey 0.0.0.101') | |
1169 | self.assertRegex(output, 'iseq') | |
1170 | self.assertRegex(output, 'oseq') | |
371810d1 | 1171 | output = check_output('ip -d link show erspan98') |
2266864b | 1172 | print(output) |
6a97a864 YW |
1173 | self.assertRegex(output, 'erspan remote 172.16.1.100 local any') |
1174 | self.assertRegex(output, '102') | |
38f4bb44 YW |
1175 | self.assertRegex(output, 'ikey 0.0.0.102') |
1176 | self.assertRegex(output, 'okey 0.0.0.102') | |
1177 | self.assertRegex(output, 'iseq') | |
1178 | self.assertRegex(output, 'oseq') | |
2266864b | 1179 | |
1f0e3109 | 1180 | def test_tunnel_independent(self): |
ec38833c | 1181 | copy_unit_to_networkd_unit_path('25-ipip-tunnel-independent.netdev', 'netdev-link-local-addressing-yes.network') |
2cf6fdff | 1182 | start_networkd() |
e40a58b5 | 1183 | |
e2aea43f | 1184 | self.wait_online(['ipiptun99:carrier']) |
1f0e3109 | 1185 | |
95082dbe YW |
1186 | def test_tunnel_independent_loopback(self): |
1187 | copy_unit_to_networkd_unit_path('25-ipip-tunnel-independent-loopback.netdev', 'netdev-link-local-addressing-yes.network') | |
1188 | start_networkd() | |
1189 | ||
e2aea43f | 1190 | self.wait_online(['ipiptun99:carrier']) |
95082dbe | 1191 | |
e64dc406 YW |
1192 | @expectedFailureIfModuleIsNotAvailable('xfrm_interface') |
1193 | def test_xfrm(self): | |
1194 | copy_unit_to_networkd_unit_path('12-dummy.netdev', 'xfrm.network', | |
1195 | '25-xfrm.netdev', 'netdev-link-local-addressing-yes.network') | |
1196 | start_networkd() | |
1197 | ||
e2aea43f | 1198 | self.wait_online(['xfrm99:degraded', 'dummy98:degraded']) |
e64dc406 YW |
1199 | |
1200 | output = check_output('ip link show dev xfrm99') | |
1201 | print(output) | |
1202 | ||
1203 | @expectedFailureIfModuleIsNotAvailable('xfrm_interface') | |
1204 | def test_xfrm_independent(self): | |
1205 | copy_unit_to_networkd_unit_path('25-xfrm-independent.netdev', 'netdev-link-local-addressing-yes.network') | |
1206 | start_networkd() | |
1207 | ||
e2aea43f | 1208 | self.wait_online(['xfrm99:degraded']) |
e64dc406 | 1209 | |
4b6a6d1e YW |
1210 | @expectedFailureIfModuleIsNotAvailable('fou') |
1211 | def test_fou(self): | |
1212 | # The following redundant check is necessary for CentOS CI. | |
1213 | # Maybe, error handling in lookup_id() in sd-netlink/generic-netlink.c needs to be updated. | |
1214 | self.assertTrue(is_module_available('fou')) | |
1215 | ||
ec38833c ZJS |
1216 | copy_unit_to_networkd_unit_path('25-fou-ipproto-ipip.netdev', '25-fou-ipproto-gre.netdev', |
1217 | '25-fou-ipip.netdev', '25-fou-sit.netdev', | |
1218 | '25-fou-gre.netdev', '25-fou-gretap.netdev') | |
2cf6fdff | 1219 | start_networkd() |
4b6a6d1e | 1220 | |
e2aea43f | 1221 | self.wait_online(['ipiptun96:off', 'sittun96:off', 'gretun96:off', 'gretap96:off'], setup_state='unmanaged') |
4b6a6d1e | 1222 | |
371810d1 | 1223 | output = check_output('ip fou show') |
4b6a6d1e YW |
1224 | print(output) |
1225 | self.assertRegex(output, 'port 55555 ipproto 4') | |
1226 | self.assertRegex(output, 'port 55556 ipproto 47') | |
1227 | ||
371810d1 | 1228 | output = check_output('ip -d link show ipiptun96') |
4b6a6d1e YW |
1229 | print(output) |
1230 | self.assertRegex(output, 'encap fou encap-sport auto encap-dport 55555') | |
371810d1 | 1231 | output = check_output('ip -d link show sittun96') |
4b6a6d1e YW |
1232 | print(output) |
1233 | self.assertRegex(output, 'encap fou encap-sport auto encap-dport 55555') | |
371810d1 | 1234 | output = check_output('ip -d link show gretun96') |
4b6a6d1e YW |
1235 | print(output) |
1236 | self.assertRegex(output, 'encap fou encap-sport 1001 encap-dport 55556') | |
371810d1 | 1237 | output = check_output('ip -d link show gretap96') |
4b6a6d1e YW |
1238 | print(output) |
1239 | self.assertRegex(output, 'encap fou encap-sport auto encap-dport 55556') | |
1240 | ||
1f0e3109 | 1241 | def test_vxlan(self): |
ec38833c ZJS |
1242 | copy_unit_to_networkd_unit_path('25-vxlan.netdev', 'vxlan.network', |
1243 | '11-dummy.netdev', 'vxlan-test1.network') | |
2cf6fdff | 1244 | start_networkd() |
1f0e3109 | 1245 | |
e2aea43f | 1246 | self.wait_online(['test1:degraded', 'vxlan99:degraded']) |
1f0e3109 | 1247 | |
371810d1 | 1248 | output = check_output('ip -d link show vxlan99') |
14ecd604 | 1249 | print(output) |
1c862fe0 | 1250 | self.assertRegex(output, '999') |
1f0e3109 SS |
1251 | self.assertRegex(output, '5555') |
1252 | self.assertRegex(output, 'l2miss') | |
1253 | self.assertRegex(output, 'l3miss') | |
1254 | self.assertRegex(output, 'udpcsum') | |
1255 | self.assertRegex(output, 'udp6zerocsumtx') | |
1256 | self.assertRegex(output, 'udp6zerocsumrx') | |
1257 | self.assertRegex(output, 'remcsumtx') | |
1258 | self.assertRegex(output, 'remcsumrx') | |
1259 | self.assertRegex(output, 'gbp') | |
1260 | ||
371810d1 | 1261 | output = check_output('bridge fdb show dev vxlan99') |
1c862fe0 YW |
1262 | print(output) |
1263 | self.assertRegex(output, '00:11:22:33:44:55 dst 10.0.0.5 self permanent') | |
1264 | self.assertRegex(output, '00:11:22:33:44:66 dst 10.0.0.6 self permanent') | |
1265 | self.assertRegex(output, '00:11:22:33:44:77 dst 10.0.0.7 self permanent') | |
1266 | ||
02849d8b | 1267 | def test_macsec(self): |
ec38833c ZJS |
1268 | copy_unit_to_networkd_unit_path('25-macsec.netdev', '25-macsec.network', '25-macsec.key', |
1269 | 'macsec.network', '12-dummy.netdev') | |
2cf6fdff | 1270 | start_networkd() |
02849d8b | 1271 | |
e2aea43f | 1272 | self.wait_online(['dummy98:degraded', 'macsec99:routable']) |
02849d8b | 1273 | |
371810d1 | 1274 | output = check_output('ip -d link show macsec99') |
02849d8b YW |
1275 | print(output) |
1276 | self.assertRegex(output, 'macsec99@dummy98') | |
1277 | self.assertRegex(output, 'macsec sci [0-9a-f]*000b') | |
1278 | self.assertRegex(output, 'encrypt on') | |
1279 | ||
371810d1 | 1280 | output = check_output('ip macsec show macsec99') |
02849d8b YW |
1281 | print(output) |
1282 | self.assertRegex(output, 'encrypt on') | |
1283 | self.assertRegex(output, 'TXSC: [0-9a-f]*000b on SA 1') | |
1284 | self.assertRegex(output, '0: PN [0-9]*, state on, key 01000000000000000000000000000000') | |
1285 | self.assertRegex(output, '1: PN [0-9]*, state on, key 02030000000000000000000000000000') | |
1286 | self.assertRegex(output, 'RXSC: c619528fe6a00100, state on') | |
1287 | self.assertRegex(output, '0: PN [0-9]*, state on, key 02030405000000000000000000000000') | |
1288 | self.assertRegex(output, '1: PN [0-9]*, state on, key 02030405060000000000000000000000') | |
1289 | self.assertRegex(output, '2: PN [0-9]*, state off, key 02030405060700000000000000000000') | |
1290 | self.assertRegex(output, '3: PN [0-9]*, state off, key 02030405060708000000000000000000') | |
1291 | self.assertNotRegex(output, 'key 02030405067080900000000000000000') | |
1292 | self.assertRegex(output, 'RXSC: 8c16456c83a90002, state on') | |
1293 | self.assertRegex(output, '0: PN [0-9]*, state off, key 02030400000000000000000000000000') | |
1294 | ||
811f33d0 | 1295 | def test_nlmon(self): |
ec38833c | 1296 | copy_unit_to_networkd_unit_path('25-nlmon.netdev', 'netdev-link-local-addressing-yes.network') |
2cf6fdff | 1297 | start_networkd() |
811f33d0 | 1298 | |
e2aea43f | 1299 | self.wait_online(['nlmon99:carrier']) |
02849d8b | 1300 | |
cff83db9 YW |
1301 | class NetworkdL2TPTests(unittest.TestCase, Utilities): |
1302 | ||
1303 | links =[ | |
1304 | 'l2tp-ses1', | |
1305 | 'l2tp-ses2', | |
1306 | 'l2tp-ses3', | |
1307 | 'l2tp-ses4', | |
1308 | 'test1'] | |
1309 | ||
1310 | units = [ | |
1311 | '11-dummy.netdev', | |
1312 | '25-l2tp-dummy.network', | |
e2aea43f | 1313 | '25-l2tp.network', |
cff83db9 YW |
1314 | '25-l2tp-ip.netdev', |
1315 | '25-l2tp-udp.netdev'] | |
1316 | ||
1317 | l2tp_tunnel_ids = [ '10' ] | |
1318 | ||
1319 | def setUp(self): | |
ad78d7b0 | 1320 | remove_l2tp_tunnels(self.l2tp_tunnel_ids) |
ec38833c | 1321 | remove_links(self.links) |
aaae5713 | 1322 | stop_networkd(show_logs=False) |
cff83db9 YW |
1323 | |
1324 | def tearDown(self): | |
ad78d7b0 | 1325 | remove_l2tp_tunnels(self.l2tp_tunnel_ids) |
ec38833c ZJS |
1326 | remove_links(self.links) |
1327 | remove_unit_from_networkd_path(self.units) | |
aaae5713 | 1328 | stop_networkd(show_logs=True) |
cff83db9 YW |
1329 | |
1330 | @expectedFailureIfModuleIsNotAvailable('l2tp_eth') | |
1331 | def test_l2tp_udp(self): | |
e2aea43f YW |
1332 | copy_unit_to_networkd_unit_path('11-dummy.netdev', '25-l2tp-dummy.network', |
1333 | '25-l2tp-udp.netdev', '25-l2tp.network') | |
2cf6fdff | 1334 | start_networkd() |
cff83db9 | 1335 | |
e2aea43f | 1336 | self.wait_online(['test1:routable', 'l2tp-ses1:degraded', 'l2tp-ses2:degraded']) |
cff83db9 | 1337 | |
371810d1 | 1338 | output = check_output('ip l2tp show tunnel tunnel_id 10') |
cff83db9 YW |
1339 | print(output) |
1340 | self.assertRegex(output, "Tunnel 10, encap UDP") | |
1341 | self.assertRegex(output, "From 192.168.30.100 to 192.168.30.101") | |
1342 | self.assertRegex(output, "Peer tunnel 11") | |
1343 | self.assertRegex(output, "UDP source / dest ports: 3000/4000") | |
1344 | self.assertRegex(output, "UDP checksum: enabled") | |
1345 | ||
371810d1 | 1346 | output = check_output('ip l2tp show session tid 10 session_id 15') |
cff83db9 YW |
1347 | print(output) |
1348 | self.assertRegex(output, "Session 15 in tunnel 10") | |
1349 | self.assertRegex(output, "Peer session 16, tunnel 11") | |
1350 | self.assertRegex(output, "interface name: l2tp-ses1") | |
1351 | ||
371810d1 | 1352 | output = check_output('ip l2tp show session tid 10 session_id 17') |
cff83db9 YW |
1353 | print(output) |
1354 | self.assertRegex(output, "Session 17 in tunnel 10") | |
1355 | self.assertRegex(output, "Peer session 18, tunnel 11") | |
1356 | self.assertRegex(output, "interface name: l2tp-ses2") | |
1357 | ||
1358 | @expectedFailureIfModuleIsNotAvailable('l2tp_ip') | |
1359 | def test_l2tp_ip(self): | |
e2aea43f YW |
1360 | copy_unit_to_networkd_unit_path('11-dummy.netdev', '25-l2tp-dummy.network', |
1361 | '25-l2tp-ip.netdev', '25-l2tp.network') | |
2cf6fdff | 1362 | start_networkd() |
cff83db9 | 1363 | |
e2aea43f | 1364 | self.wait_online(['test1:routable', 'l2tp-ses3:degraded', 'l2tp-ses4:degraded']) |
cff83db9 | 1365 | |
371810d1 | 1366 | output = check_output('ip l2tp show tunnel tunnel_id 10') |
cff83db9 YW |
1367 | print(output) |
1368 | self.assertRegex(output, "Tunnel 10, encap IP") | |
1369 | self.assertRegex(output, "From 192.168.30.100 to 192.168.30.101") | |
1370 | self.assertRegex(output, "Peer tunnel 12") | |
1371 | ||
371810d1 | 1372 | output = check_output('ip l2tp show session tid 10 session_id 25') |
cff83db9 YW |
1373 | print(output) |
1374 | self.assertRegex(output, "Session 25 in tunnel 10") | |
1375 | self.assertRegex(output, "Peer session 26, tunnel 12") | |
1376 | self.assertRegex(output, "interface name: l2tp-ses3") | |
1377 | ||
371810d1 | 1378 | output = check_output('ip l2tp show session tid 10 session_id 27') |
cff83db9 YW |
1379 | print(output) |
1380 | self.assertRegex(output, "Session 27 in tunnel 10") | |
1381 | self.assertRegex(output, "Peer session 28, tunnel 12") | |
1382 | self.assertRegex(output, "interface name: l2tp-ses4") | |
1383 | ||
be68c2c9 | 1384 | class NetworkdNetworkTests(unittest.TestCase, Utilities): |
09ea6724 YW |
1385 | links = [ |
1386 | 'bond199', | |
1387 | 'dummy98', | |
cd65d067 | 1388 | 'dummy99', |
74761cf3 YW |
1389 | 'gretun97', |
1390 | 'test1' | |
1391 | ] | |
09ea6724 YW |
1392 | |
1393 | units = [ | |
1394 | '11-dummy.netdev', | |
1395 | '12-dummy.netdev', | |
1396 | '23-active-slave.network', | |
1e498853 | 1397 | '24-keep-configuration-static.network', |
fdcd1ec5 | 1398 | '24-search-domain.network', |
09ea6724 | 1399 | '25-address-link-section.network', |
b8102725 YW |
1400 | '25-address-preferred-lifetime-zero-ipv6.network', |
1401 | '25-address-static.network', | |
cd65d067 | 1402 | '25-bind-carrier.network', |
09ea6724 YW |
1403 | '25-bond-active-backup-slave.netdev', |
1404 | '25-fibrule-invert.network', | |
1405 | '25-fibrule-port-range.network', | |
74761cf3 | 1406 | '25-gre-tunnel-remote-any.netdev', |
09ea6724 | 1407 | '25-ipv6-address-label-section.network', |
e4a71bf3 | 1408 | '25-neighbor-section.network', |
74761cf3 YW |
1409 | '25-neighbor-ip-dummy.network', |
1410 | '25-neighbor-ip.network', | |
05514ae1 YW |
1411 | '25-link-local-addressing-no.network', |
1412 | '25-link-local-addressing-yes.network', | |
09ea6724 | 1413 | '25-link-section-unmanaged.network', |
20ca06a6 | 1414 | '25-route-ipv6-src.network', |
0ef830cf | 1415 | '25-route-static.network', |
4da33154 | 1416 | '25-sysctl-disable-ipv6.network', |
09ea6724 YW |
1417 | '25-sysctl.network', |
1418 | 'configure-without-carrier.network', | |
b677774d | 1419 | 'routing-policy-rule-dummy98.network', |
b8102725 | 1420 | 'routing-policy-rule-test1.network'] |
1f0e3109 | 1421 | |
95c74b0a | 1422 | routing_policy_rule_tables = ['7', '8'] |
5f68a6a4 | 1423 | routes = [['blackhole', '202.54.1.2'], ['unreachable', '202.54.1.3'], ['prohibit', '202.54.1.4']] |
95c74b0a | 1424 | |
1f0e3109 | 1425 | def setUp(self): |
ec38833c ZJS |
1426 | remove_routing_policy_rule_tables(self.routing_policy_rule_tables) |
1427 | remove_routes(self.routes) | |
1428 | remove_links(self.links) | |
aaae5713 | 1429 | stop_networkd(show_logs=False) |
1f0e3109 SS |
1430 | |
1431 | def tearDown(self): | |
ec38833c ZJS |
1432 | remove_routing_policy_rule_tables(self.routing_policy_rule_tables) |
1433 | remove_routes(self.routes) | |
1434 | remove_links(self.links) | |
1435 | remove_unit_from_networkd_path(self.units) | |
aaae5713 | 1436 | stop_networkd(show_logs=True) |
1f0e3109 | 1437 | |
b8102725 | 1438 | def test_address_static(self): |
ec38833c | 1439 | copy_unit_to_networkd_unit_path('25-address-static.network', '12-dummy.netdev') |
2cf6fdff | 1440 | start_networkd() |
b8102725 | 1441 | |
e2aea43f | 1442 | self.wait_online(['dummy98:routable']) |
b8102725 | 1443 | |
371810d1 | 1444 | output = check_output('ip -4 address show dev dummy98') |
b8102725 YW |
1445 | print(output) |
1446 | self.assertRegex(output, 'inet 10.1.2.3/16 brd 10.1.255.255 scope global dummy98') | |
1447 | self.assertRegex(output, 'inet 10.1.2.4/16 brd 10.1.255.255 scope global secondary dummy98') | |
1448 | self.assertRegex(output, 'inet 10.2.2.4/16 brd 10.2.255.255 scope global dummy98') | |
1449 | ||
1450 | # invalid sections | |
1451 | self.assertNotRegex(output, '10.10.0.1/16') | |
1452 | self.assertNotRegex(output, '10.10.0.2/16') | |
1453 | ||
371810d1 | 1454 | output = check_output('ip -4 address show dev dummy98 label 32') |
b8102725 YW |
1455 | self.assertRegex(output, 'inet 10.3.2.3/16 brd 10.3.255.255 scope global 32') |
1456 | ||
371810d1 | 1457 | output = check_output('ip -4 address show dev dummy98 label 33') |
b8102725 YW |
1458 | self.assertRegex(output, 'inet 10.4.2.3 peer 10.4.2.4/16 scope global 33') |
1459 | ||
371810d1 | 1460 | output = check_output('ip -4 address show dev dummy98 label 34') |
b8102725 YW |
1461 | self.assertRegex(output, 'inet 192.168.[0-9]*.1/24 brd 192.168.[0-9]*.255 scope global 34') |
1462 | ||
371810d1 | 1463 | output = check_output('ip -4 address show dev dummy98 label 35') |
b8102725 YW |
1464 | self.assertRegex(output, 'inet 172.[0-9]*.0.1/16 brd 172.[0-9]*.255.255 scope global 35') |
1465 | ||
371810d1 | 1466 | output = check_output('ip -6 address show dev dummy98') |
b8102725 YW |
1467 | print(output) |
1468 | self.assertRegex(output, 'inet6 2001:db8:0:f101::15/64 scope global') | |
1469 | self.assertRegex(output, 'inet6 2001:db8:0:f101::16/64 scope global') | |
1470 | self.assertRegex(output, 'inet6 2001:db8:0:f102::15/64 scope global') | |
1471 | self.assertRegex(output, 'inet6 2001:db8:0:f102::16/64 scope global') | |
1472 | self.assertRegex(output, 'inet6 2001:db8:0:f103::20 peer 2001:db8:0:f103::10/128 scope global') | |
1473 | self.assertRegex(output, 'inet6 fd[0-9a-f:]*1/64 scope global') | |
1474 | ||
1475 | def test_address_preferred_lifetime_zero_ipv6(self): | |
ec38833c | 1476 | copy_unit_to_networkd_unit_path('25-address-preferred-lifetime-zero-ipv6.network', '12-dummy.netdev') |
01943d43 | 1477 | start_networkd(5) |
1f0e3109 | 1478 | |
e39cc445 | 1479 | self.check_link_exists('dummy98') |
791c1140 | 1480 | self.check_operstate('dummy98', 'routable', setup_state='configuring') |
b8102725 | 1481 | |
371810d1 | 1482 | output = check_output('ip address show dummy98') |
b8102725 YW |
1483 | print(output) |
1484 | self.assertRegex(output, 'inet 10.2.3.4/16 brd 10.2.255.255 scope link deprecated dummy98') | |
1485 | self.assertRegex(output, 'inet6 2001:db8:0:f101::1/64 scope global') | |
1f0e3109 SS |
1486 | |
1487 | def test_configure_without_carrier(self): | |
ec38833c | 1488 | copy_unit_to_networkd_unit_path('configure-without-carrier.network', '11-dummy.netdev') |
2cf6fdff | 1489 | start_networkd() |
e2aea43f | 1490 | self.wait_online(['test1:routable']) |
e40a58b5 | 1491 | |
371810d1 | 1492 | output = check_output(*networkctl_cmd, 'status', 'test1') |
1f0e3109 SS |
1493 | print(output) |
1494 | self.assertRegex(output, '192.168.0.15') | |
1495 | self.assertRegex(output, '192.168.0.1') | |
1496 | self.assertRegex(output, 'routable') | |
1497 | ||
1f0e3109 | 1498 | def test_routing_policy_rule(self): |
ec38833c | 1499 | copy_unit_to_networkd_unit_path('routing-policy-rule-test1.network', '11-dummy.netdev') |
2cf6fdff | 1500 | start_networkd() |
e2aea43f | 1501 | self.wait_online(['test1:degraded']) |
e40a58b5 | 1502 | |
371810d1 | 1503 | output = check_output('ip rule') |
1f0e3109 SS |
1504 | print(output) |
1505 | self.assertRegex(output, '111') | |
1506 | self.assertRegex(output, 'from 192.168.100.18') | |
f7bdd562 | 1507 | self.assertRegex(output, r'tos (?:0x08|throughput)\s') |
1f0e3109 SS |
1508 | self.assertRegex(output, 'iif test1') |
1509 | self.assertRegex(output, 'oif test1') | |
1510 | self.assertRegex(output, 'lookup 7') | |
1511 | ||
b677774d | 1512 | def test_routing_policy_rule_issue_11280(self): |
ec38833c ZJS |
1513 | copy_unit_to_networkd_unit_path('routing-policy-rule-test1.network', '11-dummy.netdev', |
1514 | 'routing-policy-rule-dummy98.network', '12-dummy.netdev') | |
b677774d | 1515 | |
b677774d YW |
1516 | for trial in range(3): |
1517 | # Remove state files only first time | |
e2aea43f YW |
1518 | start_networkd(3) |
1519 | self.wait_online(['test1:degraded', 'dummy98:degraded']) | |
df7f9afa | 1520 | time.sleep(1) |
b677774d | 1521 | |
371810d1 | 1522 | output = check_output('ip rule list table 7') |
b677774d YW |
1523 | print(output) |
1524 | self.assertRegex(output, '111: from 192.168.100.18 tos (?:0x08|throughput) iif test1 oif test1 lookup 7') | |
1525 | ||
371810d1 | 1526 | output = check_output('ip rule list table 8') |
b677774d YW |
1527 | print(output) |
1528 | self.assertRegex(output, '112: from 192.168.101.18 tos (?:0x08|throughput) iif dummy98 oif dummy98 lookup 8') | |
1529 | ||
aaae5713 YW |
1530 | stop_networkd(remove_state_files=False) |
1531 | ||
d586a2c3 | 1532 | @expectedFailureIfRoutingPolicyPortRangeIsNotAvailable() |
926062f0 | 1533 | def test_routing_policy_rule_port_range(self): |
ec38833c | 1534 | copy_unit_to_networkd_unit_path('25-fibrule-port-range.network', '11-dummy.netdev') |
2cf6fdff | 1535 | start_networkd() |
e2aea43f | 1536 | self.wait_online(['test1:degraded']) |
e40a58b5 | 1537 | |
371810d1 | 1538 | output = check_output('ip rule') |
926062f0 SS |
1539 | print(output) |
1540 | self.assertRegex(output, '111') | |
1541 | self.assertRegex(output, 'from 192.168.100.18') | |
1542 | self.assertRegex(output, '1123-1150') | |
1543 | self.assertRegex(output, '3224-3290') | |
1544 | self.assertRegex(output, 'tcp') | |
1545 | self.assertRegex(output, 'lookup 7') | |
1f0e3109 | 1546 | |
d586a2c3 | 1547 | @expectedFailureIfRoutingPolicyIPProtoIsNotAvailable() |
efecf9cd | 1548 | def test_routing_policy_rule_invert(self): |
ec38833c | 1549 | copy_unit_to_networkd_unit_path('25-fibrule-invert.network', '11-dummy.netdev') |
2cf6fdff | 1550 | start_networkd() |
e2aea43f | 1551 | self.wait_online(['test1:degraded']) |
e40a58b5 | 1552 | |
371810d1 | 1553 | output = check_output('ip rule') |
efecf9cd | 1554 | print(output) |
efecf9cd SS |
1555 | self.assertRegex(output, '111') |
1556 | self.assertRegex(output, 'not.*?from.*?192.168.100.18') | |
1557 | self.assertRegex(output, 'tcp') | |
1558 | self.assertRegex(output, 'lookup 7') | |
1559 | ||
0ef830cf | 1560 | def test_route_static(self): |
ec38833c | 1561 | copy_unit_to_networkd_unit_path('25-route-static.network', '12-dummy.netdev') |
2cf6fdff | 1562 | start_networkd() |
e2aea43f YW |
1563 | self.wait_online(['dummy98:routable']) |
1564 | ||
1565 | output = check_output(*networkctl_cmd, 'status', 'dummy98', env=env) | |
1566 | print(output) | |
0d34228f | 1567 | |
6d60f9db | 1568 | print('### ip -6 route show dev dummy98') |
371810d1 | 1569 | output = check_output('ip -6 route show dev dummy98') |
0d34228f | 1570 | print(output) |
0ef830cf YW |
1571 | self.assertRegex(output, '2001:1234:5:8fff:ff:ff:ff:ff proto static') |
1572 | self.assertRegex(output, '2001:1234:5:8f63::1 proto kernel') | |
1f0e3109 | 1573 | |
6d60f9db | 1574 | print('### ip -6 route show dev dummy98 default') |
371810d1 | 1575 | output = check_output('ip -6 route show dev dummy98 default') |
6d60f9db | 1576 | print(output) |
0ef830cf | 1577 | self.assertRegex(output, 'default via 2001:1234:5:8fff:ff:ff:ff:ff proto static metric 1024 pref medium') |
1f0e3109 | 1578 | |
6d60f9db | 1579 | print('### ip -4 route show dev dummy98') |
371810d1 | 1580 | output = check_output('ip -4 route show dev dummy98') |
1f0e3109 | 1581 | print(output) |
0ef830cf YW |
1582 | self.assertRegex(output, '149.10.124.48/28 proto kernel scope link src 149.10.124.58') |
1583 | self.assertRegex(output, '149.10.124.64 proto static scope link') | |
2b00dff8 | 1584 | self.assertRegex(output, '169.254.0.0/16 proto static scope link metric 2048') |
0ef830cf YW |
1585 | self.assertRegex(output, '192.168.1.1 proto static initcwnd 20') |
1586 | self.assertRegex(output, '192.168.1.2 proto static initrwnd 30') | |
6d60f9db | 1587 | self.assertRegex(output, 'multicast 149.10.123.4 proto static') |
1f0e3109 | 1588 | |
6d60f9db | 1589 | print('### ip -4 route show dev dummy98 default') |
371810d1 | 1590 | output = check_output('ip -4 route show dev dummy98 default') |
6d60f9db | 1591 | print(output) |
0ef830cf YW |
1592 | self.assertRegex(output, 'default via 149.10.125.65 proto static onlink') |
1593 | self.assertRegex(output, 'default via 149.10.124.64 proto static') | |
6543b7fd | 1594 | self.assertRegex(output, 'default proto static') |
1f0e3109 | 1595 | |
6d60f9db YW |
1596 | print('### ip -4 route show table local dev dummy98') |
1597 | output = check_output('ip -4 route show table local dev dummy98') | |
1598 | print(output) | |
1599 | self.assertRegex(output, 'local 149.10.123.1 proto static scope host') | |
1600 | self.assertRegex(output, 'anycast 149.10.123.2 proto static scope link') | |
1601 | self.assertRegex(output, 'broadcast 149.10.123.3 proto static scope link') | |
1602 | ||
1603 | print('### ip route show type blackhole') | |
371810d1 | 1604 | output = check_output('ip route show type blackhole') |
1f0e3109 | 1605 | print(output) |
0ef830cf | 1606 | self.assertRegex(output, 'blackhole 202.54.1.2 proto static') |
f5050e48 | 1607 | |
6d60f9db | 1608 | print('### ip route show type unreachable') |
371810d1 | 1609 | output = check_output('ip route show type unreachable') |
f5050e48 | 1610 | print(output) |
0ef830cf | 1611 | self.assertRegex(output, 'unreachable 202.54.1.3 proto static') |
f5050e48 | 1612 | |
6d60f9db | 1613 | print('### ip route show type prohibit') |
371810d1 | 1614 | output = check_output('ip route show type prohibit') |
f5050e48 | 1615 | print(output) |
0ef830cf | 1616 | self.assertRegex(output, 'prohibit 202.54.1.4 proto static') |
f5050e48 | 1617 | |
20ca06a6 DA |
1618 | def test_ip_route_ipv6_src_route(self): |
1619 | # a dummy device does not make the addresses go through tentative state, so we | |
1620 | # reuse a bond from an earlier test, which does make the addresses go through | |
1621 | # tentative state, and do our test on that | |
ec38833c | 1622 | copy_unit_to_networkd_unit_path('23-active-slave.network', '25-route-ipv6-src.network', '25-bond-active-backup-slave.netdev', '12-dummy.netdev') |
2cf6fdff | 1623 | start_networkd() |
e2aea43f | 1624 | self.wait_online(['dummy98:enslaved', 'bond199:routable']) |
20ca06a6 | 1625 | |
371810d1 | 1626 | output = check_output('ip -6 route list dev bond199') |
20ca06a6 DA |
1627 | print(output) |
1628 | self.assertRegex(output, 'abcd::/16') | |
1629 | self.assertRegex(output, 'src') | |
1630 | self.assertRegex(output, '2001:1234:56:8f63::2') | |
1631 | ||
1f0e3109 | 1632 | def test_ip_link_mac_address(self): |
ec38833c | 1633 | copy_unit_to_networkd_unit_path('25-address-link-section.network', '12-dummy.netdev') |
2cf6fdff | 1634 | start_networkd() |
e2aea43f | 1635 | self.wait_online(['dummy98:degraded']) |
1f0e3109 | 1636 | |
371810d1 | 1637 | output = check_output('ip link show dummy98') |
1f0e3109 SS |
1638 | print(output) |
1639 | self.assertRegex(output, '00:01:02:aa:bb:cc') | |
1640 | ||
1641 | def test_ip_link_unmanaged(self): | |
ec38833c | 1642 | copy_unit_to_networkd_unit_path('25-link-section-unmanaged.network', '12-dummy.netdev') |
df7f9afa | 1643 | start_networkd(5) |
1f0e3109 | 1644 | |
e39cc445 | 1645 | self.check_link_exists('dummy98') |
1f0e3109 | 1646 | |
df7f9afa | 1647 | self.check_operstate('dummy98', 'off', setup_state='unmanaged') |
1f0e3109 SS |
1648 | |
1649 | def test_ipv6_address_label(self): | |
ec38833c | 1650 | copy_unit_to_networkd_unit_path('25-ipv6-address-label-section.network', '12-dummy.netdev') |
2cf6fdff | 1651 | start_networkd() |
e2aea43f | 1652 | self.wait_online(['dummy98:degraded']) |
1f0e3109 | 1653 | |
371810d1 | 1654 | output = check_output('ip addrlabel list') |
1f0e3109 SS |
1655 | print(output) |
1656 | self.assertRegex(output, '2004:da8:1::/64') | |
1657 | ||
d86f5c19 | 1658 | def test_neighbor_section(self): |
ec38833c | 1659 | copy_unit_to_networkd_unit_path('25-neighbor-section.network', '12-dummy.netdev') |
2cf6fdff | 1660 | start_networkd() |
e2aea43f | 1661 | self.wait_online(['dummy98:degraded'], timeout='40s') |
e4a71bf3 | 1662 | |
df7f9afa | 1663 | output = check_output('ip neigh list dev dummy98') |
e4a71bf3 WKI |
1664 | print(output) |
1665 | self.assertRegex(output, '192.168.10.1.*00:00:5e:00:02:65.*PERMANENT') | |
094b5479 | 1666 | self.assertRegex(output, '2004:da8:1::1.*00:00:5e:00:02:66.*PERMANENT') |
e4a71bf3 | 1667 | |
74761cf3 YW |
1668 | def test_neighbor_gre(self): |
1669 | copy_unit_to_networkd_unit_path('25-neighbor-ip.network', '25-neighbor-ip-dummy.network', | |
1670 | '12-dummy.netdev', '25-gre-tunnel-remote-any.netdev') | |
1671 | start_networkd() | |
e2aea43f | 1672 | self.wait_online(['dummy98:degraded', 'gretun97:routable'], timeout='40s') |
74761cf3 YW |
1673 | |
1674 | output = check_output('ip neigh list dev gretun97') | |
1675 | print(output) | |
1676 | self.assertRegex(output, '10.0.0.22 lladdr 10.65.223.239 PERMANENT') | |
1677 | ||
05514ae1 | 1678 | def test_link_local_addressing(self): |
ec38833c ZJS |
1679 | copy_unit_to_networkd_unit_path('25-link-local-addressing-yes.network', '11-dummy.netdev', |
1680 | '25-link-local-addressing-no.network', '12-dummy.netdev') | |
2cf6fdff | 1681 | start_networkd() |
e2aea43f | 1682 | self.wait_online(['test1:degraded', 'dummy98:carrier']) |
05514ae1 | 1683 | |
371810d1 | 1684 | output = check_output('ip address show dev test1') |
05514ae1 YW |
1685 | print(output) |
1686 | self.assertRegex(output, 'inet .* scope link') | |
1687 | self.assertRegex(output, 'inet6 .* scope link') | |
1688 | ||
371810d1 | 1689 | output = check_output('ip address show dev dummy98') |
05514ae1 YW |
1690 | print(output) |
1691 | self.assertNotRegex(output, 'inet6* .* scope link') | |
1692 | ||
05514ae1 YW |
1693 | ''' |
1694 | Documentation/networking/ip-sysctl.txt | |
1695 | ||
1696 | addr_gen_mode - INTEGER | |
1697 | Defines how link-local and autoconf addresses are generated. | |
1698 | ||
1699 | 0: generate address based on EUI64 (default) | |
1700 | 1: do no generate a link-local address, use EUI64 for addresses generated | |
1701 | from autoconf | |
1702 | 2: generate stable privacy addresses, using the secret from | |
1703 | stable_secret (RFC7217) | |
1704 | 3: generate stable privacy addresses, using a random secret if unset | |
1705 | ''' | |
1706 | ||
1707 | test1_addr_gen_mode = '' | |
1708 | if os.path.exists(os.path.join(os.path.join(network_sysctl_ipv6_path, 'test1'), 'stable_secret')): | |
1709 | with open(os.path.join(os.path.join(network_sysctl_ipv6_path, 'test1'), 'stable_secret')) as f: | |
1710 | try: | |
1711 | f.readline() | |
1712 | except IOError: | |
1713 | # if stable_secret is unset, then EIO is returned | |
1714 | test1_addr_gen_mode = '0' | |
1715 | else: | |
1716 | test1_addr_gen_mode = '2' | |
1717 | else: | |
1718 | test1_addr_gen_mode = '0' | |
1719 | ||
1720 | if os.path.exists(os.path.join(os.path.join(network_sysctl_ipv6_path, 'test1'), 'addr_gen_mode')): | |
ec38833c | 1721 | self.assertEqual(read_ipv6_sysctl_attr('test1', 'addr_gen_mode'), test1_addr_gen_mode) |
05514ae1 YW |
1722 | |
1723 | if os.path.exists(os.path.join(os.path.join(network_sysctl_ipv6_path, 'dummy98'), 'addr_gen_mode')): | |
ec38833c | 1724 | self.assertEqual(read_ipv6_sysctl_attr('dummy98', 'addr_gen_mode'), '1') |
05514ae1 | 1725 | |
1f0e3109 | 1726 | def test_sysctl(self): |
ec38833c | 1727 | copy_unit_to_networkd_unit_path('25-sysctl.network', '12-dummy.netdev') |
2cf6fdff | 1728 | start_networkd() |
e2aea43f | 1729 | self.wait_online(['dummy98:degraded']) |
ec38833c ZJS |
1730 | |
1731 | self.assertEqual(read_ipv6_sysctl_attr('dummy98', 'forwarding'), '1') | |
1732 | self.assertEqual(read_ipv6_sysctl_attr('dummy98', 'use_tempaddr'), '2') | |
1733 | self.assertEqual(read_ipv6_sysctl_attr('dummy98', 'dad_transmits'), '3') | |
1734 | self.assertEqual(read_ipv6_sysctl_attr('dummy98', 'hop_limit'), '5') | |
1735 | self.assertEqual(read_ipv6_sysctl_attr('dummy98', 'proxy_ndp'), '1') | |
1736 | self.assertEqual(read_ipv4_sysctl_attr('dummy98', 'forwarding'),'1') | |
1737 | self.assertEqual(read_ipv4_sysctl_attr('dummy98', 'proxy_arp'), '1') | |
1f0e3109 | 1738 | |
4da33154 | 1739 | def test_sysctl_disable_ipv6(self): |
ec38833c | 1740 | copy_unit_to_networkd_unit_path('25-sysctl-disable-ipv6.network', '12-dummy.netdev') |
4da33154 YW |
1741 | |
1742 | print('## Disable ipv6') | |
cefd6b3d ZJS |
1743 | check_output('sysctl net.ipv6.conf.all.disable_ipv6=1') |
1744 | check_output('sysctl net.ipv6.conf.default.disable_ipv6=1') | |
4da33154 | 1745 | |
2cf6fdff | 1746 | start_networkd() |
e2aea43f | 1747 | self.wait_online(['dummy98:routable']) |
4da33154 | 1748 | |
371810d1 | 1749 | output = check_output('ip -4 address show dummy98') |
4da33154 YW |
1750 | print(output) |
1751 | self.assertRegex(output, 'inet 10.2.3.4/16 brd 10.2.255.255 scope global dummy98') | |
371810d1 | 1752 | output = check_output('ip -6 address show dummy98') |
4da33154 YW |
1753 | print(output) |
1754 | self.assertEqual(output, '') | |
4933b97d YW |
1755 | output = check_output('ip -4 route show dev dummy98') |
1756 | print(output) | |
1757 | self.assertEqual(output, '10.2.0.0/16 proto kernel scope link src 10.2.3.4') | |
1758 | output = check_output('ip -6 route show dev dummy98') | |
1759 | print(output) | |
1760 | self.assertEqual(output, '') | |
4da33154 | 1761 | |
cefd6b3d | 1762 | check_output('ip link del dummy98') |
4da33154 YW |
1763 | |
1764 | print('## Enable ipv6') | |
cefd6b3d ZJS |
1765 | check_output('sysctl net.ipv6.conf.all.disable_ipv6=0') |
1766 | check_output('sysctl net.ipv6.conf.default.disable_ipv6=0') | |
4da33154 | 1767 | |
e2aea43f YW |
1768 | restart_networkd(3) |
1769 | self.wait_online(['dummy98:routable']) | |
4da33154 | 1770 | |
371810d1 | 1771 | output = check_output('ip -4 address show dummy98') |
4da33154 YW |
1772 | print(output) |
1773 | self.assertRegex(output, 'inet 10.2.3.4/16 brd 10.2.255.255 scope global dummy98') | |
371810d1 | 1774 | output = check_output('ip -6 address show dummy98') |
4da33154 | 1775 | print(output) |
4933b97d | 1776 | self.assertRegex(output, 'inet6 2607:5300:203:3906::/64 scope global') |
4da33154 | 1777 | self.assertRegex(output, 'inet6 .* scope link') |
4933b97d YW |
1778 | output = check_output('ip -4 route show dev dummy98') |
1779 | print(output) | |
1780 | self.assertEqual(output, '10.2.0.0/16 proto kernel scope link src 10.2.3.4') | |
1781 | output = check_output('ip -6 route show dev dummy98') | |
1782 | print(output) | |
1783 | self.assertRegex(output, 'default via 2607:5300:203:39ff:ff:ff:ff:ff proto static') | |
4da33154 | 1784 | |
cd65d067 | 1785 | def test_bind_carrier(self): |
ec38833c | 1786 | copy_unit_to_networkd_unit_path('25-bind-carrier.network', '11-dummy.netdev') |
2cf6fdff | 1787 | start_networkd() |
e2aea43f | 1788 | self.wait_online(['test1:routable']) |
cd65d067 | 1789 | |
cefd6b3d ZJS |
1790 | check_output('ip link add dummy98 type dummy') |
1791 | check_output('ip link set dummy98 up') | |
b117044c | 1792 | time.sleep(2) |
371810d1 | 1793 | output = check_output('ip address show test1') |
cd65d067 YW |
1794 | print(output) |
1795 | self.assertRegex(output, 'UP,LOWER_UP') | |
1796 | self.assertRegex(output, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1') | |
791c1140 | 1797 | self.check_operstate('test1', 'routable') |
cd65d067 | 1798 | |
cefd6b3d ZJS |
1799 | check_output('ip link add dummy99 type dummy') |
1800 | check_output('ip link set dummy99 up') | |
b117044c | 1801 | time.sleep(2) |
371810d1 | 1802 | output = check_output('ip address show test1') |
cd65d067 YW |
1803 | print(output) |
1804 | self.assertRegex(output, 'UP,LOWER_UP') | |
1805 | self.assertRegex(output, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1') | |
791c1140 | 1806 | self.check_operstate('test1', 'routable') |
cd65d067 | 1807 | |
cefd6b3d | 1808 | check_output('ip link del dummy98') |
b117044c | 1809 | time.sleep(2) |
371810d1 | 1810 | output = check_output('ip address show test1') |
cd65d067 YW |
1811 | print(output) |
1812 | self.assertRegex(output, 'UP,LOWER_UP') | |
1813 | self.assertRegex(output, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1') | |
791c1140 | 1814 | self.check_operstate('test1', 'routable') |
cd65d067 | 1815 | |
cefd6b3d | 1816 | check_output('ip link del dummy99') |
b117044c | 1817 | time.sleep(2) |
371810d1 | 1818 | output = check_output('ip address show test1') |
cd65d067 YW |
1819 | print(output) |
1820 | self.assertNotRegex(output, 'UP,LOWER_UP') | |
1821 | self.assertRegex(output, 'DOWN') | |
1822 | self.assertNotRegex(output, '192.168.10') | |
791c1140 | 1823 | self.check_operstate('test1', 'off') |
cd65d067 | 1824 | |
cefd6b3d ZJS |
1825 | check_output('ip link add dummy98 type dummy') |
1826 | check_output('ip link set dummy98 up') | |
b117044c | 1827 | time.sleep(2) |
371810d1 | 1828 | output = check_output('ip address show test1') |
cd65d067 YW |
1829 | print(output) |
1830 | self.assertRegex(output, 'UP,LOWER_UP') | |
1831 | self.assertRegex(output, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1') | |
791c1140 | 1832 | self.check_operstate('test1', 'routable') |
cd65d067 | 1833 | |
fdcd1ec5 | 1834 | def test_domain(self): |
ec38833c | 1835 | copy_unit_to_networkd_unit_path('12-dummy.netdev', '24-search-domain.network') |
2cf6fdff | 1836 | start_networkd() |
e2aea43f | 1837 | self.wait_online(['dummy98:routable']) |
fdcd1ec5 | 1838 | |
371810d1 | 1839 | output = check_output(*networkctl_cmd, 'status', 'dummy98', env=env) |
fdcd1ec5 YW |
1840 | print(output) |
1841 | self.assertRegex(output, 'Address: 192.168.42.100') | |
1842 | self.assertRegex(output, 'DNS: 192.168.42.1') | |
1843 | self.assertRegex(output, 'Search Domains: one') | |
1844 | ||
1e498853 YW |
1845 | def test_keep_configuration_static(self): |
1846 | check_output('systemctl stop systemd-networkd') | |
1847 | ||
1848 | check_output('ip link add name dummy98 type dummy') | |
1849 | check_output('ip address add 10.1.2.3/16 dev dummy98') | |
1850 | check_output('ip address add 10.2.3.4/16 dev dummy98 valid_lft 600 preferred_lft 500') | |
1851 | output = check_output('ip address show dummy98') | |
1852 | print(output) | |
1853 | self.assertRegex(output, 'inet 10.1.2.3/16 scope global dummy98') | |
1854 | self.assertRegex(output, 'inet 10.2.3.4/16 scope global dynamic dummy98') | |
1855 | output = check_output('ip route show dev dummy98') | |
1856 | print(output) | |
1857 | ||
1858 | copy_unit_to_networkd_unit_path('24-keep-configuration-static.network') | |
2cf6fdff | 1859 | start_networkd() |
e2aea43f | 1860 | self.wait_online(['dummy98:routable']) |
1e498853 YW |
1861 | |
1862 | output = check_output('ip address show dummy98') | |
1863 | print(output) | |
1864 | self.assertRegex(output, 'inet 10.1.2.3/16 scope global dummy98') | |
1865 | self.assertNotRegex(output, 'inet 10.2.3.4/16 scope global dynamic dummy98') | |
1866 | ||
336d18f0 YW |
1867 | class NetworkdStateFileTests(unittest.TestCase, Utilities): |
1868 | links = [ | |
1869 | 'dummy98', | |
1870 | ] | |
1871 | ||
1872 | units = [ | |
1873 | '12-dummy.netdev', | |
1874 | 'state-file-tests.network', | |
1875 | ] | |
1876 | ||
1877 | def setUp(self): | |
1878 | remove_links(self.links) | |
1879 | stop_networkd(show_logs=False) | |
1880 | ||
1881 | def tearDown(self): | |
1882 | remove_links(self.links) | |
1883 | remove_unit_from_networkd_path(self.units) | |
1884 | stop_networkd(show_logs=True) | |
1885 | ||
1886 | def test_state_file(self): | |
1887 | copy_unit_to_networkd_unit_path('12-dummy.netdev', 'state-file-tests.network') | |
1888 | start_networkd() | |
1889 | self.wait_online(['dummy98:routable']) | |
1890 | ||
1891 | output = check_output(*networkctl_cmd, '--no-legend', 'list', 'dummy98', env=env) | |
1892 | print(output) | |
1893 | ifindex = output.split()[0] | |
1894 | ||
1895 | path = os.path.join('/run/systemd/netif/links/', ifindex) | |
1896 | self.assertTrue(os.path.exists(path)) | |
1897 | time.sleep(2) | |
1898 | ||
1899 | with open(path) as f: | |
1900 | data = f.read() | |
1901 | self.assertRegex(data, r'ADMIN_STATE=configured') | |
1902 | self.assertRegex(data, r'OPER_STATE=routable') | |
1903 | self.assertRegex(data, r'REQUIRED_FOR_ONLINE=yes') | |
1904 | self.assertRegex(data, r'REQUIRED_OPER_STATE_FOR_ONLINE=routable') | |
1905 | self.assertRegex(data, r'NETWORK_FILE=/run/systemd/network/state-file-tests.network') | |
1906 | self.assertRegex(data, r'DNS=10.10.10.10 10.10.10.11') | |
1907 | self.assertRegex(data, r'NTP=0.fedora.pool.ntp.org 1.fedora.pool.ntp.org') | |
1908 | self.assertRegex(data, r'DOMAINS=hogehoge') | |
1909 | self.assertRegex(data, r'ROUTE_DOMAINS=foofoo') | |
1910 | self.assertRegex(data, r'LLMNR=no') | |
1911 | self.assertRegex(data, r'MDNS=yes') | |
1912 | self.assertRegex(data, r'DNSSEC=no') | |
1913 | self.assertRegex(data, r'ADDRESSES=192.168.(?:10.10|12.12)/24 192.168.(?:12.12|10.10)/24') | |
1914 | ||
1915 | check_output(*resolvectl_cmd, 'dns', 'dummy98', '10.10.10.12', '10.10.10.13', env=env) | |
1916 | check_output(*resolvectl_cmd, 'domain', 'dummy98', 'hogehogehoge', '~foofoofoo', env=env) | |
1917 | check_output(*resolvectl_cmd, 'llmnr', 'dummy98', 'yes', env=env) | |
1918 | check_output(*resolvectl_cmd, 'mdns', 'dummy98', 'no', env=env) | |
1919 | check_output(*resolvectl_cmd, 'dnssec', 'dummy98', 'yes', env=env) | |
1920 | check_output(*timedatectl_cmd, 'ntp-servers', 'dummy98', '2.fedora.pool.ntp.org', '3.fedora.pool.ntp.org', env=env) | |
1921 | time.sleep(2) | |
1922 | ||
1923 | with open(path) as f: | |
1924 | data = f.read() | |
1925 | self.assertRegex(data, r'DNS=10.10.10.12 10.10.10.13') | |
1926 | self.assertRegex(data, r'NTP=2.fedora.pool.ntp.org 3.fedora.pool.ntp.org') | |
1927 | self.assertRegex(data, r'DOMAINS=hogehogehoge') | |
1928 | self.assertRegex(data, r'ROUTE_DOMAINS=foofoofoo') | |
1929 | self.assertRegex(data, r'LLMNR=yes') | |
1930 | self.assertRegex(data, r'MDNS=no') | |
1931 | self.assertRegex(data, r'DNSSEC=yes') | |
1932 | ||
1933 | check_output(*timedatectl_cmd, 'revert', 'dummy98', env=env) | |
1934 | time.sleep(2) | |
1935 | ||
1936 | with open(path) as f: | |
1937 | data = f.read() | |
1938 | self.assertRegex(data, r'DNS=10.10.10.12 10.10.10.13') | |
1939 | self.assertRegex(data, r'NTP=0.fedora.pool.ntp.org 1.fedora.pool.ntp.org') | |
1940 | self.assertRegex(data, r'DOMAINS=hogehogehoge') | |
1941 | self.assertRegex(data, r'ROUTE_DOMAINS=foofoofoo') | |
1942 | self.assertRegex(data, r'LLMNR=yes') | |
1943 | self.assertRegex(data, r'MDNS=no') | |
1944 | self.assertRegex(data, r'DNSSEC=yes') | |
1945 | ||
1946 | check_output(*resolvectl_cmd, 'revert', 'dummy98', env=env) | |
1947 | time.sleep(2) | |
1948 | ||
1949 | with open(path) as f: | |
1950 | data = f.read() | |
1951 | self.assertRegex(data, r'DNS=10.10.10.10 10.10.10.11') | |
1952 | self.assertRegex(data, r'NTP=0.fedora.pool.ntp.org 1.fedora.pool.ntp.org') | |
1953 | self.assertRegex(data, r'DOMAINS=hogehoge') | |
1954 | self.assertRegex(data, r'ROUTE_DOMAINS=foofoo') | |
1955 | self.assertRegex(data, r'LLMNR=no') | |
1956 | self.assertRegex(data, r'MDNS=yes') | |
1957 | self.assertRegex(data, r'DNSSEC=no') | |
1958 | ||
be68c2c9 | 1959 | class NetworkdBondTests(unittest.TestCase, Utilities): |
c3a8853f | 1960 | links = [ |
c2990ec3 | 1961 | 'bond199', |
c3a8853f | 1962 | 'bond99', |
cc3e488c YW |
1963 | 'dummy98', |
1964 | 'test1'] | |
c3a8853f YW |
1965 | |
1966 | units = [ | |
cc3e488c YW |
1967 | '11-dummy.netdev', |
1968 | '12-dummy.netdev', | |
c2990ec3 YW |
1969 | '23-active-slave.network', |
1970 | '23-bond199.network', | |
1971 | '23-primary-slave.network', | |
c2990ec3 | 1972 | '25-bond-active-backup-slave.netdev', |
c3a8853f | 1973 | '25-bond.netdev', |
c3a8853f | 1974 | 'bond99.network', |
cc3e488c | 1975 | 'bond-slave.network'] |
c3a8853f YW |
1976 | |
1977 | def setUp(self): | |
ec38833c | 1978 | remove_links(self.links) |
aaae5713 | 1979 | stop_networkd(show_logs=False) |
c3a8853f YW |
1980 | |
1981 | def tearDown(self): | |
ec38833c ZJS |
1982 | remove_links(self.links) |
1983 | remove_unit_from_networkd_path(self.units) | |
aaae5713 | 1984 | stop_networkd(show_logs=True) |
c3a8853f | 1985 | |
c2990ec3 | 1986 | def test_bond_active_slave(self): |
ec38833c | 1987 | copy_unit_to_networkd_unit_path('23-active-slave.network', '23-bond199.network', '25-bond-active-backup-slave.netdev', '12-dummy.netdev') |
2cf6fdff | 1988 | start_networkd() |
e2aea43f | 1989 | self.wait_online(['dummy98:enslaved', 'bond199:degraded']) |
c2990ec3 | 1990 | |
371810d1 | 1991 | output = check_output('ip -d link show bond199') |
c2990ec3 YW |
1992 | print(output) |
1993 | self.assertRegex(output, 'active_slave dummy98') | |
1994 | ||
1995 | def test_bond_primary_slave(self): | |
35a78c51 | 1996 | copy_unit_to_networkd_unit_path('23-primary-slave.network', '23-bond199.network', '25-bond-active-backup-slave.netdev', '12-dummy.netdev') |
2cf6fdff | 1997 | start_networkd() |
e2aea43f | 1998 | self.wait_online(['dummy98:enslaved', 'bond199:degraded']) |
c2990ec3 | 1999 | |
371810d1 | 2000 | output = check_output('ip -d link show bond199') |
c2990ec3 | 2001 | print(output) |
35a78c51 | 2002 | self.assertRegex(output, 'primary dummy98') |
c2990ec3 | 2003 | |
cc3e488c | 2004 | def test_bond_operstate(self): |
ec38833c ZJS |
2005 | copy_unit_to_networkd_unit_path('25-bond.netdev', '11-dummy.netdev', '12-dummy.netdev', |
2006 | 'bond99.network','bond-slave.network') | |
2cf6fdff | 2007 | start_networkd() |
e2aea43f | 2008 | self.wait_online(['dummy98:enslaved', 'test1:enslaved', 'bond99:routable']) |
c3a8853f | 2009 | |
371810d1 | 2010 | output = check_output('ip -d link show dummy98') |
c3a8853f | 2011 | print(output) |
cc3e488c | 2012 | self.assertRegex(output, 'SLAVE,UP,LOWER_UP') |
c3a8853f | 2013 | |
371810d1 | 2014 | output = check_output('ip -d link show test1') |
c3a8853f YW |
2015 | print(output) |
2016 | self.assertRegex(output, 'SLAVE,UP,LOWER_UP') | |
2017 | ||
371810d1 | 2018 | output = check_output('ip -d link show bond99') |
c3a8853f YW |
2019 | print(output) |
2020 | self.assertRegex(output, 'MASTER,UP,LOWER_UP') | |
2021 | ||
791c1140 YW |
2022 | self.check_operstate('dummy98', 'enslaved') |
2023 | self.check_operstate('test1', 'enslaved') | |
2024 | self.check_operstate('bond99', 'routable') | |
c3a8853f | 2025 | |
cefd6b3d | 2026 | check_output('ip link set dummy98 down') |
c3a8853f YW |
2027 | time.sleep(2) |
2028 | ||
791c1140 YW |
2029 | self.check_operstate('dummy98', 'off') |
2030 | self.check_operstate('test1', 'enslaved') | |
2031 | self.check_operstate('bond99', 'degraded-carrier') | |
c3a8853f | 2032 | |
cefd6b3d | 2033 | check_output('ip link set dummy98 up') |
c3a8853f YW |
2034 | time.sleep(2) |
2035 | ||
791c1140 YW |
2036 | self.check_operstate('dummy98', 'enslaved') |
2037 | self.check_operstate('test1', 'enslaved') | |
2038 | self.check_operstate('bond99', 'routable') | |
c3a8853f | 2039 | |
cefd6b3d ZJS |
2040 | check_output('ip link set dummy98 down') |
2041 | check_output('ip link set test1 down') | |
2700d2c7 | 2042 | time.sleep(2) |
cc3e488c | 2043 | |
791c1140 YW |
2044 | self.check_operstate('dummy98', 'off') |
2045 | self.check_operstate('test1', 'off') | |
2700d2c7 | 2046 | |
2700d2c7 YW |
2047 | for trial in range(30): |
2048 | if trial > 0: | |
2049 | time.sleep(1) | |
371810d1 | 2050 | output = check_output('ip address show bond99') |
2700d2c7 | 2051 | print(output) |
ec38833c | 2052 | if get_operstate('bond99') == 'no-carrier': |
2700d2c7 YW |
2053 | break |
2054 | else: | |
2055 | # Huh? Kernel does not recognize that all slave interfaces are down? | |
2056 | # Let's confirm that networkd's operstate is consistent with ip's result. | |
2057 | self.assertNotRegex(output, 'NO-CARRIER') | |
cc3e488c | 2058 | |
be68c2c9 | 2059 | class NetworkdBridgeTests(unittest.TestCase, Utilities): |
09ea6724 YW |
2060 | links = [ |
2061 | 'bridge99', | |
2062 | 'dummy98', | |
2063 | 'test1'] | |
2064 | ||
2065 | units = [ | |
2066 | '11-dummy.netdev', | |
2067 | '12-dummy.netdev', | |
2068 | '26-bridge.netdev', | |
2069 | '26-bridge-slave-interface-1.network', | |
2070 | '26-bridge-slave-interface-2.network', | |
6f943798 YW |
2071 | '26-bridge-vlan-master.network', |
2072 | '26-bridge-vlan-slave.network', | |
804b6cd2 | 2073 | 'bridge99-ignore-carrier-loss.network', |
09ea6724 | 2074 | 'bridge99.network'] |
1f0e3109 | 2075 | |
8d17c386 YW |
2076 | routing_policy_rule_tables = ['100'] |
2077 | ||
1f0e3109 | 2078 | def setUp(self): |
8d17c386 | 2079 | remove_routing_policy_rule_tables(self.routing_policy_rule_tables) |
ec38833c | 2080 | remove_links(self.links) |
aaae5713 | 2081 | stop_networkd(show_logs=False) |
1f0e3109 SS |
2082 | |
2083 | def tearDown(self): | |
8d17c386 | 2084 | remove_routing_policy_rule_tables(self.routing_policy_rule_tables) |
ec38833c ZJS |
2085 | remove_links(self.links) |
2086 | remove_unit_from_networkd_path(self.units) | |
aaae5713 | 2087 | stop_networkd(show_logs=True) |
1f0e3109 | 2088 | |
6f943798 YW |
2089 | def test_bridge_vlan(self): |
2090 | copy_unit_to_networkd_unit_path('11-dummy.netdev', '26-bridge-vlan-slave.network', | |
2091 | '26-bridge.netdev', '26-bridge-vlan-master.network') | |
2092 | start_networkd() | |
e2aea43f | 2093 | self.wait_online(['test1:enslaved', 'bridge99:degraded']) |
6f943798 YW |
2094 | |
2095 | output = check_output('bridge vlan show dev test1') | |
2096 | print(output) | |
2097 | self.assertNotRegex(output, '4063') | |
2098 | for i in range(4064, 4095): | |
2099 | self.assertRegex(output, f'{i}') | |
2100 | self.assertNotRegex(output, '4095') | |
2101 | ||
2102 | output = check_output('bridge vlan show dev bridge99') | |
2103 | print(output) | |
2104 | self.assertNotRegex(output, '4059') | |
2105 | for i in range(4060, 4095): | |
2106 | self.assertRegex(output, f'{i}') | |
2107 | self.assertNotRegex(output, '4095') | |
2108 | ||
1f0e3109 | 2109 | def test_bridge_property(self): |
ec38833c ZJS |
2110 | copy_unit_to_networkd_unit_path('11-dummy.netdev', '12-dummy.netdev', '26-bridge.netdev', |
2111 | '26-bridge-slave-interface-1.network', '26-bridge-slave-interface-2.network', | |
2112 | 'bridge99.network') | |
2cf6fdff | 2113 | start_networkd() |
e2aea43f | 2114 | self.wait_online(['dummy98:enslaved', 'test1:enslaved', 'bridge99:routable']) |
1f0e3109 | 2115 | |
371810d1 | 2116 | output = check_output('ip -d link show test1') |
1f0e3109 SS |
2117 | print(output) |
2118 | self.assertRegex(output, 'master') | |
2119 | self.assertRegex(output, 'bridge') | |
2120 | ||
371810d1 | 2121 | output = check_output('ip -d link show dummy98') |
1f0e3109 SS |
2122 | print(output) |
2123 | self.assertRegex(output, 'master') | |
2124 | self.assertRegex(output, 'bridge') | |
2125 | ||
371810d1 | 2126 | output = check_output('ip addr show bridge99') |
1f0e3109 | 2127 | print(output) |
2be6c5d2 | 2128 | self.assertRegex(output, '192.168.0.15/24') |
1f0e3109 | 2129 | |
371810d1 | 2130 | output = check_output('bridge -d link show dummy98') |
1f0e3109 | 2131 | print(output) |
ec38833c | 2132 | self.assertEqual(read_bridge_port_attr('bridge99', 'dummy98', 'path_cost'), '400') |
5424fd95 YW |
2133 | self.assertEqual(read_bridge_port_attr('bridge99', 'dummy98', 'hairpin_mode'), '1') |
2134 | self.assertEqual(read_bridge_port_attr('bridge99', 'dummy98', 'multicast_fast_leave'), '1') | |
ec38833c ZJS |
2135 | self.assertEqual(read_bridge_port_attr('bridge99', 'dummy98', 'unicast_flood'), '1') |
2136 | self.assertEqual(read_bridge_port_attr('bridge99', 'dummy98', 'multicast_flood'), '0') | |
5424fd95 YW |
2137 | # CONFIG_BRIDGE_IGMP_SNOOPING=y |
2138 | if (os.path.exists('/sys/devices/virtual/net/bridge00/lower_dummy98/brport/multicast_to_unicast')): | |
2139 | self.assertEqual(read_bridge_port_attr('bridge99', 'dummy98', 'multicast_to_unicast'), '1') | |
7f15b714 | 2140 | if (os.path.exists('/sys/devices/virtual/net/bridge99/lower_dummy98/brport/neigh_suppress')): |
ec38833c ZJS |
2141 | self.assertEqual(read_bridge_port_attr('bridge99', 'dummy98', 'neigh_suppress'), '1') |
2142 | self.assertEqual(read_bridge_port_attr('bridge99', 'dummy98', 'learning'), '0') | |
5424fd95 YW |
2143 | self.assertEqual(read_bridge_port_attr('bridge99', 'dummy98', 'priority'), '23') |
2144 | self.assertEqual(read_bridge_port_attr('bridge99', 'dummy98', 'bpdu_guard'), '1') | |
2145 | self.assertEqual(read_bridge_port_attr('bridge99', 'dummy98', 'root_block'), '1') | |
4d7ed14f | 2146 | |
5424fd95 YW |
2147 | output = check_output('bridge -d link show test1') |
2148 | print(output) | |
2149 | self.assertEqual(read_bridge_port_attr('bridge99', 'test1', 'priority'), '0') | |
1f0e3109 | 2150 | |
371810d1 | 2151 | check_output('ip address add 192.168.0.16/24 dev bridge99') |
804b6cd2 YW |
2152 | time.sleep(1) |
2153 | ||
371810d1 | 2154 | output = check_output('ip addr show bridge99') |
2be6c5d2 YW |
2155 | print(output) |
2156 | self.assertRegex(output, '192.168.0.16/24') | |
2157 | ||
371810d1 | 2158 | self.assertEqual(call('ip link del test1'), 0) |
2be6c5d2 YW |
2159 | time.sleep(3) |
2160 | ||
791c1140 | 2161 | self.check_operstate('bridge99', 'degraded-carrier') |
2be6c5d2 | 2162 | |
cefd6b3d | 2163 | check_output('ip link del dummy98') |
804b6cd2 YW |
2164 | time.sleep(3) |
2165 | ||
791c1140 | 2166 | self.check_operstate('bridge99', 'no-carrier') |
2be6c5d2 | 2167 | |
371810d1 | 2168 | output = check_output('ip address show bridge99') |
804b6cd2 YW |
2169 | print(output) |
2170 | self.assertRegex(output, 'NO-CARRIER') | |
2171 | self.assertNotRegex(output, '192.168.0.15/24') | |
2172 | self.assertNotRegex(output, '192.168.0.16/24') | |
2173 | ||
2174 | def test_bridge_ignore_carrier_loss(self): | |
ec38833c ZJS |
2175 | copy_unit_to_networkd_unit_path('11-dummy.netdev', '12-dummy.netdev', '26-bridge.netdev', |
2176 | '26-bridge-slave-interface-1.network', '26-bridge-slave-interface-2.network', | |
2177 | 'bridge99-ignore-carrier-loss.network') | |
2cf6fdff | 2178 | start_networkd() |
e2aea43f | 2179 | self.wait_online(['dummy98:enslaved', 'test1:enslaved', 'bridge99:routable']) |
804b6cd2 | 2180 | |
371810d1 | 2181 | check_output('ip address add 192.168.0.16/24 dev bridge99') |
804b6cd2 YW |
2182 | time.sleep(1) |
2183 | ||
371810d1 ZJS |
2184 | check_output('ip link del test1') |
2185 | check_output('ip link del dummy98') | |
804b6cd2 YW |
2186 | time.sleep(3) |
2187 | ||
371810d1 | 2188 | output = check_output('ip address show bridge99') |
804b6cd2 YW |
2189 | print(output) |
2190 | self.assertRegex(output, 'NO-CARRIER') | |
2191 | self.assertRegex(output, 'inet 192.168.0.15/24 brd 192.168.0.255 scope global bridge99') | |
2192 | self.assertRegex(output, 'inet 192.168.0.16/24 scope global secondary bridge99') | |
2193 | ||
6609924c | 2194 | def test_bridge_ignore_carrier_loss_frequent_loss_and_gain(self): |
ec38833c ZJS |
2195 | copy_unit_to_networkd_unit_path('26-bridge.netdev', '26-bridge-slave-interface-1.network', |
2196 | 'bridge99-ignore-carrier-loss.network') | |
2cf6fdff | 2197 | start_networkd() |
e2aea43f | 2198 | self.wait_online(['bridge99:no-carrier']) |
6609924c | 2199 | |
90e3bcbd YW |
2200 | for trial in range(4): |
2201 | check_output('ip link add dummy98 type dummy') | |
2202 | check_output('ip link set dummy98 up') | |
2203 | if trial < 3: | |
2204 | check_output('ip link del dummy98') | |
6609924c | 2205 | |
e2aea43f | 2206 | self.wait_online(['bridge99:routable', 'dummy98:enslaved']) |
6609924c | 2207 | |
371810d1 | 2208 | output = check_output('ip address show bridge99') |
6609924c YW |
2209 | print(output) |
2210 | self.assertRegex(output, 'inet 192.168.0.15/24 brd 192.168.0.255 scope global bridge99') | |
2211 | ||
371810d1 | 2212 | output = check_output('ip rule list table 100') |
6609924c YW |
2213 | print(output) |
2214 | self.assertEqual(output, '0: from all to 8.8.8.8 lookup 100') | |
2215 | ||
be68c2c9 | 2216 | class NetworkdLLDPTests(unittest.TestCase, Utilities): |
1f0e3109 SS |
2217 | links = ['veth99'] |
2218 | ||
09ea6724 YW |
2219 | units = [ |
2220 | '23-emit-lldp.network', | |
2221 | '24-lldp.network', | |
2222 | '25-veth.netdev'] | |
1f0e3109 SS |
2223 | |
2224 | def setUp(self): | |
ec38833c | 2225 | remove_links(self.links) |
aaae5713 | 2226 | stop_networkd(show_logs=False) |
1f0e3109 SS |
2227 | |
2228 | def tearDown(self): | |
ec38833c ZJS |
2229 | remove_links(self.links) |
2230 | remove_unit_from_networkd_path(self.units) | |
aaae5713 | 2231 | stop_networkd(show_logs=True) |
1f0e3109 SS |
2232 | |
2233 | def test_lldp(self): | |
ec38833c | 2234 | copy_unit_to_networkd_unit_path('23-emit-lldp.network', '24-lldp.network', '25-veth.netdev') |
2cf6fdff | 2235 | start_networkd() |
e2aea43f | 2236 | self.wait_online(['veth99:degraded', 'veth-peer:degraded']) |
1f0e3109 | 2237 | |
371810d1 | 2238 | output = check_output(*networkctl_cmd, 'lldp', env=env) |
1f0e3109 SS |
2239 | print(output) |
2240 | self.assertRegex(output, 'veth-peer') | |
2241 | self.assertRegex(output, 'veth99') | |
2242 | ||
be68c2c9 | 2243 | class NetworkdRATests(unittest.TestCase, Utilities): |
1f0e3109 SS |
2244 | links = ['veth99'] |
2245 | ||
09ea6724 YW |
2246 | units = [ |
2247 | '25-veth.netdev', | |
2248 | 'ipv6-prefix.network', | |
2249 | 'ipv6-prefix-veth.network'] | |
1f0e3109 SS |
2250 | |
2251 | def setUp(self): | |
ec38833c | 2252 | remove_links(self.links) |
aaae5713 | 2253 | stop_networkd(show_logs=False) |
1f0e3109 SS |
2254 | |
2255 | def tearDown(self): | |
ec38833c ZJS |
2256 | remove_links(self.links) |
2257 | remove_unit_from_networkd_path(self.units) | |
aaae5713 | 2258 | stop_networkd(show_logs=True) |
1f0e3109 SS |
2259 | |
2260 | def test_ipv6_prefix_delegation(self): | |
ec38833c ZJS |
2261 | warn_about_firewalld() |
2262 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'ipv6-prefix.network', 'ipv6-prefix-veth.network') | |
2cf6fdff | 2263 | start_networkd() |
e2aea43f | 2264 | self.wait_online(['veth99:routable', 'veth-peer:degraded']) |
1f0e3109 | 2265 | |
371810d1 | 2266 | output = check_output(*networkctl_cmd, 'status', 'veth99', env=env) |
1f0e3109 SS |
2267 | print(output) |
2268 | self.assertRegex(output, '2002:da8:1:0') | |
2269 | ||
be68c2c9 | 2270 | class NetworkdDHCPServerTests(unittest.TestCase, Utilities): |
fdcd1ec5 | 2271 | links = ['veth99'] |
09ea6724 YW |
2272 | |
2273 | units = [ | |
09ea6724 YW |
2274 | '25-veth.netdev', |
2275 | 'dhcp-client.network', | |
2276 | 'dhcp-client-timezone-router.network', | |
2277 | 'dhcp-server.network', | |
2278 | 'dhcp-server-timezone-router.network'] | |
1f0e3109 SS |
2279 | |
2280 | def setUp(self): | |
ec38833c | 2281 | remove_links(self.links) |
aaae5713 | 2282 | stop_networkd(show_logs=False) |
1f0e3109 SS |
2283 | |
2284 | def tearDown(self): | |
ec38833c ZJS |
2285 | remove_links(self.links) |
2286 | remove_unit_from_networkd_path(self.units) | |
aaae5713 | 2287 | stop_networkd(show_logs=True) |
1f0e3109 SS |
2288 | |
2289 | def test_dhcp_server(self): | |
ec38833c ZJS |
2290 | warn_about_firewalld() |
2291 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-client.network', 'dhcp-server.network') | |
2cf6fdff | 2292 | start_networkd() |
e2aea43f | 2293 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
1f0e3109 | 2294 | |
371810d1 | 2295 | output = check_output(*networkctl_cmd, 'status', 'veth99', env=env) |
1f0e3109 SS |
2296 | print(output) |
2297 | self.assertRegex(output, '192.168.5.*') | |
2298 | self.assertRegex(output, 'Gateway: 192.168.5.1') | |
2299 | self.assertRegex(output, 'DNS: 192.168.5.1') | |
2300 | self.assertRegex(output, 'NTP: 192.168.5.1') | |
2301 | ||
1f0e3109 | 2302 | def test_emit_router_timezone(self): |
ec38833c ZJS |
2303 | warn_about_firewalld() |
2304 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-client-timezone-router.network', 'dhcp-server-timezone-router.network') | |
2cf6fdff | 2305 | start_networkd() |
e2aea43f | 2306 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
1f0e3109 | 2307 | |
371810d1 | 2308 | output = check_output(*networkctl_cmd, 'status', 'veth99', env=env) |
1f0e3109 SS |
2309 | print(output) |
2310 | self.assertRegex(output, 'Gateway: 192.168.5.*') | |
2311 | self.assertRegex(output, '192.168.5.*') | |
2312 | self.assertRegex(output, 'Europe/Berlin') | |
2313 | ||
be68c2c9 | 2314 | class NetworkdDHCPClientTests(unittest.TestCase, Utilities): |
09ea6724 | 2315 | links = [ |
18c613dc YW |
2316 | 'veth99', |
2317 | 'vrf99'] | |
09ea6724 YW |
2318 | |
2319 | units = [ | |
2320 | '25-veth.netdev', | |
18c613dc YW |
2321 | '25-vrf.netdev', |
2322 | '25-vrf.network', | |
09ea6724 | 2323 | 'dhcp-client-anonymize.network', |
af3b1498 | 2324 | 'dhcp-client-gateway-onlink-implicit.network', |
09ea6724 YW |
2325 | 'dhcp-client-ipv4-dhcp-settings.network', |
2326 | 'dhcp-client-ipv4-only-ipv6-disabled.network', | |
2327 | 'dhcp-client-ipv4-only.network', | |
2328 | 'dhcp-client-ipv6-only.network', | |
2329 | 'dhcp-client-ipv6-rapid-commit.network', | |
1e498853 YW |
2330 | 'dhcp-client-keep-configuration-dhcp-on-stop.network', |
2331 | 'dhcp-client-keep-configuration-dhcp.network', | |
09ea6724 | 2332 | 'dhcp-client-listen-port.network', |
c1b01a62 YW |
2333 | 'dhcp-client-reassign-static-routes-ipv4.network', |
2334 | 'dhcp-client-reassign-static-routes-ipv6.network', | |
09ea6724 YW |
2335 | 'dhcp-client-route-metric.network', |
2336 | 'dhcp-client-route-table.network', | |
e2d5aab3 YW |
2337 | 'dhcp-client-use-dns-ipv4-and-ra.network', |
2338 | 'dhcp-client-use-dns-ipv4.network', | |
2339 | 'dhcp-client-use-dns-no.network', | |
2340 | 'dhcp-client-use-dns-yes.network', | |
e0c1341d | 2341 | 'dhcp-client-use-domains.network', |
c38d2d4d | 2342 | 'dhcp-client-use-routes-no.network', |
18c613dc | 2343 | 'dhcp-client-vrf.network', |
117a55c7 YW |
2344 | 'dhcp-client-with-ipv4ll-fallback-with-dhcp-server.network', |
2345 | 'dhcp-client-with-ipv4ll-fallback-without-dhcp-server.network', | |
4c882c16 | 2346 | 'dhcp-client-with-static-address.network', |
3e9d5552 | 2347 | 'dhcp-client.network', |
09ea6724 | 2348 | 'dhcp-server-veth-peer.network', |
30d3b54e | 2349 | 'dhcp-v4-server-veth-peer.network', |
e0c1341d | 2350 | 'dhcp-client-use-domains.network', |
30d3b54e | 2351 | 'static.network'] |
1f0e3109 SS |
2352 | |
2353 | def setUp(self): | |
ec38833c ZJS |
2354 | stop_dnsmasq(dnsmasq_pid_file) |
2355 | remove_links(self.links) | |
aaae5713 | 2356 | stop_networkd(show_logs=False) |
1f0e3109 SS |
2357 | |
2358 | def tearDown(self): | |
ec38833c ZJS |
2359 | stop_dnsmasq(dnsmasq_pid_file) |
2360 | remove_lease_file() | |
2361 | remove_log_file() | |
2362 | remove_links(self.links) | |
2363 | remove_unit_from_networkd_path(self.units) | |
aaae5713 | 2364 | stop_networkd(show_logs=True) |
1f0e3109 SS |
2365 | |
2366 | def test_dhcp_client_ipv6_only(self): | |
ec38833c | 2367 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network') |
1f0e3109 | 2368 | |
2cf6fdff | 2369 | start_networkd() |
e2aea43f | 2370 | self.wait_online(['veth-peer:carrier']) |
ec38833c | 2371 | start_dnsmasq() |
e2aea43f | 2372 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
1f0e3109 | 2373 | |
371810d1 | 2374 | output = check_output(*networkctl_cmd, 'status', 'veth99', env=env) |
1f0e3109 SS |
2375 | print(output) |
2376 | self.assertRegex(output, '2600::') | |
2377 | self.assertNotRegex(output, '192.168.5') | |
2378 | ||
3a956d38 | 2379 | # Confirm that ipv6 token is not set in the kernel |
371810d1 | 2380 | output = check_output('ip token show dev veth99') |
3a956d38 YW |
2381 | print(output) |
2382 | self.assertRegex(output, 'token :: dev veth99') | |
2383 | ||
1f0e3109 | 2384 | def test_dhcp_client_ipv4_only(self): |
ec38833c | 2385 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv4-only-ipv6-disabled.network') |
1f0e3109 | 2386 | |
2cf6fdff | 2387 | start_networkd() |
e2aea43f | 2388 | self.wait_online(['veth-peer:carrier']) |
ec38833c | 2389 | start_dnsmasq() |
e2aea43f | 2390 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
1f0e3109 | 2391 | |
371810d1 | 2392 | output = check_output(*networkctl_cmd, 'status', 'veth99', env=env) |
1f0e3109 SS |
2393 | print(output) |
2394 | self.assertNotRegex(output, '2600::') | |
2395 | self.assertRegex(output, '192.168.5') | |
2396 | ||
2397 | def test_dhcp_client_ipv4_ipv6(self): | |
ec38833c ZJS |
2398 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network', |
2399 | 'dhcp-client-ipv4-only.network') | |
2cf6fdff | 2400 | start_networkd() |
e2aea43f | 2401 | self.wait_online(['veth-peer:carrier']) |
ec38833c | 2402 | start_dnsmasq() |
e2aea43f | 2403 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
2629df47 YW |
2404 | |
2405 | # link become 'routable' when at least one protocol provide an valid address. | |
e16ffe79 YW |
2406 | self.wait_address('veth99', r'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic', ipv='-4') |
2407 | self.wait_address('veth99', r'inet6 2600::[0-9a-f]*/128 scope global (?:dynamic noprefixroute|noprefixroute dynamic)', ipv='-6') | |
1f0e3109 | 2408 | |
371810d1 | 2409 | output = check_output(*networkctl_cmd, 'status', 'veth99', env=env) |
1f0e3109 SS |
2410 | print(output) |
2411 | self.assertRegex(output, '2600::') | |
2412 | self.assertRegex(output, '192.168.5') | |
2413 | ||
2414 | def test_dhcp_client_settings(self): | |
ec38833c | 2415 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv4-dhcp-settings.network') |
1f0e3109 | 2416 | |
2cf6fdff | 2417 | start_networkd() |
e2aea43f | 2418 | self.wait_online(['veth-peer:carrier']) |
ec38833c | 2419 | start_dnsmasq() |
e2aea43f | 2420 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
1f0e3109 | 2421 | |
0ae7a66d | 2422 | print('## ip address show dev veth99') |
371810d1 | 2423 | output = check_output('ip address show dev veth99') |
1f0e3109 SS |
2424 | print(output) |
2425 | self.assertRegex(output, '12:34:56:78:9a:bc') | |
2426 | self.assertRegex(output, '192.168.5') | |
2427 | self.assertRegex(output, '1492') | |
2428 | ||
0ae7a66d YW |
2429 | # issue #8726 |
2430 | print('## ip route show table main dev veth99') | |
371810d1 | 2431 | output = check_output('ip route show table main dev veth99') |
1f0e3109 | 2432 | print(output) |
0ae7a66d | 2433 | self.assertNotRegex(output, 'proto dhcp') |
1f0e3109 | 2434 | |
0ae7a66d | 2435 | print('## ip route show table 211 dev veth99') |
371810d1 | 2436 | output = check_output('ip route show table 211 dev veth99') |
0ae7a66d YW |
2437 | print(output) |
2438 | self.assertRegex(output, 'default via 192.168.5.1 proto dhcp') | |
2439 | self.assertRegex(output, '192.168.5.0/24 via 192.168.5.5 proto dhcp') | |
2440 | self.assertRegex(output, '192.168.5.1 proto dhcp scope link') | |
2441 | ||
2442 | print('## dnsmasq log') | |
ec38833c ZJS |
2443 | self.assertTrue(search_words_in_dnsmasq_log('vendor class: SusantVendorTest', True)) |
2444 | self.assertTrue(search_words_in_dnsmasq_log('DHCPDISCOVER(veth-peer) 12:34:56:78:9a:bc')) | |
2445 | self.assertTrue(search_words_in_dnsmasq_log('client provides name: test-hostname')) | |
2446 | self.assertTrue(search_words_in_dnsmasq_log('26:mtu')) | |
1f0e3109 SS |
2447 | |
2448 | def test_dhcp6_client_settings_rapidcommit_true(self): | |
ec38833c | 2449 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network') |
2cf6fdff | 2450 | start_networkd() |
e2aea43f | 2451 | self.wait_online(['veth-peer:carrier']) |
ec38833c | 2452 | start_dnsmasq() |
e2aea43f | 2453 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
1f0e3109 | 2454 | |
371810d1 | 2455 | output = check_output('ip address show dev veth99') |
1f0e3109 SS |
2456 | print(output) |
2457 | self.assertRegex(output, '12:34:56:78:9a:bc') | |
ec38833c | 2458 | self.assertTrue(search_words_in_dnsmasq_log('14:rapid-commit', True)) |
1f0e3109 SS |
2459 | |
2460 | def test_dhcp6_client_settings_rapidcommit_false(self): | |
ec38833c | 2461 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-rapid-commit.network') |
2cf6fdff | 2462 | start_networkd() |
e2aea43f | 2463 | self.wait_online(['veth-peer:carrier']) |
ec38833c | 2464 | start_dnsmasq() |
e2aea43f | 2465 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
1f0e3109 | 2466 | |
371810d1 | 2467 | output = check_output('ip address show dev veth99') |
1f0e3109 SS |
2468 | print(output) |
2469 | self.assertRegex(output, '12:34:56:78:9a:bc') | |
ec38833c | 2470 | self.assertFalse(search_words_in_dnsmasq_log('14:rapid-commit', True)) |
1f0e3109 SS |
2471 | |
2472 | def test_dhcp_client_settings_anonymize(self): | |
ec38833c | 2473 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-anonymize.network') |
2cf6fdff | 2474 | start_networkd() |
e2aea43f | 2475 | self.wait_online(['veth-peer:carrier']) |
ec38833c | 2476 | start_dnsmasq() |
e2aea43f | 2477 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
e40a58b5 | 2478 | |
ec38833c ZJS |
2479 | self.assertFalse(search_words_in_dnsmasq_log('VendorClassIdentifier=SusantVendorTest', True)) |
2480 | self.assertFalse(search_words_in_dnsmasq_log('test-hostname')) | |
2481 | self.assertFalse(search_words_in_dnsmasq_log('26:mtu')) | |
1f0e3109 SS |
2482 | |
2483 | def test_dhcp_client_listen_port(self): | |
ec38833c | 2484 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-listen-port.network') |
2cf6fdff | 2485 | start_networkd() |
e2aea43f | 2486 | self.wait_online(['veth-peer:carrier']) |
ec38833c | 2487 | start_dnsmasq('--dhcp-alternate-port=67,5555') |
e2aea43f | 2488 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
2629df47 YW |
2489 | |
2490 | # link become 'routable' when at least one protocol provide an valid address. | |
e16ffe79 YW |
2491 | self.wait_address('veth99', r'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic', ipv='-4') |
2492 | self.wait_address('veth99', r'inet6 2600::[0-9a-f]*/128 scope global (?:dynamic noprefixroute|noprefixroute dynamic)', ipv='-6') | |
1f0e3109 | 2493 | |
371810d1 | 2494 | output = check_output('ip -4 address show dev veth99') |
b412fce8 YW |
2495 | print(output) |
2496 | self.assertRegex(output, '192.168.5.* dynamic') | |
1f0e3109 | 2497 | |
4c882c16 YW |
2498 | def test_dhcp_client_with_static_address(self): |
2499 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', | |
2500 | 'dhcp-client-with-static-address.network') | |
2501 | start_networkd() | |
e2aea43f | 2502 | self.wait_online(['veth-peer:carrier']) |
4c882c16 | 2503 | start_dnsmasq() |
e2aea43f | 2504 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
4c882c16 YW |
2505 | |
2506 | output = check_output('ip address show dev veth99 scope global') | |
2507 | print(output) | |
2508 | self.assertRegex(output, r'inet 192.168.5.250/24 brd 192.168.5.255 scope global veth99') | |
2509 | self.assertRegex(output, r'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global secondary dynamic veth99') | |
2510 | ||
2511 | output = check_output('ip route show dev veth99') | |
2512 | print(output) | |
2513 | self.assertRegex(output, r'default via 192.168.5.1 proto dhcp src 192.168.5.[0-9]* metric 1024') | |
2514 | self.assertRegex(output, r'192.168.5.0/24 proto kernel scope link src 192.168.5.250') | |
2515 | self.assertRegex(output, r'192.168.5.0/24 via 192.168.5.5 proto dhcp src 192.168.5.[0-9]* metric 1024') | |
2516 | self.assertRegex(output, r'192.168.5.1 proto dhcp scope link src 192.168.5.[0-9]* metric 1024') | |
2517 | ||
1f0e3109 | 2518 | def test_dhcp_route_table_id(self): |
ec38833c | 2519 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-route-table.network') |
2cf6fdff | 2520 | start_networkd() |
e2aea43f | 2521 | self.wait_online(['veth-peer:carrier']) |
ec38833c | 2522 | start_dnsmasq() |
e2aea43f | 2523 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
e40a58b5 | 2524 | |
371810d1 | 2525 | output = check_output('ip route show table 12') |
1f0e3109 | 2526 | print(output) |
1f0e3109 SS |
2527 | self.assertRegex(output, 'veth99 proto dhcp') |
2528 | self.assertRegex(output, '192.168.5.1') | |
2529 | ||
2530 | def test_dhcp_route_metric(self): | |
ec38833c | 2531 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-route-metric.network') |
2cf6fdff | 2532 | start_networkd() |
e2aea43f | 2533 | self.wait_online(['veth-peer:carrier']) |
ec38833c | 2534 | start_dnsmasq() |
e2aea43f | 2535 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
e40a58b5 | 2536 | |
371810d1 | 2537 | output = check_output('ip route show dev veth99') |
1f0e3109 | 2538 | print(output) |
1f0e3109 SS |
2539 | self.assertRegex(output, 'metric 24') |
2540 | ||
c1b01a62 | 2541 | def test_dhcp_client_reassign_static_routes_ipv4(self): |
c38d2d4d | 2542 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', |
c1b01a62 | 2543 | 'dhcp-client-reassign-static-routes-ipv4.network') |
c38d2d4d | 2544 | start_networkd() |
e2aea43f | 2545 | self.wait_online(['veth-peer:carrier']) |
c38d2d4d | 2546 | start_dnsmasq(lease_time='2m') |
e2aea43f | 2547 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
c38d2d4d YW |
2548 | |
2549 | output = check_output('ip address show dev veth99 scope global') | |
2550 | print(output) | |
2551 | self.assertRegex(output, r'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99') | |
2552 | ||
2553 | output = check_output('ip route show dev veth99') | |
2554 | print(output) | |
2555 | self.assertRegex(output, r'192.168.5.0/24 proto kernel scope link src 192.168.5.[0-9]*') | |
2556 | self.assertRegex(output, r'192.168.5.0/24 proto static') | |
2557 | self.assertRegex(output, r'192.168.6.0/24 proto static') | |
2558 | self.assertRegex(output, r'192.168.7.0/24 proto static') | |
2559 | ||
c1b01a62 YW |
2560 | stop_dnsmasq(dnsmasq_pid_file) |
2561 | start_dnsmasq(ipv4_range='192.168.5.210,192.168.5.220', lease_time='2m') | |
2562 | ||
c38d2d4d YW |
2563 | # Sleep for 120 sec as the dnsmasq minimum lease time can only be set to 120 |
2564 | print('Wait for the dynamic address to be renewed') | |
2565 | time.sleep(125) | |
2566 | ||
e2aea43f | 2567 | self.wait_online(['veth99:routable']) |
c38d2d4d YW |
2568 | |
2569 | output = check_output('ip route show dev veth99') | |
2570 | print(output) | |
2571 | self.assertRegex(output, r'192.168.5.0/24 proto kernel scope link src 192.168.5.[0-9]*') | |
2572 | self.assertRegex(output, r'192.168.5.0/24 proto static') | |
2573 | self.assertRegex(output, r'192.168.6.0/24 proto static') | |
2574 | self.assertRegex(output, r'192.168.7.0/24 proto static') | |
2575 | ||
c1b01a62 YW |
2576 | def test_dhcp_client_reassign_static_routes_ipv6(self): |
2577 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', | |
2578 | 'dhcp-client-reassign-static-routes-ipv6.network') | |
2579 | start_networkd() | |
e2aea43f | 2580 | self.wait_online(['veth-peer:carrier']) |
c1b01a62 | 2581 | start_dnsmasq(lease_time='2m') |
e2aea43f | 2582 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
c1b01a62 YW |
2583 | |
2584 | output = check_output('ip address show dev veth99 scope global') | |
2585 | print(output) | |
2586 | self.assertRegex(output, r'inet6 2600::[0-9a-f]*/128 scope global (?:noprefixroute dynamic|dynamic noprefixroute)') | |
2587 | ||
2588 | output = check_output('ip -6 route show dev veth99') | |
2589 | print(output) | |
2590 | self.assertRegex(output, r'2600::/64 proto ra metric 1024') | |
2591 | self.assertRegex(output, r'2600:0:0:1::/64 proto static metric 1024 pref medium') | |
2592 | ||
2593 | stop_dnsmasq(dnsmasq_pid_file) | |
2594 | start_dnsmasq(ipv6_range='2600::30,2600::40', lease_time='2m') | |
2595 | ||
2596 | # Sleep for 120 sec as the dnsmasq minimum lease time can only be set to 120 | |
2597 | print('Wait for the dynamic address to be renewed') | |
2598 | time.sleep(125) | |
2599 | ||
e2aea43f | 2600 | self.wait_online(['veth99:routable']) |
c1b01a62 YW |
2601 | |
2602 | output = check_output('ip -6 route show dev veth99') | |
2603 | print(output) | |
2604 | self.assertRegex(output, r'2600::/64 proto ra metric 1024') | |
2605 | self.assertRegex(output, r'2600:0:0:1::/64 proto static metric 1024 pref medium') | |
2606 | ||
1e498853 YW |
2607 | def test_dhcp_keep_configuration_dhcp(self): |
2608 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-keep-configuration-dhcp.network') | |
2cf6fdff | 2609 | start_networkd() |
e2aea43f | 2610 | self.wait_online(['veth-peer:carrier']) |
1e498853 | 2611 | start_dnsmasq(lease_time='2m') |
e2aea43f | 2612 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
e40a58b5 | 2613 | |
1e498853 YW |
2614 | output = check_output('ip address show dev veth99 scope global') |
2615 | print(output) | |
2616 | self.assertRegex(output, r'192.168.5.*') | |
2617 | ||
371810d1 | 2618 | output = check_output(*networkctl_cmd, 'status', 'veth99', env=env) |
1f0e3109 | 2619 | print(output) |
1e498853 | 2620 | self.assertRegex(output, r'192.168.5.*') |
e40a58b5 | 2621 | |
5238e957 | 2622 | # Stopping dnsmasq as networkd won't be allowed to renew the DHCP lease. |
ec38833c | 2623 | stop_dnsmasq(dnsmasq_pid_file) |
1f0e3109 SS |
2624 | |
2625 | # Sleep for 120 sec as the dnsmasq minimum lease time can only be set to 120 | |
1e498853 | 2626 | print('Wait for the dynamic address to be expired') |
1f0e3109 SS |
2627 | time.sleep(125) |
2628 | ||
1e498853 YW |
2629 | print('The lease address should be kept after lease expired') |
2630 | output = check_output('ip address show dev veth99 scope global') | |
2631 | print(output) | |
2632 | self.assertRegex(output, r'192.168.5.*') | |
2633 | ||
371810d1 | 2634 | output = check_output(*networkctl_cmd, 'status', 'veth99', env=env) |
1f0e3109 | 2635 | print(output) |
1e498853 YW |
2636 | self.assertRegex(output, r'192.168.5.*') |
2637 | ||
2638 | check_output('systemctl stop systemd-networkd') | |
2639 | ||
2640 | print('The lease address should be kept after networkd stopped') | |
2641 | output = check_output('ip address show dev veth99 scope global') | |
2642 | print(output) | |
2643 | self.assertRegex(output, r'192.168.5.*') | |
2644 | ||
2645 | output = check_output(*networkctl_cmd, 'status', 'veth99', env=env) | |
2646 | print(output) | |
2647 | self.assertRegex(output, r'192.168.5.*') | |
2648 | ||
e2aea43f YW |
2649 | start_networkd(3) |
2650 | self.wait_online(['veth-peer:routable']) | |
1e498853 YW |
2651 | |
2652 | print('Still the lease address should be kept after networkd restarted') | |
2653 | output = check_output('ip address show dev veth99 scope global') | |
2654 | print(output) | |
2655 | self.assertRegex(output, r'192.168.5.*') | |
2656 | ||
2657 | output = check_output(*networkctl_cmd, 'status', 'veth99', env=env) | |
2658 | print(output) | |
2659 | self.assertRegex(output, r'192.168.5.*') | |
2660 | ||
2661 | def test_dhcp_keep_configuration_dhcp_on_stop(self): | |
2662 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-keep-configuration-dhcp-on-stop.network') | |
2cf6fdff | 2663 | start_networkd() |
e2aea43f | 2664 | self.wait_online(['veth-peer:carrier']) |
1e498853 | 2665 | start_dnsmasq(lease_time='2m') |
e2aea43f | 2666 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
1e498853 YW |
2667 | |
2668 | output = check_output('ip address show dev veth99 scope global') | |
2669 | print(output) | |
2670 | self.assertRegex(output, r'192.168.5.*') | |
2671 | ||
2672 | stop_dnsmasq(dnsmasq_pid_file) | |
2673 | check_output('systemctl stop systemd-networkd') | |
2674 | ||
2675 | output = check_output('ip address show dev veth99 scope global') | |
2676 | print(output) | |
2677 | self.assertRegex(output, r'192.168.5.*') | |
2678 | ||
e2aea43f YW |
2679 | restart_networkd(3) |
2680 | self.wait_online(['veth-peer:routable']) | |
1e498853 YW |
2681 | |
2682 | output = check_output('ip address show dev veth99 scope global') | |
2683 | print(output) | |
2684 | self.assertNotRegex(output, r'192.168.5.*') | |
1f0e3109 | 2685 | |
30d3b54e | 2686 | def test_dhcp_client_reuse_address_as_static(self): |
ec38833c | 2687 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client.network') |
2cf6fdff | 2688 | start_networkd() |
e2aea43f | 2689 | self.wait_online(['veth-peer:carrier']) |
ec38833c | 2690 | start_dnsmasq() |
e2aea43f | 2691 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
2629df47 YW |
2692 | |
2693 | # link become 'routable' when at least one protocol provide an valid address. | |
e16ffe79 YW |
2694 | self.wait_address('veth99', r'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic', ipv='-4') |
2695 | self.wait_address('veth99', r'inet6 2600::[0-9a-f]*/128 scope global (?:dynamic noprefixroute|noprefixroute dynamic)', ipv='-6') | |
30d3b54e | 2696 | |
371810d1 | 2697 | output = check_output('ip address show dev veth99 scope global') |
30d3b54e YW |
2698 | print(output) |
2699 | self.assertRegex(output, '192.168.5') | |
2700 | self.assertRegex(output, '2600::') | |
2701 | ||
2629df47 YW |
2702 | ipv4_address = re.search(r'192.168.5.[0-9]*/24', output) |
2703 | ipv6_address = re.search(r'2600::[0-9a-f:]*/128', output) | |
30d3b54e YW |
2704 | static_network = '\n'.join(['[Match]', 'Name=veth99', '[Network]', 'IPv6AcceptRA=no', 'Address=' + ipv4_address.group(), 'Address=' + ipv6_address.group()]) |
2705 | print(static_network) | |
2706 | ||
ec38833c | 2707 | remove_unit_from_networkd_path(['dhcp-client.network']) |
30d3b54e YW |
2708 | |
2709 | with open(os.path.join(network_unit_file_path, 'static.network'), mode='w') as f: | |
2710 | f.write(static_network) | |
2711 | ||
2629df47 YW |
2712 | # When networkd started, the links are already configured, so let's wait for 5 seconds |
2713 | # the links to be re-configured. | |
aaae5713 | 2714 | restart_networkd(5) |
e2aea43f | 2715 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
30d3b54e | 2716 | |
371810d1 | 2717 | output = check_output('ip -4 address show dev veth99 scope global') |
30d3b54e YW |
2718 | print(output) |
2719 | self.assertRegex(output, '192.168.5') | |
2720 | self.assertRegex(output, 'valid_lft forever preferred_lft forever') | |
2721 | ||
371810d1 | 2722 | output = check_output('ip -6 address show dev veth99 scope global') |
30d3b54e YW |
2723 | print(output) |
2724 | self.assertRegex(output, '2600::') | |
2725 | self.assertRegex(output, 'valid_lft forever preferred_lft forever') | |
2726 | ||
18c613dc YW |
2727 | @expectedFailureIfModuleIsNotAvailable('vrf') |
2728 | def test_dhcp_client_vrf(self): | |
ec38833c ZJS |
2729 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-vrf.network', |
2730 | '25-vrf.netdev', '25-vrf.network') | |
2cf6fdff | 2731 | start_networkd() |
e2aea43f | 2732 | self.wait_online(['veth-peer:carrier']) |
ec38833c | 2733 | start_dnsmasq() |
e2aea43f | 2734 | self.wait_online(['veth99:routable', 'veth-peer:routable', 'vrf99:carrier']) |
2629df47 YW |
2735 | |
2736 | # link become 'routable' when at least one protocol provide an valid address. | |
e16ffe79 YW |
2737 | self.wait_address('veth99', r'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic', ipv='-4') |
2738 | self.wait_address('veth99', r'inet6 2600::[0-9a-f]*/128 scope global (?:dynamic noprefixroute|noprefixroute dynamic)', ipv='-6') | |
18c613dc YW |
2739 | |
2740 | print('## ip -d link show dev vrf99') | |
371810d1 | 2741 | output = check_output('ip -d link show dev vrf99') |
18c613dc YW |
2742 | print(output) |
2743 | self.assertRegex(output, 'vrf table 42') | |
2744 | ||
2745 | print('## ip address show vrf vrf99') | |
371810d1 | 2746 | output = check_output('ip address show vrf vrf99') |
d90f4f7d YW |
2747 | print(output) |
2748 | self.assertRegex(output, 'inet 169.254.[0-9]*.[0-9]*/16 brd 169.254.255.255 scope link veth99') | |
2749 | self.assertRegex(output, 'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99') | |
2750 | self.assertRegex(output, 'inet6 2600::[0-9a-f]*/128 scope global (?:dynamic noprefixroute|noprefixroute dynamic)') | |
2751 | self.assertRegex(output, 'inet6 .* scope link') | |
18c613dc YW |
2752 | |
2753 | print('## ip address show dev veth99') | |
371810d1 | 2754 | output = check_output('ip address show dev veth99') |
18c613dc | 2755 | print(output) |
18c613dc YW |
2756 | self.assertRegex(output, 'inet 169.254.[0-9]*.[0-9]*/16 brd 169.254.255.255 scope link veth99') |
2757 | self.assertRegex(output, 'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99') | |
d90f4f7d | 2758 | self.assertRegex(output, 'inet6 2600::[0-9a-f]*/128 scope global (?:dynamic noprefixroute|noprefixroute dynamic)') |
18c613dc YW |
2759 | self.assertRegex(output, 'inet6 .* scope link') |
2760 | ||
2761 | print('## ip route show vrf vrf99') | |
371810d1 | 2762 | output = check_output('ip route show vrf vrf99') |
18c613dc YW |
2763 | print(output) |
2764 | self.assertRegex(output, 'default via 192.168.5.1 dev veth99 proto dhcp src 192.168.5.') | |
2765 | self.assertRegex(output, 'default dev veth99 proto static scope link') | |
2766 | self.assertRegex(output, '169.254.0.0/16 dev veth99 proto kernel scope link src 169.254') | |
2767 | self.assertRegex(output, '192.168.5.0/24 dev veth99 proto kernel scope link src 192.168.5') | |
2768 | self.assertRegex(output, '192.168.5.0/24 via 192.168.5.5 dev veth99 proto dhcp') | |
2769 | self.assertRegex(output, '192.168.5.1 dev veth99 proto dhcp scope link src 192.168.5') | |
2770 | ||
2771 | print('## ip route show table main dev veth99') | |
371810d1 | 2772 | output = check_output('ip route show table main dev veth99') |
18c613dc YW |
2773 | print(output) |
2774 | self.assertEqual(output, '') | |
2775 | ||
af3b1498 | 2776 | def test_dhcp_client_gateway_onlink_implicit(self): |
ec38833c ZJS |
2777 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', |
2778 | 'dhcp-client-gateway-onlink-implicit.network') | |
2cf6fdff | 2779 | start_networkd() |
e2aea43f | 2780 | self.wait_online(['veth-peer:carrier']) |
ec38833c | 2781 | start_dnsmasq() |
e2aea43f | 2782 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
af3b1498 | 2783 | |
371810d1 | 2784 | output = check_output(*networkctl_cmd, 'status', 'veth99', env=env) |
af3b1498 YW |
2785 | print(output) |
2786 | self.assertRegex(output, '192.168.5') | |
2787 | ||
371810d1 | 2788 | output = check_output('ip route list dev veth99 10.0.0.0/8') |
af3b1498 YW |
2789 | print(output) |
2790 | self.assertRegex(output, 'onlink') | |
371810d1 | 2791 | output = check_output('ip route list dev veth99 192.168.100.0/24') |
af3b1498 YW |
2792 | print(output) |
2793 | self.assertRegex(output, 'onlink') | |
2794 | ||
117a55c7 | 2795 | def test_dhcp_client_with_ipv4ll_fallback_with_dhcp_server(self): |
ec38833c ZJS |
2796 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', |
2797 | 'dhcp-client-with-ipv4ll-fallback-with-dhcp-server.network') | |
2cf6fdff | 2798 | start_networkd() |
e2aea43f | 2799 | self.wait_online(['veth-peer:carrier']) |
ec38833c | 2800 | start_dnsmasq(lease_time='2m') |
e2aea43f | 2801 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
63c598ed | 2802 | |
371810d1 | 2803 | output = check_output('ip address show dev veth99') |
63c598ed YW |
2804 | print(output) |
2805 | ||
371810d1 | 2806 | output = check_output('ip -6 address show dev veth99 scope global dynamic') |
63c598ed | 2807 | self.assertNotRegex(output, 'inet6 2600::[0-9a-f]*/128 scope global dynamic') |
371810d1 | 2808 | output = check_output('ip -6 address show dev veth99 scope link') |
63c598ed | 2809 | self.assertRegex(output, 'inet6 .* scope link') |
371810d1 | 2810 | output = check_output('ip -4 address show dev veth99 scope global dynamic') |
63c598ed | 2811 | self.assertRegex(output, 'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99') |
371810d1 | 2812 | output = check_output('ip -4 address show dev veth99 scope link') |
63c598ed YW |
2813 | self.assertNotRegex(output, 'inet .* scope link') |
2814 | ||
2815 | print('Wait for the dynamic address to be expired') | |
2816 | time.sleep(130) | |
2817 | ||
371810d1 | 2818 | output = check_output('ip address show dev veth99') |
63c598ed YW |
2819 | print(output) |
2820 | ||
371810d1 | 2821 | output = check_output('ip -6 address show dev veth99 scope global dynamic') |
63c598ed | 2822 | self.assertNotRegex(output, 'inet6 2600::[0-9a-f]*/128 scope global dynamic') |
371810d1 | 2823 | output = check_output('ip -6 address show dev veth99 scope link') |
63c598ed | 2824 | self.assertRegex(output, 'inet6 .* scope link') |
371810d1 | 2825 | output = check_output('ip -4 address show dev veth99 scope global dynamic') |
63c598ed | 2826 | self.assertRegex(output, 'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99') |
371810d1 | 2827 | output = check_output('ip -4 address show dev veth99 scope link') |
63c598ed YW |
2828 | self.assertNotRegex(output, 'inet .* scope link') |
2829 | ||
ec38833c | 2830 | search_words_in_dnsmasq_log('DHCPOFFER', show_all=True) |
63c598ed | 2831 | |
117a55c7 | 2832 | def test_dhcp_client_with_ipv4ll_fallback_without_dhcp_server(self): |
ec38833c ZJS |
2833 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', |
2834 | 'dhcp-client-with-ipv4ll-fallback-without-dhcp-server.network') | |
2cf6fdff | 2835 | start_networkd() |
e2aea43f | 2836 | self.wait_online(['veth99:degraded', 'veth-peer:routable']) |
117a55c7 | 2837 | |
371810d1 | 2838 | output = check_output('ip address show dev veth99') |
117a55c7 YW |
2839 | print(output) |
2840 | ||
371810d1 | 2841 | output = check_output('ip -6 address show dev veth99 scope global dynamic') |
117a55c7 | 2842 | self.assertNotRegex(output, 'inet6 2600::[0-9a-f]*/128 scope global dynamic') |
371810d1 | 2843 | output = check_output('ip -6 address show dev veth99 scope link') |
117a55c7 | 2844 | self.assertRegex(output, 'inet6 .* scope link') |
371810d1 | 2845 | output = check_output('ip -4 address show dev veth99 scope global dynamic') |
117a55c7 | 2846 | self.assertNotRegex(output, 'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99') |
371810d1 | 2847 | output = check_output('ip -4 address show dev veth99 scope link') |
117a55c7 YW |
2848 | self.assertRegex(output, 'inet .* scope link') |
2849 | ||
b6efd661 | 2850 | def test_dhcp_client_route_remove_on_renew(self): |
ec38833c ZJS |
2851 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', |
2852 | 'dhcp-client-ipv4-only-ipv6-disabled.network') | |
2cf6fdff | 2853 | start_networkd() |
e2aea43f | 2854 | self.wait_online(['veth-peer:carrier']) |
ec38833c | 2855 | start_dnsmasq(ipv4_range='192.168.5.100,192.168.5.199', lease_time='2m') |
e2aea43f | 2856 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
b6efd661 YW |
2857 | |
2858 | # test for issue #12490 | |
2859 | ||
371810d1 | 2860 | output = check_output('ip -4 address show dev veth99 scope global dynamic') |
b6efd661 YW |
2861 | print(output) |
2862 | self.assertRegex(output, 'inet 192.168.5.1[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99') | |
2863 | address1=None | |
2864 | for line in output.splitlines(): | |
2865 | if 'brd 192.168.5.255 scope global dynamic veth99' in line: | |
2866 | address1 = line.split()[1].split('/')[0] | |
2867 | break | |
2868 | ||
371810d1 | 2869 | output = check_output('ip -4 route show dev veth99') |
b6efd661 YW |
2870 | print(output) |
2871 | self.assertRegex(output, f'default via 192.168.5.1 proto dhcp src {address1} metric 1024') | |
2872 | self.assertRegex(output, f'192.168.5.1 proto dhcp scope link src {address1} metric 1024') | |
2873 | ||
ec38833c ZJS |
2874 | stop_dnsmasq(dnsmasq_pid_file) |
2875 | start_dnsmasq(ipv4_range='192.168.5.200,192.168.5.250', lease_time='2m') | |
b6efd661 YW |
2876 | |
2877 | print('Wait for the dynamic address to be expired') | |
2878 | time.sleep(130) | |
2879 | ||
371810d1 | 2880 | output = check_output('ip -4 address show dev veth99 scope global dynamic') |
b6efd661 YW |
2881 | print(output) |
2882 | self.assertRegex(output, 'inet 192.168.5.2[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99') | |
2883 | address2=None | |
2884 | for line in output.splitlines(): | |
2885 | if 'brd 192.168.5.255 scope global dynamic veth99' in line: | |
2886 | address2 = line.split()[1].split('/')[0] | |
2887 | break | |
2888 | ||
2889 | self.assertNotEqual(address1, address2) | |
2890 | ||
371810d1 | 2891 | output = check_output('ip -4 route show dev veth99') |
b6efd661 YW |
2892 | print(output) |
2893 | self.assertNotRegex(output, f'default via 192.168.5.1 proto dhcp src {address1} metric 1024') | |
2894 | self.assertNotRegex(output, f'192.168.5.1 proto dhcp scope link src {address1} metric 1024') | |
2895 | self.assertRegex(output, f'default via 192.168.5.1 proto dhcp src {address2} metric 1024') | |
2896 | self.assertRegex(output, f'192.168.5.1 proto dhcp scope link src {address2} metric 1024') | |
2897 | ||
e2d5aab3 YW |
2898 | def test_dhcp_client_use_dns_yes(self): |
2899 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-use-dns-yes.network') | |
2900 | ||
2901 | start_networkd() | |
e2aea43f | 2902 | self.wait_online(['veth-peer:carrier']) |
e2d5aab3 | 2903 | start_dnsmasq('--dhcp-option=option:dns-server,192.168.5.1 --dhcp-option=option6:dns-server,[2600::1]') |
e2aea43f | 2904 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
e2d5aab3 YW |
2905 | |
2906 | # link become 'routable' when at least one protocol provide an valid address. | |
2907 | self.wait_address('veth99', r'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic', ipv='-4') | |
2908 | self.wait_address('veth99', r'inet6 2600::[0-9a-f]*/128 scope global (?:dynamic noprefixroute|noprefixroute dynamic)', ipv='-6') | |
2909 | ||
7d7bb5c8 | 2910 | time.sleep(10) |
e2d5aab3 YW |
2911 | output = check_output(*resolvectl_cmd, 'dns', 'veth99', env=env) |
2912 | print(output) | |
2913 | self.assertRegex(output, '192.168.5.1') | |
2914 | self.assertRegex(output, '2600::1') | |
2915 | ||
2916 | def test_dhcp_client_use_dns_no(self): | |
2917 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-use-dns-no.network') | |
2918 | ||
2919 | start_networkd() | |
e2aea43f | 2920 | self.wait_online(['veth-peer:carrier']) |
e2d5aab3 | 2921 | start_dnsmasq('--dhcp-option=option:dns-server,192.168.5.1 --dhcp-option=option6:dns-server,[2600::1]') |
e2aea43f | 2922 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
e2d5aab3 YW |
2923 | |
2924 | # link become 'routable' when at least one protocol provide an valid address. | |
2925 | self.wait_address('veth99', r'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic', ipv='-4') | |
2926 | self.wait_address('veth99', r'inet6 2600::[0-9a-f]*/128 scope global (?:dynamic noprefixroute|noprefixroute dynamic)', ipv='-6') | |
2927 | ||
7d7bb5c8 | 2928 | time.sleep(10) |
e2d5aab3 YW |
2929 | output = check_output(*resolvectl_cmd, 'dns', 'veth99', env=env) |
2930 | print(output) | |
2931 | self.assertNotRegex(output, '192.168.5.1') | |
2932 | self.assertNotRegex(output, '2600::1') | |
2933 | ||
2934 | def test_dhcp_client_use_dns_ipv4(self): | |
2935 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-use-dns-ipv4.network') | |
2936 | ||
2937 | start_networkd() | |
e2aea43f | 2938 | self.wait_online(['veth-peer:carrier']) |
e2d5aab3 | 2939 | start_dnsmasq('--dhcp-option=option:dns-server,192.168.5.1 --dhcp-option=option6:dns-server,[2600::1]') |
e2aea43f | 2940 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
e2d5aab3 YW |
2941 | |
2942 | # link become 'routable' when at least one protocol provide an valid address. | |
2943 | self.wait_address('veth99', r'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic', ipv='-4') | |
2944 | self.wait_address('veth99', r'inet6 2600::[0-9a-f]*/128 scope global (?:dynamic noprefixroute|noprefixroute dynamic)', ipv='-6') | |
2945 | ||
7d7bb5c8 | 2946 | time.sleep(10) |
e2d5aab3 YW |
2947 | output = check_output(*resolvectl_cmd, 'dns', 'veth99', env=env) |
2948 | print(output) | |
2949 | self.assertRegex(output, '192.168.5.1') | |
2950 | self.assertNotRegex(output, '2600::1') | |
2951 | ||
2952 | def test_dhcp_client_use_dns_ipv4_and_ra(self): | |
2953 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-use-dns-ipv4-and-ra.network') | |
2954 | ||
2955 | start_networkd() | |
e2aea43f | 2956 | self.wait_online(['veth-peer:carrier']) |
e2d5aab3 | 2957 | start_dnsmasq('--dhcp-option=option:dns-server,192.168.5.1 --dhcp-option=option6:dns-server,[2600::1]') |
e2aea43f | 2958 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
e2d5aab3 YW |
2959 | |
2960 | # link become 'routable' when at least one protocol provide an valid address. | |
2961 | self.wait_address('veth99', r'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic', ipv='-4') | |
2962 | self.wait_address('veth99', r'inet6 2600::[0-9a-f]*/128 scope global (?:dynamic noprefixroute|noprefixroute dynamic)', ipv='-6') | |
2963 | ||
7d7bb5c8 | 2964 | time.sleep(10) |
e2d5aab3 YW |
2965 | output = check_output(*resolvectl_cmd, 'dns', 'veth99', env=env) |
2966 | print(output) | |
2967 | self.assertRegex(output, '192.168.5.1') | |
2968 | self.assertRegex(output, '2600::1') | |
2969 | ||
e0c1341d YW |
2970 | def test_dhcp_client_use_domains(self): |
2971 | copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-use-domains.network') | |
2972 | ||
2973 | start_networkd() | |
e2aea43f | 2974 | self.wait_online(['veth-peer:carrier']) |
e0c1341d | 2975 | start_dnsmasq('--dhcp-option=option:domain-search,example.com') |
e2aea43f | 2976 | self.wait_online(['veth99:routable', 'veth-peer:routable']) |
e0c1341d YW |
2977 | |
2978 | output = check_output(*networkctl_cmd, 'status', 'veth99', env=env) | |
2979 | print(output) | |
2980 | self.assertRegex(output, 'Search Domains: example.com') | |
2981 | ||
2982 | time.sleep(3) | |
2983 | output = check_output(*resolvectl_cmd, 'domain', 'veth99', env=env) | |
2984 | print(output) | |
2985 | self.assertRegex(output, 'example.com') | |
2986 | ||
1f0e3109 | 2987 | if __name__ == '__main__': |
9c1ae484 YW |
2988 | parser = argparse.ArgumentParser() |
2989 | parser.add_argument('--build-dir', help='Path to build dir', dest='build_dir') | |
2990 | parser.add_argument('--networkd', help='Path to systemd-networkd', dest='networkd_bin') | |
b6d587d1 | 2991 | parser.add_argument('--resolved', help='Path to systemd-resolved', dest='resolved_bin') |
9c1ae484 YW |
2992 | parser.add_argument('--wait-online', help='Path to systemd-networkd-wait-online', dest='wait_online_bin') |
2993 | parser.add_argument('--networkctl', help='Path to networkctl', dest='networkctl_bin') | |
b6d587d1 YW |
2994 | parser.add_argument('--resolvectl', help='Path to resolvectl', dest='resolvectl_bin') |
2995 | parser.add_argument('--timedatectl', help='Path to timedatectl', dest='timedatectl_bin') | |
9c1ae484 YW |
2996 | parser.add_argument('--valgrind', help='Enable valgrind', dest='use_valgrind', type=bool, nargs='?', const=True, default=use_valgrind) |
2997 | parser.add_argument('--debug', help='Generate debugging logs', dest='enable_debug', type=bool, nargs='?', const=True, default=enable_debug) | |
94c03122 | 2998 | parser.add_argument('--asan-options', help='ASAN options', dest='asan_options') |
fa4c6095 | 2999 | parser.add_argument('--lsan-options', help='LSAN options', dest='lsan_options') |
94c03122 | 3000 | parser.add_argument('--ubsan-options', help='UBSAN options', dest='ubsan_options') |
9c1ae484 YW |
3001 | ns, args = parser.parse_known_args(namespace=unittest) |
3002 | ||
3003 | if ns.build_dir: | |
b6d587d1 YW |
3004 | if ns.networkd_bin or ns.resolved_bin or ns.wait_online_bin or ns.networkctl_bin or ns.resolvectl_bin or ns.timedatectl_bin: |
3005 | print('WARNING: --networkd, --resolved, --wait-online, --networkctl, --resolvectl, or --timedatectl options are ignored when --build-dir is specified.') | |
9c1ae484 | 3006 | networkd_bin = os.path.join(ns.build_dir, 'systemd-networkd') |
b6d587d1 | 3007 | resolved_bin = os.path.join(ns.build_dir, 'systemd-resolved') |
9c1ae484 YW |
3008 | wait_online_bin = os.path.join(ns.build_dir, 'systemd-networkd-wait-online') |
3009 | networkctl_bin = os.path.join(ns.build_dir, 'networkctl') | |
b6d587d1 YW |
3010 | resolvectl_bin = os.path.join(ns.build_dir, 'resolvectl') |
3011 | timedatectl_bin = os.path.join(ns.build_dir, 'timedatectl') | |
9c1ae484 YW |
3012 | else: |
3013 | if ns.networkd_bin: | |
3014 | networkd_bin = ns.networkd_bin | |
b6d587d1 YW |
3015 | if ns.resolved_bin: |
3016 | resolved_bin = ns.resolved_bin | |
9c1ae484 YW |
3017 | if ns.wait_online_bin: |
3018 | wait_online_bin = ns.wait_online_bin | |
3019 | if ns.networkctl_bin: | |
3020 | networkctl_bin = ns.networkctl_bin | |
b6d587d1 YW |
3021 | if ns.resolvectl_bin: |
3022 | resolvectl_bin = ns.resolvectl_bin | |
3023 | if ns.timedatectl_bin: | |
3024 | timedatectl_bin = ns.timedatectl_bin | |
9c1ae484 YW |
3025 | |
3026 | use_valgrind = ns.use_valgrind | |
3027 | enable_debug = ns.enable_debug | |
94c03122 | 3028 | asan_options = ns.asan_options |
fa4c6095 | 3029 | lsan_options = ns.lsan_options |
94c03122 | 3030 | ubsan_options = ns.ubsan_options |
9c1ae484 YW |
3031 | |
3032 | if use_valgrind: | |
3033 | networkctl_cmd = ['valgrind', '--track-origins=yes', '--leak-check=full', '--show-leak-kinds=all', networkctl_bin] | |
b6d587d1 YW |
3034 | resolvectl_cmd = ['valgrind', '--track-origins=yes', '--leak-check=full', '--show-leak-kinds=all', resolvectl_bin] |
3035 | timedatectl_cmd = ['valgrind', '--track-origins=yes', '--leak-check=full', '--show-leak-kinds=all', timedatectl_bin] | |
9c1ae484 YW |
3036 | wait_online_cmd = ['valgrind', '--track-origins=yes', '--leak-check=full', '--show-leak-kinds=all', wait_online_bin] |
3037 | else: | |
3038 | networkctl_cmd = [networkctl_bin] | |
b6d587d1 YW |
3039 | resolvectl_cmd = [resolvectl_bin] |
3040 | timedatectl_cmd = [timedatectl_bin] | |
9c1ae484 YW |
3041 | wait_online_cmd = [wait_online_bin] |
3042 | ||
3043 | if enable_debug: | |
3044 | env.update({ 'SYSTEMD_LOG_LEVEL' : 'debug' }) | |
94c03122 YW |
3045 | if asan_options: |
3046 | env.update({ 'ASAN_OPTIONS' : asan_options }) | |
fa4c6095 YW |
3047 | if lsan_options: |
3048 | env.update({ 'LSAN_OPTIONS' : lsan_options }) | |
94c03122 YW |
3049 | if ubsan_options: |
3050 | env.update({ 'UBSAN_OPTIONS' : ubsan_options }) | |
9c1ae484 YW |
3051 | |
3052 | sys.argv[1:] = args | |
1f0e3109 SS |
3053 | unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, |
3054 | verbosity=3)) |