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