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