2018-09-29 15:36:25 +03:00
#!/usr/bin/env python3
# SPDX-License-Identifier: LGPL-2.1+
# systemd-networkd tests
2019-05-30 06:33:57 +03:00
import argparse
2020-04-15 23:26:20 +03:00
import itertools
2018-09-29 15:36:25 +03:00
import os
2018-11-05 06:47:38 +03:00
import re
2018-09-29 15:36:25 +03:00
import shutil
import signal
2018-12-06 16:59:49 +03:00
import subprocess
import sys
import time
import unittest
2018-09-29 15:36:25 +03:00
from shutil import copytree
2018-11-28 21:55:01 +03:00
network_unit_file_path = ' /run/systemd/network '
2018-11-28 22:03:56 +03:00
networkd_runtime_directory = ' /run/systemd/netif '
2018-11-28 21:55:01 +03:00
networkd_ci_path = ' /run/networkd-ci '
2018-09-29 15:36:25 +03:00
network_sysctl_ipv6_path = ' /proc/sys/net/ipv6/conf '
network_sysctl_ipv4_path = ' /proc/sys/net/ipv4/conf '
2018-11-28 21:55:01 +03:00
dnsmasq_pid_file = ' /run/networkd-ci/test-test-dnsmasq.pid '
dnsmasq_log_file = ' /run/networkd-ci/test-dnsmasq-log-file '
2018-09-29 15:36:25 +03:00
2019-10-31 13:44:20 +03:00
systemd_lib_paths = [ ' /usr/lib/systemd ' , ' /lib/systemd ' ]
which_paths = ' : ' . join ( systemd_lib_paths + os . getenv ( ' PATH ' , os . defpath ) . lstrip ( ' : ' ) . split ( ' : ' ) )
networkd_bin = shutil . which ( ' systemd-networkd ' , path = which_paths )
resolved_bin = shutil . which ( ' systemd-resolved ' , path = which_paths )
2020-02-04 17:51:58 +03:00
udevd_bin = shutil . which ( ' systemd-udevd ' , path = which_paths )
2019-10-31 13:44:20 +03:00
wait_online_bin = shutil . which ( ' systemd-networkd-wait-online ' , path = which_paths )
networkctl_bin = shutil . which ( ' networkctl ' , path = which_paths )
resolvectl_bin = shutil . which ( ' resolvectl ' , path = which_paths )
timedatectl_bin = shutil . which ( ' timedatectl ' , path = which_paths )
2019-05-30 06:33:57 +03:00
use_valgrind = False
2019-07-03 21:46:14 +03:00
enable_debug = True
2019-05-30 06:33:57 +03:00
env = { }
2019-05-30 09:49:11 +03:00
asan_options = None
2019-05-31 02:49:48 +03:00
lsan_options = None
2019-05-30 09:49:11 +03:00
ubsan_options = None
2019-03-21 23:06:09 +03:00
2019-07-16 04:12:05 +03:00
running_units = [ ]
2019-06-05 12:43:28 +03:00
def check_output ( * command , * * kwargs ) :
# This replaces both check_output and check_call (output can be ignored)
command = command [ 0 ] . split ( ) + list ( command [ 1 : ] )
return subprocess . check_output ( command , universal_newlines = True , * * kwargs ) . rstrip ( )
def call ( * command , * * kwargs ) :
command = command [ 0 ] . split ( ) + list ( command [ 1 : ] )
return subprocess . call ( command , universal_newlines = True , * * kwargs )
def run ( * command , * * kwargs ) :
command = command [ 0 ] . split ( ) + list ( command [ 1 : ] )
return subprocess . run ( command , universal_newlines = True , * * kwargs )
2018-11-03 00:08:30 +03:00
def is_module_available ( module_name ) :
2019-06-05 12:43:28 +03:00
lsmod_output = check_output ( ' lsmod ' )
module_re = re . compile ( rf ' ^ { re . escape ( module_name ) } \ b ' , re . MULTILINE )
2019-10-31 13:07:33 +03:00
return module_re . search ( lsmod_output ) or not call ( ' modprobe ' , module_name , stderr = subprocess . DEVNULL )
2018-11-03 00:08:30 +03:00
def expectedFailureIfModuleIsNotAvailable ( module_name ) :
def f ( func ) :
if not is_module_available ( module_name ) :
return unittest . expectedFailure ( func )
return func
return f
2019-01-30 14:52:37 +03:00
def expectedFailureIfERSPANModuleIsNotAvailable ( ) :
def f ( func ) :
2019-10-31 13:07:33 +03:00
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 )
2019-01-30 14:52:37 +03:00
if rc == 0 :
2019-06-05 12:43:28 +03:00
call ( ' ip link del erspan99 ' )
2019-01-30 14:52:37 +03:00
return func
else :
return unittest . expectedFailure ( func )
return f
2019-02-06 11:27:28 +03:00
def expectedFailureIfRoutingPolicyPortRangeIsNotAvailable ( ) :
def f ( func ) :
2019-10-31 13:07:33 +03:00
rc = call ( ' ip rule add from 192.168.100.19 sport 1123-1150 dport 3224-3290 table 7 ' , stderr = subprocess . DEVNULL )
2019-02-06 11:27:28 +03:00
if rc == 0 :
2019-06-05 12:43:28 +03:00
call ( ' ip rule del from 192.168.100.19 sport 1123-1150 dport 3224-3290 table 7 ' )
2019-02-06 11:27:28 +03:00
return func
else :
return unittest . expectedFailure ( func )
return f
def expectedFailureIfRoutingPolicyIPProtoIsNotAvailable ( ) :
def f ( func ) :
2019-10-31 13:07:33 +03:00
rc = call ( ' ip rule add not from 192.168.100.19 ipproto tcp table 7 ' , stderr = subprocess . DEVNULL )
2019-02-06 11:27:28 +03:00
if rc == 0 :
2019-06-05 12:43:28 +03:00
call ( ' ip rule del not from 192.168.100.19 ipproto tcp table 7 ' )
2019-02-06 11:27:28 +03:00
return func
else :
return unittest . expectedFailure ( func )
return f
2020-01-26 16:39:32 +03:00
def expectedFailureIfRoutingPolicyUIDRangeIsNotAvailable ( ) :
def f ( func ) :
support = False
rc = call ( ' ip rule add from 192.168.100.19 table 7 uidrange 200-300 ' , stderr = subprocess . DEVNULL )
if rc == 0 :
ret = run ( ' ip rule list from 192.168.100.19 table 7 ' , stdout = subprocess . PIPE , stderr = subprocess . STDOUT )
if ret . returncode == 0 and ' uidrange 200-300 ' in ret . stdout . rstrip ( ) :
support = True
call ( ' ip rule del from 192.168.100.19 table 7 uidrange 200-300 ' )
if support :
return func
else :
return unittest . expectedFailure ( func )
return f
2019-06-01 04:31:09 +03:00
def expectedFailureIfLinkFileFieldIsNotSet ( ) :
def f ( func ) :
support = False
2019-10-31 13:07:33 +03:00
rc = call ( ' ip link add name dummy99 type dummy ' , stderr = subprocess . DEVNULL )
2019-06-01 04:31:09 +03:00
if rc == 0 :
ret = run ( ' udevadm info -w10s /sys/class/net/dummy99 ' , stdout = subprocess . PIPE , stderr = subprocess . STDOUT )
if ret . returncode == 0 and ' E: ID_NET_LINK_FILE= ' in ret . stdout . rstrip ( ) :
support = True
call ( ' ip link del dummy99 ' )
if support :
return func
else :
return unittest . expectedFailure ( func )
return f
2019-10-14 15:18:01 +03:00
def expectedFailureIfNexthopIsNotAvailable ( ) :
def f ( func ) :
2019-10-31 13:07:33 +03:00
rc = call ( ' ip nexthop list ' , stderr = subprocess . DEVNULL )
2019-10-14 15:18:01 +03:00
if rc == 0 :
return func
else :
return unittest . expectedFailure ( func )
return f
2020-08-13 19:52:19 +03:00
def expectedFailureIfRTA_VIAIsNotSupported ( ) :
def f ( func ) :
call ( ' ip link add dummy98 type dummy ' , stderr = subprocess . DEVNULL )
call ( ' ip link set up dev dummy98 ' , stderr = subprocess . DEVNULL )
call ( ' ip route add 2001:1234:5:8fff:ff:ff:ff:fe/128 dev dummy98 ' , stderr = subprocess . DEVNULL )
rc = call ( ' ip route add 10.10.10.10 via inet6 2001:1234:5:8fff:ff:ff:ff:fe dev dummy98 ' , stderr = subprocess . DEVNULL )
call ( ' ip link del dummy98 ' , stderr = subprocess . DEVNULL )
if rc == 0 :
return func
else :
return unittest . expectedFailure ( func )
return f
2019-12-15 22:17:57 +03:00
def expectedFailureIfAlternativeNameIsNotAvailable ( ) :
def f ( func ) :
call ( ' ip link add dummy98 type dummy ' , stderr = subprocess . DEVNULL )
rc = call ( ' ip link prop add dev dummy98 altname hogehogehogehogehoge ' , stderr = subprocess . DEVNULL )
2020-02-17 18:12:22 +03:00
call ( ' ip link del dummy98 ' , stderr = subprocess . DEVNULL )
2019-12-15 22:17:57 +03:00
if rc == 0 :
return func
else :
return unittest . expectedFailure ( func )
return f
2020-06-22 13:48:34 +03:00
def expectedFailureIfNetdevsimWithSRIOVIsNotAvailable ( ) :
def f ( func ) :
call ( ' rmmod netdevsim ' , stderr = subprocess . DEVNULL )
rc = call ( ' modprobe netdevsim ' , stderr = subprocess . DEVNULL )
if rc != 0 :
return unittest . expectedFailure ( func )
try :
with open ( ' /sys/bus/netdevsim/new_device ' , mode = ' w ' ) as f :
f . write ( ' 99 1 ' )
except Exception as error :
return unittest . expectedFailure ( func )
call ( ' udevadm settle ' )
call ( ' udevadm info -w10s /sys/devices/netdevsim99/net/eni99np1 ' , stderr = subprocess . DEVNULL )
try :
with open ( ' /sys/class/net/eni99np1/device/sriov_numvfs ' , mode = ' w ' ) as f :
f . write ( ' 3 ' )
except Exception as error :
call ( ' rmmod netdevsim ' , stderr = subprocess . DEVNULL )
return unittest . expectedFailure ( func )
call ( ' rmmod netdevsim ' , stderr = subprocess . DEVNULL )
return func
return f
2020-02-17 15:03:12 +03:00
def expectedFailureIfCAKEIsNotAvailable ( ) :
def f ( func ) :
call ( ' ip link add dummy98 type dummy ' , stderr = subprocess . DEVNULL )
rc = call ( ' tc qdisc add dev dummy98 parent root cake ' , stderr = subprocess . DEVNULL )
call ( ' ip link del dummy98 ' , stderr = subprocess . DEVNULL )
if rc == 0 :
return func
else :
return unittest . expectedFailure ( func )
return f
2020-03-11 16:48:10 +03:00
def expectedFailureIfPIEIsNotAvailable ( ) :
def f ( func ) :
call ( ' ip link add dummy98 type dummy ' , stderr = subprocess . DEVNULL )
rc = call ( ' tc qdisc add dev dummy98 parent root pie ' , stderr = subprocess . DEVNULL )
call ( ' ip link del dummy98 ' , stderr = subprocess . DEVNULL )
if rc == 0 :
return func
else :
return unittest . expectedFailure ( func )
return f
2020-03-11 20:40:29 +03:00
def expectedFailureIfHHFIsNotAvailable ( ) :
def f ( func ) :
call ( ' ip link add dummy98 type dummy ' , stderr = subprocess . DEVNULL )
rc = call ( ' tc qdisc add dev dummy98 parent root hhf ' , stderr = subprocess . DEVNULL )
call ( ' ip link del dummy98 ' , stderr = subprocess . DEVNULL )
if rc == 0 :
return func
else :
return unittest . expectedFailure ( func )
return f
2020-06-09 11:24:04 +03:00
def expectedFailureIfETSIsNotAvailable ( ) :
def f ( func ) :
call ( ' ip link add dummy98 type dummy ' , stderr = subprocess . DEVNULL )
rc = call ( ' tc qdisc add dev dummy98 parent root ets bands 10 ' , stderr = subprocess . DEVNULL )
call ( ' ip link del dummy98 ' , stderr = subprocess . DEVNULL )
if rc == 0 :
return func
else :
return unittest . expectedFailure ( func )
return f
2020-09-17 11:18:48 +03:00
def expectedFailureIfFQPIEIsNotAvailable ( ) :
def f ( func ) :
call ( ' ip link add dummy98 type dummy ' , stderr = subprocess . DEVNULL )
rc = call ( ' tc qdisc add dev dummy98 parent root fq_pie ' , stderr = subprocess . DEVNULL )
call ( ' ip link del dummy98 ' , stderr = subprocess . DEVNULL )
if rc == 0 :
return func
else :
return unittest . expectedFailure ( func )
return f
2018-09-29 15:36:25 +03:00
def setUpModule ( ) :
2019-07-16 04:12:05 +03:00
global running_units
2018-09-29 15:36:25 +03:00
os . makedirs ( network_unit_file_path , exist_ok = True )
os . makedirs ( networkd_ci_path , exist_ok = True )
shutil . rmtree ( networkd_ci_path )
2018-10-03 08:38:30 +03:00
copytree ( os . path . join ( os . path . dirname ( os . path . abspath ( __file__ ) ) , ' conf ' ) , networkd_ci_path )
2018-09-29 15:36:25 +03:00
2020-02-09 18:43:58 +03:00
for u in [ ' systemd-networkd.socket ' , ' systemd-networkd.service ' , ' systemd-resolved.service ' ,
' systemd-udevd-kernel.socket ' , ' systemd-udevd-control.socket ' , ' systemd-udevd.service ' ,
' firewalld.service ' ] :
2019-07-16 04:12:05 +03:00
if call ( f ' systemctl is-active --quiet { u } ' ) == 0 :
check_output ( f ' systemctl stop { u } ' )
running_units . append ( u )
2018-11-29 00:00:19 +03:00
2019-05-30 06:33:57 +03:00
drop_in = [
2019-11-26 23:36:53 +03:00
' [Unit] ' ,
' StartLimitIntervalSec=0 ' ,
2019-05-30 06:33:57 +03:00
' [Service] ' ,
' Restart=no ' ,
' ExecStart= ' ,
]
if use_valgrind :
drop_in + = [
' ExecStart=!!valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all ' + networkd_bin ,
2019-05-30 09:49:11 +03:00
' PrivateTmp=yes '
2019-05-30 06:33:57 +03:00
]
else :
drop_in + = [ ' ExecStart=!! ' + networkd_bin ]
if enable_debug :
drop_in + = [ ' Environment=SYSTEMD_LOG_LEVEL=debug ' ]
2019-05-30 09:49:11 +03:00
if asan_options :
drop_in + = [ ' Environment=ASAN_OPTIONS= " ' + asan_options + ' " ' ]
2019-05-31 02:49:48 +03:00
if lsan_options :
drop_in + = [ ' Environment=LSAN_OPTIONS= " ' + lsan_options + ' " ' ]
2019-05-30 09:49:11 +03:00
if ubsan_options :
drop_in + = [ ' Environment=UBSAN_OPTIONS= " ' + ubsan_options + ' " ' ]
2019-06-01 09:55:16 +03:00
if asan_options or lsan_options or ubsan_options :
drop_in + = [ ' SystemCallFilter= ' ]
2019-05-31 02:49:48 +03:00
if use_valgrind or asan_options or lsan_options or ubsan_options :
2019-05-30 09:49:11 +03:00
drop_in + = [ ' MemoryDenyWriteExecute=no ' ]
2019-05-30 06:33:57 +03:00
os . makedirs ( ' /run/systemd/system/systemd-networkd.service.d ' , exist_ok = True )
with open ( ' /run/systemd/system/systemd-networkd.service.d/00-override.conf ' , mode = ' w ' ) as f :
2019-05-31 07:54:08 +03:00
f . write ( ' \n ' . join ( drop_in ) )
2019-05-30 06:33:57 +03:00
2019-06-04 01:05:07 +03:00
drop_in = [
' [Service] ' ,
' Restart=no ' ,
' ExecStart= ' ,
]
if use_valgrind :
drop_in + = [ ' ExecStart=!!valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all ' + resolved_bin ]
else :
drop_in + = [ ' ExecStart=!! ' + resolved_bin ]
if enable_debug :
drop_in + = [ ' Environment=SYSTEMD_LOG_LEVEL=debug ' ]
if asan_options :
drop_in + = [ ' Environment=ASAN_OPTIONS= " ' + asan_options + ' " ' ]
if lsan_options :
drop_in + = [ ' Environment=LSAN_OPTIONS= " ' + lsan_options + ' " ' ]
if ubsan_options :
drop_in + = [ ' Environment=UBSAN_OPTIONS= " ' + ubsan_options + ' " ' ]
if asan_options or lsan_options or ubsan_options :
drop_in + = [ ' SystemCallFilter= ' ]
if use_valgrind or asan_options or lsan_options or ubsan_options :
drop_in + = [ ' MemoryDenyWriteExecute=no ' ]
os . makedirs ( ' /run/systemd/system/systemd-resolved.service.d ' , exist_ok = True )
with open ( ' /run/systemd/system/systemd-resolved.service.d/00-override.conf ' , mode = ' w ' ) as f :
f . write ( ' \n ' . join ( drop_in ) )
2020-02-04 17:51:58 +03:00
drop_in = [
' [Service] ' ,
' ExecStart= ' ,
' ExecStart=!! ' + udevd_bin ,
]
os . makedirs ( ' /run/systemd/system/systemd-udevd.service.d ' , exist_ok = True )
with open ( ' /run/systemd/system/systemd-udevd.service.d/00-override.conf ' , mode = ' w ' ) as f :
f . write ( ' \n ' . join ( drop_in ) )
2019-06-05 12:43:28 +03:00
check_output ( ' systemctl daemon-reload ' )
print ( check_output ( ' systemctl cat systemd-networkd.service ' ) )
2019-06-04 01:05:07 +03:00
print ( check_output ( ' systemctl cat systemd-resolved.service ' ) )
2020-02-04 17:51:58 +03:00
print ( check_output ( ' systemctl cat systemd-udevd.service ' ) )
2019-06-04 01:05:07 +03:00
check_output ( ' systemctl restart systemd-resolved ' )
2020-02-04 17:51:58 +03:00
check_output ( ' systemctl restart systemd-udevd ' )
2019-05-30 06:33:57 +03:00
2018-09-29 15:36:25 +03:00
def tearDownModule ( ) :
2019-07-16 04:12:05 +03:00
global running_units
2018-09-29 15:36:25 +03:00
shutil . rmtree ( networkd_ci_path )
2019-05-31 03:52:27 +03:00
2020-08-28 18:21:27 +03:00
for u in [ ' systemd-networkd.socket ' , ' systemd-networkd.service ' , ' systemd-resolved.service ' ] :
2019-07-16 04:12:05 +03:00
check_output ( f ' systemctl stop { u } ' )
2019-05-31 03:52:27 +03:00
2019-05-30 06:33:57 +03:00
shutil . rmtree ( ' /run/systemd/system/systemd-networkd.service.d ' )
2019-06-04 01:05:07 +03:00
shutil . rmtree ( ' /run/systemd/system/systemd-resolved.service.d ' )
2020-02-04 17:51:58 +03:00
shutil . rmtree ( ' /run/systemd/system/systemd-udevd.service.d ' )
2019-06-05 12:43:28 +03:00
check_output ( ' systemctl daemon-reload ' )
2020-02-09 18:43:58 +03:00
check_output ( ' systemctl restart systemd-udevd.service ' )
2018-09-29 15:36:25 +03:00
2019-07-16 04:12:05 +03:00
for u in running_units :
check_output ( f ' systemctl start { u } ' )
2018-11-29 00:00:19 +03:00
2019-10-31 17:15:53 +03:00
def read_link_attr ( * args ) :
with open ( os . path . join ( ' /sys/class/net/ ' , * args ) ) as f :
2019-06-05 13:08:09 +03:00
return f . readline ( ) . strip ( )
def read_bridge_port_attr ( bridge , link , attribute ) :
path_bridge = os . path . join ( ' /sys/devices/virtual/net ' , bridge )
path_port = ' lower_ ' + link + ' /brport '
path = os . path . join ( path_bridge , path_port )
with open ( os . path . join ( path , attribute ) ) as f :
return f . readline ( ) . strip ( )
def link_exists ( link ) :
return os . path . exists ( os . path . join ( ' /sys/class/net ' , link ) )
def remove_links ( links ) :
for link in links :
if link_exists ( link ) :
call ( ' ip link del dev ' , link )
time . sleep ( 1 )
def remove_fou_ports ( ports ) :
for port in ports :
2019-06-14 10:45:50 +03:00
call ( ' ip fou del port ' , port , stdout = subprocess . DEVNULL , stderr = subprocess . DEVNULL )
2019-06-05 13:08:09 +03:00
def remove_routing_policy_rule_tables ( tables ) :
for table in tables :
2019-06-17 13:57:54 +03:00
rc = 0
while rc == 0 :
rc = call ( ' ip rule del table ' , table , stdout = subprocess . DEVNULL , stderr = subprocess . DEVNULL )
2020-10-05 23:25:01 +03:00
rc = 0
while rc == 0 :
rc = call ( ' ip -6 rule del table ' , table , stdout = subprocess . DEVNULL , stderr = subprocess . DEVNULL )
2019-06-05 13:08:09 +03:00
def remove_routes ( routes ) :
for route_type , addr in routes :
2019-06-14 10:45:50 +03:00
call ( ' ip route del ' , route_type , addr , stdout = subprocess . DEVNULL , stderr = subprocess . DEVNULL )
2019-06-05 13:08:09 +03:00
2019-06-17 05:11:30 +03:00
def remove_l2tp_tunnels ( tunnel_ids ) :
2019-06-05 13:08:09 +03:00
output = check_output ( ' ip l2tp show tunnel ' )
for tid in tunnel_ids :
words = ' Tunnel ' + tid + ' , encap '
if words in output :
call ( ' ip l2tp del tunnel tid ' , tid )
time . sleep ( 1 )
def read_ipv6_sysctl_attr ( link , attribute ) :
with open ( os . path . join ( os . path . join ( network_sysctl_ipv6_path , link ) , attribute ) ) as f :
return f . readline ( ) . strip ( )
def read_ipv4_sysctl_attr ( link , attribute ) :
with open ( os . path . join ( os . path . join ( network_sysctl_ipv4_path , link ) , attribute ) ) as f :
return f . readline ( ) . strip ( )
2019-11-02 11:43:18 +03:00
def copy_unit_to_networkd_unit_path ( * units , dropins = True ) :
""" Copy networkd unit files into the testbed.
Any networkd unit file type can be specified , as well as drop - in files .
By default , all drop - ins for a specified unit file are copied in ;
to avoid that specify dropins = False .
When a drop - in file is specified , its unit file is also copied in automatically .
"""
2019-06-05 13:08:09 +03:00
print ( )
for unit in units :
2019-11-02 11:43:18 +03:00
if dropins and os . path . exists ( os . path . join ( networkd_ci_path , unit + ' .d ' ) ) :
2019-06-05 13:08:09 +03:00
copytree ( os . path . join ( networkd_ci_path , unit + ' .d ' ) , os . path . join ( network_unit_file_path , unit + ' .d ' ) )
2019-11-02 11:43:18 +03:00
if unit . endswith ( ' .conf ' ) :
dropin = unit
dropindir = os . path . join ( network_unit_file_path , os . path . dirname ( dropin ) )
os . makedirs ( dropindir , exist_ok = True )
shutil . copy ( os . path . join ( networkd_ci_path , dropin ) , dropindir )
unit = os . path . dirname ( dropin ) . rstrip ( ' .d ' )
shutil . copy ( os . path . join ( networkd_ci_path , unit ) , network_unit_file_path )
2019-06-05 13:08:09 +03:00
def remove_unit_from_networkd_path ( units ) :
2019-11-02 11:43:18 +03:00
""" Remove previously copied unit files from the testbed.
Drop - ins will be removed automatically .
"""
2019-06-05 13:08:09 +03:00
for unit in units :
if ( os . path . exists ( os . path . join ( network_unit_file_path , unit ) ) ) :
os . remove ( os . path . join ( network_unit_file_path , unit ) )
if ( os . path . exists ( os . path . join ( network_unit_file_path , unit + ' .d ' ) ) ) :
shutil . rmtree ( os . path . join ( network_unit_file_path , unit + ' .d ' ) )
def start_dnsmasq ( additional_options = ' ' , ipv4_range = ' 192.168.5.10,192.168.5.200 ' , ipv6_range = ' 2600::10,2600::20 ' , lease_time = ' 1h ' ) :
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
check_output ( dnsmasq_command )
def stop_dnsmasq ( pid_file ) :
if os . path . exists ( pid_file ) :
with open ( pid_file , ' r ' ) as f :
pid = f . read ( ) . rstrip ( ' \t \r \n \0 ' )
os . kill ( int ( pid ) , signal . SIGTERM )
os . remove ( pid_file )
def search_words_in_dnsmasq_log ( words , show_all = False ) :
if os . path . exists ( dnsmasq_log_file ) :
with open ( dnsmasq_log_file ) as in_file :
contents = in_file . read ( )
if show_all :
print ( contents )
for line in contents . splitlines ( ) :
if words in line :
in_file . close ( )
print ( " %s , %s " % ( words , line ) )
return True
return False
def remove_lease_file ( ) :
if os . path . exists ( os . path . join ( networkd_ci_path , ' lease ' ) ) :
os . remove ( os . path . join ( networkd_ci_path , ' lease ' ) )
def remove_log_file ( ) :
if os . path . exists ( dnsmasq_log_file ) :
os . remove ( dnsmasq_log_file )
2019-07-03 21:46:14 +03:00
def remove_networkd_state_files ( ) :
if os . path . exists ( os . path . join ( networkd_runtime_directory , ' state ' ) ) :
2019-06-05 13:08:09 +03:00
os . remove ( os . path . join ( networkd_runtime_directory , ' state ' ) )
2019-07-03 21:46:14 +03:00
def stop_networkd ( show_logs = True , remove_state_files = True ) :
if show_logs :
invocation_id = check_output ( ' systemctl show systemd-networkd -p InvocationID --value ' )
2020-08-28 18:21:27 +03:00
check_output ( ' systemctl stop systemd-networkd.socket ' )
check_output ( ' systemctl stop systemd-networkd.service ' )
2019-07-03 21:46:14 +03:00
if show_logs :
print ( check_output ( ' journalctl _SYSTEMD_INVOCATION_ID= ' + invocation_id ) )
if remove_state_files :
remove_networkd_state_files ( )
def start_networkd ( sleep_sec = 0 ) :
check_output ( ' systemctl start systemd-networkd ' )
2019-06-05 13:08:09 +03:00
if sleep_sec > 0 :
time . sleep ( sleep_sec )
2019-07-03 21:46:14 +03:00
def restart_networkd ( sleep_sec = 0 , show_logs = True , remove_state_files = True ) :
stop_networkd ( show_logs , remove_state_files )
start_networkd ( sleep_sec )
2018-09-29 15:36:25 +03:00
2019-06-05 13:08:09 +03:00
class Utilities ( ) :
2019-05-20 04:05:50 +03:00
def check_link_exists ( self , link ) :
2019-06-05 13:08:09 +03:00
self . assertTrue ( link_exists ( link ) )
2019-05-15 12:25:30 +03:00
2020-04-27 22:47:28 +03:00
def check_link_attr ( self , * args ) :
self . assertEqual ( read_link_attr ( * args [ : - 1 ] ) , args [ - 1 ] ) ;
2020-01-08 15:28:29 +03:00
def wait_operstate ( self , link , operstate = ' degraded ' , setup_state = ' configured ' , setup_timeout = 5 , fail_assert = True ) :
""" Wait for the link to reach the specified operstate and/or setup state.
Specify None or ' ' for either operstate or setup_state to ignore that state .
This will recheck until the state conditions are met or the timeout expires .
If the link successfully matches the requested state , this returns True .
If this times out waiting for the link to match , the behavior depends on the
' fail_assert ' parameter ; if True , this causes a test assertion failure ,
otherwise this returns False . The default is to cause assertion failure .
Note that this function matches on * exactly * the given operstate and setup_state .
To wait for a link to reach * or exceed * a given operstate , use wait_online ( ) .
"""
if not operstate :
operstate = r ' \ S+ '
if not setup_state :
setup_state = r ' \ S+ '
for secs in range ( setup_timeout + 1 ) :
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , link , env = env )
print ( output )
if re . search ( rf ' (?m)^ \ s*State: \ s+ { operstate } \ s+ \ ( { setup_state } \ ) \ s*$ ' , output ) :
return True
# don't bother sleeping if time is up
if secs < setup_timeout :
time . sleep ( 1 )
if fail_assert :
self . fail ( f ' Timed out waiting for { link } to reach state { operstate } / { setup_state } ' )
return False
2019-05-15 12:25:30 +03:00
2019-11-02 12:09:11 +03:00
def wait_online ( self , links_with_operstate , timeout = ' 20s ' , bool_any = False , setup_state = ' configured ' , setup_timeout = 5 ) :
2020-01-08 15:32:19 +03:00
""" Wait for the link(s) to reach the specified operstate and/or setup state.
This is similar to wait_operstate ( ) but can be used for multiple links ,
and it also calls systemd - networkd - wait - online to wait for the given operstate .
The operstate should be specified in the link name , like ' eth0:degraded ' .
If just a link name is provided , wait - online ' s default operstate to wait for is degraded.
The ' timeout ' parameter controls the systemd - networkd - wait - online timeout , and the
' setup_timeout ' controls the per - link timeout waiting for the setup_state .
Set ' bool_any ' to True to wait for any ( instead of all ) of the given links .
If this is set , no setup_state checks are done .
Note that this function waits for the link ( s ) to reach * or exceed * the given operstate .
However , the setup_state , if specified , must be matched * exactly * .
This returns if the link ( s ) reached the requested operstate / setup_state ; otherwise it
raises CalledProcessError or fails test assertion .
"""
2019-07-15 08:18:06 +03:00
args = wait_online_cmd + [ f ' --timeout= { timeout } ' ] + [ f ' --interface= { link } ' for link in links_with_operstate ]
if bool_any :
args + = [ ' --any ' ]
try :
check_output ( * args , env = env )
except subprocess . CalledProcessError :
for link in links_with_operstate :
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , link . split ( ' : ' ) [ 0 ] , env = env )
2019-07-15 08:18:06 +03:00
print ( output )
raise
2019-11-02 12:09:11 +03:00
if not bool_any and setup_state :
2020-01-08 15:32:19 +03:00
for link in links_with_operstate :
self . wait_operstate ( link . split ( ' : ' ) [ 0 ] , None , setup_state , setup_timeout )
2019-07-15 08:18:06 +03:00
2019-05-29 06:07:36 +03:00
def wait_address ( self , link , address_regex , scope = ' global ' , ipv = ' ' , timeout_sec = 100 ) :
2019-05-24 07:59:34 +03:00
for i in range ( timeout_sec ) :
if i > 0 :
time . sleep ( 1 )
2019-06-05 12:43:28 +03:00
output = check_output ( f ' ip { ipv } address show dev { link } scope { scope } ' )
2020-07-12 03:28:53 +03:00
if re . search ( address_regex , output ) and ' tentative ' not in output :
2019-05-24 07:59:34 +03:00
break
else :
self . assertRegex ( output , address_regex )
2019-06-01 04:29:08 +03:00
class NetworkctlTests ( unittest . TestCase , Utilities ) :
links = [
2019-09-08 14:35:05 +03:00
' dummy98 ' ,
2019-06-01 04:29:08 +03:00
' test1 ' ,
' veth99 ' ,
]
units = [
' 11-dummy.netdev ' ,
2019-06-01 09:44:04 +03:00
' 11-dummy-mtu.netdev ' ,
2019-06-01 04:29:08 +03:00
' 11-dummy.network ' ,
2019-09-08 14:35:05 +03:00
' 12-dummy.netdev ' ,
2019-12-15 22:17:57 +03:00
' 12-dummy.link ' ,
2019-09-08 14:35:05 +03:00
' 25-address-static.network ' ,
2019-06-01 04:29:08 +03:00
' 25-veth.netdev ' ,
' netdev-link-local-addressing-yes.network ' ,
]
def setUp ( self ) :
2019-06-05 13:08:09 +03:00
remove_links ( self . links )
2019-07-03 21:46:14 +03:00
stop_networkd ( show_logs = False )
2019-06-01 04:29:08 +03:00
def tearDown ( self ) :
2019-06-05 13:08:09 +03:00
remove_links ( self . links )
remove_unit_from_networkd_path ( self . units )
2019-07-03 21:46:14 +03:00
stop_networkd ( show_logs = True )
2019-06-01 04:29:08 +03:00
2019-12-15 22:17:57 +03:00
@expectedFailureIfAlternativeNameIsNotAvailable ( )
def test_altname ( self ) :
copy_unit_to_networkd_unit_path ( ' netdev-link-local-addressing-yes.network ' , ' 12-dummy.netdev ' , ' 12-dummy.link ' )
check_output ( ' udevadm control --reload ' )
start_networkd ( )
self . wait_online ( [ ' dummy98:degraded ' ] )
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' dummy98 ' , env = env )
2019-12-15 22:17:57 +03:00
self . assertRegex ( output , ' hogehogehogehogehogehoge ' )
2019-09-08 14:35:05 +03:00
def test_reconfigure ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-address-static.network ' , ' 12-dummy.netdev ' )
start_networkd ( )
self . wait_online ( [ ' dummy98:routable ' ] )
output = check_output ( ' ip -4 address show dev dummy98 ' )
print ( output )
self . assertRegex ( output , ' inet 10.1.2.3/16 brd 10.1.255.255 scope global dummy98 ' )
self . assertRegex ( output , ' inet 10.1.2.4/16 brd 10.1.255.255 scope global secondary dummy98 ' )
self . assertRegex ( output , ' inet 10.2.2.4/16 brd 10.2.255.255 scope global dummy98 ' )
check_output ( ' ip address del 10.1.2.3/16 dev dummy98 ' )
check_output ( ' ip address del 10.1.2.4/16 dev dummy98 ' )
check_output ( ' ip address del 10.2.2.4/16 dev dummy98 ' )
check_output ( * networkctl_cmd , ' reconfigure ' , ' dummy98 ' , env = env )
self . wait_online ( [ ' dummy98:routable ' ] )
output = check_output ( ' ip -4 address show dev dummy98 ' )
print ( output )
self . assertRegex ( output , ' inet 10.1.2.3/16 brd 10.1.255.255 scope global dummy98 ' )
self . assertRegex ( output , ' inet 10.1.2.4/16 brd 10.1.255.255 scope global secondary dummy98 ' )
self . assertRegex ( output , ' inet 10.2.2.4/16 brd 10.2.255.255 scope global dummy98 ' )
2019-09-02 16:40:31 +03:00
def test_reload ( self ) :
start_networkd ( 3 )
copy_unit_to_networkd_unit_path ( ' 11-dummy.netdev ' )
check_output ( * networkctl_cmd , ' reload ' , env = env )
2020-01-08 15:25:16 +03:00
self . wait_operstate ( ' test1 ' , ' off ' , setup_state = ' unmanaged ' )
2019-09-02 16:40:31 +03:00
copy_unit_to_networkd_unit_path ( ' 11-dummy.network ' )
check_output ( * networkctl_cmd , ' reload ' , env = env )
self . wait_online ( [ ' test1:degraded ' ] )
remove_unit_from_networkd_path ( [ ' 11-dummy.network ' ] )
check_output ( * networkctl_cmd , ' reload ' , env = env )
2020-01-08 15:25:16 +03:00
self . wait_operstate ( ' test1 ' , ' degraded ' , setup_state = ' unmanaged ' )
2019-09-02 16:40:31 +03:00
remove_unit_from_networkd_path ( [ ' 11-dummy.netdev ' ] )
check_output ( * networkctl_cmd , ' reload ' , env = env )
2020-01-08 15:25:16 +03:00
self . wait_operstate ( ' test1 ' , ' degraded ' , setup_state = ' unmanaged ' )
2019-09-02 16:40:31 +03:00
copy_unit_to_networkd_unit_path ( ' 11-dummy.netdev ' , ' 11-dummy.network ' )
check_output ( * networkctl_cmd , ' reload ' , env = env )
2020-01-08 15:25:16 +03:00
self . wait_operstate ( ' test1 ' , ' degraded ' )
2019-09-02 16:40:31 +03:00
2019-06-01 04:29:08 +03:00
def test_glob ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 11-dummy.netdev ' , ' 11-dummy.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-06-01 04:29:08 +03:00
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' test1:degraded ' ] )
2019-06-01 04:29:08 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( * networkctl_cmd , ' list ' , env = env )
2019-06-01 04:29:08 +03:00
self . assertRegex ( output , ' 1 lo ' )
self . assertRegex ( output , ' test1 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( * networkctl_cmd , ' list ' , ' test1 ' , env = env )
2019-06-01 04:29:08 +03:00
self . assertNotRegex ( output , ' 1 lo ' )
self . assertRegex ( output , ' test1 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( * networkctl_cmd , ' list ' , ' te* ' , env = env )
2019-06-01 04:29:08 +03:00
self . assertNotRegex ( output , ' 1 lo ' )
self . assertRegex ( output , ' test1 ' )
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' te* ' , env = env )
2019-06-01 04:29:08 +03:00
self . assertNotRegex ( output , ' 1: lo ' )
self . assertRegex ( output , ' test1 ' )
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' tes[a-z][0-9] ' , env = env )
2019-06-01 04:29:08 +03:00
self . assertNotRegex ( output , ' 1: lo ' )
self . assertRegex ( output , ' test1 ' )
2019-06-01 09:44:04 +03:00
def test_mtu ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 11-dummy-mtu.netdev ' , ' 11-dummy.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-06-01 09:44:04 +03:00
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' test1:degraded ' ] )
2019-06-01 09:44:04 +03:00
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' test1 ' , env = env )
2019-06-01 09:44:04 +03:00
self . assertRegex ( output , ' MTU: 1600 ' )
2019-06-01 04:31:09 +03:00
def test_type ( self ) :
copy_unit_to_networkd_unit_path ( ' 11-dummy.netdev ' , ' 11-dummy.network ' )
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' test1:degraded ' ] )
2019-06-01 04:31:09 +03:00
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' test1 ' , env = env )
2019-06-01 04:31:09 +03:00
print ( output )
self . assertRegex ( output , ' Type: ether ' )
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' lo ' , env = env )
2019-06-01 04:31:09 +03:00
print ( output )
self . assertRegex ( output , ' Type: loopback ' )
@expectedFailureIfLinkFileFieldIsNotSet ( )
def test_udev_link_file ( self ) :
copy_unit_to_networkd_unit_path ( ' 11-dummy.netdev ' , ' 11-dummy.network ' )
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' test1:degraded ' ] )
2019-06-01 04:31:09 +03:00
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' test1 ' , env = env )
2019-06-01 04:31:09 +03:00
print ( output )
2019-10-31 19:19:23 +03:00
self . assertRegex ( output , r ' Link File: (/usr)?/lib/systemd/network/99-default.link ' )
2019-06-01 04:31:09 +03:00
self . assertRegex ( output , r ' Network File: /run/systemd/network/11-dummy.network ' )
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' lo ' , env = env )
2019-06-01 04:31:09 +03:00
print ( output )
2019-10-31 19:19:23 +03:00
self . assertRegex ( output , r ' Link File: (/usr)?/lib/systemd/network/99-default.link ' )
2019-06-01 04:31:09 +03:00
self . assertRegex ( output , r ' Network File: n/a ' )
2019-05-31 10:11:53 +03:00
def test_delete_links ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 11-dummy.netdev ' , ' 11-dummy.network ' ,
' 25-veth.netdev ' , ' netdev-link-local-addressing-yes.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-05-31 10:11:53 +03:00
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' test1:degraded ' , ' veth99:degraded ' , ' veth-peer:degraded ' ] )
2019-05-31 10:11:53 +03:00
2019-12-15 22:37:00 +03:00
check_output ( * networkctl_cmd , ' delete ' , ' test1 ' , ' veth99 ' , env = env )
2019-06-05 13:08:09 +03:00
self . assertFalse ( link_exists ( ' test1 ' ) )
self . assertFalse ( link_exists ( ' veth99 ' ) )
self . assertFalse ( link_exists ( ' veth-peer ' ) )
2019-05-31 10:11:53 +03:00
2018-09-29 15:36:25 +03:00
class NetworkdNetDevTests ( unittest . TestCase , Utilities ) :
2019-07-10 17:54:26 +03:00
links_remove_earlier = [
' xfrm99 ' ,
]
links = [
2018-12-06 16:57:20 +03:00
' 6rdtun99 ' ,
2020-09-17 09:31:54 +03:00
' bareudp99 ' ,
2020-10-05 22:53:35 +03:00
' bond98 ' ,
2018-12-06 16:57:20 +03:00
' bond99 ' ,
' bridge99 ' ,
' dropin-test ' ,
' dummy98 ' ,
2019-03-21 19:48:49 +03:00
' erspan98 ' ,
' erspan99 ' ,
2018-12-06 16:57:20 +03:00
' geneve99 ' ,
2019-03-31 16:04:00 +03:00
' gretap96 ' ,
2019-03-21 19:48:49 +03:00
' gretap98 ' ,
2018-12-06 16:57:20 +03:00
' gretap99 ' ,
2019-03-31 16:04:00 +03:00
' gretun96 ' ,
2019-03-21 19:48:49 +03:00
' gretun97 ' ,
' gretun98 ' ,
2018-12-06 16:57:20 +03:00
' gretun99 ' ,
2019-12-07 18:03:29 +03:00
' ifb99 ' ,
2019-03-21 19:48:49 +03:00
' ip6gretap98 ' ,
2018-12-06 16:57:20 +03:00
' ip6gretap99 ' ,
2019-07-11 05:39:27 +03:00
' ip6gretun96 ' ,
2019-03-21 19:48:49 +03:00
' ip6gretun97 ' ,
' ip6gretun98 ' ,
' ip6gretun99 ' ,
' ip6tnl97 ' ,
' ip6tnl98 ' ,
2018-12-06 16:57:20 +03:00
' ip6tnl99 ' ,
2019-03-31 16:04:00 +03:00
' ipiptun96 ' ,
2019-03-21 19:48:49 +03:00
' ipiptun97 ' ,
' ipiptun98 ' ,
2018-12-06 16:57:20 +03:00
' ipiptun99 ' ,
' ipvlan99 ' ,
2019-05-16 03:48:34 +03:00
' ipvtap99 ' ,
2018-12-06 16:57:20 +03:00
' isataptun99 ' ,
' macvlan99 ' ,
' macvtap99 ' ,
2019-05-23 05:37:53 +03:00
' nlmon99 ' ,
2019-03-31 16:04:00 +03:00
' sittun96 ' ,
2019-03-21 19:48:49 +03:00
' sittun97 ' ,
' sittun98 ' ,
2018-12-06 16:57:20 +03:00
' sittun99 ' ,
' tap99 ' ,
' test1 ' ,
' tun99 ' ,
' vcan99 ' ,
' veth99 ' ,
' vlan99 ' ,
' vrf99 ' ,
2019-03-21 19:48:49 +03:00
' vti6tun97 ' ,
' vti6tun98 ' ,
2018-12-06 16:57:20 +03:00
' vti6tun99 ' ,
2019-07-11 05:39:27 +03:00
' vtitun96 ' ,
2019-03-21 19:48:49 +03:00
' vtitun97 ' ,
' vtitun98 ' ,
2018-12-06 16:57:20 +03:00
' vtitun99 ' ,
2019-05-23 18:51:22 +03:00
' vxcan99 ' ,
2020-09-17 09:58:41 +03:00
' vxlan98 ' ,
2018-12-06 16:57:20 +03:00
' vxlan99 ' ,
2020-06-01 08:23:03 +03:00
' wg97 ' ,
2019-01-14 04:06:21 +03:00
' wg98 ' ,
2019-07-10 17:54:26 +03:00
' wg99 ' ,
]
2018-12-06 16:57:20 +03:00
units = [
' 10-dropin-test.netdev ' ,
' 11-dummy.netdev ' ,
2019-04-01 04:28:32 +03:00
' 11-dummy.network ' ,
2018-12-06 16:57:20 +03:00
' 12-dummy.netdev ' ,
2019-06-29 20:28:42 +03:00
' 13-not-match-udev-property.network ' ,
' 14-match-udev-property.network ' ,
2019-03-31 19:06:22 +03:00
' 15-name-conflict-test.netdev ' ,
2018-12-06 16:57:20 +03:00
' 21-macvlan.netdev ' ,
' 21-macvtap.netdev ' ,
2019-03-08 06:34:56 +03:00
' 21-vlan-test1.network ' ,
2018-12-06 16:57:20 +03:00
' 21-vlan.netdev ' ,
' 21-vlan.network ' ,
' 25-6rd-tunnel.netdev ' ,
2020-09-17 09:31:54 +03:00
' 25-bareudp.netdev ' ,
2018-12-06 16:57:20 +03:00
' 25-bond.netdev ' ,
2018-12-13 12:23:07 +03:00
' 25-bond-balanced-tlb.netdev ' ,
2018-12-06 16:57:20 +03:00
' 25-bridge.netdev ' ,
2019-06-13 23:25:00 +03:00
' 25-bridge-configure-without-carrier.network ' ,
2019-04-01 04:28:32 +03:00
' 25-bridge.network ' ,
2019-03-21 19:48:49 +03:00
' 25-erspan-tunnel-local-any.netdev ' ,
2018-12-06 16:57:20 +03:00
' 25-erspan-tunnel.netdev ' ,
2019-03-31 16:04:00 +03:00
' 25-fou-gretap.netdev ' ,
' 25-fou-gre.netdev ' ,
' 25-fou-ipip.netdev ' ,
' 25-fou-ipproto-gre.netdev ' ,
' 25-fou-ipproto-ipip.netdev ' ,
' 25-fou-sit.netdev ' ,
2018-12-06 16:57:20 +03:00
' 25-geneve.netdev ' ,
2019-03-21 19:48:49 +03:00
' 25-gretap-tunnel-local-any.netdev ' ,
2018-12-06 16:57:20 +03:00
' 25-gretap-tunnel.netdev ' ,
2019-07-11 05:39:27 +03:00
' 25-gre-tunnel-any-any.netdev ' ,
2019-03-21 19:48:49 +03:00
' 25-gre-tunnel-local-any.netdev ' ,
' 25-gre-tunnel-remote-any.netdev ' ,
2018-12-06 16:57:20 +03:00
' 25-gre-tunnel.netdev ' ,
2019-12-07 18:03:29 +03:00
' 25-ifb.netdev ' ,
2019-03-21 19:48:49 +03:00
' 25-ip6gretap-tunnel-local-any.netdev ' ,
' 25-ip6gretap-tunnel.netdev ' ,
2019-07-11 05:39:27 +03:00
' 25-ip6gre-tunnel-any-any.netdev ' ,
2019-03-21 19:48:49 +03:00
' 25-ip6gre-tunnel-local-any.netdev ' ,
' 25-ip6gre-tunnel-remote-any.netdev ' ,
2018-12-06 16:57:20 +03:00
' 25-ip6gre-tunnel.netdev ' ,
2019-07-11 05:39:27 +03:00
' 25-ip6tnl-tunnel-any-any.netdev ' ,
2019-03-21 19:48:49 +03:00
' 25-ip6tnl-tunnel-local-any.netdev ' ,
2019-07-11 05:39:27 +03:00
' 25-ip6tnl-tunnel-remote-any.netdev ' ,
2018-12-06 16:57:20 +03:00
' 25-ip6tnl-tunnel.netdev ' ,
2019-07-11 05:39:27 +03:00
' 25-ipip-tunnel-any-any.netdev ' ,
2018-12-06 16:57:20 +03:00
' 25-ipip-tunnel-independent.netdev ' ,
2019-07-10 17:53:30 +03:00
' 25-ipip-tunnel-independent-loopback.netdev ' ,
2019-03-21 19:48:49 +03:00
' 25-ipip-tunnel-local-any.netdev ' ,
' 25-ipip-tunnel-remote-any.netdev ' ,
2018-12-06 16:57:20 +03:00
' 25-ipip-tunnel.netdev ' ,
' 25-ipvlan.netdev ' ,
2019-05-16 03:48:34 +03:00
' 25-ipvtap.netdev ' ,
2018-12-06 16:57:20 +03:00
' 25-isatap-tunnel.netdev ' ,
2019-04-05 09:58:50 +03:00
' 25-macsec.key ' ,
' 25-macsec.netdev ' ,
' 25-macsec.network ' ,
2019-05-23 05:37:53 +03:00
' 25-nlmon.netdev ' ,
2019-07-11 05:39:27 +03:00
' 25-sit-tunnel-any-any.netdev ' ,
2019-03-21 19:48:49 +03:00
' 25-sit-tunnel-local-any.netdev ' ,
' 25-sit-tunnel-remote-any.netdev ' ,
2018-12-06 16:57:20 +03:00
' 25-sit-tunnel.netdev ' ,
' 25-tap.netdev ' ,
' 25-tun.netdev ' ,
2020-10-05 22:47:44 +03:00
' 25-tunnel-any-any.network ' ,
2019-05-13 00:55:16 +03:00
' 25-tunnel-local-any.network ' ,
' 25-tunnel-remote-any.network ' ,
' 25-tunnel.network ' ,
2018-12-06 16:57:20 +03:00
' 25-vcan.netdev ' ,
' 25-veth.netdev ' ,
' 25-vrf.netdev ' ,
2019-07-11 05:39:27 +03:00
' 25-vti6-tunnel-any-any.netdev ' ,
2019-03-21 19:48:49 +03:00
' 25-vti6-tunnel-local-any.netdev ' ,
' 25-vti6-tunnel-remote-any.netdev ' ,
2018-12-06 16:57:20 +03:00
' 25-vti6-tunnel.netdev ' ,
2019-07-11 05:39:27 +03:00
' 25-vti-tunnel-any-any.netdev ' ,
2019-03-21 19:48:49 +03:00
' 25-vti-tunnel-local-any.netdev ' ,
' 25-vti-tunnel-remote-any.netdev ' ,
2018-12-06 16:57:20 +03:00
' 25-vti-tunnel.netdev ' ,
2019-05-23 18:51:22 +03:00
' 25-vxcan.netdev ' ,
2020-09-17 09:58:41 +03:00
' 25-vxlan-independent.netdev ' ,
2018-12-06 16:57:20 +03:00
' 25-vxlan.netdev ' ,
2019-01-14 04:06:21 +03:00
' 25-wireguard-23-peers.netdev ' ,
' 25-wireguard-23-peers.network ' ,
2020-06-01 08:23:03 +03:00
' 25-wireguard-no-peer.netdev ' ,
' 25-wireguard-no-peer.network ' ,
2019-04-05 11:52:29 +03:00
' 25-wireguard-preshared-key.txt ' ,
2019-03-04 08:42:03 +03:00
' 25-wireguard-private-key.txt ' ,
2018-12-06 16:57:20 +03:00
' 25-wireguard.netdev ' ,
2019-03-31 17:56:39 +03:00
' 25-wireguard.network ' ,
2019-07-10 17:54:26 +03:00
' 25-xfrm.netdev ' ,
' 25-xfrm-independent.netdev ' ,
2018-12-06 16:57:20 +03:00
' 6rd.network ' ,
2019-03-29 21:50:11 +03:00
' erspan.network ' ,
2018-12-06 16:57:20 +03:00
' gre.network ' ,
' gretap.network ' ,
' gretun.network ' ,
' ip6gretap.network ' ,
2019-03-21 19:48:49 +03:00
' ip6gretun.network ' ,
2018-12-06 16:57:20 +03:00
' ip6tnl.network ' ,
' ipip.network ' ,
' ipvlan.network ' ,
2019-05-16 03:48:34 +03:00
' ipvtap.network ' ,
2018-12-06 16:57:20 +03:00
' isatap.network ' ,
2019-04-05 09:58:50 +03:00
' macsec.network ' ,
2018-12-06 16:57:20 +03:00
' macvlan.network ' ,
' macvtap.network ' ,
2019-05-20 07:16:55 +03:00
' netdev-link-local-addressing-yes.network ' ,
2018-12-06 16:57:20 +03:00
' sit.network ' ,
' vti6.network ' ,
' vti.network ' ,
2019-05-03 07:08:55 +03:00
' vxlan-test1.network ' ,
2019-07-10 17:54:26 +03:00
' vxlan.network ' ,
' xfrm.network ' ,
]
2018-09-29 15:36:25 +03:00
2019-05-24 07:39:50 +03:00
fou_ports = [
' 55555 ' ,
' 55556 ' ]
2018-09-29 15:36:25 +03:00
def setUp ( self ) :
2019-06-05 13:08:09 +03:00
remove_fou_ports ( self . fou_ports )
2019-07-10 17:54:26 +03:00
remove_links ( self . links_remove_earlier )
2019-06-05 13:08:09 +03:00
remove_links ( self . links )
2019-07-03 21:46:14 +03:00
stop_networkd ( show_logs = False )
2018-09-29 15:36:25 +03:00
def tearDown ( self ) :
2019-06-05 13:08:09 +03:00
remove_fou_ports ( self . fou_ports )
2019-07-10 17:54:26 +03:00
remove_links ( self . links_remove_earlier )
2019-06-05 13:08:09 +03:00
remove_links ( self . links )
remove_unit_from_networkd_path ( self . units )
2019-07-03 21:46:14 +03:00
stop_networkd ( show_logs = True )
2018-09-29 15:36:25 +03:00
2019-06-01 04:29:08 +03:00
def test_dropin_and_name_conflict ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 10-dropin-test.netdev ' , ' 15-name-conflict-test.netdev ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2018-11-26 16:05:48 +03:00
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' dropin-test:off ' ] , setup_state = ' unmanaged ' )
2018-11-26 16:05:48 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip link show dropin-test ' )
2018-11-26 16:05:48 +03:00
print ( output )
self . assertRegex ( output , ' 00:50:56:c0:00:28 ' )
2019-06-29 20:28:42 +03:00
def test_match_udev_property ( self ) :
copy_unit_to_networkd_unit_path ( ' 12-dummy.netdev ' , ' 13-not-match-udev-property.network ' , ' 14-match-udev-property.network ' )
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' dummy98:routable ' ] )
2019-06-29 20:28:42 +03:00
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' dummy98 ' , env = env )
2019-06-29 20:28:42 +03:00
print ( output )
self . assertRegex ( output , ' Network File: /run/systemd/network/14-match-udev-property ' )
2019-04-01 04:28:32 +03:00
def test_wait_online_any ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-bridge.netdev ' , ' 25-bridge.network ' , ' 11-dummy.netdev ' , ' 11-dummy.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-04-01 04:28:32 +03:00
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' bridge99 ' , ' test1:degraded ' ] , bool_any = True )
2019-04-01 04:28:32 +03:00
2020-01-08 15:25:16 +03:00
self . wait_operstate ( ' bridge99 ' , ' (off|no-carrier) ' , setup_state = ' configuring ' )
self . wait_operstate ( ' test1 ' , ' degraded ' )
2019-04-01 04:28:32 +03:00
2020-09-17 09:31:54 +03:00
@expectedFailureIfModuleIsNotAvailable ( ' bareudp ' )
def test_bareudp ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-bareudp.netdev ' , ' netdev-link-local-addressing-yes.network ' )
start_networkd ( )
self . wait_online ( [ ' bareudp99:degraded ' ] )
output = check_output ( ' ip -d link show bareudp99 ' )
print ( output )
self . assertRegex ( output , ' dstport 1000 ' )
self . assertRegex ( output , ' ethertype ip ' )
2018-09-29 15:36:25 +03:00
def test_bridge ( self ) :
2019-06-13 23:25:00 +03:00
copy_unit_to_networkd_unit_path ( ' 25-bridge.netdev ' , ' 25-bridge-configure-without-carrier.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2018-09-29 15:36:25 +03:00
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' bridge99:no-carrier ' ] )
2018-09-29 15:36:25 +03:00
2019-05-20 04:43:50 +03:00
tick = os . sysconf ( ' SC_CLK_TCK ' )
2019-06-05 13:08:09 +03:00
self . assertEqual ( 9 , round ( float ( read_link_attr ( ' bridge99 ' , ' bridge ' , ' hello_time ' ) ) / tick ) )
self . assertEqual ( 9 , round ( float ( read_link_attr ( ' bridge99 ' , ' bridge ' , ' max_age ' ) ) / tick ) )
2019-07-25 04:01:46 +03:00
self . assertEqual ( 9 , round ( float ( read_link_attr ( ' bridge99 ' , ' bridge ' , ' forward_delay ' ) ) / tick ) )
self . assertEqual ( 9 , round ( float ( read_link_attr ( ' bridge99 ' , ' bridge ' , ' ageing_time ' ) ) / tick ) )
self . assertEqual ( 9 , int ( read_link_attr ( ' bridge99 ' , ' bridge ' , ' priority ' ) ) )
self . assertEqual ( 1 , int ( read_link_attr ( ' bridge99 ' , ' bridge ' , ' multicast_querier ' ) ) )
self . assertEqual ( 1 , int ( read_link_attr ( ' bridge99 ' , ' bridge ' , ' multicast_snooping ' ) ) )
self . assertEqual ( 1 , int ( read_link_attr ( ' bridge99 ' , ' bridge ' , ' stp_state ' ) ) )
self . assertEqual ( 3 , int ( read_link_attr ( ' bridge99 ' , ' bridge ' , ' multicast_igmp_version ' ) ) )
2018-09-29 15:36:25 +03:00
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' bridge99 ' , env = env )
2019-07-28 09:23:39 +03:00
print ( output )
self . assertRegex ( output , ' Priority: 9 ' )
self . assertRegex ( output , ' STP: yes ' )
self . assertRegex ( output , ' Multicast IGMP Version: 3 ' )
2018-09-29 15:36:25 +03:00
def test_bond ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-bond.netdev ' , ' 25-bond-balanced-tlb.netdev ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-06-05 13:08:09 +03:00
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' bond99:off ' , ' bond98:off ' ] , setup_state = ' unmanaged ' )
2019-06-05 13:08:09 +03:00
self . assertEqual ( ' 802.3ad 4 ' , read_link_attr ( ' bond99 ' , ' bonding ' , ' mode ' ) )
self . assertEqual ( ' layer3+4 1 ' , read_link_attr ( ' bond99 ' , ' bonding ' , ' xmit_hash_policy ' ) )
self . assertEqual ( ' 1000 ' , read_link_attr ( ' bond99 ' , ' bonding ' , ' miimon ' ) )
self . assertEqual ( ' fast 1 ' , read_link_attr ( ' bond99 ' , ' bonding ' , ' lacp_rate ' ) )
self . assertEqual ( ' 2000 ' , read_link_attr ( ' bond99 ' , ' bonding ' , ' updelay ' ) )
self . assertEqual ( ' 2000 ' , read_link_attr ( ' bond99 ' , ' bonding ' , ' downdelay ' ) )
self . assertEqual ( ' 4 ' , read_link_attr ( ' bond99 ' , ' bonding ' , ' resend_igmp ' ) )
self . assertEqual ( ' 1 ' , read_link_attr ( ' bond99 ' , ' bonding ' , ' min_links ' ) )
self . assertEqual ( ' 1218 ' , read_link_attr ( ' bond99 ' , ' bonding ' , ' ad_actor_sys_prio ' ) )
self . assertEqual ( ' 811 ' , read_link_attr ( ' bond99 ' , ' bonding ' , ' ad_user_port_key ' ) )
self . assertEqual ( ' 00:11:22:33:44:55 ' , read_link_attr ( ' bond99 ' , ' bonding ' , ' ad_actor_system ' ) )
self . assertEqual ( ' balance-tlb 5 ' , read_link_attr ( ' bond98 ' , ' bonding ' , ' mode ' ) )
self . assertEqual ( ' 1 ' , read_link_attr ( ' bond98 ' , ' bonding ' , ' tlb_dynamic_lb ' ) )
2018-12-13 12:23:07 +03:00
2018-09-29 15:36:25 +03:00
def test_vlan ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 21-vlan.netdev ' , ' 11-dummy.netdev ' ,
' 21-vlan.network ' , ' 21-vlan-test1.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2018-09-29 15:36:25 +03:00
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' test1:degraded ' , ' vlan99:routable ' ] )
2018-09-29 15:36:25 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show test1 ' )
2019-02-23 13:25:01 +03:00
print ( output )
2019-05-16 05:49:13 +03:00
self . assertRegex ( output , ' mtu 2000 ' )
2019-02-23 13:25:01 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show vlan99 ' )
2018-12-06 17:12:28 +03:00
print ( output )
2019-04-25 01:29:20 +03:00
self . assertRegex ( output , ' mtu 2000 ' )
self . assertRegex ( output , ' REORDER_HDR ' )
self . assertRegex ( output , ' LOOSE_BINDING ' )
self . assertRegex ( output , ' GVRP ' )
self . assertRegex ( output , ' MVRP ' )
self . assertRegex ( output , ' id 99 ' )
2018-09-29 15:36:25 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -4 address show dev test1 ' )
2019-03-08 06:34:56 +03:00
print ( output )
self . assertRegex ( output , ' inet 192.168.24.5/24 brd 192.168.24.255 scope global test1 ' )
self . assertRegex ( output , ' inet 192.168.25.5/24 brd 192.168.25.255 scope global test1 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -4 address show dev vlan99 ' )
2019-03-08 06:34:56 +03:00
print ( output )
self . assertRegex ( output , ' inet 192.168.23.5/24 brd 192.168.23.255 scope global vlan99 ' )
2018-09-29 15:36:25 +03:00
def test_macvtap ( self ) :
2019-05-20 05:47:24 +03:00
for mode in [ ' private ' , ' vepa ' , ' bridge ' , ' passthru ' ] :
with self . subTest ( mode = mode ) :
if mode != ' private ' :
self . tearDown ( )
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 21-macvtap.netdev ' , ' netdev-link-local-addressing-yes.network ' ,
' 11-dummy.netdev ' , ' macvtap.network ' )
2019-05-20 05:47:24 +03:00
with open ( os . path . join ( network_unit_file_path , ' 21-macvtap.netdev ' ) , mode = ' a ' ) as f :
f . write ( ' [MACVTAP] \n Mode= ' + mode )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2018-09-29 15:36:25 +03:00
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' macvtap99:degraded ' , ' test1:degraded ' ] )
2019-05-20 05:47:24 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show macvtap99 ' )
2019-05-20 05:47:24 +03:00
print ( output )
self . assertRegex ( output , ' macvtap mode ' + mode + ' ' )
2018-09-29 15:36:25 +03:00
def test_macvlan ( self ) :
2019-05-20 05:39:05 +03:00
for mode in [ ' private ' , ' vepa ' , ' bridge ' , ' passthru ' ] :
with self . subTest ( mode = mode ) :
if mode != ' private ' :
self . tearDown ( )
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 21-macvlan.netdev ' , ' netdev-link-local-addressing-yes.network ' ,
' 11-dummy.netdev ' , ' macvlan.network ' )
2019-05-20 05:39:05 +03:00
with open ( os . path . join ( network_unit_file_path , ' 21-macvlan.netdev ' ) , mode = ' a ' ) as f :
f . write ( ' [MACVLAN] \n Mode= ' + mode )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-05-20 05:39:05 +03:00
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' macvlan99:degraded ' , ' test1:degraded ' ] )
2019-05-20 05:39:05 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show test1 ' )
2019-05-20 05:39:05 +03:00
print ( output )
self . assertRegex ( output , ' mtu 2000 ' )
2019-02-23 13:25:01 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show macvlan99 ' )
2019-05-20 05:39:05 +03:00
print ( output )
self . assertRegex ( output , ' mtu 2000 ' )
self . assertRegex ( output , ' macvlan mode ' + mode + ' ' )
2019-02-23 13:25:01 +03:00
2018-11-03 00:08:30 +03:00
@expectedFailureIfModuleIsNotAvailable ( ' ipvlan ' )
2018-09-29 15:36:25 +03:00
def test_ipvlan ( self ) :
2019-05-20 06:47:31 +03:00
for mode , flag in [ [ ' L2 ' , ' private ' ] , [ ' L3 ' , ' vepa ' ] , [ ' L3S ' , ' bridge ' ] ] :
with self . subTest ( mode = mode , flag = flag ) :
if mode != ' L2 ' :
self . tearDown ( )
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-ipvlan.netdev ' , ' netdev-link-local-addressing-yes.network ' ,
' 11-dummy.netdev ' , ' ipvlan.network ' )
2019-05-20 06:47:31 +03:00
with open ( os . path . join ( network_unit_file_path , ' 25-ipvlan.netdev ' ) , mode = ' a ' ) as f :
f . write ( ' [IPVLAN] \n Mode= ' + mode + ' \n Flags= ' + flag )
2018-09-29 15:36:25 +03:00
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' ipvlan99:degraded ' , ' test1:degraded ' ] )
2019-05-20 06:47:31 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show ipvlan99 ' )
2019-05-20 06:47:31 +03:00
print ( output )
self . assertRegex ( output , ' ipvlan *mode ' + mode . lower ( ) + ' ' + flag )
2018-09-29 15:36:25 +03:00
2019-05-16 03:48:34 +03:00
@expectedFailureIfModuleIsNotAvailable ( ' ipvtap ' )
def test_ipvtap ( self ) :
2019-05-20 06:48:05 +03:00
for mode , flag in [ [ ' L2 ' , ' private ' ] , [ ' L3 ' , ' vepa ' ] , [ ' L3S ' , ' bridge ' ] ] :
with self . subTest ( mode = mode , flag = flag ) :
if mode != ' L2 ' :
self . tearDown ( )
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-ipvtap.netdev ' , ' netdev-link-local-addressing-yes.network ' ,
' 11-dummy.netdev ' , ' ipvtap.network ' )
2019-05-20 06:48:05 +03:00
with open ( os . path . join ( network_unit_file_path , ' 25-ipvtap.netdev ' ) , mode = ' a ' ) as f :
f . write ( ' [IPVTAP] \n Mode= ' + mode + ' \n Flags= ' + flag )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' ipvtap99:degraded ' , ' test1:degraded ' ] )
2019-05-16 03:48:34 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show ipvtap99 ' )
2019-05-20 06:48:05 +03:00
print ( output )
self . assertRegex ( output , ' ipvtap *mode ' + mode . lower ( ) + ' ' + flag )
2019-05-16 03:48:34 +03:00
2018-09-29 15:36:25 +03:00
def test_veth ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' netdev-link-local-addressing-yes.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2018-09-29 15:36:25 +03:00
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:degraded ' , ' veth-peer:degraded ' ] )
2019-05-20 09:29:54 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show veth99 ' )
2019-05-20 09:29:54 +03:00
print ( output )
self . assertRegex ( output , ' link/ether 12:34:56:78:9a:bc ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show veth-peer ' )
2019-05-20 09:29:54 +03:00
print ( output )
self . assertRegex ( output , ' link/ether 12:34:56:78:9a:bd ' )
2018-09-29 15:36:25 +03:00
def test_tun ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-tun.netdev ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2018-09-29 15:36:25 +03:00
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' tun99:off ' ] , setup_state = ' unmanaged ' )
2018-09-29 15:36:25 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show tun99 ' )
2019-05-20 07:59:34 +03:00
print ( output )
# Old ip command does not support IFF_ flags
2019-10-31 19:19:23 +03:00
self . assertRegex ( output , ' tun (type tun pi on vnet_hdr on multi_queue|addrgenmode) ' )
2019-05-20 07:59:34 +03:00
2018-09-29 15:36:25 +03:00
def test_tap ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-tap.netdev ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2018-09-29 15:36:25 +03:00
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' tap99:off ' ] , setup_state = ' unmanaged ' )
2018-09-29 15:36:25 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show tap99 ' )
2019-05-20 07:59:34 +03:00
print ( output )
# Old ip command does not support IFF_ flags
2019-10-31 19:19:23 +03:00
self . assertRegex ( output , ' tun (type tap pi on vnet_hdr on multi_queue|addrgenmode) ' )
2019-05-20 07:59:34 +03:00
2018-11-03 00:08:30 +03:00
@expectedFailureIfModuleIsNotAvailable ( ' vrf ' )
2018-09-29 15:36:25 +03:00
def test_vrf ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-vrf.netdev ' , ' netdev-link-local-addressing-yes.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2018-09-29 15:36:25 +03:00
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' vrf99:carrier ' ] )
2018-09-29 15:36:25 +03:00
2018-11-03 00:08:30 +03:00
@expectedFailureIfModuleIsNotAvailable ( ' vcan ' )
2018-09-29 15:36:25 +03:00
def test_vcan ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-vcan.netdev ' , ' netdev-link-local-addressing-yes.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2018-09-29 15:36:25 +03:00
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' vcan99:carrier ' ] )
2018-09-29 15:36:25 +03:00
2019-05-23 18:51:22 +03:00
@expectedFailureIfModuleIsNotAvailable ( ' vxcan ' )
def test_vxcan ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-vxcan.netdev ' , ' netdev-link-local-addressing-yes.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-05-23 18:51:22 +03:00
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' vxcan99:carrier ' , ' vxcan-peer:carrier ' ] )
2019-05-23 18:51:22 +03:00
2018-11-03 20:03:43 +03:00
@expectedFailureIfModuleIsNotAvailable ( ' wireguard ' )
def test_wireguard ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-wireguard.netdev ' , ' 25-wireguard.network ' ,
' 25-wireguard-23-peers.netdev ' , ' 25-wireguard-23-peers.network ' ,
2020-06-01 08:23:03 +03:00
' 25-wireguard-preshared-key.txt ' , ' 25-wireguard-private-key.txt ' ,
' 25-wireguard-no-peer.netdev ' , ' 25-wireguard-no-peer.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2020-06-01 08:23:03 +03:00
self . wait_online ( [ ' wg99:carrier ' , ' wg98:routable ' , ' wg97:carrier ' ] )
2019-03-31 17:56:39 +03:00
2018-11-03 20:03:43 +03:00
if shutil . which ( ' wg ' ) :
2019-06-05 12:43:28 +03:00
call ( ' wg ' )
2019-03-31 17:56:39 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' wg show wg99 listen-port ' )
2019-04-25 01:29:20 +03:00
self . assertRegex ( output , ' 51820 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' wg show wg99 fwmark ' )
2019-04-25 01:29:20 +03:00
self . assertRegex ( output , ' 0x4d2 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' wg show wg99 allowed-ips ' )
2019-06-06 15:08:01 +03:00
self . assertRegex ( output , r ' RDf \ +LSpeEre7YEIKaxg \ +wbpsNV7du \ +ktR99uBEtIiCA= \ t192.168.26.0/24 fd31:bf08:57cb::/48 ' )
self . assertRegex ( output , r ' lsDtM3AbjxNlauRKzHEPfgS1Zp7cp/VX5Use/P4PQSc= \ tfdbc:bae2:7871:e1fe:793:8636::/96 fdbc:bae2:7871:500:e1fe:793:8636:dad1/128 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' wg show wg99 persistent-keepalive ' )
2019-06-06 15:08:01 +03:00
self . assertRegex ( output , r ' RDf \ +LSpeEre7YEIKaxg \ +wbpsNV7du \ +ktR99uBEtIiCA= \ t20 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' wg show wg99 endpoints ' )
2019-06-06 15:08:01 +03:00
self . assertRegex ( output , r ' RDf \ +LSpeEre7YEIKaxg \ +wbpsNV7du \ +ktR99uBEtIiCA= \ t192.168.27.3:51820 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' wg show wg99 private-key ' )
2019-06-06 15:08:01 +03:00
self . assertRegex ( output , r ' EEGlnEPYJV//kbvvIqxKkQwOiS \ +UENyPncC4bF46ong= ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' wg show wg99 preshared-keys ' )
2019-06-06 15:08:01 +03:00
self . assertRegex ( output , r ' RDf \ +LSpeEre7YEIKaxg \ +wbpsNV7du \ +ktR99uBEtIiCA= IIWIV17wutHv7t4cR6pOT91z6NSz/T8Arh0yaywhw3M= ' )
self . assertRegex ( output , r ' lsDtM3AbjxNlauRKzHEPfgS1Zp7cp/VX5Use/P4PQSc= cPLOy1YUrEI0EMMIycPJmOo0aTu3RZnw8bL5meVD6m0= ' )
2018-11-03 20:03:43 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' wg show wg98 private-key ' )
2019-06-06 15:08:01 +03:00
self . assertRegex ( output , r ' CJQUtcS9emY2fLYqDlpSZiE/QJyHkPWr \ +WHtZLZ90FU= ' )
2019-01-14 04:06:21 +03:00
2020-06-01 08:23:03 +03:00
output = check_output ( ' wg show wg97 listen-port ' )
self . assertRegex ( output , ' 51821 ' )
output = check_output ( ' wg show wg97 fwmark ' )
self . assertRegex ( output , ' 0x4d3 ' )
2018-09-29 15:36:25 +03:00
def test_geneve ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-geneve.netdev ' , ' netdev-link-local-addressing-yes.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2018-09-29 15:36:25 +03:00
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' geneve99:degraded ' ] )
2018-09-29 15:36:25 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show geneve99 ' )
2018-12-06 17:12:28 +03:00
print ( output )
2019-04-25 01:29:20 +03:00
self . assertRegex ( output , ' 192.168.22.1 ' )
self . assertRegex ( output , ' 6082 ' )
self . assertRegex ( output , ' udpcsum ' )
self . assertRegex ( output , ' udp6zerocsumrx ' )
2018-09-29 15:36:25 +03:00
def test_ipip_tunnel ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 12-dummy.netdev ' , ' ipip.network ' ,
' 25-ipip-tunnel.netdev ' , ' 25-tunnel.network ' ,
' 25-ipip-tunnel-local-any.netdev ' , ' 25-tunnel-local-any.network ' ,
2019-07-11 05:39:27 +03:00
' 25-ipip-tunnel-remote-any.netdev ' , ' 25-tunnel-remote-any.network ' ,
' 25-ipip-tunnel-any-any.netdev ' , ' 25-tunnel-any-any.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' ipiptun99:routable ' , ' ipiptun98:routable ' , ' ipiptun97:routable ' , ' ipiptun96:routable ' , ' dummy98:degraded ' ] )
2019-03-21 19:48:49 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show ipiptun99 ' )
2019-03-21 19:48:49 +03:00
print ( output )
2019-10-31 19:19:23 +03:00
self . assertRegex ( output , ' ipip (ipip )?remote 192.169.224.239 local 192.168.223.238 dev dummy98 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show ipiptun98 ' )
2019-03-21 19:48:49 +03:00
print ( output )
2019-10-31 19:19:23 +03:00
self . assertRegex ( output , ' ipip (ipip )?remote 192.169.224.239 local any dev dummy98 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show ipiptun97 ' )
2019-03-21 19:48:49 +03:00
print ( output )
2019-10-31 19:19:23 +03:00
self . assertRegex ( output , ' ipip (ipip )?remote any local 192.168.223.238 dev dummy98 ' )
2019-07-11 05:39:27 +03:00
output = check_output ( ' ip -d link show ipiptun96 ' )
print ( output )
2019-10-31 19:19:23 +03:00
self . assertRegex ( output , ' ipip (ipip )?remote any local any dev dummy98 ' )
2018-09-29 15:36:25 +03:00
def test_gre_tunnel ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 12-dummy.netdev ' , ' gretun.network ' ,
' 25-gre-tunnel.netdev ' , ' 25-tunnel.network ' ,
' 25-gre-tunnel-local-any.netdev ' , ' 25-tunnel-local-any.network ' ,
2019-07-11 05:39:27 +03:00
' 25-gre-tunnel-remote-any.netdev ' , ' 25-tunnel-remote-any.network ' ,
' 25-gre-tunnel-any-any.netdev ' , ' 25-tunnel-any-any.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' gretun99:routable ' , ' gretun98:routable ' , ' gretun97:routable ' , ' gretun96:routable ' , ' dummy98:degraded ' ] )
2019-03-21 19:48:49 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show gretun99 ' )
2019-03-21 19:48:49 +03:00
print ( output )
self . assertRegex ( output , ' gre remote 10.65.223.239 local 10.65.223.238 dev dummy98 ' )
2019-03-31 09:44:42 +03:00
self . assertRegex ( output , ' ikey 1.2.3.103 ' )
self . assertRegex ( output , ' okey 1.2.4.103 ' )
self . assertRegex ( output , ' iseq ' )
self . assertRegex ( output , ' oseq ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show gretun98 ' )
2019-03-21 19:48:49 +03:00
print ( output )
self . assertRegex ( output , ' gre remote 10.65.223.239 local any dev dummy98 ' )
2019-03-31 09:44:42 +03:00
self . assertRegex ( output , ' ikey 0.0.0.104 ' )
self . assertRegex ( output , ' okey 0.0.0.104 ' )
self . assertNotRegex ( output , ' iseq ' )
self . assertNotRegex ( output , ' oseq ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show gretun97 ' )
2019-03-21 19:48:49 +03:00
print ( output )
self . assertRegex ( output , ' gre remote any local 10.65.223.238 dev dummy98 ' )
2019-03-31 09:44:42 +03:00
self . assertRegex ( output , ' ikey 0.0.0.105 ' )
self . assertRegex ( output , ' okey 0.0.0.105 ' )
self . assertNotRegex ( output , ' iseq ' )
self . assertNotRegex ( output , ' oseq ' )
2019-07-11 05:39:27 +03:00
output = check_output ( ' ip -d link show gretun96 ' )
print ( output )
self . assertRegex ( output , ' gre remote any local any dev dummy98 ' )
self . assertRegex ( output , ' ikey 0.0.0.106 ' )
self . assertRegex ( output , ' okey 0.0.0.106 ' )
self . assertNotRegex ( output , ' iseq ' )
self . assertNotRegex ( output , ' oseq ' )
2019-03-21 19:48:49 +03:00
def test_ip6gre_tunnel ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 12-dummy.netdev ' , ' ip6gretun.network ' ,
' 25-ip6gre-tunnel.netdev ' , ' 25-tunnel.network ' ,
' 25-ip6gre-tunnel-local-any.netdev ' , ' 25-tunnel-local-any.network ' ,
2019-07-11 05:39:27 +03:00
' 25-ip6gre-tunnel-remote-any.netdev ' , ' 25-tunnel-remote-any.network ' ,
' 25-ip6gre-tunnel-any-any.netdev ' , ' 25-tunnel-any-any.network ' )
2019-06-14 10:47:06 +03:00
start_networkd ( 5 )
2019-03-21 19:48:49 +03:00
2019-05-22 12:02:20 +03:00
# Old kernels seem not to support IPv6LL address on ip6gre tunnel, So please do not use wait_online() here.
2019-05-20 04:05:50 +03:00
self . check_link_exists ( ' dummy98 ' )
self . check_link_exists ( ' ip6gretun99 ' )
self . check_link_exists ( ' ip6gretun98 ' )
self . check_link_exists ( ' ip6gretun97 ' )
2019-07-11 05:39:27 +03:00
self . check_link_exists ( ' ip6gretun96 ' )
2019-03-21 19:48:49 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show ip6gretun99 ' )
2019-03-21 19:48:49 +03:00
print ( output )
self . assertRegex ( output , ' ip6gre remote 2001:473:fece:cafe::5179 local 2a00:ffde:4567:edde::4987 dev dummy98 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show ip6gretun98 ' )
2019-03-21 19:48:49 +03:00
print ( output )
self . assertRegex ( output , ' ip6gre remote 2001:473:fece:cafe::5179 local any dev dummy98 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show ip6gretun97 ' )
2019-03-21 19:48:49 +03:00
print ( output )
self . assertRegex ( output , ' ip6gre remote any local 2a00:ffde:4567:edde::4987 dev dummy98 ' )
2019-07-11 05:39:27 +03:00
output = check_output ( ' ip -d link show ip6gretun96 ' )
print ( output )
self . assertRegex ( output , ' ip6gre remote any local any dev dummy98 ' )
2018-09-29 15:36:25 +03:00
2019-05-13 00:55:16 +03:00
def test_gretap_tunnel ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 12-dummy.netdev ' , ' gretap.network ' ,
' 25-gretap-tunnel.netdev ' , ' 25-tunnel.network ' ,
' 25-gretap-tunnel-local-any.netdev ' , ' 25-tunnel-local-any.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' gretap99:routable ' , ' gretap98:routable ' , ' dummy98:degraded ' ] )
2019-03-21 19:48:49 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show gretap99 ' )
2019-03-21 19:48:49 +03:00
print ( output )
self . assertRegex ( output , ' gretap remote 10.65.223.239 local 10.65.223.238 dev dummy98 ' )
2019-03-31 09:44:42 +03:00
self . assertRegex ( output , ' ikey 0.0.0.106 ' )
self . assertRegex ( output , ' okey 0.0.0.106 ' )
self . assertRegex ( output , ' iseq ' )
self . assertRegex ( output , ' oseq ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show gretap98 ' )
2019-03-21 19:48:49 +03:00
print ( output )
self . assertRegex ( output , ' gretap remote 10.65.223.239 local any dev dummy98 ' )
2019-03-31 09:44:42 +03:00
self . assertRegex ( output , ' ikey 0.0.0.107 ' )
self . assertRegex ( output , ' okey 0.0.0.107 ' )
self . assertRegex ( output , ' iseq ' )
self . assertRegex ( output , ' oseq ' )
2018-09-29 15:36:25 +03:00
def test_ip6gretap_tunnel ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 12-dummy.netdev ' , ' ip6gretap.network ' ,
' 25-ip6gretap-tunnel.netdev ' , ' 25-tunnel.network ' ,
' 25-ip6gretap-tunnel-local-any.netdev ' , ' 25-tunnel-local-any.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' ip6gretap99:routable ' , ' ip6gretap98:routable ' , ' dummy98:degraded ' ] )
2019-03-21 19:48:49 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show ip6gretap99 ' )
2019-03-21 19:48:49 +03:00
print ( output )
self . assertRegex ( output , ' ip6gretap remote 2001:473:fece:cafe::5179 local 2a00:ffde:4567:edde::4987 dev dummy98 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show ip6gretap98 ' )
2019-03-21 19:48:49 +03:00
print ( output )
self . assertRegex ( output , ' ip6gretap remote 2001:473:fece:cafe::5179 local any dev dummy98 ' )
2018-09-29 15:36:25 +03:00
def test_vti_tunnel ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 12-dummy.netdev ' , ' vti.network ' ,
' 25-vti-tunnel.netdev ' , ' 25-tunnel.network ' ,
' 25-vti-tunnel-local-any.netdev ' , ' 25-tunnel-local-any.network ' ,
2019-07-11 05:39:27 +03:00
' 25-vti-tunnel-remote-any.netdev ' , ' 25-tunnel-remote-any.network ' ,
' 25-vti-tunnel-any-any.netdev ' , ' 25-tunnel-any-any.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' vtitun99:routable ' , ' vtitun98:routable ' , ' vtitun97:routable ' , ' vtitun96:routable ' , ' dummy98:degraded ' ] )
2019-03-21 19:48:49 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show vtitun99 ' )
2019-03-21 19:48:49 +03:00
print ( output )
self . assertRegex ( output , ' vti remote 10.65.223.239 local 10.65.223.238 dev dummy98 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show vtitun98 ' )
2019-03-21 19:48:49 +03:00
print ( output )
self . assertRegex ( output , ' vti remote 10.65.223.239 local any dev dummy98 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show vtitun97 ' )
2019-03-21 19:48:49 +03:00
print ( output )
self . assertRegex ( output , ' vti remote any local 10.65.223.238 dev dummy98 ' )
2019-07-11 05:39:27 +03:00
output = check_output ( ' ip -d link show vtitun96 ' )
print ( output )
self . assertRegex ( output , ' vti remote any local any dev dummy98 ' )
2018-09-29 15:36:25 +03:00
def test_vti6_tunnel ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 12-dummy.netdev ' , ' vti6.network ' ,
' 25-vti6-tunnel.netdev ' , ' 25-tunnel.network ' ,
' 25-vti6-tunnel-local-any.netdev ' , ' 25-tunnel-local-any.network ' ,
' 25-vti6-tunnel-remote-any.netdev ' , ' 25-tunnel-remote-any.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' vti6tun99:routable ' , ' vti6tun98:routable ' , ' vti6tun97:routable ' , ' dummy98:degraded ' ] )
2019-03-21 19:48:49 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show vti6tun99 ' )
2019-03-21 19:48:49 +03:00
print ( output )
self . assertRegex ( output , ' vti6 remote 2001:473:fece:cafe::5179 local 2a00:ffde:4567:edde::4987 dev dummy98 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show vti6tun98 ' )
2019-03-21 19:48:49 +03:00
print ( output )
2019-10-31 19:19:23 +03:00
self . assertRegex ( output , ' vti6 remote 2001:473:fece:cafe::5179 local (any|::) dev dummy98 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show vti6tun97 ' )
2019-03-21 19:48:49 +03:00
print ( output )
2019-10-31 19:19:23 +03:00
self . assertRegex ( output , ' vti6 remote (any|::) local 2a00:ffde:4567:edde::4987 dev dummy98 ' )
2018-09-29 15:36:25 +03:00
def test_ip6tnl_tunnel ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 12-dummy.netdev ' , ' ip6tnl.network ' ,
' 25-ip6tnl-tunnel.netdev ' , ' 25-tunnel.network ' ,
' 25-ip6tnl-tunnel-local-any.netdev ' , ' 25-tunnel-local-any.network ' ,
' 25-ip6tnl-tunnel-remote-any.netdev ' , ' 25-tunnel-remote-any.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' ip6tnl99:routable ' , ' ip6tnl98:routable ' , ' ip6tnl97:routable ' , ' dummy98:degraded ' ] )
2019-03-21 19:48:49 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show ip6tnl99 ' )
2019-03-21 19:48:49 +03:00
print ( output )
self . assertRegex ( output , ' ip6tnl ip6ip6 remote 2001:473:fece:cafe::5179 local 2a00:ffde:4567:edde::4987 dev dummy98 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show ip6tnl98 ' )
2019-03-21 19:48:49 +03:00
print ( output )
2019-10-31 19:19:23 +03:00
self . assertRegex ( output , ' ip6tnl ip6ip6 remote 2001:473:fece:cafe::5179 local (any|::) dev dummy98 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show ip6tnl97 ' )
2019-03-21 19:48:49 +03:00
print ( output )
2019-10-31 19:19:23 +03:00
self . assertRegex ( output , ' ip6tnl ip6ip6 remote (any|::) local 2a00:ffde:4567:edde::4987 dev dummy98 ' )
2018-09-29 15:36:25 +03:00
def test_sit_tunnel ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 12-dummy.netdev ' , ' sit.network ' ,
' 25-sit-tunnel.netdev ' , ' 25-tunnel.network ' ,
' 25-sit-tunnel-local-any.netdev ' , ' 25-tunnel-local-any.network ' ,
2019-07-11 05:39:27 +03:00
' 25-sit-tunnel-remote-any.netdev ' , ' 25-tunnel-remote-any.network ' ,
' 25-sit-tunnel-any-any.netdev ' , ' 25-tunnel-any-any.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' sittun99:routable ' , ' sittun98:routable ' , ' sittun97:routable ' , ' sittun96:routable ' , ' dummy98:degraded ' ] )
2019-03-21 19:48:49 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show sittun99 ' )
2019-03-21 19:48:49 +03:00
print ( output )
2019-10-31 19:19:23 +03:00
self . assertRegex ( output , " sit (ip6ip )?remote 10.65.223.239 local 10.65.223.238 dev dummy98 " )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show sittun98 ' )
2019-03-21 19:48:49 +03:00
print ( output )
2019-10-31 19:19:23 +03:00
self . assertRegex ( output , " sit (ip6ip )?remote 10.65.223.239 local any dev dummy98 " )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show sittun97 ' )
2019-03-21 19:48:49 +03:00
print ( output )
2019-10-31 19:19:23 +03:00
self . assertRegex ( output , " sit (ip6ip )?remote any local 10.65.223.238 dev dummy98 " )
2019-07-11 05:39:27 +03:00
output = check_output ( ' ip -d link show sittun96 ' )
print ( output )
2019-10-31 19:19:23 +03:00
self . assertRegex ( output , " sit (ip6ip )?remote any local any dev dummy98 " )
2018-09-29 15:36:25 +03:00
2018-12-02 17:59:13 +03:00
def test_isatap_tunnel ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 12-dummy.netdev ' , ' isatap.network ' ,
' 25-isatap-tunnel.netdev ' , ' 25-tunnel.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' isataptun99:routable ' , ' dummy98:degraded ' ] )
2018-12-02 17:59:13 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show isataptun99 ' )
2018-12-06 17:12:28 +03:00
print ( output )
2018-12-02 17:59:13 +03:00
self . assertRegex ( output , " isatap " )
2018-11-09 07:44:16 +03:00
def test_6rd_tunnel ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 12-dummy.netdev ' , ' 6rd.network ' ,
' 25-6rd-tunnel.netdev ' , ' 25-tunnel.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' sittun99:routable ' , ' dummy98:degraded ' ] )
2018-11-09 07:44:16 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show sittun99 ' )
2019-03-21 19:48:49 +03:00
print ( output )
self . assertRegex ( output , ' 6rd-prefix 2602::/24 ' )
2019-01-30 14:52:37 +03:00
@expectedFailureIfERSPANModuleIsNotAvailable ( )
2018-11-26 14:50:09 +03:00
def test_erspan_tunnel ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 12-dummy.netdev ' , ' erspan.network ' ,
' 25-erspan-tunnel.netdev ' , ' 25-tunnel.network ' ,
' 25-erspan-tunnel-local-any.netdev ' , ' 25-tunnel-local-any.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' erspan99:routable ' , ' erspan98:routable ' , ' dummy98:degraded ' ] )
2018-11-26 14:50:09 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show erspan99 ' )
2019-03-21 19:48:49 +03:00
print ( output )
self . assertRegex ( output , ' erspan remote 172.16.1.100 local 172.16.1.200 ' )
2019-03-31 09:44:42 +03:00
self . assertRegex ( output , ' ikey 0.0.0.101 ' )
self . assertRegex ( output , ' okey 0.0.0.101 ' )
self . assertRegex ( output , ' iseq ' )
self . assertRegex ( output , ' oseq ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show erspan98 ' )
2018-11-26 14:50:09 +03:00
print ( output )
2019-03-21 19:48:49 +03:00
self . assertRegex ( output , ' erspan remote 172.16.1.100 local any ' )
self . assertRegex ( output , ' 102 ' )
2019-03-31 09:44:42 +03:00
self . assertRegex ( output , ' ikey 0.0.0.102 ' )
self . assertRegex ( output , ' okey 0.0.0.102 ' )
self . assertRegex ( output , ' iseq ' )
self . assertRegex ( output , ' oseq ' )
2018-11-26 14:50:09 +03:00
2018-09-29 15:36:25 +03:00
def test_tunnel_independent ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-ipip-tunnel-independent.netdev ' , ' netdev-link-local-addressing-yes.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2018-12-06 17:14:57 +03:00
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' ipiptun99:carrier ' ] )
2018-09-29 15:36:25 +03:00
2019-07-10 17:53:30 +03:00
def test_tunnel_independent_loopback ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-ipip-tunnel-independent-loopback.netdev ' , ' netdev-link-local-addressing-yes.network ' )
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' ipiptun99:carrier ' ] )
2019-07-10 17:53:30 +03:00
2019-07-10 17:54:26 +03:00
@expectedFailureIfModuleIsNotAvailable ( ' xfrm_interface ' )
def test_xfrm ( self ) :
copy_unit_to_networkd_unit_path ( ' 12-dummy.netdev ' , ' xfrm.network ' ,
' 25-xfrm.netdev ' , ' netdev-link-local-addressing-yes.network ' )
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' xfrm99:degraded ' , ' dummy98:degraded ' ] )
2019-07-10 17:54:26 +03:00
output = check_output ( ' ip link show dev xfrm99 ' )
print ( output )
@expectedFailureIfModuleIsNotAvailable ( ' xfrm_interface ' )
def test_xfrm_independent ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-xfrm-independent.netdev ' , ' netdev-link-local-addressing-yes.network ' )
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' xfrm99:degraded ' ] )
2019-07-10 17:54:26 +03:00
2019-03-31 16:04:00 +03:00
@expectedFailureIfModuleIsNotAvailable ( ' fou ' )
def test_fou ( self ) :
# The following redundant check is necessary for CentOS CI.
# Maybe, error handling in lookup_id() in sd-netlink/generic-netlink.c needs to be updated.
self . assertTrue ( is_module_available ( ' fou ' ) )
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-fou-ipproto-ipip.netdev ' , ' 25-fou-ipproto-gre.netdev ' ,
' 25-fou-ipip.netdev ' , ' 25-fou-sit.netdev ' ,
' 25-fou-gre.netdev ' , ' 25-fou-gretap.netdev ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-03-31 16:04:00 +03:00
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' ipiptun96:off ' , ' sittun96:off ' , ' gretun96:off ' , ' gretap96:off ' ] , setup_state = ' unmanaged ' )
2019-03-31 16:04:00 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip fou show ' )
2019-03-31 16:04:00 +03:00
print ( output )
self . assertRegex ( output , ' port 55555 ipproto 4 ' )
self . assertRegex ( output , ' port 55556 ipproto 47 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show ipiptun96 ' )
2019-03-31 16:04:00 +03:00
print ( output )
self . assertRegex ( output , ' encap fou encap-sport auto encap-dport 55555 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show sittun96 ' )
2019-03-31 16:04:00 +03:00
print ( output )
self . assertRegex ( output , ' encap fou encap-sport auto encap-dport 55555 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show gretun96 ' )
2019-03-31 16:04:00 +03:00
print ( output )
self . assertRegex ( output , ' encap fou encap-sport 1001 encap-dport 55556 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show gretap96 ' )
2019-03-31 16:04:00 +03:00
print ( output )
self . assertRegex ( output , ' encap fou encap-sport auto encap-dport 55556 ' )
2018-09-29 15:36:25 +03:00
def test_vxlan ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-vxlan.netdev ' , ' vxlan.network ' ,
2020-09-17 09:58:41 +03:00
' 25-vxlan-independent.netdev ' , ' netdev-link-local-addressing-yes.network ' ,
2019-06-05 13:08:09 +03:00
' 11-dummy.netdev ' , ' vxlan-test1.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2018-09-29 15:36:25 +03:00
2020-09-17 09:58:41 +03:00
self . wait_online ( [ ' test1:degraded ' , ' vxlan99:degraded ' , ' vxlan98:degraded ' ] )
2018-09-29 15:36:25 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show vxlan99 ' )
2018-12-06 17:12:28 +03:00
print ( output )
2019-05-03 07:08:55 +03:00
self . assertRegex ( output , ' 999 ' )
2018-09-29 15:36:25 +03:00
self . assertRegex ( output , ' 5555 ' )
self . assertRegex ( output , ' l2miss ' )
self . assertRegex ( output , ' l3miss ' )
self . assertRegex ( output , ' udpcsum ' )
self . assertRegex ( output , ' udp6zerocsumtx ' )
self . assertRegex ( output , ' udp6zerocsumrx ' )
self . assertRegex ( output , ' remcsumtx ' )
self . assertRegex ( output , ' remcsumrx ' )
self . assertRegex ( output , ' gbp ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' bridge fdb show dev vxlan99 ' )
2019-05-03 07:08:55 +03:00
print ( output )
self . assertRegex ( output , ' 00:11:22:33:44:55 dst 10.0.0.5 self permanent ' )
self . assertRegex ( output , ' 00:11:22:33:44:66 dst 10.0.0.6 self permanent ' )
self . assertRegex ( output , ' 00:11:22:33:44:77 dst 10.0.0.7 self permanent ' )
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' vxlan99 ' , env = env )
2019-07-28 09:23:39 +03:00
print ( output )
self . assertRegex ( output , ' VNI: 999 ' )
self . assertRegex ( output , ' Destination Port: 5555 ' )
self . assertRegex ( output , ' Underlying Device: test1 ' )
2020-09-17 09:58:41 +03:00
output = check_output ( ' ip -d link show vxlan98 ' )
print ( output )
2019-04-05 09:58:50 +03:00
def test_macsec ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-macsec.netdev ' , ' 25-macsec.network ' , ' 25-macsec.key ' ,
' macsec.network ' , ' 12-dummy.netdev ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-04-05 09:58:50 +03:00
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' dummy98:degraded ' , ' macsec99:routable ' ] )
2019-04-05 09:58:50 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show macsec99 ' )
2019-04-05 09:58:50 +03:00
print ( output )
self . assertRegex ( output , ' macsec99@dummy98 ' )
self . assertRegex ( output , ' macsec sci [0-9a-f]*000b ' )
self . assertRegex ( output , ' encrypt on ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip macsec show macsec99 ' )
2019-04-05 09:58:50 +03:00
print ( output )
self . assertRegex ( output , ' encrypt on ' )
self . assertRegex ( output , ' TXSC: [0-9a-f]*000b on SA 1 ' )
self . assertRegex ( output , ' 0: PN [0-9]*, state on, key 01000000000000000000000000000000 ' )
self . assertRegex ( output , ' 1: PN [0-9]*, state on, key 02030000000000000000000000000000 ' )
self . assertRegex ( output , ' RXSC: c619528fe6a00100, state on ' )
self . assertRegex ( output , ' 0: PN [0-9]*, state on, key 02030405000000000000000000000000 ' )
self . assertRegex ( output , ' 1: PN [0-9]*, state on, key 02030405060000000000000000000000 ' )
self . assertRegex ( output , ' 2: PN [0-9]*, state off, key 02030405060700000000000000000000 ' )
self . assertRegex ( output , ' 3: PN [0-9]*, state off, key 02030405060708000000000000000000 ' )
self . assertNotRegex ( output , ' key 02030405067080900000000000000000 ' )
self . assertRegex ( output , ' RXSC: 8c16456c83a90002, state on ' )
self . assertRegex ( output , ' 0: PN [0-9]*, state off, key 02030400000000000000000000000000 ' )
2019-05-23 05:37:53 +03:00
def test_nlmon ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-nlmon.netdev ' , ' netdev-link-local-addressing-yes.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-05-23 05:37:53 +03:00
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' nlmon99:carrier ' ] )
2019-04-05 09:58:50 +03:00
2019-12-07 18:03:29 +03:00
@expectedFailureIfModuleIsNotAvailable ( ' ifb ' )
def test_ifb ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-ifb.netdev ' , ' netdev-link-local-addressing-yes.network ' )
start_networkd ( )
self . wait_online ( [ ' ifb99:degraded ' ] )
2019-03-12 11:11:24 +03:00
class NetworkdL2TPTests ( unittest . TestCase , Utilities ) :
links = [
' l2tp-ses1 ' ,
' l2tp-ses2 ' ,
' l2tp-ses3 ' ,
' l2tp-ses4 ' ,
' test1 ' ]
units = [
' 11-dummy.netdev ' ,
' 25-l2tp-dummy.network ' ,
2019-07-15 08:18:06 +03:00
' 25-l2tp.network ' ,
2019-03-12 11:11:24 +03:00
' 25-l2tp-ip.netdev ' ,
' 25-l2tp-udp.netdev ' ]
l2tp_tunnel_ids = [ ' 10 ' ]
def setUp ( self ) :
2019-06-17 05:11:30 +03:00
remove_l2tp_tunnels ( self . l2tp_tunnel_ids )
2019-06-05 13:08:09 +03:00
remove_links ( self . links )
2019-07-03 21:46:14 +03:00
stop_networkd ( show_logs = False )
2019-03-12 11:11:24 +03:00
def tearDown ( self ) :
2019-06-17 05:11:30 +03:00
remove_l2tp_tunnels ( self . l2tp_tunnel_ids )
2019-06-05 13:08:09 +03:00
remove_links ( self . links )
remove_unit_from_networkd_path ( self . units )
2019-07-03 21:46:14 +03:00
stop_networkd ( show_logs = True )
2019-03-12 11:11:24 +03:00
@expectedFailureIfModuleIsNotAvailable ( ' l2tp_eth ' )
def test_l2tp_udp ( self ) :
2019-07-15 08:18:06 +03:00
copy_unit_to_networkd_unit_path ( ' 11-dummy.netdev ' , ' 25-l2tp-dummy.network ' ,
' 25-l2tp-udp.netdev ' , ' 25-l2tp.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-03-12 11:11:24 +03:00
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' test1:routable ' , ' l2tp-ses1:degraded ' , ' l2tp-ses2:degraded ' ] )
2019-03-12 11:11:24 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip l2tp show tunnel tunnel_id 10 ' )
2019-03-12 11:11:24 +03:00
print ( output )
self . assertRegex ( output , " Tunnel 10, encap UDP " )
self . assertRegex ( output , " From 192.168.30.100 to 192.168.30.101 " )
self . assertRegex ( output , " Peer tunnel 11 " )
self . assertRegex ( output , " UDP source / dest ports: 3000/4000 " )
self . assertRegex ( output , " UDP checksum: enabled " )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip l2tp show session tid 10 session_id 15 ' )
2019-03-12 11:11:24 +03:00
print ( output )
self . assertRegex ( output , " Session 15 in tunnel 10 " )
self . assertRegex ( output , " Peer session 16, tunnel 11 " )
self . assertRegex ( output , " interface name: l2tp-ses1 " )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip l2tp show session tid 10 session_id 17 ' )
2019-03-12 11:11:24 +03:00
print ( output )
self . assertRegex ( output , " Session 17 in tunnel 10 " )
self . assertRegex ( output , " Peer session 18, tunnel 11 " )
self . assertRegex ( output , " interface name: l2tp-ses2 " )
@expectedFailureIfModuleIsNotAvailable ( ' l2tp_ip ' )
def test_l2tp_ip ( self ) :
2019-07-15 08:18:06 +03:00
copy_unit_to_networkd_unit_path ( ' 11-dummy.netdev ' , ' 25-l2tp-dummy.network ' ,
' 25-l2tp-ip.netdev ' , ' 25-l2tp.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-03-12 11:11:24 +03:00
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' test1:routable ' , ' l2tp-ses3:degraded ' , ' l2tp-ses4:degraded ' ] )
2019-03-12 11:11:24 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip l2tp show tunnel tunnel_id 10 ' )
2019-03-12 11:11:24 +03:00
print ( output )
self . assertRegex ( output , " Tunnel 10, encap IP " )
self . assertRegex ( output , " From 192.168.30.100 to 192.168.30.101 " )
self . assertRegex ( output , " Peer tunnel 12 " )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip l2tp show session tid 10 session_id 25 ' )
2019-03-12 11:11:24 +03:00
print ( output )
self . assertRegex ( output , " Session 25 in tunnel 10 " )
self . assertRegex ( output , " Peer session 26, tunnel 12 " )
self . assertRegex ( output , " interface name: l2tp-ses3 " )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip l2tp show session tid 10 session_id 27 ' )
2019-03-12 11:11:24 +03:00
print ( output )
self . assertRegex ( output , " Session 27 in tunnel 10 " )
self . assertRegex ( output , " Peer session 28, tunnel 12 " )
self . assertRegex ( output , " interface name: l2tp-ses4 " )
2019-05-24 09:17:41 +03:00
class NetworkdNetworkTests ( unittest . TestCase , Utilities ) :
2018-12-06 16:57:20 +03:00
links = [
' bond199 ' ,
' dummy98 ' ,
2019-02-07 08:22:23 +03:00
' dummy99 ' ,
2019-07-10 21:26:30 +03:00
' gretun97 ' ,
2019-07-18 07:09:42 +03:00
' ip6gretun97 ' ,
2019-10-14 15:18:01 +03:00
' test1 ' ,
' veth99 ' ,
2020-02-26 09:55:08 +03:00
' vrf99 ' ,
2019-07-10 21:26:30 +03:00
]
2018-12-06 16:57:20 +03:00
units = [
' 11-dummy.netdev ' ,
' 12-dummy.netdev ' ,
' 23-active-slave.network ' ,
2019-06-03 07:21:13 +03:00
' 24-keep-configuration-static.network ' ,
2019-05-24 09:34:19 +03:00
' 24-search-domain.network ' ,
2019-12-06 17:29:28 +03:00
' 25-address-dad-veth-peer.network ' ,
' 25-address-dad-veth99.network ' ,
2018-12-06 16:57:20 +03:00
' 25-address-link-section.network ' ,
2020-10-13 06:36:26 +03:00
' 25-address-peer-ipv4.network ' ,
2019-08-17 20:15:11 +03:00
' 25-address-preferred-lifetime-zero.network ' ,
2019-03-21 23:08:20 +03:00
' 25-address-static.network ' ,
2019-02-07 08:22:23 +03:00
' 25-bind-carrier.network ' ,
2018-12-06 16:57:20 +03:00
' 25-bond-active-backup-slave.netdev ' ,
' 25-fibrule-invert.network ' ,
' 25-fibrule-port-range.network ' ,
2020-01-26 16:39:32 +03:00
' 25-fibrule-uidrange.network ' ,
2019-07-10 21:26:30 +03:00
' 25-gre-tunnel-remote-any.netdev ' ,
2019-07-18 07:09:42 +03:00
' 25-ip6gre-tunnel-remote-any.netdev ' ,
2018-12-06 16:57:20 +03:00
' 25-ipv6-address-label-section.network ' ,
2019-10-29 18:33:19 +03:00
' 25-link-local-addressing-no.network ' ,
' 25-link-local-addressing-yes.network ' ,
' 25-link-section-unmanaged.network ' ,
2018-11-29 06:00:58 +03:00
' 25-neighbor-section.network ' ,
2019-04-19 10:53:34 +03:00
' 25-neighbor-next.network ' ,
2019-07-18 07:09:42 +03:00
' 25-neighbor-ipv6.network ' ,
2019-07-10 21:26:30 +03:00
' 25-neighbor-ip-dummy.network ' ,
' 25-neighbor-ip.network ' ,
2019-10-14 15:18:01 +03:00
' 25-nexthop.network ' ,
2020-02-17 15:03:12 +03:00
' 25-qdisc-cake.network ' ,
2020-02-12 03:53:15 +03:00
' 25-qdisc-clsact-and-htb.network ' ,
2020-03-11 18:58:25 +03:00
' 25-qdisc-drr.network ' ,
2020-06-09 11:24:04 +03:00
' 25-qdisc-ets.network ' ,
2020-09-17 11:18:48 +03:00
' 25-qdisc-fq_pie.network ' ,
2020-03-11 20:40:29 +03:00
' 25-qdisc-hhf.network ' ,
2020-02-05 13:23:11 +03:00
' 25-qdisc-ingress-netem-compat.network ' ,
2020-03-11 16:48:10 +03:00
' 25-qdisc-pie.network ' ,
2020-06-03 09:18:55 +03:00
' 25-qdisc-qfq.network ' ,
2020-06-04 07:21:02 +03:00
' 25-prefix-route-with-vrf.network ' ,
' 25-prefix-route-without-vrf.network ' ,
2019-01-14 17:15:15 +03:00
' 25-route-ipv6-src.network ' ,
2019-03-27 23:53:45 +03:00
' 25-route-static.network ' ,
2020-08-13 19:52:19 +03:00
' 25-route-via-ipv6.network ' ,
2020-02-26 09:55:08 +03:00
' 25-route-vrf.network ' ,
2019-04-19 03:52:28 +03:00
' 25-gateway-static.network ' ,
' 25-gateway-next-static.network ' ,
2020-06-22 13:48:34 +03:00
' 25-sriov.network ' ,
2019-02-18 09:26:26 +03:00
' 25-sysctl-disable-ipv6.network ' ,
2018-12-06 16:57:20 +03:00
' 25-sysctl.network ' ,
2020-04-27 22:35:30 +03:00
' 25-test1.network ' ,
2019-10-14 15:18:01 +03:00
' 25-veth-peer.network ' ,
' 25-veth.netdev ' ,
2020-02-26 09:55:08 +03:00
' 25-vrf.netdev ' ,
2020-06-04 07:21:02 +03:00
' 25-vrf.network ' ,
2019-09-16 00:16:48 +03:00
' 26-link-local-addressing-ipv6.network ' ,
2019-02-22 06:28:51 +03:00
' routing-policy-rule-dummy98.network ' ,
2020-09-08 23:09:58 +03:00
' routing-policy-rule-test1.network ' ,
' routing-policy-rule-reconfigure.network ' ,
]
2018-09-29 15:36:25 +03:00
2020-09-08 23:09:58 +03:00
routing_policy_rule_tables = [ ' 7 ' , ' 8 ' , ' 9 ' , ' 1011 ' ]
2019-05-24 07:49:51 +03:00
routes = [ [ ' blackhole ' , ' 202.54.1.2 ' ] , [ ' unreachable ' , ' 202.54.1.3 ' ] , [ ' prohibit ' , ' 202.54.1.4 ' ] ]
2019-05-24 07:44:49 +03:00
2018-09-29 15:36:25 +03:00
def setUp ( self ) :
2019-06-05 13:08:09 +03:00
remove_routing_policy_rule_tables ( self . routing_policy_rule_tables )
remove_routes ( self . routes )
remove_links ( self . links )
2019-07-03 21:46:14 +03:00
stop_networkd ( show_logs = False )
2018-09-29 15:36:25 +03:00
def tearDown ( self ) :
2019-06-05 13:08:09 +03:00
remove_routing_policy_rule_tables ( self . routing_policy_rule_tables )
remove_routes ( self . routes )
remove_links ( self . links )
remove_unit_from_networkd_path ( self . units )
2019-07-03 21:46:14 +03:00
stop_networkd ( show_logs = True )
2018-09-29 15:36:25 +03:00
2019-03-21 23:08:20 +03:00
def test_address_static ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-address-static.network ' , ' 12-dummy.netdev ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-03-21 23:08:20 +03:00
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' dummy98:routable ' ] )
2019-03-21 23:08:20 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -4 address show dev dummy98 ' )
2019-03-21 23:08:20 +03:00
print ( output )
self . assertRegex ( output , ' inet 10.1.2.3/16 brd 10.1.255.255 scope global dummy98 ' )
self . assertRegex ( output , ' inet 10.1.2.4/16 brd 10.1.255.255 scope global secondary dummy98 ' )
self . assertRegex ( output , ' inet 10.2.2.4/16 brd 10.2.255.255 scope global dummy98 ' )
2020-09-11 07:57:07 +03:00
# test for ENOBUFS issue #17012
for i in range ( 1 , 254 ) :
self . assertRegex ( output , f ' inet 10.3.3. { i } /16 brd 10.3.255.255 ' )
2019-03-21 23:08:20 +03:00
# invalid sections
self . assertNotRegex ( output , ' 10.10.0.1/16 ' )
self . assertNotRegex ( output , ' 10.10.0.2/16 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -4 address show dev dummy98 label 32 ' )
2019-03-21 23:08:20 +03:00
self . assertRegex ( output , ' inet 10.3.2.3/16 brd 10.3.255.255 scope global 32 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -4 address show dev dummy98 label 33 ' )
2019-03-21 23:08:20 +03:00
self . assertRegex ( output , ' inet 10.4.2.3 peer 10.4.2.4/16 scope global 33 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -4 address show dev dummy98 label 34 ' )
2019-03-21 23:08:20 +03:00
self . assertRegex ( output , ' inet 192.168.[0-9]*.1/24 brd 192.168.[0-9]*.255 scope global 34 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -4 address show dev dummy98 label 35 ' )
2019-03-21 23:08:20 +03:00
self . assertRegex ( output , ' inet 172.[0-9]*.0.1/16 brd 172.[0-9]*.255.255 scope global 35 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -6 address show dev dummy98 ' )
2019-03-21 23:08:20 +03:00
print ( output )
self . assertRegex ( output , ' inet6 2001:db8:0:f101::15/64 scope global ' )
self . assertRegex ( output , ' inet6 2001:db8:0:f101::16/64 scope global ' )
self . assertRegex ( output , ' inet6 2001:db8:0:f102::15/64 scope global ' )
self . assertRegex ( output , ' inet6 2001:db8:0:f102::16/64 scope global ' )
self . assertRegex ( output , ' inet6 2001:db8:0:f103::20 peer 2001:db8:0:f103::10/128 scope global ' )
self . assertRegex ( output , ' inet6 fd[0-9a-f:]*1/64 scope global ' )
2020-09-11 07:57:07 +03:00
restart_networkd ( )
self . wait_online ( [ ' dummy98:routable ' ] )
# test for ENOBUFS issue #17012
output = check_output ( ' ip -4 address show dev dummy98 ' )
for i in range ( 1 , 254 ) :
self . assertRegex ( output , f ' inet 10.3.3. { i } /16 brd 10.3.255.255 ' )
2019-03-21 23:08:20 +03:00
def test_address_preferred_lifetime_zero_ipv6 ( self ) :
2019-08-17 20:15:11 +03:00
copy_unit_to_networkd_unit_path ( ' 25-address-preferred-lifetime-zero.network ' , ' 12-dummy.netdev ' )
2019-06-14 10:47:06 +03:00
start_networkd ( 5 )
2018-09-29 15:36:25 +03:00
2019-08-17 20:15:11 +03:00
self . wait_online ( [ ' dummy98:routable ' ] )
2019-03-21 23:08:20 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip address show dummy98 ' )
2019-03-21 23:08:20 +03:00
print ( output )
self . assertRegex ( output , ' inet 10.2.3.4/16 brd 10.2.255.255 scope link deprecated dummy98 ' )
self . assertRegex ( output , ' inet6 2001:db8:0:f101::1/64 scope global ' )
2018-09-29 15:36:25 +03:00
2019-08-17 20:15:11 +03:00
output = check_output ( ' ip route show dev dummy98 ' )
print ( output )
self . assertRegex ( output , ' default via 20.20.20.1 proto static ' )
2019-12-06 17:29:28 +03:00
def test_address_dad ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-address-dad-veth99.network ' , ' 25-address-dad-veth-peer.network ' ,
' 25-veth.netdev ' )
start_networkd ( )
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:degraded ' ] )
output = check_output ( ' ip -4 address show dev veth99 ' )
print ( output )
self . assertRegex ( output , ' 192.168.100.10/24 ' )
output = check_output ( ' ip -4 address show dev veth-peer ' )
print ( output )
self . assertNotRegex ( output , ' 192.168.100.10/24 ' )
2020-10-13 06:36:26 +03:00
def test_address_peer_ipv4 ( self ) :
# test for issue #17304
copy_unit_to_networkd_unit_path ( ' 25-address-peer-ipv4.network ' , ' 12-dummy.netdev ' )
for trial in range ( 2 ) :
if trial == 0 :
start_networkd ( )
else :
restart_networkd ( )
self . wait_online ( [ ' dummy98:routable ' ] )
output = check_output ( ' ip -4 address show dev dummy98 ' )
self . assertIn ( ' inet 100.64.0.1 peer 100.64.0.2/32 scope global ' , output )
2020-06-04 07:21:02 +03:00
@expectedFailureIfModuleIsNotAvailable ( ' vrf ' )
def test_prefix_route ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-prefix-route-with-vrf.network ' , ' 12-dummy.netdev ' ,
' 25-prefix-route-without-vrf.network ' , ' 11-dummy.netdev ' ,
' 25-vrf.netdev ' , ' 25-vrf.network ' )
for trial in range ( 2 ) :
if trial == 0 :
start_networkd ( )
else :
restart_networkd ( 3 )
self . wait_online ( [ ' dummy98:routable ' , ' test1:routable ' , ' vrf99:carrier ' ] )
output = check_output ( ' ip route show table 42 dev dummy98 ' )
print ( ' ### ip route show table 42 dev dummy98 ' )
print ( output )
self . assertRegex ( output , ' local 10.20.22.1 proto kernel scope host src 10.20.22.1 ' )
self . assertRegex ( output , ' broadcast 10.20.33.0 proto kernel scope link src 10.20.33.1 ' )
self . assertRegex ( output , ' 10.20.33.0/24 proto kernel scope link src 10.20.33.1 ' )
self . assertRegex ( output , ' local 10.20.33.1 proto kernel scope host src 10.20.33.1 ' )
self . assertRegex ( output , ' broadcast 10.20.33.255 proto kernel scope link src 10.20.33.1 ' )
self . assertRegex ( output , ' local 10.20.44.1 proto kernel scope host src 10.20.44.1 ' )
self . assertRegex ( output , ' broadcast 10.20.55.0 proto kernel scope link src 10.20.55.1 ' )
self . assertRegex ( output , ' local 10.20.55.1 proto kernel scope host src 10.20.55.1 ' )
self . assertRegex ( output , ' broadcast 10.20.55.255 proto kernel scope link src 10.20.55.1 ' )
output = check_output ( ' ip -6 route show table 42 dev dummy98 ' )
print ( ' ### ip -6 route show table 42 dev dummy98 ' )
print ( output )
if trial == 0 :
# Kernel's bug?
self . assertRegex ( output , ' local fdde:11:22::1 proto kernel metric 0 pref medium ' )
#self.assertRegex(output, 'fdde:11:22::1 proto kernel metric 256 pref medium')
self . assertRegex ( output , ' local fdde:11:33::1 proto kernel metric 0 pref medium ' )
self . assertRegex ( output , ' fdde:11:33::/64 proto kernel metric 256 pref medium ' )
self . assertRegex ( output , ' local fdde:11:44::1 proto kernel metric 0 pref medium ' )
self . assertRegex ( output , ' local fdde:11:55::1 proto kernel metric 0 pref medium ' )
self . assertRegex ( output , ' fe80::/64 proto kernel metric 256 pref medium ' )
self . assertRegex ( output , ' ff00::/8 metric 256 pref medium ' )
print ( )
output = check_output ( ' ip route show dev test1 ' )
print ( ' ### ip route show dev test1 ' )
print ( output )
self . assertRegex ( output , ' 10.21.33.0/24 proto kernel scope link src 10.21.33.1 ' )
output = check_output ( ' ip route show table local dev test1 ' )
print ( ' ### ip route show table local dev test1 ' )
print ( output )
self . assertRegex ( output , ' local 10.21.22.1 proto kernel scope host src 10.21.22.1 ' )
self . assertRegex ( output , ' broadcast 10.21.33.0 proto kernel scope link src 10.21.33.1 ' )
self . assertRegex ( output , ' local 10.21.33.1 proto kernel scope host src 10.21.33.1 ' )
self . assertRegex ( output , ' broadcast 10.21.33.255 proto kernel scope link src 10.21.33.1 ' )
self . assertRegex ( output , ' local 10.21.44.1 proto kernel scope host src 10.21.44.1 ' )
self . assertRegex ( output , ' broadcast 10.21.55.0 proto kernel scope link src 10.21.55.1 ' )
self . assertRegex ( output , ' local 10.21.55.1 proto kernel scope host src 10.21.55.1 ' )
self . assertRegex ( output , ' broadcast 10.21.55.255 proto kernel scope link src 10.21.55.1 ' )
output = check_output ( ' ip -6 route show dev test1 ' )
print ( ' ### ip -6 route show dev test1 ' )
print ( output )
self . assertRegex ( output , ' fdde:12:22::1 proto kernel metric 256 pref medium ' )
self . assertRegex ( output , ' fdde:12:33::/64 proto kernel metric 256 pref medium ' )
self . assertRegex ( output , ' fe80::/64 proto kernel metric 256 pref medium ' )
output = check_output ( ' ip -6 route show table local dev test1 ' )
print ( ' ### ip -6 route show table local dev test1 ' )
print ( output )
self . assertRegex ( output , ' local fdde:12:22::1 proto kernel metric 0 pref medium ' )
self . assertRegex ( output , ' local fdde:12:33::1 proto kernel metric 0 pref medium ' )
self . assertRegex ( output , ' local fdde:12:44::1 proto kernel metric 0 pref medium ' )
self . assertRegex ( output , ' local fdde:12:55::1 proto kernel metric 0 pref medium ' )
self . assertRegex ( output , ' ff00::/8 metric 256 pref medium ' )
2018-09-29 15:36:25 +03:00
def test_configure_without_carrier ( self ) :
2020-04-27 22:35:30 +03:00
copy_unit_to_networkd_unit_path ( ' 11-dummy.netdev ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2020-04-27 22:35:30 +03:00
self . wait_operstate ( ' test1 ' , ' off ' , ' ' )
check_output ( ' ip link set dev test1 up carrier off ' )
copy_unit_to_networkd_unit_path ( ' 25-test1.network.d/configure-without-carrier.conf ' , dropins = False )
restart_networkd ( )
self . wait_online ( [ ' test1:no-carrier ' ] )
carrier_map = { ' on ' : ' 1 ' , ' off ' : ' 0 ' }
routable_map = { ' on ' : ' routable ' , ' off ' : ' no-carrier ' }
for carrier in [ ' off ' , ' on ' , ' off ' ] :
with self . subTest ( carrier = carrier ) :
if carrier_map [ carrier ] != read_link_attr ( ' test1 ' , ' carrier ' ) :
check_output ( f ' ip link set dev test1 carrier { carrier } ' )
self . wait_online ( [ f ' test1: { routable_map [ carrier ] } ' ] )
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' test1 ' , env = env )
print ( output )
self . assertRegex ( output , ' 192.168.0.15 ' )
self . assertRegex ( output , ' 192.168.0.1 ' )
self . assertRegex ( output , routable_map [ carrier ] )
2018-12-06 17:14:57 +03:00
2020-04-27 22:35:30 +03:00
def test_configure_without_carrier_yes_ignore_carrier_loss_no ( self ) :
copy_unit_to_networkd_unit_path ( ' 11-dummy.netdev ' )
start_networkd ( )
self . wait_operstate ( ' test1 ' , ' off ' , ' ' )
check_output ( ' ip link set dev test1 up carrier off ' )
copy_unit_to_networkd_unit_path ( ' 25-test1.network ' )
restart_networkd ( )
self . wait_online ( [ ' test1:no-carrier ' ] )
carrier_map = { ' on ' : ' 1 ' , ' off ' : ' 0 ' }
routable_map = { ' on ' : ' routable ' , ' off ' : ' no-carrier ' }
for ( carrier , have_config ) in [ ( ' off ' , True ) , ( ' on ' , True ) , ( ' off ' , False ) ] :
with self . subTest ( carrier = carrier , have_config = have_config ) :
if carrier_map [ carrier ] != read_link_attr ( ' test1 ' , ' carrier ' ) :
check_output ( f ' ip link set dev test1 carrier { carrier } ' )
self . wait_online ( [ f ' test1: { routable_map [ carrier ] } ' ] )
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' test1 ' , env = env )
print ( output )
if have_config :
self . assertRegex ( output , ' 192.168.0.15 ' )
self . assertRegex ( output , ' 192.168.0.1 ' )
else :
self . assertNotRegex ( output , ' 192.168.0.15 ' )
self . assertNotRegex ( output , ' 192.168.0.1 ' )
self . assertRegex ( output , routable_map [ carrier ] )
2018-09-29 15:36:25 +03:00
def test_routing_policy_rule ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' routing-policy-rule-test1.network ' , ' 11-dummy.netdev ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' test1:degraded ' ] )
2018-12-06 17:14:57 +03:00
2019-07-31 06:09:03 +03:00
output = check_output ( ' ip rule list iif test1 priority 111 ' )
2018-09-29 15:36:25 +03:00
print ( output )
2019-07-31 06:09:03 +03:00
self . assertRegex ( output , ' 111: ' )
2018-09-29 15:36:25 +03:00
self . assertRegex ( output , ' from 192.168.100.18 ' )
2019-10-31 19:19:23 +03:00
self . assertRegex ( output , r ' tos (0x08|throughput) \ s ' )
2018-09-29 15:36:25 +03:00
self . assertRegex ( output , ' iif test1 ' )
self . assertRegex ( output , ' oif test1 ' )
self . assertRegex ( output , ' lookup 7 ' )
2019-07-31 06:09:03 +03:00
output = check_output ( ' ip rule list iif test1 priority 101 ' )
print ( output )
self . assertRegex ( output , ' 101: ' )
self . assertRegex ( output , ' from all ' )
self . assertRegex ( output , ' iif test1 ' )
self . assertRegex ( output , ' lookup 9 ' )
output = check_output ( ' ip -6 rule list iif test1 priority 100 ' )
print ( output )
self . assertRegex ( output , ' 100: ' )
self . assertRegex ( output , ' from all ' )
self . assertRegex ( output , ' iif test1 ' )
self . assertRegex ( output , ' lookup 8 ' )
2019-02-22 06:28:51 +03:00
def test_routing_policy_rule_issue_11280 ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' routing-policy-rule-test1.network ' , ' 11-dummy.netdev ' ,
' routing-policy-rule-dummy98.network ' , ' 12-dummy.netdev ' )
2019-02-22 06:28:51 +03:00
for trial in range ( 3 ) :
# Remove state files only first time
2019-07-15 08:18:06 +03:00
start_networkd ( 3 )
self . wait_online ( [ ' test1:degraded ' , ' dummy98:degraded ' ] )
2019-06-14 10:49:39 +03:00
time . sleep ( 1 )
2019-02-22 06:28:51 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip rule list table 7 ' )
2019-02-22 06:28:51 +03:00
print ( output )
2019-10-31 19:19:23 +03:00
self . assertRegex ( output , ' 111: from 192.168.100.18 tos (0x08|throughput) iif test1 oif test1 lookup 7 ' )
2019-02-22 06:28:51 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip rule list table 8 ' )
2019-02-22 06:28:51 +03:00
print ( output )
2019-10-31 19:19:23 +03:00
self . assertRegex ( output , ' 112: from 192.168.101.18 tos (0x08|throughput) iif dummy98 oif dummy98 lookup 8 ' )
2019-02-22 06:28:51 +03:00
2019-07-03 21:46:14 +03:00
stop_networkd ( remove_state_files = False )
2020-09-08 23:09:58 +03:00
def test_routing_policy_rule_reconfigure ( self ) :
copy_unit_to_networkd_unit_path ( ' routing-policy-rule-reconfigure.network ' , ' 11-dummy.netdev ' )
start_networkd ( )
self . wait_online ( [ ' test1:degraded ' ] )
output = check_output ( ' ip rule list table 1011 ' )
print ( output )
self . assertRegex ( output , ' 10111: from all fwmark 0x3f3 lookup 1011 ' )
self . assertRegex ( output , ' 10112: from all oif test1 lookup 1011 ' )
self . assertRegex ( output , ' 10113: from all iif test1 lookup 1011 ' )
self . assertRegex ( output , ' 10114: from 192.168.8.254 lookup 1011 ' )
run ( ' ip rule delete priority 10111 ' )
run ( ' ip rule delete priority 10112 ' )
run ( ' ip rule delete priority 10113 ' )
run ( ' ip rule delete priority 10114 ' )
run ( ' ip rule delete priority 10115 ' )
output = check_output ( ' ip rule list table 1011 ' )
print ( output )
self . assertEqual ( output , ' ' )
run ( * networkctl_cmd , ' reconfigure ' , ' test1 ' , env = env )
self . wait_online ( [ ' test1:degraded ' ] )
output = check_output ( ' ip rule list table 1011 ' )
print ( output )
self . assertRegex ( output , ' 10111: from all fwmark 0x3f3 lookup 1011 ' )
self . assertRegex ( output , ' 10112: from all oif test1 lookup 1011 ' )
self . assertRegex ( output , ' 10113: from all iif test1 lookup 1011 ' )
self . assertRegex ( output , ' 10114: from 192.168.8.254 lookup 1011 ' )
2019-02-06 11:27:28 +03:00
@expectedFailureIfRoutingPolicyPortRangeIsNotAvailable ( )
2018-11-27 08:28:54 +03:00
def test_routing_policy_rule_port_range ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-fibrule-port-range.network ' , ' 11-dummy.netdev ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' test1:degraded ' ] )
2018-12-06 17:14:57 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip rule ' )
2018-11-27 08:28:54 +03:00
print ( output )
self . assertRegex ( output , ' 111 ' )
self . assertRegex ( output , ' from 192.168.100.18 ' )
self . assertRegex ( output , ' 1123-1150 ' )
self . assertRegex ( output , ' 3224-3290 ' )
self . assertRegex ( output , ' tcp ' )
self . assertRegex ( output , ' lookup 7 ' )
2018-09-29 15:36:25 +03:00
2019-02-06 11:27:28 +03:00
@expectedFailureIfRoutingPolicyIPProtoIsNotAvailable ( )
2018-12-06 08:30:36 +03:00
def test_routing_policy_rule_invert ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-fibrule-invert.network ' , ' 11-dummy.netdev ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' test1:degraded ' ] )
2018-12-06 17:14:57 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip rule ' )
2018-12-06 08:30:36 +03:00
print ( output )
self . assertRegex ( output , ' 111 ' )
self . assertRegex ( output , ' not.*?from.*?192.168.100.18 ' )
self . assertRegex ( output , ' tcp ' )
self . assertRegex ( output , ' lookup 7 ' )
2020-01-26 16:39:32 +03:00
@expectedFailureIfRoutingPolicyUIDRangeIsNotAvailable ( )
def test_routing_policy_rule_uidrange ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-fibrule-uidrange.network ' , ' 11-dummy.netdev ' )
start_networkd ( )
self . wait_online ( [ ' test1:degraded ' ] )
output = check_output ( ' ip rule ' )
print ( output )
self . assertRegex ( output , ' 111 ' )
self . assertRegex ( output , ' from 192.168.100.18 ' )
self . assertRegex ( output , ' lookup 7 ' )
self . assertRegex ( output , ' uidrange 100-200 ' )
2019-03-27 23:53:45 +03:00
def test_route_static ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-route-static.network ' , ' 12-dummy.netdev ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' dummy98:routable ' ] )
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' dummy98 ' , env = env )
2019-07-15 08:18:06 +03:00
print ( output )
2018-11-26 20:13:17 +03:00
2019-07-07 15:57:22 +03:00
print ( ' ### ip -6 route show dev dummy98 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -6 route show dev dummy98 ' )
2018-11-26 20:13:17 +03:00
print ( output )
2019-03-27 23:53:45 +03:00
self . assertRegex ( output , ' 2001:1234:5:8fff:ff:ff:ff:ff proto static ' )
self . assertRegex ( output , ' 2001:1234:5:8f63::1 proto kernel ' )
2018-09-29 15:36:25 +03:00
2020-10-07 14:02:00 +03:00
print ( ' ### ip -6 route show default ' )
output = check_output ( ' ip -6 route show default ' )
2019-07-07 15:57:22 +03:00
print ( output )
2020-10-07 14:02:00 +03:00
self . assertRegex ( output , ' default ' )
self . assertRegex ( output , ' via 2001:1234:5:8fff:ff:ff:ff:ff ' )
2018-09-29 15:36:25 +03:00
2019-07-07 15:57:22 +03:00
print ( ' ### ip -4 route show dev dummy98 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -4 route show dev dummy98 ' )
2018-09-29 15:36:25 +03:00
print ( output )
2019-03-27 23:53:45 +03:00
self . assertRegex ( output , ' 149.10.124.48/28 proto kernel scope link src 149.10.124.58 ' )
self . assertRegex ( output , ' 149.10.124.64 proto static scope link ' )
2019-05-15 06:43:36 +03:00
self . assertRegex ( output , ' 169.254.0.0/16 proto static scope link metric 2048 ' )
2019-03-27 23:53:45 +03:00
self . assertRegex ( output , ' 192.168.1.1 proto static initcwnd 20 ' )
self . assertRegex ( output , ' 192.168.1.2 proto static initrwnd 30 ' )
2019-07-07 15:57:22 +03:00
self . assertRegex ( output , ' multicast 149.10.123.4 proto static ' )
2018-09-29 15:36:25 +03:00
2019-07-07 15:57:22 +03:00
print ( ' ### ip -4 route show dev dummy98 default ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -4 route show dev dummy98 default ' )
2019-07-07 15:57:22 +03:00
print ( output )
2019-03-27 23:53:45 +03:00
self . assertRegex ( output , ' default via 149.10.125.65 proto static onlink ' )
self . assertRegex ( output , ' default via 149.10.124.64 proto static ' )
2019-05-07 07:18:30 +03:00
self . assertRegex ( output , ' default proto static ' )
2018-09-29 15:36:25 +03:00
2019-07-07 15:57:22 +03:00
print ( ' ### ip -4 route show table local dev dummy98 ' )
output = check_output ( ' ip -4 route show table local dev dummy98 ' )
print ( output )
self . assertRegex ( output , ' local 149.10.123.1 proto static scope host ' )
self . assertRegex ( output , ' anycast 149.10.123.2 proto static scope link ' )
self . assertRegex ( output , ' broadcast 149.10.123.3 proto static scope link ' )
print ( ' ### ip route show type blackhole ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip route show type blackhole ' )
2018-09-29 15:36:25 +03:00
print ( output )
2019-03-27 23:53:45 +03:00
self . assertRegex ( output , ' blackhole 202.54.1.2 proto static ' )
2018-11-26 09:46:55 +03:00
2019-07-07 15:57:22 +03:00
print ( ' ### ip route show type unreachable ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip route show type unreachable ' )
2018-11-26 09:46:55 +03:00
print ( output )
2019-03-27 23:53:45 +03:00
self . assertRegex ( output , ' unreachable 202.54.1.3 proto static ' )
2018-11-26 09:46:55 +03:00
2019-07-07 15:57:22 +03:00
print ( ' ### ip route show type prohibit ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip route show type prohibit ' )
2018-11-26 09:46:55 +03:00
print ( output )
2019-03-27 23:53:45 +03:00
self . assertRegex ( output , ' prohibit 202.54.1.4 proto static ' )
2018-11-26 09:46:55 +03:00
2019-11-28 19:45:24 +03:00
print ( ' ### ip route show 192.168.10.1 ' )
output = check_output ( ' ip route show 192.168.10.1 ' )
print ( output )
self . assertRegex ( output , ' 192.168.10.1 proto static ' )
self . assertRegex ( output , ' nexthop via 149.10.124.59 dev dummy98 weight 10 ' )
self . assertRegex ( output , ' nexthop via 149.10.124.60 dev dummy98 weight 5 ' )
print ( ' ### ip route show 192.168.10.2 ' )
output = check_output ( ' ip route show 192.168.10.2 ' )
print ( output )
# old ip command does not show IPv6 gateways...
self . assertRegex ( output , ' 192.168.10.2 proto static ' )
self . assertRegex ( output , ' nexthop ' )
self . assertRegex ( output , ' dev dummy98 weight 10 ' )
self . assertRegex ( output , ' dev dummy98 weight 5 ' )
print ( ' ### ip -6 route show 2001:1234:5:7fff:ff:ff:ff:ff ' )
output = check_output ( ' ip -6 route show 2001:1234:5:7fff:ff:ff:ff:ff ' )
print ( output )
# old ip command does not show 'nexthop' keyword and weight...
self . assertRegex ( output , ' 2001:1234:5:7fff:ff:ff:ff:ff ' )
self . assertRegex ( output , ' via 2001:1234:5:8fff:ff:ff:ff:ff dev dummy98 ' )
self . assertRegex ( output , ' via 2001:1234:5:9fff:ff:ff:ff:ff dev dummy98 ' )
2020-08-13 19:52:19 +03:00
@expectedFailureIfRTA_VIAIsNotSupported ( )
def test_route_via_ipv6 ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-route-via-ipv6.network ' , ' 12-dummy.netdev ' )
start_networkd ( )
self . wait_online ( [ ' dummy98:routable ' ] )
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' dummy98 ' , env = env )
print ( output )
print ( ' ### ip -6 route show dev dummy98 ' )
output = check_output ( ' ip -6 route show dev dummy98 ' )
print ( output )
self . assertRegex ( output , ' 2001:1234:5:8fff:ff:ff:ff:ff proto static ' )
self . assertRegex ( output , ' 2001:1234:5:8f63::1 proto kernel ' )
print ( ' ### ip -4 route show dev dummy98 ' )
output = check_output ( ' ip -4 route show dev dummy98 ' )
print ( output )
self . assertRegex ( output , ' 149.10.124.48/28 proto kernel scope link src 149.10.124.58 ' )
self . assertRegex ( output , ' 149.10.124.66 via inet6 2001:1234:5:8fff:ff:ff:ff:ff proto static ' )
2020-02-26 09:55:08 +03:00
@expectedFailureIfModuleIsNotAvailable ( ' vrf ' )
def test_route_vrf ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-route-vrf.network ' , ' 12-dummy.netdev ' ,
' 25-vrf.netdev ' , ' 25-vrf.network ' )
start_networkd ( )
self . wait_online ( [ ' dummy98:routable ' , ' vrf99:carrier ' ] )
output = check_output ( ' ip route show vrf vrf99 ' )
print ( output )
self . assertRegex ( output , ' default via 192.168.100.1 ' )
output = check_output ( ' ip route show ' )
print ( output )
self . assertNotRegex ( output , ' default via 192.168.100.1 ' )
2019-04-19 03:52:28 +03:00
def test_gateway_reconfigure ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-gateway-static.network ' , ' 12-dummy.netdev ' )
start_networkd ( )
self . wait_online ( [ ' dummy98:routable ' ] )
print ( ' ### ip -4 route show dev dummy98 default ' )
output = check_output ( ' ip -4 route show dev dummy98 default ' )
print ( output )
self . assertRegex ( output , ' default via 149.10.124.59 proto static ' )
self . assertNotRegex ( output , ' 149.10.124.60 ' )
remove_unit_from_networkd_path ( [ ' 25-gateway-static.network ' ] )
copy_unit_to_networkd_unit_path ( ' 25-gateway-next-static.network ' )
restart_networkd ( 3 )
self . wait_online ( [ ' dummy98:routable ' ] )
print ( ' ### ip -4 route show dev dummy98 default ' )
output = check_output ( ' ip -4 route show dev dummy98 default ' )
print ( output )
self . assertNotRegex ( output , ' 149.10.124.59 ' )
self . assertRegex ( output , ' default via 149.10.124.60 proto static ' )
2019-01-14 17:15:15 +03:00
def test_ip_route_ipv6_src_route ( self ) :
# a dummy device does not make the addresses go through tentative state, so we
# reuse a bond from an earlier test, which does make the addresses go through
# tentative state, and do our test on that
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 23-active-slave.network ' , ' 25-route-ipv6-src.network ' , ' 25-bond-active-backup-slave.netdev ' , ' 12-dummy.netdev ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' dummy98:enslaved ' , ' bond199:routable ' ] )
2019-01-14 17:15:15 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -6 route list dev bond199 ' )
2019-01-14 17:15:15 +03:00
print ( output )
self . assertRegex ( output , ' abcd::/16 ' )
self . assertRegex ( output , ' src ' )
self . assertRegex ( output , ' 2001:1234:56:8f63::2 ' )
2018-09-29 15:36:25 +03:00
def test_ip_link_mac_address ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-address-link-section.network ' , ' 12-dummy.netdev ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' dummy98:degraded ' ] )
2018-09-29 15:36:25 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip link show dummy98 ' )
2018-09-29 15:36:25 +03:00
print ( output )
self . assertRegex ( output , ' 00:01:02:aa:bb:cc ' )
def test_ip_link_unmanaged ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-link-section-unmanaged.network ' , ' 12-dummy.netdev ' )
2019-06-14 10:49:39 +03:00
start_networkd ( 5 )
2018-09-29 15:36:25 +03:00
2019-05-20 04:05:50 +03:00
self . check_link_exists ( ' dummy98 ' )
2018-09-29 15:36:25 +03:00
2020-01-08 15:25:16 +03:00
self . wait_operstate ( ' dummy98 ' , ' off ' , setup_state = ' unmanaged ' )
2018-09-29 15:36:25 +03:00
def test_ipv6_address_label ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-ipv6-address-label-section.network ' , ' 12-dummy.netdev ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' dummy98:degraded ' ] )
2018-09-29 15:36:25 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip addrlabel list ' )
2018-09-29 15:36:25 +03:00
print ( output )
self . assertRegex ( output , ' 2004:da8:1::/64 ' )
2019-07-10 20:25:21 +03:00
def test_neighbor_section ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-neighbor-section.network ' , ' 12-dummy.netdev ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' dummy98:degraded ' ] , timeout = ' 40s ' )
2018-11-29 06:00:58 +03:00
2019-04-19 10:53:34 +03:00
print ( ' ### ip neigh list dev dummy98 ' )
2019-06-14 10:49:39 +03:00
output = check_output ( ' ip neigh list dev dummy98 ' )
2018-11-29 06:00:58 +03:00
print ( output )
self . assertRegex ( output , ' 192.168.10.1.*00:00:5e:00:02:65.*PERMANENT ' )
2018-12-27 01:16:20 +03:00
self . assertRegex ( output , ' 2004:da8:1::1.*00:00:5e:00:02:66.*PERMANENT ' )
2018-11-29 06:00:58 +03:00
2019-04-19 10:53:34 +03:00
def test_neighbor_reconfigure ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-neighbor-section.network ' , ' 12-dummy.netdev ' )
start_networkd ( )
self . wait_online ( [ ' dummy98:degraded ' ] , timeout = ' 40s ' )
print ( ' ### ip neigh list dev dummy98 ' )
output = check_output ( ' ip neigh list dev dummy98 ' )
print ( output )
self . assertRegex ( output , ' 192.168.10.1.*00:00:5e:00:02:65.*PERMANENT ' )
self . assertRegex ( output , ' 2004:da8:1::1.*00:00:5e:00:02:66.*PERMANENT ' )
remove_unit_from_networkd_path ( [ ' 25-neighbor-section.network ' ] )
copy_unit_to_networkd_unit_path ( ' 25-neighbor-next.network ' )
restart_networkd ( 3 )
self . wait_online ( [ ' dummy98:degraded ' ] , timeout = ' 40s ' )
print ( ' ### ip neigh list dev dummy98 ' )
output = check_output ( ' ip neigh list dev dummy98 ' )
print ( output )
self . assertNotRegex ( output , ' 192.168.10.1.*00:00:5e:00:02:65.*PERMANENT ' )
self . assertRegex ( output , ' 192.168.10.1.*00:00:5e:00:02:66.*PERMANENT ' )
self . assertNotRegex ( output , ' 2004:da8:1::1.*PERMANENT ' )
2019-07-10 21:26:30 +03:00
def test_neighbor_gre ( self ) :
2019-07-18 07:09:42 +03:00
copy_unit_to_networkd_unit_path ( ' 25-neighbor-ip.network ' , ' 25-neighbor-ipv6.network ' , ' 25-neighbor-ip-dummy.network ' ,
' 12-dummy.netdev ' , ' 25-gre-tunnel-remote-any.netdev ' , ' 25-ip6gre-tunnel-remote-any.netdev ' )
2019-07-10 21:26:30 +03:00
start_networkd ( )
2019-07-18 07:09:42 +03:00
self . wait_online ( [ ' dummy98:degraded ' , ' gretun97:routable ' , ' ip6gretun97:routable ' ] , timeout = ' 40s ' )
2019-07-10 21:26:30 +03:00
output = check_output ( ' ip neigh list dev gretun97 ' )
print ( output )
self . assertRegex ( output , ' 10.0.0.22 lladdr 10.65.223.239 PERMANENT ' )
2019-07-18 07:09:42 +03:00
output = check_output ( ' ip neigh list dev ip6gretun97 ' )
print ( output )
self . assertRegex ( output , ' 2001:db8:0:f102::17 lladdr 2a:?00:ff:?de:45:?67:ed:?de:[0:]*:49:?88 PERMANENT ' )
2019-07-10 21:26:30 +03:00
2019-02-12 04:28:49 +03:00
def test_link_local_addressing ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-link-local-addressing-yes.network ' , ' 11-dummy.netdev ' ,
' 25-link-local-addressing-no.network ' , ' 12-dummy.netdev ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' test1:degraded ' , ' dummy98:carrier ' ] )
2019-02-12 04:28:49 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip address show dev test1 ' )
2019-02-12 04:28:49 +03:00
print ( output )
self . assertRegex ( output , ' inet .* scope link ' )
self . assertRegex ( output , ' inet6 .* scope link ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip address show dev dummy98 ' )
2019-02-12 04:28:49 +03:00
print ( output )
self . assertNotRegex ( output , ' inet6* .* scope link ' )
'''
Documentation / networking / ip - sysctl . txt
addr_gen_mode - INTEGER
Defines how link - local and autoconf addresses are generated .
0 : generate address based on EUI64 ( default )
1 : do no generate a link - local address , use EUI64 for addresses generated
from autoconf
2 : generate stable privacy addresses , using the secret from
stable_secret ( RFC7217 )
3 : generate stable privacy addresses , using a random secret if unset
'''
test1_addr_gen_mode = ' '
if os . path . exists ( os . path . join ( os . path . join ( network_sysctl_ipv6_path , ' test1 ' ) , ' stable_secret ' ) ) :
with open ( os . path . join ( os . path . join ( network_sysctl_ipv6_path , ' test1 ' ) , ' stable_secret ' ) ) as f :
try :
f . readline ( )
except IOError :
# if stable_secret is unset, then EIO is returned
test1_addr_gen_mode = ' 0 '
else :
test1_addr_gen_mode = ' 2 '
else :
test1_addr_gen_mode = ' 0 '
if os . path . exists ( os . path . join ( os . path . join ( network_sysctl_ipv6_path , ' test1 ' ) , ' addr_gen_mode ' ) ) :
2019-06-05 13:08:09 +03:00
self . assertEqual ( read_ipv6_sysctl_attr ( ' test1 ' , ' addr_gen_mode ' ) , test1_addr_gen_mode )
2019-02-12 04:28:49 +03:00
if os . path . exists ( os . path . join ( os . path . join ( network_sysctl_ipv6_path , ' dummy98 ' ) , ' addr_gen_mode ' ) ) :
2019-06-05 13:08:09 +03:00
self . assertEqual ( read_ipv6_sysctl_attr ( ' dummy98 ' , ' addr_gen_mode ' ) , ' 1 ' )
2019-02-12 04:28:49 +03:00
2019-09-16 00:16:48 +03:00
def test_link_local_addressing_remove_ipv6ll ( self ) :
copy_unit_to_networkd_unit_path ( ' 26-link-local-addressing-ipv6.network ' , ' 12-dummy.netdev ' )
start_networkd ( )
self . wait_online ( [ ' dummy98:degraded ' ] )
output = check_output ( ' ip address show dev dummy98 ' )
print ( output )
self . assertRegex ( output , ' inet6 .* scope link ' )
copy_unit_to_networkd_unit_path ( ' 25-link-local-addressing-no.network ' )
restart_networkd ( 1 )
self . wait_online ( [ ' dummy98:carrier ' ] )
output = check_output ( ' ip address show dev dummy98 ' )
print ( output )
self . assertNotRegex ( output , ' inet6* .* scope link ' )
2018-09-29 15:36:25 +03:00
def test_sysctl ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-sysctl.network ' , ' 12-dummy.netdev ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' dummy98:degraded ' ] )
2019-06-05 13:08:09 +03:00
self . assertEqual ( read_ipv6_sysctl_attr ( ' dummy98 ' , ' forwarding ' ) , ' 1 ' )
self . assertEqual ( read_ipv6_sysctl_attr ( ' dummy98 ' , ' use_tempaddr ' ) , ' 2 ' )
self . assertEqual ( read_ipv6_sysctl_attr ( ' dummy98 ' , ' dad_transmits ' ) , ' 3 ' )
self . assertEqual ( read_ipv6_sysctl_attr ( ' dummy98 ' , ' hop_limit ' ) , ' 5 ' )
self . assertEqual ( read_ipv6_sysctl_attr ( ' dummy98 ' , ' proxy_ndp ' ) , ' 1 ' )
self . assertEqual ( read_ipv4_sysctl_attr ( ' dummy98 ' , ' forwarding ' ) , ' 1 ' )
self . assertEqual ( read_ipv4_sysctl_attr ( ' dummy98 ' , ' proxy_arp ' ) , ' 1 ' )
2020-06-08 07:51:50 +03:00
self . assertEqual ( read_ipv4_sysctl_attr ( ' dummy98 ' , ' accept_local ' ) , ' 1 ' )
2018-09-29 15:36:25 +03:00
2019-02-18 09:26:26 +03:00
def test_sysctl_disable_ipv6 ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-sysctl-disable-ipv6.network ' , ' 12-dummy.netdev ' )
2019-02-18 09:26:26 +03:00
print ( ' ## Disable ipv6 ' )
2019-06-05 13:03:01 +03:00
check_output ( ' sysctl net.ipv6.conf.all.disable_ipv6=1 ' )
check_output ( ' sysctl net.ipv6.conf.default.disable_ipv6=1 ' )
2019-02-18 09:26:26 +03:00
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' dummy98:routable ' ] )
2019-02-18 09:26:26 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -4 address show dummy98 ' )
2019-02-18 09:26:26 +03:00
print ( output )
self . assertRegex ( output , ' inet 10.2.3.4/16 brd 10.2.255.255 scope global dummy98 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -6 address show dummy98 ' )
2019-02-18 09:26:26 +03:00
print ( output )
2019-08-22 14:26:54 +03:00
self . assertRegex ( output , ' inet6 2607:5300:203:3906::/64 scope global ' )
self . assertRegex ( output , ' inet6 .* scope link ' )
2019-06-12 05:01:32 +03:00
output = check_output ( ' ip -4 route show dev dummy98 ' )
print ( output )
2020-06-22 13:48:34 +03:00
self . assertRegex ( output , ' 10.2.0.0/16 proto kernel scope link src 10.2.3.4 ' )
2020-10-07 14:02:00 +03:00
output = check_output ( ' ip -6 route show default ' )
2019-06-12 05:01:32 +03:00
print ( output )
2020-10-07 14:02:00 +03:00
self . assertRegex ( output , ' default ' )
self . assertRegex ( output , ' via 2607:5300:203:39ff:ff:ff:ff:ff ' )
2019-02-18 09:26:26 +03:00
2019-06-05 13:03:01 +03:00
check_output ( ' ip link del dummy98 ' )
2019-02-18 09:26:26 +03:00
print ( ' ## Enable ipv6 ' )
2019-06-05 13:03:01 +03:00
check_output ( ' sysctl net.ipv6.conf.all.disable_ipv6=0 ' )
check_output ( ' sysctl net.ipv6.conf.default.disable_ipv6=0 ' )
2019-02-18 09:26:26 +03:00
2019-07-15 08:18:06 +03:00
restart_networkd ( 3 )
self . wait_online ( [ ' dummy98:routable ' ] )
2019-02-18 09:26:26 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -4 address show dummy98 ' )
2019-02-18 09:26:26 +03:00
print ( output )
self . assertRegex ( output , ' inet 10.2.3.4/16 brd 10.2.255.255 scope global dummy98 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -6 address show dummy98 ' )
2019-02-18 09:26:26 +03:00
print ( output )
2019-06-12 05:01:32 +03:00
self . assertRegex ( output , ' inet6 2607:5300:203:3906::/64 scope global ' )
2019-02-18 09:26:26 +03:00
self . assertRegex ( output , ' inet6 .* scope link ' )
2019-06-12 05:01:32 +03:00
output = check_output ( ' ip -4 route show dev dummy98 ' )
print ( output )
2020-06-22 13:48:34 +03:00
self . assertRegex ( output , ' 10.2.0.0/16 proto kernel scope link src 10.2.3.4 ' )
2020-10-07 14:02:00 +03:00
output = check_output ( ' ip -6 route show default ' )
2019-06-12 05:01:32 +03:00
print ( output )
2020-10-07 14:02:00 +03:00
self . assertRegex ( output , ' via 2607:5300:203:39ff:ff:ff:ff:ff ' )
2019-02-18 09:26:26 +03:00
2019-02-07 08:22:23 +03:00
def test_bind_carrier ( self ) :
2019-12-08 18:39:33 +03:00
check_output ( ' ip link add dummy98 type dummy ' )
check_output ( ' ip link set dummy98 up ' )
time . sleep ( 2 )
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-bind-carrier.network ' , ' 11-dummy.netdev ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' test1:routable ' ] )
2019-02-07 08:22:23 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip address show test1 ' )
2019-02-07 08:22:23 +03:00
print ( output )
self . assertRegex ( output , ' UP,LOWER_UP ' )
self . assertRegex ( output , ' inet 192.168.10.30/24 brd 192.168.10.255 scope global test1 ' )
2020-01-08 15:25:16 +03:00
self . wait_operstate ( ' test1 ' , ' routable ' )
2019-02-07 08:22:23 +03:00
2019-06-05 13:03:01 +03:00
check_output ( ' ip link add dummy99 type dummy ' )
check_output ( ' ip link set dummy99 up ' )
2019-02-16 21:59:15 +03:00
time . sleep ( 2 )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip address show test1 ' )
2019-02-07 08:22:23 +03:00
print ( output )
self . assertRegex ( output , ' UP,LOWER_UP ' )
self . assertRegex ( output , ' inet 192.168.10.30/24 brd 192.168.10.255 scope global test1 ' )
2020-01-08 15:25:16 +03:00
self . wait_operstate ( ' test1 ' , ' routable ' )
2019-02-07 08:22:23 +03:00
2019-06-05 13:03:01 +03:00
check_output ( ' ip link del dummy98 ' )
2019-02-16 21:59:15 +03:00
time . sleep ( 2 )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip address show test1 ' )
2019-02-07 08:22:23 +03:00
print ( output )
self . assertRegex ( output , ' UP,LOWER_UP ' )
self . assertRegex ( output , ' inet 192.168.10.30/24 brd 192.168.10.255 scope global test1 ' )
2020-01-08 15:25:16 +03:00
self . wait_operstate ( ' test1 ' , ' routable ' )
2019-02-07 08:22:23 +03:00
2019-12-08 18:39:33 +03:00
check_output ( ' ip link set dummy99 down ' )
2019-02-16 21:59:15 +03:00
time . sleep ( 2 )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip address show test1 ' )
2019-02-07 08:22:23 +03:00
print ( output )
self . assertNotRegex ( output , ' UP,LOWER_UP ' )
self . assertRegex ( output , ' DOWN ' )
self . assertNotRegex ( output , ' 192.168.10 ' )
2020-01-08 15:25:16 +03:00
self . wait_operstate ( ' test1 ' , ' off ' )
2019-02-07 08:22:23 +03:00
2019-12-08 18:39:33 +03:00
check_output ( ' ip link set dummy99 up ' )
2019-02-16 21:59:15 +03:00
time . sleep ( 2 )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip address show test1 ' )
2019-02-07 08:22:23 +03:00
print ( output )
self . assertRegex ( output , ' UP,LOWER_UP ' )
self . assertRegex ( output , ' inet 192.168.10.30/24 brd 192.168.10.255 scope global test1 ' )
2020-01-08 15:25:16 +03:00
self . wait_operstate ( ' test1 ' , ' routable ' )
2019-02-07 08:22:23 +03:00
2019-05-24 09:34:19 +03:00
def test_domain ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 12-dummy.netdev ' , ' 24-search-domain.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' dummy98:routable ' ] )
2019-05-24 09:34:19 +03:00
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' dummy98 ' , env = env )
2019-05-24 09:34:19 +03:00
print ( output )
self . assertRegex ( output , ' Address: 192.168.42.100 ' )
self . assertRegex ( output , ' DNS: 192.168.42.1 ' )
self . assertRegex ( output , ' Search Domains: one ' )
2019-06-03 07:21:13 +03:00
def test_keep_configuration_static ( self ) :
2020-08-28 18:21:27 +03:00
check_output ( ' systemctl stop systemd-networkd.socket ' )
check_output ( ' systemctl stop systemd-networkd.service ' )
2019-06-03 07:21:13 +03:00
check_output ( ' ip link add name dummy98 type dummy ' )
check_output ( ' ip address add 10.1.2.3/16 dev dummy98 ' )
check_output ( ' ip address add 10.2.3.4/16 dev dummy98 valid_lft 600 preferred_lft 500 ' )
output = check_output ( ' ip address show dummy98 ' )
print ( output )
self . assertRegex ( output , ' inet 10.1.2.3/16 scope global dummy98 ' )
self . assertRegex ( output , ' inet 10.2.3.4/16 scope global dynamic dummy98 ' )
output = check_output ( ' ip route show dev dummy98 ' )
print ( output )
copy_unit_to_networkd_unit_path ( ' 24-keep-configuration-static.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' dummy98:routable ' ] )
2019-06-03 07:21:13 +03:00
output = check_output ( ' ip address show dummy98 ' )
print ( output )
self . assertRegex ( output , ' inet 10.1.2.3/16 scope global dummy98 ' )
self . assertNotRegex ( output , ' inet 10.2.3.4/16 scope global dynamic dummy98 ' )
2019-10-14 15:18:01 +03:00
@expectedFailureIfNexthopIsNotAvailable ( )
def test_nexthop ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-nexthop.network ' , ' 25-veth.netdev ' , ' 25-veth-peer.network ' )
start_networkd ( )
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
output = check_output ( ' ip nexthop list dev veth99 ' )
print ( output )
self . assertRegex ( output , ' 192.168.5.1 ' )
2019-10-29 18:33:19 +03:00
def test_qdisc ( self ) :
2020-02-12 03:53:15 +03:00
copy_unit_to_networkd_unit_path ( ' 25-qdisc-clsact-and-htb.network ' , ' 12-dummy.netdev ' ,
' 25-qdisc-ingress-netem-compat.network ' , ' 11-dummy.netdev ' )
check_output ( ' modprobe sch_teql max_equalizers=2 ' )
2019-10-29 18:33:19 +03:00
start_networkd ( )
2019-11-24 15:23:48 +03:00
self . wait_online ( [ ' dummy98:routable ' , ' test1:routable ' ] )
2019-10-29 18:33:19 +03:00
2020-02-12 03:53:15 +03:00
output = check_output ( ' tc qdisc show dev test1 ' )
print ( output )
self . assertRegex ( output , ' qdisc netem ' )
2020-06-06 13:50:48 +03:00
self . assertRegex ( output , ' limit 100 delay 50(.0)?ms 10(.0)?ms loss 20 % ' )
2020-02-12 03:53:15 +03:00
self . assertRegex ( output , ' qdisc ingress ' )
2019-10-29 18:33:19 +03:00
output = check_output ( ' tc qdisc show dev dummy98 ' )
print ( output )
2020-02-12 03:53:15 +03:00
self . assertRegex ( output , ' qdisc clsact ' )
self . assertRegex ( output , ' qdisc htb 2: root ' )
self . assertRegex ( output , r ' default (0x30|30) ' )
self . assertRegex ( output , ' qdisc netem 30: parent 2:30 ' )
2020-06-06 13:50:48 +03:00
self . assertRegex ( output , ' limit 100 delay 50(.0)?ms 10(.0)?ms loss 20 % ' )
2019-12-10 17:46:38 +03:00
self . assertRegex ( output , ' qdisc fq_codel ' )
2020-06-06 13:50:48 +03:00
self . assertRegex ( output , ' limit 20480p flows 2048 quantum 1400 target 10(.0)?ms ce_threshold 100(.0)?ms interval 200(.0)?ms memory_limit 64Mb ecn ' )
2019-10-29 18:33:19 +03:00
2020-02-12 03:53:15 +03:00
self . assertRegex ( output , ' qdisc teql1 31: parent 2:31 ' )
2019-12-12 10:29:23 +03:00
2020-02-12 03:53:15 +03:00
self . assertRegex ( output , ' qdisc fq 32: parent 2:32 ' )
2020-01-28 20:05:48 +03:00
self . assertRegex ( output , ' limit 1000p flow_limit 200p buckets 512 orphan_mask 511 ' )
self . assertRegex ( output , ' quantum 1500 ' )
self . assertRegex ( output , ' initial_quantum 13000 ' )
self . assertRegex ( output , ' maxrate 1Mbit ' )
2020-02-05 13:23:11 +03:00
2020-02-12 03:53:15 +03:00
self . assertRegex ( output , ' qdisc codel 33: parent 2:33 ' )
2020-06-06 13:50:48 +03:00
self . assertRegex ( output , ' limit 2000p target 10(.0)?ms ce_threshold 100(.0)?ms interval 50(.0)?ms ecn ' )
2020-02-05 13:23:11 +03:00
2020-02-12 03:53:15 +03:00
self . assertRegex ( output , ' qdisc fq_codel 34: parent 2:34 ' )
2020-06-06 13:50:48 +03:00
self . assertRegex ( output , ' limit 20480p flows 2048 quantum 1400 target 10(.0)?ms ce_threshold 100(.0)?ms interval 200(.0)?ms memory_limit 64Mb ecn ' )
2020-02-05 13:23:11 +03:00
2020-02-12 03:53:15 +03:00
self . assertRegex ( output , ' qdisc tbf 35: parent 2:35 ' )
2020-06-06 13:50:48 +03:00
self . assertRegex ( output , ' rate 1Gbit burst 5000b peakrate 100Gbit minburst 987500b lat 70(.0)?ms ' )
2020-02-05 13:23:11 +03:00
2020-02-12 03:53:15 +03:00
self . assertRegex ( output , ' qdisc sfq 36: parent 2:36 ' )
self . assertRegex ( output , ' perturb 5sec ' )
2020-02-06 11:53:04 +03:00
2020-02-16 18:37:03 +03:00
self . assertRegex ( output , ' qdisc pfifo 37: parent 2:37 ' )
self . assertRegex ( output , ' limit 100000p ' )
2020-02-16 19:09:05 +03:00
self . assertRegex ( output , ' qdisc gred 38: parent 2:38 ' )
self . assertRegex ( output , ' vqs 12 default 10 grio ' )
2020-02-16 19:27:59 +03:00
self . assertRegex ( output , ' qdisc sfb 39: parent 2:39 ' )
self . assertRegex ( output , ' limit 200000 ' )
2020-03-11 19:58:21 +03:00
self . assertRegex ( output , ' qdisc bfifo 3a: parent 2:3a ' )
self . assertRegex ( output , ' limit 1000000 ' )
2020-03-11 20:09:06 +03:00
self . assertRegex ( output , ' qdisc pfifo_head_drop 3b: parent 2:3b ' )
self . assertRegex ( output , ' limit 1023p ' )
2020-03-11 20:28:59 +03:00
self . assertRegex ( output , ' qdisc pfifo_fast 3c: parent 2:3c ' )
2020-06-08 11:38:50 +03:00
output = check_output ( ' tc -d class show dev dummy98 ' )
2020-02-05 13:23:11 +03:00
print ( output )
2020-02-12 03:53:15 +03:00
self . assertRegex ( output , ' class htb 2:30 root leaf 30: ' )
self . assertRegex ( output , ' class htb 2:31 root leaf 31: ' )
self . assertRegex ( output , ' class htb 2:32 root leaf 32: ' )
self . assertRegex ( output , ' class htb 2:33 root leaf 33: ' )
self . assertRegex ( output , ' class htb 2:34 root leaf 34: ' )
self . assertRegex ( output , ' class htb 2:35 root leaf 35: ' )
self . assertRegex ( output , ' class htb 2:36 root leaf 36: ' )
2020-02-16 18:37:03 +03:00
self . assertRegex ( output , ' class htb 2:37 root leaf 37: ' )
2020-02-16 19:09:05 +03:00
self . assertRegex ( output , ' class htb 2:38 root leaf 38: ' )
2020-02-16 19:27:59 +03:00
self . assertRegex ( output , ' class htb 2:39 root leaf 39: ' )
2020-03-11 19:58:21 +03:00
self . assertRegex ( output , ' class htb 2:3a root leaf 3a: ' )
2020-03-11 20:09:06 +03:00
self . assertRegex ( output , ' class htb 2:3b root leaf 3b: ' )
2020-03-11 20:28:59 +03:00
self . assertRegex ( output , ' class htb 2:3c root leaf 3c: ' )
2020-06-08 11:38:50 +03:00
self . assertRegex ( output , ' prio 1 quantum 4000 rate 1Mbit overhead 100 ceil 500Kbit ' )
self . assertRegex ( output , ' burst 123456 ' )
self . assertRegex ( output , ' cburst 123457 ' )
2019-12-12 10:29:23 +03:00
2020-03-11 18:58:25 +03:00
def test_qdisc2 ( self ) :
2020-06-03 09:18:55 +03:00
copy_unit_to_networkd_unit_path ( ' 25-qdisc-drr.network ' , ' 12-dummy.netdev ' ,
' 25-qdisc-qfq.network ' , ' 11-dummy.netdev ' )
2020-03-11 18:58:25 +03:00
start_networkd ( )
2020-06-03 09:18:55 +03:00
self . wait_online ( [ ' dummy98:routable ' , ' test1:routable ' ] )
2020-03-11 18:58:25 +03:00
output = check_output ( ' tc qdisc show dev dummy98 ' )
print ( output )
self . assertRegex ( output , ' qdisc drr 2: root ' )
output = check_output ( ' tc class show dev dummy98 ' )
print ( output )
self . assertRegex ( output , ' class drr 2:30 root quantum 2000b ' )
2020-06-03 09:18:55 +03:00
output = check_output ( ' tc qdisc show dev test1 ' )
print ( output )
self . assertRegex ( output , ' qdisc qfq 2: root ' )
output = check_output ( ' tc class show dev test1 ' )
print ( output )
self . assertRegex ( output , ' class qfq 2:30 root weight 2 maxpkt 16000 ' )
self . assertRegex ( output , ' class qfq 2:31 root weight 10 maxpkt 8000 ' )
2020-02-17 15:03:12 +03:00
@expectedFailureIfCAKEIsNotAvailable ( )
def test_qdisc_cake ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-qdisc-cake.network ' , ' 12-dummy.netdev ' )
2020-02-06 11:53:04 +03:00
start_networkd ( )
self . wait_online ( [ ' dummy98:routable ' ] )
output = check_output ( ' tc qdisc show dev dummy98 ' )
print ( output )
2020-02-17 15:03:12 +03:00
self . assertRegex ( output , ' qdisc cake 3a: root ' )
self . assertRegex ( output , ' bandwidth 500Mbit ' )
self . assertRegex ( output , ' overhead 128 ' )
2020-02-06 11:53:04 +03:00
2020-03-11 16:48:10 +03:00
@expectedFailureIfPIEIsNotAvailable ( )
def test_qdisc_pie ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-qdisc-pie.network ' , ' 12-dummy.netdev ' )
start_networkd ( )
self . wait_online ( [ ' dummy98:routable ' ] )
output = check_output ( ' tc qdisc show dev dummy98 ' )
print ( output )
self . assertRegex ( output , ' qdisc pie 3a: root ' )
self . assertRegex ( output , ' limit 200000 ' )
2020-03-11 20:40:29 +03:00
@expectedFailureIfHHFIsNotAvailable ( )
def test_qdisc_hhf ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-qdisc-hhf.network ' , ' 12-dummy.netdev ' )
start_networkd ( )
self . wait_online ( [ ' dummy98:routable ' ] )
output = check_output ( ' tc qdisc show dev dummy98 ' )
print ( output )
self . assertRegex ( output , ' qdisc hhf 3a: root ' )
self . assertRegex ( output , ' limit 1022p ' )
2020-06-09 11:24:04 +03:00
@expectedFailureIfETSIsNotAvailable ( )
def test_qdisc_ets ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-qdisc-ets.network ' , ' 12-dummy.netdev ' )
start_networkd ( )
self . wait_online ( [ ' dummy98:routable ' ] )
output = check_output ( ' tc qdisc show dev dummy98 ' )
print ( output )
2020-09-17 11:18:48 +03:00
2020-06-09 11:24:04 +03:00
self . assertRegex ( output , ' qdisc ets 3a: root ' )
self . assertRegex ( output , ' bands 10 strict 3 ' )
self . assertRegex ( output , ' quanta 1 2 3 4 5 ' )
self . assertRegex ( output , ' priomap 3 4 5 6 7 ' )
2020-09-17 11:18:48 +03:00
@expectedFailureIfFQPIEIsNotAvailable ( )
def test_qdisc_fq_pie ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-qdisc-fq_pie.network ' , ' 12-dummy.netdev ' )
start_networkd ( )
self . wait_online ( [ ' dummy98:routable ' ] )
output = check_output ( ' tc qdisc show dev dummy98 ' )
print ( output )
self . assertRegex ( output , ' qdisc fq_pie 3a: root ' )
self . assertRegex ( output , ' limit 200000p ' )
2020-06-22 13:48:34 +03:00
@expectedFailureIfNetdevsimWithSRIOVIsNotAvailable ( )
def test_sriov ( self ) :
call ( ' rmmod netdevsim ' , stderr = subprocess . DEVNULL )
call ( ' modprobe netdevsim ' , stderr = subprocess . DEVNULL )
with open ( ' /sys/bus/netdevsim/new_device ' , mode = ' w ' ) as f :
f . write ( ' 99 1 ' )
call ( ' udevadm settle ' )
call ( ' udevadm info -w10s /sys/devices/netdevsim99/net/eni99np1 ' , stderr = subprocess . DEVNULL )
with open ( ' /sys/class/net/eni99np1/device/sriov_numvfs ' , mode = ' w ' ) as f :
f . write ( ' 3 ' )
copy_unit_to_networkd_unit_path ( ' 25-sriov.network ' )
start_networkd ( )
self . wait_online ( [ ' eni99np1:routable ' ] )
output = check_output ( ' ip link show dev eni99np1 ' )
print ( output )
self . assertRegex ( output ,
' vf 0 .*00:11:22:33:44:55.*vlan 5, qos 1, vlan protocol 802.1ad, spoof checking on, link-state enable, trust on, query_rss on \n * '
' vf 1 .*00:11:22:33:44:56.*vlan 6, qos 2, spoof checking off, link-state disable, trust off, query_rss off \n * '
' vf 2 .*00:11:22:33:44:57.*vlan 7, qos 3, spoof checking off, link-state auto, trust off, query_rss off '
)
call ( ' rmmod netdevsim ' , stderr = subprocess . DEVNULL )
2019-06-04 01:05:07 +03:00
class NetworkdStateFileTests ( unittest . TestCase , Utilities ) :
links = [
' dummy98 ' ,
]
units = [
' 12-dummy.netdev ' ,
' state-file-tests.network ' ,
]
def setUp ( self ) :
remove_links ( self . links )
stop_networkd ( show_logs = False )
def tearDown ( self ) :
remove_links ( self . links )
remove_unit_from_networkd_path ( self . units )
stop_networkd ( show_logs = True )
def test_state_file ( self ) :
copy_unit_to_networkd_unit_path ( ' 12-dummy.netdev ' , ' state-file-tests.network ' )
start_networkd ( )
self . wait_online ( [ ' dummy98:routable ' ] )
output = check_output ( * networkctl_cmd , ' --no-legend ' , ' list ' , ' dummy98 ' , env = env )
print ( output )
ifindex = output . split ( ) [ 0 ]
path = os . path . join ( ' /run/systemd/netif/links/ ' , ifindex )
self . assertTrue ( os . path . exists ( path ) )
2020-07-20 23:50:15 +03:00
# make link state file updated
check_output ( * resolvectl_cmd , ' revert ' , ' dummy98 ' , env = env )
2019-06-04 01:05:07 +03:00
with open ( path ) as f :
data = f . read ( )
self . assertRegex ( data , r ' ADMIN_STATE=configured ' )
self . assertRegex ( data , r ' OPER_STATE=routable ' )
self . assertRegex ( data , r ' REQUIRED_FOR_ONLINE=yes ' )
self . assertRegex ( data , r ' REQUIRED_OPER_STATE_FOR_ONLINE=routable ' )
self . assertRegex ( data , r ' NETWORK_FILE=/run/systemd/network/state-file-tests.network ' )
2020-07-03 16:16:55 +03:00
self . assertRegex ( data , r ' DNS=10.10.10.10#aaa.com 10.10.10.11:1111#bbb.com \ [1111:2222::3333 \ ]:1234#ccc.com ' )
2019-06-04 01:05:07 +03:00
self . assertRegex ( data , r ' NTP=0.fedora.pool.ntp.org 1.fedora.pool.ntp.org ' )
self . assertRegex ( data , r ' DOMAINS=hogehoge ' )
self . assertRegex ( data , r ' ROUTE_DOMAINS=foofoo ' )
self . assertRegex ( data , r ' LLMNR=no ' )
self . assertRegex ( data , r ' MDNS=yes ' )
self . assertRegex ( data , r ' DNSSEC=no ' )
2019-10-31 19:19:23 +03:00
self . assertRegex ( data , r ' ADDRESSES=192.168.(10.10|12.12)/24 192.168.(12.12|10.10)/24 ' )
2019-06-04 01:05:07 +03:00
2020-07-03 16:16:55 +03:00
check_output ( * resolvectl_cmd , ' dns ' , ' dummy98 ' , ' 10.10.10.12#ccc.com ' , ' 10.10.10.13 ' , ' 1111:2222::3333 ' , env = env )
2019-06-04 01:05:07 +03:00
check_output ( * resolvectl_cmd , ' domain ' , ' dummy98 ' , ' hogehogehoge ' , ' ~foofoofoo ' , env = env )
check_output ( * resolvectl_cmd , ' llmnr ' , ' dummy98 ' , ' yes ' , env = env )
check_output ( * resolvectl_cmd , ' mdns ' , ' dummy98 ' , ' no ' , env = env )
check_output ( * resolvectl_cmd , ' dnssec ' , ' dummy98 ' , ' yes ' , env = env )
check_output ( * timedatectl_cmd , ' ntp-servers ' , ' dummy98 ' , ' 2.fedora.pool.ntp.org ' , ' 3.fedora.pool.ntp.org ' , env = env )
with open ( path ) as f :
data = f . read ( )
2020-07-03 16:16:55 +03:00
self . assertRegex ( data , r ' DNS=10.10.10.12#ccc.com 10.10.10.13 1111:2222::3333 ' )
2019-06-04 01:05:07 +03:00
self . assertRegex ( data , r ' NTP=2.fedora.pool.ntp.org 3.fedora.pool.ntp.org ' )
self . assertRegex ( data , r ' DOMAINS=hogehogehoge ' )
self . assertRegex ( data , r ' ROUTE_DOMAINS=foofoofoo ' )
self . assertRegex ( data , r ' LLMNR=yes ' )
self . assertRegex ( data , r ' MDNS=no ' )
self . assertRegex ( data , r ' DNSSEC=yes ' )
check_output ( * timedatectl_cmd , ' revert ' , ' dummy98 ' , env = env )
with open ( path ) as f :
data = f . read ( )
2020-07-03 16:16:55 +03:00
self . assertRegex ( data , r ' DNS=10.10.10.12#ccc.com 10.10.10.13 1111:2222::3333 ' )
2019-06-04 01:05:07 +03:00
self . assertRegex ( data , r ' NTP=0.fedora.pool.ntp.org 1.fedora.pool.ntp.org ' )
self . assertRegex ( data , r ' DOMAINS=hogehogehoge ' )
self . assertRegex ( data , r ' ROUTE_DOMAINS=foofoofoo ' )
self . assertRegex ( data , r ' LLMNR=yes ' )
self . assertRegex ( data , r ' MDNS=no ' )
self . assertRegex ( data , r ' DNSSEC=yes ' )
check_output ( * resolvectl_cmd , ' revert ' , ' dummy98 ' , env = env )
with open ( path ) as f :
data = f . read ( )
2020-07-03 16:16:55 +03:00
self . assertRegex ( data , r ' DNS=10.10.10.10#aaa.com 10.10.10.11:1111#bbb.com \ [1111:2222::3333 \ ]:1234#ccc.com ' )
2019-06-04 01:05:07 +03:00
self . assertRegex ( data , r ' NTP=0.fedora.pool.ntp.org 1.fedora.pool.ntp.org ' )
self . assertRegex ( data , r ' DOMAINS=hogehoge ' )
self . assertRegex ( data , r ' ROUTE_DOMAINS=foofoo ' )
self . assertRegex ( data , r ' LLMNR=no ' )
self . assertRegex ( data , r ' MDNS=yes ' )
self . assertRegex ( data , r ' DNSSEC=no ' )
2019-05-24 09:17:41 +03:00
class NetworkdBondTests ( unittest . TestCase , Utilities ) :
2019-02-09 16:56:42 +03:00
links = [
2019-03-21 23:20:04 +03:00
' bond199 ' ,
2019-02-09 16:56:42 +03:00
' bond99 ' ,
2019-02-20 09:04:15 +03:00
' dummy98 ' ,
' test1 ' ]
2019-02-09 16:56:42 +03:00
units = [
2019-02-20 09:04:15 +03:00
' 11-dummy.netdev ' ,
' 12-dummy.netdev ' ,
2019-03-21 23:20:04 +03:00
' 23-active-slave.network ' ,
' 23-bond199.network ' ,
' 23-primary-slave.network ' ,
' 25-bond-active-backup-slave.netdev ' ,
2019-02-09 16:56:42 +03:00
' 25-bond.netdev ' ,
' bond99.network ' ,
2019-02-20 09:04:15 +03:00
' bond-slave.network ' ]
2019-02-09 16:56:42 +03:00
def setUp ( self ) :
2019-06-05 13:08:09 +03:00
remove_links ( self . links )
2019-07-03 21:46:14 +03:00
stop_networkd ( show_logs = False )
2019-02-09 16:56:42 +03:00
def tearDown ( self ) :
2019-06-05 13:08:09 +03:00
remove_links ( self . links )
remove_unit_from_networkd_path ( self . units )
2019-07-03 21:46:14 +03:00
stop_networkd ( show_logs = True )
2019-02-09 16:56:42 +03:00
2019-03-21 23:20:04 +03:00
def test_bond_active_slave ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 23-active-slave.network ' , ' 23-bond199.network ' , ' 25-bond-active-backup-slave.netdev ' , ' 12-dummy.netdev ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' dummy98:enslaved ' , ' bond199:degraded ' ] )
2019-03-21 23:20:04 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show bond199 ' )
2019-03-21 23:20:04 +03:00
print ( output )
self . assertRegex ( output , ' active_slave dummy98 ' )
def test_bond_primary_slave ( self ) :
2019-06-17 04:52:16 +03:00
copy_unit_to_networkd_unit_path ( ' 23-primary-slave.network ' , ' 23-bond199.network ' , ' 25-bond-active-backup-slave.netdev ' , ' 12-dummy.netdev ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' dummy98:enslaved ' , ' bond199:degraded ' ] )
2019-03-21 23:20:04 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show bond199 ' )
2019-03-21 23:20:04 +03:00
print ( output )
2019-06-17 04:52:16 +03:00
self . assertRegex ( output , ' primary dummy98 ' )
2019-03-21 23:20:04 +03:00
2019-02-20 09:04:15 +03:00
def test_bond_operstate ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-bond.netdev ' , ' 11-dummy.netdev ' , ' 12-dummy.netdev ' ,
' bond99.network ' , ' bond-slave.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' dummy98:enslaved ' , ' test1:enslaved ' , ' bond99:routable ' ] )
2019-02-09 16:56:42 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show dummy98 ' )
2019-02-09 16:56:42 +03:00
print ( output )
2019-02-20 09:04:15 +03:00
self . assertRegex ( output , ' SLAVE,UP,LOWER_UP ' )
2019-02-09 16:56:42 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show test1 ' )
2019-02-09 16:56:42 +03:00
print ( output )
self . assertRegex ( output , ' SLAVE,UP,LOWER_UP ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show bond99 ' )
2019-02-09 16:56:42 +03:00
print ( output )
self . assertRegex ( output , ' MASTER,UP,LOWER_UP ' )
2020-01-08 15:25:16 +03:00
self . wait_operstate ( ' dummy98 ' , ' enslaved ' )
self . wait_operstate ( ' test1 ' , ' enslaved ' )
self . wait_operstate ( ' bond99 ' , ' routable ' )
2019-02-09 16:56:42 +03:00
2019-06-05 13:03:01 +03:00
check_output ( ' ip link set dummy98 down ' )
2019-02-09 16:56:42 +03:00
2020-01-08 15:25:16 +03:00
self . wait_operstate ( ' dummy98 ' , ' off ' )
self . wait_operstate ( ' test1 ' , ' enslaved ' )
self . wait_operstate ( ' bond99 ' , ' degraded-carrier ' )
2019-02-09 16:56:42 +03:00
2019-06-05 13:03:01 +03:00
check_output ( ' ip link set dummy98 up ' )
2019-02-09 16:56:42 +03:00
2020-01-08 15:25:16 +03:00
self . wait_operstate ( ' dummy98 ' , ' enslaved ' )
self . wait_operstate ( ' test1 ' , ' enslaved ' )
self . wait_operstate ( ' bond99 ' , ' routable ' )
2019-02-09 16:56:42 +03:00
2019-06-05 13:03:01 +03:00
check_output ( ' ip link set dummy98 down ' )
check_output ( ' ip link set test1 down ' )
2019-02-20 09:04:15 +03:00
2020-01-08 15:25:16 +03:00
self . wait_operstate ( ' dummy98 ' , ' off ' )
self . wait_operstate ( ' test1 ' , ' off ' )
2019-05-15 12:46:41 +03:00
2020-01-08 15:28:29 +03:00
if not self . wait_operstate ( ' bond99 ' , ' no-carrier ' , setup_timeout = 30 , fail_assert = False ) :
2019-05-15 12:46:41 +03:00
# Huh? Kernel does not recognize that all slave interfaces are down?
# Let's confirm that networkd's operstate is consistent with ip's result.
self . assertNotRegex ( output , ' NO-CARRIER ' )
2019-02-20 09:04:15 +03:00
2019-05-24 09:17:41 +03:00
class NetworkdBridgeTests ( unittest . TestCase , Utilities ) :
2018-12-06 16:57:20 +03:00
links = [
' bridge99 ' ,
' dummy98 ' ,
' test1 ' ]
units = [
' 11-dummy.netdev ' ,
' 12-dummy.netdev ' ,
' 26-bridge.netdev ' ,
2020-04-27 22:47:28 +03:00
' 26-bridge-configure-without-carrier.network ' ,
2020-09-15 10:28:09 +03:00
' 26-bridge-mdb-master.network ' ,
' 26-bridge-mdb-slave.network ' ,
2018-12-06 16:57:20 +03:00
' 26-bridge-slave-interface-1.network ' ,
' 26-bridge-slave-interface-2.network ' ,
2019-07-04 22:43:27 +03:00
' 26-bridge-vlan-master.network ' ,
' 26-bridge-vlan-slave.network ' ,
2019-02-06 14:45:56 +03:00
' bridge99-ignore-carrier-loss.network ' ,
2018-12-06 16:57:20 +03:00
' bridge99.network ' ]
2018-09-29 15:36:25 +03:00
2019-06-17 05:09:25 +03:00
routing_policy_rule_tables = [ ' 100 ' ]
2018-09-29 15:36:25 +03:00
def setUp ( self ) :
2019-06-17 05:09:25 +03:00
remove_routing_policy_rule_tables ( self . routing_policy_rule_tables )
2019-06-05 13:08:09 +03:00
remove_links ( self . links )
2019-07-03 21:46:14 +03:00
stop_networkd ( show_logs = False )
2018-09-29 15:36:25 +03:00
def tearDown ( self ) :
2019-06-17 05:09:25 +03:00
remove_routing_policy_rule_tables ( self . routing_policy_rule_tables )
2019-06-05 13:08:09 +03:00
remove_links ( self . links )
remove_unit_from_networkd_path ( self . units )
2019-07-03 21:46:14 +03:00
stop_networkd ( show_logs = True )
2018-09-29 15:36:25 +03:00
2019-07-04 22:43:27 +03:00
def test_bridge_vlan ( self ) :
copy_unit_to_networkd_unit_path ( ' 11-dummy.netdev ' , ' 26-bridge-vlan-slave.network ' ,
' 26-bridge.netdev ' , ' 26-bridge-vlan-master.network ' )
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' test1:enslaved ' , ' bridge99:degraded ' ] )
2019-07-04 22:43:27 +03:00
output = check_output ( ' bridge vlan show dev test1 ' )
print ( output )
self . assertNotRegex ( output , ' 4063 ' )
for i in range ( 4064 , 4095 ) :
self . assertRegex ( output , f ' { i } ' )
self . assertNotRegex ( output , ' 4095 ' )
output = check_output ( ' bridge vlan show dev bridge99 ' )
print ( output )
self . assertNotRegex ( output , ' 4059 ' )
for i in range ( 4060 , 4095 ) :
self . assertRegex ( output , f ' { i } ' )
self . assertNotRegex ( output , ' 4095 ' )
2020-09-15 10:28:09 +03:00
def test_bridge_mdb ( self ) :
copy_unit_to_networkd_unit_path ( ' 11-dummy.netdev ' , ' 26-bridge-mdb-slave.network ' ,
' 26-bridge.netdev ' , ' 26-bridge-mdb-master.network ' )
start_networkd ( )
self . wait_online ( [ ' test1:enslaved ' , ' bridge99:degraded ' ] )
output = check_output ( ' bridge mdb show dev bridge99 ' )
print ( output )
self . assertRegex ( output , ' dev bridge99 port test1 grp ff02:aaaa:fee5::1:3 permanent *vid 4064 ' )
self . assertRegex ( output , ' dev bridge99 port test1 grp 224.0.1.1 permanent *vid 4065 ' )
2020-09-17 08:32:03 +03:00
# Old kernel may not support bridge MDB entries on bridge master
if call ( ' bridge mdb add dev bridge99 port bridge99 grp 224.0.1.3 temp vid 4068 ' , stderr = subprocess . DEVNULL ) == 0 :
self . assertRegex ( output , ' dev bridge99 port bridge99 grp ff02:aaaa:fee5::1:4 temp *vid 4066 ' )
self . assertRegex ( output , ' dev bridge99 port bridge99 grp 224.0.1.2 temp *vid 4067 ' )
2018-09-29 15:36:25 +03:00
def test_bridge_property ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 11-dummy.netdev ' , ' 12-dummy.netdev ' , ' 26-bridge.netdev ' ,
' 26-bridge-slave-interface-1.network ' , ' 26-bridge-slave-interface-2.network ' ,
' bridge99.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' dummy98:enslaved ' , ' test1:enslaved ' , ' bridge99:routable ' ] )
2018-09-29 15:36:25 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show test1 ' )
2018-09-29 15:36:25 +03:00
print ( output )
self . assertRegex ( output , ' master ' )
self . assertRegex ( output , ' bridge ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show dummy98 ' )
2018-09-29 15:36:25 +03:00
print ( output )
self . assertRegex ( output , ' master ' )
self . assertRegex ( output , ' bridge ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip addr show bridge99 ' )
2018-09-29 15:36:25 +03:00
print ( output )
2019-02-20 05:33:00 +03:00
self . assertRegex ( output , ' 192.168.0.15/24 ' )
2018-09-29 15:36:25 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' bridge -d link show dummy98 ' )
2018-09-29 15:36:25 +03:00
print ( output )
2019-06-05 13:08:09 +03:00
self . assertEqual ( read_bridge_port_attr ( ' bridge99 ' , ' dummy98 ' , ' path_cost ' ) , ' 400 ' )
2019-07-07 01:46:08 +03:00
self . assertEqual ( read_bridge_port_attr ( ' bridge99 ' , ' dummy98 ' , ' hairpin_mode ' ) , ' 1 ' )
self . assertEqual ( read_bridge_port_attr ( ' bridge99 ' , ' dummy98 ' , ' multicast_fast_leave ' ) , ' 1 ' )
2019-06-05 13:08:09 +03:00
self . assertEqual ( read_bridge_port_attr ( ' bridge99 ' , ' dummy98 ' , ' unicast_flood ' ) , ' 1 ' )
self . assertEqual ( read_bridge_port_attr ( ' bridge99 ' , ' dummy98 ' , ' multicast_flood ' ) , ' 0 ' )
2019-07-07 01:46:08 +03:00
# CONFIG_BRIDGE_IGMP_SNOOPING=y
if ( os . path . exists ( ' /sys/devices/virtual/net/bridge00/lower_dummy98/brport/multicast_to_unicast ' ) ) :
self . assertEqual ( read_bridge_port_attr ( ' bridge99 ' , ' dummy98 ' , ' multicast_to_unicast ' ) , ' 1 ' )
2019-03-10 23:25:24 +03:00
if ( os . path . exists ( ' /sys/devices/virtual/net/bridge99/lower_dummy98/brport/neigh_suppress ' ) ) :
2019-06-05 13:08:09 +03:00
self . assertEqual ( read_bridge_port_attr ( ' bridge99 ' , ' dummy98 ' , ' neigh_suppress ' ) , ' 1 ' )
self . assertEqual ( read_bridge_port_attr ( ' bridge99 ' , ' dummy98 ' , ' learning ' ) , ' 0 ' )
2019-07-07 01:46:08 +03:00
self . assertEqual ( read_bridge_port_attr ( ' bridge99 ' , ' dummy98 ' , ' priority ' ) , ' 23 ' )
self . assertEqual ( read_bridge_port_attr ( ' bridge99 ' , ' dummy98 ' , ' bpdu_guard ' ) , ' 1 ' )
self . assertEqual ( read_bridge_port_attr ( ' bridge99 ' , ' dummy98 ' , ' root_block ' ) , ' 1 ' )
2018-12-06 09:24:14 +03:00
2019-07-07 01:46:08 +03:00
output = check_output ( ' bridge -d link show test1 ' )
print ( output )
self . assertEqual ( read_bridge_port_attr ( ' bridge99 ' , ' test1 ' , ' priority ' ) , ' 0 ' )
2018-09-29 15:36:25 +03:00
2019-06-05 12:43:28 +03:00
check_output ( ' ip address add 192.168.0.16/24 dev bridge99 ' )
2019-02-06 14:45:56 +03:00
time . sleep ( 1 )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip addr show bridge99 ' )
2019-02-20 05:33:00 +03:00
print ( output )
self . assertRegex ( output , ' 192.168.0.16/24 ' )
2019-07-08 20:38:14 +03:00
# for issue #6088
print ( ' ### ip -6 route list table all dev bridge99 ' )
output = check_output ( ' ip -6 route list table all dev bridge99 ' )
print ( output )
self . assertRegex ( output , ' ff00::/8 table local metric 256 pref medium ' )
2019-06-05 12:43:28 +03:00
self . assertEqual ( call ( ' ip link del test1 ' ) , 0 )
2019-02-20 05:33:00 +03:00
2020-01-08 15:25:16 +03:00
self . wait_operstate ( ' bridge99 ' , ' degraded-carrier ' )
2019-02-20 05:33:00 +03:00
2019-06-05 13:03:01 +03:00
check_output ( ' ip link del dummy98 ' )
2019-02-06 14:45:56 +03:00
2020-01-08 15:25:16 +03:00
self . wait_operstate ( ' bridge99 ' , ' no-carrier ' )
2019-02-20 05:33:00 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip address show bridge99 ' )
2019-02-06 14:45:56 +03:00
print ( output )
self . assertRegex ( output , ' NO-CARRIER ' )
self . assertNotRegex ( output , ' 192.168.0.15/24 ' )
self . assertNotRegex ( output , ' 192.168.0.16/24 ' )
2019-07-08 20:38:14 +03:00
print ( ' ### ip -6 route list table all dev bridge99 ' )
output = check_output ( ' ip -6 route list table all dev bridge99 ' )
print ( output )
2019-10-31 19:19:23 +03:00
self . assertRegex ( output , ' ff00::/8 table local metric 256 (linkdown )?pref medium ' )
2019-07-08 20:38:14 +03:00
2020-04-27 22:47:28 +03:00
def test_bridge_configure_without_carrier ( self ) :
copy_unit_to_networkd_unit_path ( ' 26-bridge.netdev ' , ' 26-bridge-configure-without-carrier.network ' ,
' 11-dummy.netdev ' )
start_networkd ( )
# With ConfigureWithoutCarrier=yes, the bridge should remain configured for all these situations
for test in [ ' no-slave ' , ' add-slave ' , ' slave-up ' , ' slave-no-carrier ' , ' slave-carrier ' , ' slave-down ' ] :
with self . subTest ( test = test ) :
if test == ' no-slave ' :
# bridge has no slaves; it's up but *might* not have carrier
2020-07-09 00:05:03 +03:00
self . wait_operstate ( ' bridge99 ' , operstate = r ' (no-carrier|routable) ' , setup_state = None , setup_timeout = 30 )
2020-04-27 22:47:28 +03:00
# due to a bug in the kernel, newly-created bridges are brought up
# *with* carrier, unless they have had any setting changed; e.g.
# their mac set, priority set, etc. Then, they will lose carrier
# as soon as a (down) slave interface is added, and regain carrier
# again once the slave interface is brought up.
#self.check_link_attr('bridge99', 'carrier', '0')
elif test == ' add-slave ' :
# add slave to bridge, but leave it down; bridge is definitely no-carrier
self . check_link_attr ( ' test1 ' , ' operstate ' , ' down ' )
check_output ( ' ip link set dev test1 master bridge99 ' )
2020-07-09 00:05:03 +03:00
self . wait_operstate ( ' bridge99 ' , operstate = ' no-carrier ' , setup_state = None )
2020-04-27 22:47:28 +03:00
self . check_link_attr ( ' bridge99 ' , ' carrier ' , ' 0 ' )
elif test == ' slave-up ' :
# bring up slave, which will have carrier; bridge gains carrier
check_output ( ' ip link set dev test1 up ' )
self . wait_online ( [ ' bridge99:routable ' ] )
self . check_link_attr ( ' bridge99 ' , ' carrier ' , ' 1 ' )
elif test == ' slave-no-carrier ' :
# drop slave carrier; bridge loses carrier
check_output ( ' ip link set dev test1 carrier off ' )
self . wait_online ( [ ' bridge99:no-carrier:no-carrier ' ] )
self . check_link_attr ( ' bridge99 ' , ' carrier ' , ' 0 ' )
elif test == ' slave-carrier ' :
# restore slave carrier; bridge gains carrier
check_output ( ' ip link set dev test1 carrier on ' )
self . wait_online ( [ ' bridge99:routable ' ] )
self . check_link_attr ( ' bridge99 ' , ' carrier ' , ' 1 ' )
elif test == ' slave-down ' :
# bring down slave; bridge loses carrier
check_output ( ' ip link set dev test1 down ' )
self . wait_online ( [ ' bridge99:no-carrier:no-carrier ' ] )
self . check_link_attr ( ' bridge99 ' , ' carrier ' , ' 0 ' )
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' bridge99 ' , env = env )
self . assertRegex ( output , ' 10.1.2.3 ' )
self . assertRegex ( output , ' 10.1.2.1 ' )
2019-02-06 14:45:56 +03:00
def test_bridge_ignore_carrier_loss ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 11-dummy.netdev ' , ' 12-dummy.netdev ' , ' 26-bridge.netdev ' ,
' 26-bridge-slave-interface-1.network ' , ' 26-bridge-slave-interface-2.network ' ,
' bridge99-ignore-carrier-loss.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' dummy98:enslaved ' , ' test1:enslaved ' , ' bridge99:routable ' ] )
2019-02-06 14:45:56 +03:00
2019-06-05 12:43:28 +03:00
check_output ( ' ip address add 192.168.0.16/24 dev bridge99 ' )
2019-02-06 14:45:56 +03:00
time . sleep ( 1 )
2019-06-05 12:43:28 +03:00
check_output ( ' ip link del test1 ' )
check_output ( ' ip link del dummy98 ' )
2019-02-06 14:45:56 +03:00
time . sleep ( 3 )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip address show bridge99 ' )
2019-02-06 14:45:56 +03:00
print ( output )
self . assertRegex ( output , ' NO-CARRIER ' )
self . assertRegex ( output , ' inet 192.168.0.15/24 brd 192.168.0.255 scope global bridge99 ' )
self . assertRegex ( output , ' inet 192.168.0.16/24 scope global secondary bridge99 ' )
2019-02-20 06:45:40 +03:00
def test_bridge_ignore_carrier_loss_frequent_loss_and_gain ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 26-bridge.netdev ' , ' 26-bridge-slave-interface-1.network ' ,
' bridge99-ignore-carrier-loss.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' bridge99:no-carrier ' ] )
2019-02-20 06:45:40 +03:00
2019-06-17 05:06:01 +03:00
for trial in range ( 4 ) :
check_output ( ' ip link add dummy98 type dummy ' )
check_output ( ' ip link set dummy98 up ' )
if trial < 3 :
check_output ( ' ip link del dummy98 ' )
2019-02-20 06:45:40 +03:00
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' bridge99:routable ' , ' dummy98:enslaved ' ] )
2019-02-20 06:45:40 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip address show bridge99 ' )
2019-02-20 06:45:40 +03:00
print ( output )
self . assertRegex ( output , ' inet 192.168.0.15/24 brd 192.168.0.255 scope global bridge99 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip rule list table 100 ' )
2019-02-20 06:45:40 +03:00
print ( output )
self . assertEqual ( output , ' 0: from all to 8.8.8.8 lookup 100 ' )
2019-05-24 09:17:41 +03:00
class NetworkdLLDPTests ( unittest . TestCase , Utilities ) :
2018-09-29 15:36:25 +03:00
links = [ ' veth99 ' ]
2018-12-06 16:57:20 +03:00
units = [
' 23-emit-lldp.network ' ,
' 24-lldp.network ' ,
' 25-veth.netdev ' ]
2018-09-29 15:36:25 +03:00
def setUp ( self ) :
2019-06-05 13:08:09 +03:00
remove_links ( self . links )
2019-07-03 21:46:14 +03:00
stop_networkd ( show_logs = False )
2018-09-29 15:36:25 +03:00
def tearDown ( self ) :
2019-06-05 13:08:09 +03:00
remove_links ( self . links )
remove_unit_from_networkd_path ( self . units )
2019-07-03 21:46:14 +03:00
stop_networkd ( show_logs = True )
2018-09-29 15:36:25 +03:00
def test_lldp ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 23-emit-lldp.network ' , ' 24-lldp.network ' , ' 25-veth.netdev ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:degraded ' , ' veth-peer:degraded ' ] )
2018-09-29 15:36:25 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( * networkctl_cmd , ' lldp ' , env = env )
2018-09-29 15:36:25 +03:00
print ( output )
self . assertRegex ( output , ' veth-peer ' )
self . assertRegex ( output , ' veth99 ' )
2019-05-24 09:17:41 +03:00
class NetworkdRATests ( unittest . TestCase , Utilities ) :
2018-09-29 15:36:25 +03:00
links = [ ' veth99 ' ]
2018-12-06 16:57:20 +03:00
units = [
' 25-veth.netdev ' ,
' ipv6-prefix.network ' ,
2020-01-26 15:18:45 +03:00
' ipv6-prefix-veth.network ' ,
2020-02-06 14:05:16 +03:00
' ipv6-prefix-veth-token-static.network ' ,
2020-07-30 06:38:17 +03:00
' ipv6-prefix-veth-token-prefixstable.network ' ,
' ipv6-prefix-veth-token-prefixstable-without-address.network ' ]
2018-09-29 15:36:25 +03:00
def setUp ( self ) :
2019-06-05 13:08:09 +03:00
remove_links ( self . links )
2019-07-03 21:46:14 +03:00
stop_networkd ( show_logs = False )
2018-09-29 15:36:25 +03:00
def tearDown ( self ) :
2019-06-05 13:08:09 +03:00
remove_links ( self . links )
remove_unit_from_networkd_path ( self . units )
2019-07-03 21:46:14 +03:00
stop_networkd ( show_logs = True )
2018-09-29 15:36:25 +03:00
def test_ipv6_prefix_delegation ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' ipv6-prefix.network ' , ' ipv6-prefix-veth.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:degraded ' ] )
2018-09-29 15:36:25 +03:00
2020-01-31 11:56:42 +03:00
output = check_output ( * resolvectl_cmd , ' dns ' , ' veth99 ' , env = env )
print ( output )
self . assertRegex ( output , ' fe80:: ' )
self . assertRegex ( output , ' 2002:da8:1::1 ' )
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' veth99 ' , env = env )
2018-09-29 15:36:25 +03:00
print ( output )
self . assertRegex ( output , ' 2002:da8:1:0 ' )
2020-02-06 14:05:16 +03:00
def test_ipv6_token_static ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' ipv6-prefix.network ' , ' ipv6-prefix-veth-token-static.network ' )
2020-01-26 15:18:45 +03:00
start_networkd ( )
2020-02-09 04:27:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:degraded ' ] )
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' veth99 ' , env = env )
print ( output )
self . assertRegex ( output , ' 2002:da8:1:0:1a:2b:3c:4d ' )
2020-07-30 06:38:17 +03:00
self . assertRegex ( output , ' 2002:da8:1:0:fa:de:ca:fe ' )
self . assertRegex ( output , ' 2002:da8:2:0:1a:2b:3c:4d ' )
self . assertRegex ( output , ' 2002:da8:2:0:fa:de:ca:fe ' )
2020-02-09 04:27:06 +03:00
2020-07-30 06:38:17 +03:00
def test_ipv6_token_prefixstable ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' ipv6-prefix.network ' , ' ipv6-prefix-veth-token-prefixstable.network ' )
2020-02-09 15:25:59 +03:00
start_networkd ( )
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:degraded ' ] )
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' veth99 ' , env = env )
print ( output )
2020-07-30 06:38:17 +03:00
self . assertRegex ( output , ' 2002:da8:1:0 ' )
self . assertRegex ( output , ' 2002:da8:2:0.*78:9abc ' ) # EUI
2020-02-09 15:25:59 +03:00
2020-07-30 06:38:17 +03:00
def test_ipv6_token_prefixstable_without_address ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' ipv6-prefix.network ' , ' ipv6-prefix-veth-token-prefixstable-without-address.network ' )
2020-01-26 15:18:45 +03:00
start_networkd ( )
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:degraded ' ] )
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' veth99 ' , env = env )
print ( output )
self . assertRegex ( output , ' 2002:da8:1:0 ' )
2020-07-30 06:38:17 +03:00
self . assertRegex ( output , ' 2002:da8:2:0 ' )
2020-01-26 15:18:45 +03:00
2019-05-24 09:17:41 +03:00
class NetworkdDHCPServerTests ( unittest . TestCase , Utilities ) :
2019-05-24 09:34:19 +03:00
links = [ ' veth99 ' ]
2018-12-06 16:57:20 +03:00
units = [
' 25-veth.netdev ' ,
' dhcp-client.network ' ,
' dhcp-client-timezone-router.network ' ,
' dhcp-server.network ' ,
' dhcp-server-timezone-router.network ' ]
2018-09-29 15:36:25 +03:00
def setUp ( self ) :
2019-06-05 13:08:09 +03:00
remove_links ( self . links )
2019-07-03 21:46:14 +03:00
stop_networkd ( show_logs = False )
2018-09-29 15:36:25 +03:00
def tearDown ( self ) :
2019-06-05 13:08:09 +03:00
remove_links ( self . links )
remove_unit_from_networkd_path ( self . units )
2019-07-03 21:46:14 +03:00
stop_networkd ( show_logs = True )
2018-09-29 15:36:25 +03:00
def test_dhcp_server ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-client.network ' , ' dhcp-server.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2018-09-29 15:36:25 +03:00
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' veth99 ' , env = env )
2018-09-29 15:36:25 +03:00
print ( output )
self . assertRegex ( output , ' 192.168.5.* ' )
self . assertRegex ( output , ' Gateway: 192.168.5.1 ' )
self . assertRegex ( output , ' DNS: 192.168.5.1 ' )
self . assertRegex ( output , ' NTP: 192.168.5.1 ' )
def test_emit_router_timezone ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-client-timezone-router.network ' , ' dhcp-server-timezone-router.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2018-09-29 15:36:25 +03:00
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' veth99 ' , env = env )
2018-09-29 15:36:25 +03:00
print ( output )
self . assertRegex ( output , ' Gateway: 192.168.5.* ' )
self . assertRegex ( output , ' 192.168.5.* ' )
self . assertRegex ( output , ' Europe/Berlin ' )
2019-05-24 09:17:41 +03:00
class NetworkdDHCPClientTests ( unittest . TestCase , Utilities ) :
2018-12-06 16:57:20 +03:00
links = [
2019-02-12 08:42:12 +03:00
' veth99 ' ,
' vrf99 ' ]
2018-12-06 16:57:20 +03:00
units = [
' 25-veth.netdev ' ,
2019-02-12 08:42:12 +03:00
' 25-vrf.netdev ' ,
' 25-vrf.network ' ,
2018-12-06 16:57:20 +03:00
' dhcp-client-anonymize.network ' ,
2019-12-20 18:25:47 +03:00
' dhcp-client-decline.network ' ,
2020-01-07 08:55:58 +03:00
' dhcp-client-gateway-ipv4.network ' ,
' dhcp-client-gateway-ipv6.network ' ,
2019-02-27 13:10:47 +03:00
' dhcp-client-gateway-onlink-implicit.network ' ,
2018-12-06 16:57:20 +03:00
' dhcp-client-ipv4-dhcp-settings.network ' ,
' dhcp-client-ipv4-only-ipv6-disabled.network ' ,
' dhcp-client-ipv4-only.network ' ,
2020-04-15 23:26:20 +03:00
' dhcp-client-ipv4-use-routes-use-gateway.network ' ,
2018-12-06 16:57:20 +03:00
' dhcp-client-ipv6-only.network ' ,
' dhcp-client-ipv6-rapid-commit.network ' ,
2019-06-03 07:21:13 +03:00
' dhcp-client-keep-configuration-dhcp-on-stop.network ' ,
' dhcp-client-keep-configuration-dhcp.network ' ,
2018-12-06 16:57:20 +03:00
' dhcp-client-listen-port.network ' ,
2019-07-06 03:34:35 +03:00
' dhcp-client-reassign-static-routes-ipv4.network ' ,
' dhcp-client-reassign-static-routes-ipv6.network ' ,
2018-12-06 16:57:20 +03:00
' dhcp-client-route-metric.network ' ,
' dhcp-client-route-table.network ' ,
2019-07-03 05:55:40 +03:00
' dhcp-client-use-dns-ipv4-and-ra.network ' ,
' dhcp-client-use-dns-ipv4.network ' ,
' dhcp-client-use-dns-no.network ' ,
' dhcp-client-use-dns-yes.network ' ,
2019-07-14 04:46:16 +03:00
' dhcp-client-use-domains.network ' ,
2019-02-12 08:42:12 +03:00
' dhcp-client-vrf.network ' ,
2019-05-05 18:42:05 +03:00
' dhcp-client-with-ipv4ll-fallback-with-dhcp-server.network ' ,
' dhcp-client-with-ipv4ll-fallback-without-dhcp-server.network ' ,
2019-07-06 01:39:17 +03:00
' dhcp-client-with-static-address.network ' ,
2019-02-03 06:36:36 +03:00
' dhcp-client.network ' ,
2019-12-20 18:25:47 +03:00
' dhcp-server-decline.network ' ,
2018-12-06 16:57:20 +03:00
' dhcp-server-veth-peer.network ' ,
2019-01-17 09:38:17 +03:00
' dhcp-v4-server-veth-peer.network ' ,
' static.network ' ]
2018-09-29 15:36:25 +03:00
def setUp ( self ) :
2019-06-05 13:08:09 +03:00
stop_dnsmasq ( dnsmasq_pid_file )
remove_links ( self . links )
2019-07-03 21:46:14 +03:00
stop_networkd ( show_logs = False )
2018-09-29 15:36:25 +03:00
def tearDown ( self ) :
2019-06-05 13:08:09 +03:00
stop_dnsmasq ( dnsmasq_pid_file )
remove_lease_file ( )
remove_log_file ( )
remove_links ( self . links )
remove_unit_from_networkd_path ( self . units )
2019-07-03 21:46:14 +03:00
stop_networkd ( show_logs = True )
2018-09-29 15:36:25 +03:00
def test_dhcp_client_ipv6_only ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-server-veth-peer.network ' , ' dhcp-client-ipv6-only.network ' )
2018-09-29 15:36:25 +03:00
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth-peer:carrier ' ] )
2019-06-05 13:08:09 +03:00
start_dnsmasq ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2018-09-29 15:36:25 +03:00
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' veth99 ' , env = env )
2018-09-29 15:36:25 +03:00
print ( output )
self . assertRegex ( output , ' 2600:: ' )
self . assertNotRegex ( output , ' 192.168.5 ' )
2020-07-12 00:26:34 +03:00
output = check_output ( ' ip addr show dev veth99 ' )
print ( output )
self . assertRegex ( output , ' 2600:: ' )
self . assertNotRegex ( output , ' 192.168.5 ' )
self . assertNotRegex ( output , ' tentative ' )
2019-05-12 01:34:13 +03:00
# Confirm that ipv6 token is not set in the kernel
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip token show dev veth99 ' )
2019-05-12 01:34:13 +03:00
print ( output )
self . assertRegex ( output , ' token :: dev veth99 ' )
2018-09-29 15:36:25 +03:00
def test_dhcp_client_ipv4_only ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-server-veth-peer.network ' , ' dhcp-client-ipv4-only-ipv6-disabled.network ' )
2018-09-29 15:36:25 +03:00
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth-peer:carrier ' ] )
2019-07-16 08:28:40 +03:00
start_dnsmasq ( additional_options = ' --dhcp-option=option:dns-server,192.168.5.6,192.168.5.7 ' , lease_time = ' 2m ' )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2018-09-29 15:36:25 +03:00
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' veth99 ' , env = env )
2018-09-29 15:36:25 +03:00
print ( output )
self . assertNotRegex ( output , ' 2600:: ' )
self . assertRegex ( output , ' 192.168.5 ' )
2019-07-16 08:28:40 +03:00
self . assertRegex ( output , ' 192.168.5.6 ' )
self . assertRegex ( output , ' 192.168.5.7 ' )
# checking routes to DNS servers
output = check_output ( ' ip route show dev veth99 ' )
print ( output )
self . assertRegex ( output , r ' 192.168.5.1 proto dhcp scope link src 192.168.5.181 metric 1024 ' )
self . assertRegex ( output , r ' 192.168.5.6 proto dhcp scope link src 192.168.5.181 metric 1024 ' )
self . assertRegex ( output , r ' 192.168.5.7 proto dhcp scope link src 192.168.5.181 metric 1024 ' )
stop_dnsmasq ( dnsmasq_pid_file )
start_dnsmasq ( additional_options = ' --dhcp-option=option:dns-server,192.168.5.1,192.168.5.7,192.168.5.8 ' , lease_time = ' 2m ' )
# Sleep for 120 sec as the dnsmasq minimum lease time can only be set to 120
print ( ' Wait for the dynamic address to be renewed ' )
time . sleep ( 125 )
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' veth99 ' , env = env )
2019-07-16 08:28:40 +03:00
print ( output )
self . assertNotRegex ( output , ' 2600:: ' )
self . assertRegex ( output , ' 192.168.5 ' )
self . assertNotRegex ( output , ' 192.168.5.6 ' )
self . assertRegex ( output , ' 192.168.5.7 ' )
self . assertRegex ( output , ' 192.168.5.8 ' )
# checking routes to DNS servers
output = check_output ( ' ip route show dev veth99 ' )
print ( output )
self . assertNotRegex ( output , r ' 192.168.5.6 ' )
self . assertRegex ( output , r ' 192.168.5.1 proto dhcp scope link src 192.168.5.181 metric 1024 ' )
self . assertRegex ( output , r ' 192.168.5.7 proto dhcp scope link src 192.168.5.181 metric 1024 ' )
self . assertRegex ( output , r ' 192.168.5.8 proto dhcp scope link src 192.168.5.181 metric 1024 ' )
2018-09-29 15:36:25 +03:00
2020-04-15 23:26:20 +03:00
def test_dhcp_client_ipv4_use_routes_gateway ( self ) :
2020-04-16 01:30:33 +03:00
for ( routes , gateway , dnsroutes ) in itertools . product ( [ True , False , None ] , repeat = 3 ) :
2020-04-15 23:26:20 +03:00
self . setUp ( )
2020-04-16 01:30:33 +03:00
with self . subTest ( routes = routes , gateway = gateway , dnsroutes = dnsroutes ) :
self . _test_dhcp_client_ipv4_use_routes_gateway ( routes , gateway , dnsroutes )
2020-04-15 23:26:20 +03:00
self . tearDown ( )
2020-04-16 01:30:33 +03:00
def _test_dhcp_client_ipv4_use_routes_gateway ( self , routes , gateway , dnsroutes ) :
2020-04-15 23:26:20 +03:00
testunit = ' dhcp-client-ipv4-use-routes-use-gateway.network '
testunits = [ ' 25-veth.netdev ' , ' dhcp-server-veth-peer.network ' , testunit ]
if routes != None :
testunits . append ( f ' { testunit } .d/use-routes- { routes } .conf ' ) ;
if gateway != None :
testunits . append ( f ' { testunit } .d/use-gateway- { gateway } .conf ' ) ;
2020-04-16 01:30:33 +03:00
if dnsroutes != None :
testunits . append ( f ' { testunit } .d/use-dns-routes- { dnsroutes } .conf ' ) ;
2020-04-15 23:26:20 +03:00
copy_unit_to_networkd_unit_path ( * testunits , dropins = False )
2020-03-01 19:28:01 +03:00
start_networkd ( )
self . wait_online ( [ ' veth-peer:carrier ' ] )
start_dnsmasq ( additional_options = ' --dhcp-option=option:dns-server,192.168.5.6,192.168.5.7 ' , lease_time = ' 2m ' )
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
output = check_output ( ' ip route show dev veth99 ' )
print ( output )
2020-04-15 23:26:20 +03:00
# UseRoutes= defaults to true
useroutes = routes in [ True , None ]
# UseGateway= defaults to useroutes
usegateway = useroutes if gateway == None else gateway
2020-03-16 13:08:36 +03:00
2020-04-15 23:26:20 +03:00
# Check UseRoutes=
if useroutes :
self . assertRegex ( output , r ' 192.168.5.0/24 via 192.168.5.5 proto dhcp src 192.168.5.181 metric 1024 ' )
else :
self . assertNotRegex ( output , r ' 192.168.5.5 ' )
2020-03-16 13:08:36 +03:00
2020-04-15 23:26:20 +03:00
# Check UseGateway=
if usegateway :
self . assertRegex ( output , r ' default via 192.168.5.1 proto dhcp src 192.168.5.181 metric 1024 ' )
else :
self . assertNotRegex ( output , r ' default via 192.168.5.1 ' )
2020-04-16 01:30:33 +03:00
# Check RoutesToDNS=, which defaults to false
if dnsroutes :
2020-04-15 23:26:20 +03:00
self . assertRegex ( output , r ' 192.168.5.6 proto dhcp scope link src 192.168.5.181 metric 1024 ' )
self . assertRegex ( output , r ' 192.168.5.7 proto dhcp scope link src 192.168.5.181 metric 1024 ' )
else :
self . assertNotRegex ( output , r ' 192.168.5.6 ' )
self . assertNotRegex ( output , r ' 192.168.5.7 ' )
2020-03-16 13:08:36 +03:00
2018-09-29 15:36:25 +03:00
def test_dhcp_client_ipv4_ipv6 ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-server-veth-peer.network ' , ' dhcp-client-ipv6-only.network ' ,
' dhcp-client-ipv4-only.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth-peer:carrier ' ] )
2019-06-05 13:08:09 +03:00
start_dnsmasq ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2019-05-24 07:59:34 +03:00
# link become 'routable' when at least one protocol provide an valid address.
2019-06-04 21:55:32 +03:00
self . wait_address ( ' veth99 ' , r ' inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic ' , ipv = ' -4 ' )
2019-10-31 19:19:23 +03:00
self . wait_address ( ' veth99 ' , r ' inet6 2600::[0-9a-f]*/128 scope global (dynamic noprefixroute|noprefixroute dynamic) ' , ipv = ' -6 ' )
2018-09-29 15:36:25 +03:00
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' veth99 ' , env = env )
2018-09-29 15:36:25 +03:00
print ( output )
self . assertRegex ( output , ' 2600:: ' )
self . assertRegex ( output , ' 192.168.5 ' )
def test_dhcp_client_settings ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-server-veth-peer.network ' , ' dhcp-client-ipv4-dhcp-settings.network ' )
2018-09-29 15:36:25 +03:00
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth-peer:carrier ' ] )
2019-06-05 13:08:09 +03:00
start_dnsmasq ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2018-09-29 15:36:25 +03:00
2019-02-11 15:38:54 +03:00
print ( ' ## ip address show dev veth99 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip address show dev veth99 ' )
2018-09-29 15:36:25 +03:00
print ( output )
self . assertRegex ( output , ' 12:34:56:78:9a:bc ' )
self . assertRegex ( output , ' 192.168.5 ' )
self . assertRegex ( output , ' 1492 ' )
2019-02-11 15:38:54 +03:00
print ( ' ## ip route show table main dev veth99 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip route show table main dev veth99 ' )
2018-09-29 15:36:25 +03:00
print ( output )
2019-07-22 05:22:28 +03:00
# See issue #8726
2019-07-22 05:25:31 +03:00
main_table_is_empty = output == ' '
if not main_table_is_empty :
self . assertNotRegex ( output , ' proto dhcp ' )
2018-09-29 15:36:25 +03:00
2019-02-11 15:38:54 +03:00
print ( ' ## ip route show table 211 dev veth99 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip route show table 211 dev veth99 ' )
2019-02-11 15:38:54 +03:00
print ( output )
self . assertRegex ( output , ' default via 192.168.5.1 proto dhcp ' )
2019-07-22 05:25:31 +03:00
if main_table_is_empty :
self . assertRegex ( output , ' 192.168.5.0/24 proto dhcp ' )
2019-02-11 15:38:54 +03:00
self . assertRegex ( output , ' 192.168.5.0/24 via 192.168.5.5 proto dhcp ' )
self . assertRegex ( output , ' 192.168.5.1 proto dhcp scope link ' )
print ( ' ## dnsmasq log ' )
2019-06-05 13:08:09 +03:00
self . assertTrue ( search_words_in_dnsmasq_log ( ' vendor class: SusantVendorTest ' , True ) )
self . assertTrue ( search_words_in_dnsmasq_log ( ' DHCPDISCOVER(veth-peer) 12:34:56:78:9a:bc ' ) )
self . assertTrue ( search_words_in_dnsmasq_log ( ' client provides name: test-hostname ' ) )
self . assertTrue ( search_words_in_dnsmasq_log ( ' 26:mtu ' ) )
2018-09-29 15:36:25 +03:00
def test_dhcp6_client_settings_rapidcommit_true ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-server-veth-peer.network ' , ' dhcp-client-ipv6-only.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth-peer:carrier ' ] )
2019-06-05 13:08:09 +03:00
start_dnsmasq ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2018-09-29 15:36:25 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip address show dev veth99 ' )
2018-09-29 15:36:25 +03:00
print ( output )
self . assertRegex ( output , ' 12:34:56:78:9a:bc ' )
2019-06-05 13:08:09 +03:00
self . assertTrue ( search_words_in_dnsmasq_log ( ' 14:rapid-commit ' , True ) )
2018-09-29 15:36:25 +03:00
def test_dhcp6_client_settings_rapidcommit_false ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-server-veth-peer.network ' , ' dhcp-client-ipv6-rapid-commit.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth-peer:carrier ' ] )
2019-06-05 13:08:09 +03:00
start_dnsmasq ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2018-09-29 15:36:25 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip address show dev veth99 ' )
2018-09-29 15:36:25 +03:00
print ( output )
self . assertRegex ( output , ' 12:34:56:78:9a:bc ' )
2019-06-05 13:08:09 +03:00
self . assertFalse ( search_words_in_dnsmasq_log ( ' 14:rapid-commit ' , True ) )
2018-09-29 15:36:25 +03:00
def test_dhcp_client_settings_anonymize ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-server-veth-peer.network ' , ' dhcp-client-anonymize.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth-peer:carrier ' ] )
2019-06-05 13:08:09 +03:00
start_dnsmasq ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2018-12-06 17:14:57 +03:00
2019-06-05 13:08:09 +03:00
self . assertFalse ( search_words_in_dnsmasq_log ( ' VendorClassIdentifier=SusantVendorTest ' , True ) )
self . assertFalse ( search_words_in_dnsmasq_log ( ' test-hostname ' ) )
self . assertFalse ( search_words_in_dnsmasq_log ( ' 26:mtu ' ) )
2018-09-29 15:36:25 +03:00
def test_dhcp_client_listen_port ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-server-veth-peer.network ' , ' dhcp-client-listen-port.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth-peer:carrier ' ] )
2019-06-05 13:08:09 +03:00
start_dnsmasq ( ' --dhcp-alternate-port=67,5555 ' )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2019-05-24 07:59:34 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -4 address show dev veth99 ' )
2019-02-09 15:14:16 +03:00
print ( output )
self . assertRegex ( output , ' 192.168.5.* dynamic ' )
2018-09-29 15:36:25 +03:00
2019-07-06 01:39:17 +03:00
def test_dhcp_client_with_static_address ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-v4-server-veth-peer.network ' ,
' dhcp-client-with-static-address.network ' )
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth-peer:carrier ' ] )
2019-07-06 01:39:17 +03:00
start_dnsmasq ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2019-07-06 01:39:17 +03:00
output = check_output ( ' ip address show dev veth99 scope global ' )
print ( output )
self . assertRegex ( output , r ' inet 192.168.5.250/24 brd 192.168.5.255 scope global veth99 ' )
self . assertRegex ( output , r ' inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global secondary dynamic veth99 ' )
output = check_output ( ' ip route show dev veth99 ' )
print ( output )
self . assertRegex ( output , r ' default via 192.168.5.1 proto dhcp src 192.168.5.[0-9]* metric 1024 ' )
self . assertRegex ( output , r ' 192.168.5.0/24 proto kernel scope link src 192.168.5.250 ' )
self . assertRegex ( output , r ' 192.168.5.0/24 via 192.168.5.5 proto dhcp src 192.168.5.[0-9]* metric 1024 ' )
self . assertRegex ( output , r ' 192.168.5.1 proto dhcp scope link src 192.168.5.[0-9]* metric 1024 ' )
2018-09-29 15:36:25 +03:00
def test_dhcp_route_table_id ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-v4-server-veth-peer.network ' , ' dhcp-client-route-table.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth-peer:carrier ' ] )
2019-06-05 13:08:09 +03:00
start_dnsmasq ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2018-12-06 17:14:57 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip route show table 12 ' )
2018-09-29 15:36:25 +03:00
print ( output )
self . assertRegex ( output , ' veth99 proto dhcp ' )
self . assertRegex ( output , ' 192.168.5.1 ' )
def test_dhcp_route_metric ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-v4-server-veth-peer.network ' , ' dhcp-client-route-metric.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth-peer:carrier ' ] )
2019-06-05 13:08:09 +03:00
start_dnsmasq ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2018-12-06 17:14:57 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip route show dev veth99 ' )
2018-09-29 15:36:25 +03:00
print ( output )
self . assertRegex ( output , ' metric 24 ' )
2019-07-06 03:34:35 +03:00
def test_dhcp_client_reassign_static_routes_ipv4 ( self ) :
2019-07-06 00:43:28 +03:00
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-server-veth-peer.network ' ,
2019-07-06 03:34:35 +03:00
' dhcp-client-reassign-static-routes-ipv4.network ' )
2019-07-06 00:43:28 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth-peer:carrier ' ] )
2019-07-06 00:43:28 +03:00
start_dnsmasq ( lease_time = ' 2m ' )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2019-07-06 00:43:28 +03:00
output = check_output ( ' ip address show dev veth99 scope global ' )
print ( output )
self . assertRegex ( output , r ' inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99 ' )
output = check_output ( ' ip route show dev veth99 ' )
print ( output )
self . assertRegex ( output , r ' 192.168.5.0/24 proto kernel scope link src 192.168.5.[0-9]* ' )
self . assertRegex ( output , r ' 192.168.5.0/24 proto static ' )
self . assertRegex ( output , r ' 192.168.6.0/24 proto static ' )
self . assertRegex ( output , r ' 192.168.7.0/24 proto static ' )
2019-07-06 03:34:35 +03:00
stop_dnsmasq ( dnsmasq_pid_file )
start_dnsmasq ( ipv4_range = ' 192.168.5.210,192.168.5.220 ' , lease_time = ' 2m ' )
2019-07-06 00:43:28 +03:00
# Sleep for 120 sec as the dnsmasq minimum lease time can only be set to 120
print ( ' Wait for the dynamic address to be renewed ' )
time . sleep ( 125 )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' ] )
2019-07-06 00:43:28 +03:00
output = check_output ( ' ip route show dev veth99 ' )
print ( output )
self . assertRegex ( output , r ' 192.168.5.0/24 proto kernel scope link src 192.168.5.[0-9]* ' )
self . assertRegex ( output , r ' 192.168.5.0/24 proto static ' )
self . assertRegex ( output , r ' 192.168.6.0/24 proto static ' )
self . assertRegex ( output , r ' 192.168.7.0/24 proto static ' )
2019-07-06 03:34:35 +03:00
def test_dhcp_client_reassign_static_routes_ipv6 ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-server-veth-peer.network ' ,
' dhcp-client-reassign-static-routes-ipv6.network ' )
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth-peer:carrier ' ] )
2019-07-06 03:34:35 +03:00
start_dnsmasq ( lease_time = ' 2m ' )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2019-07-06 03:34:35 +03:00
output = check_output ( ' ip address show dev veth99 scope global ' )
print ( output )
2019-10-31 19:19:23 +03:00
self . assertRegex ( output , r ' inet6 2600::[0-9a-f]*/128 scope global (noprefixroute dynamic|dynamic noprefixroute) ' )
2019-07-06 03:34:35 +03:00
output = check_output ( ' ip -6 route show dev veth99 ' )
print ( output )
self . assertRegex ( output , r ' 2600::/64 proto ra metric 1024 ' )
self . assertRegex ( output , r ' 2600:0:0:1::/64 proto static metric 1024 pref medium ' )
stop_dnsmasq ( dnsmasq_pid_file )
start_dnsmasq ( ipv6_range = ' 2600::30,2600::40 ' , lease_time = ' 2m ' )
# Sleep for 120 sec as the dnsmasq minimum lease time can only be set to 120
print ( ' Wait for the dynamic address to be renewed ' )
time . sleep ( 125 )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' ] )
2019-07-06 03:34:35 +03:00
output = check_output ( ' ip -6 route show dev veth99 ' )
print ( output )
self . assertRegex ( output , r ' 2600::/64 proto ra metric 1024 ' )
self . assertRegex ( output , r ' 2600:0:0:1::/64 proto static metric 1024 pref medium ' )
2019-06-03 07:21:13 +03:00
def test_dhcp_keep_configuration_dhcp ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-v4-server-veth-peer.network ' , ' dhcp-client-keep-configuration-dhcp.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth-peer:carrier ' ] )
2019-06-03 07:21:13 +03:00
start_dnsmasq ( lease_time = ' 2m ' )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2018-12-06 17:14:57 +03:00
2019-06-03 07:21:13 +03:00
output = check_output ( ' ip address show dev veth99 scope global ' )
print ( output )
self . assertRegex ( output , r ' 192.168.5.* ' )
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' veth99 ' , env = env )
2018-09-29 15:36:25 +03:00
print ( output )
2019-06-03 07:21:13 +03:00
self . assertRegex ( output , r ' 192.168.5.* ' )
2018-12-06 17:14:57 +03:00
2019-04-27 03:22:40 +03:00
# Stopping dnsmasq as networkd won't be allowed to renew the DHCP lease.
2019-06-05 13:08:09 +03:00
stop_dnsmasq ( dnsmasq_pid_file )
2018-09-29 15:36:25 +03:00
# Sleep for 120 sec as the dnsmasq minimum lease time can only be set to 120
2019-06-03 07:21:13 +03:00
print ( ' Wait for the dynamic address to be expired ' )
2018-09-29 15:36:25 +03:00
time . sleep ( 125 )
2019-06-03 07:21:13 +03:00
print ( ' The lease address should be kept after lease expired ' )
output = check_output ( ' ip address show dev veth99 scope global ' )
print ( output )
self . assertRegex ( output , r ' 192.168.5.* ' )
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' veth99 ' , env = env )
2018-09-29 15:36:25 +03:00
print ( output )
2019-06-03 07:21:13 +03:00
self . assertRegex ( output , r ' 192.168.5.* ' )
2020-08-28 18:21:27 +03:00
check_output ( ' systemctl stop systemd-networkd.socket ' )
check_output ( ' systemctl stop systemd-networkd.service ' )
2019-06-03 07:21:13 +03:00
print ( ' The lease address should be kept after networkd stopped ' )
output = check_output ( ' ip address show dev veth99 scope global ' )
print ( output )
self . assertRegex ( output , r ' 192.168.5.* ' )
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' veth99 ' , env = env )
2019-06-03 07:21:13 +03:00
print ( output )
self . assertRegex ( output , r ' 192.168.5.* ' )
2019-07-15 08:18:06 +03:00
start_networkd ( 3 )
self . wait_online ( [ ' veth-peer:routable ' ] )
2019-06-03 07:21:13 +03:00
print ( ' Still the lease address should be kept after networkd restarted ' )
output = check_output ( ' ip address show dev veth99 scope global ' )
print ( output )
self . assertRegex ( output , r ' 192.168.5.* ' )
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' veth99 ' , env = env )
2019-06-03 07:21:13 +03:00
print ( output )
self . assertRegex ( output , r ' 192.168.5.* ' )
def test_dhcp_keep_configuration_dhcp_on_stop ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-v4-server-veth-peer.network ' , ' dhcp-client-keep-configuration-dhcp-on-stop.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth-peer:carrier ' ] )
2019-06-03 07:21:13 +03:00
start_dnsmasq ( lease_time = ' 2m ' )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2019-06-03 07:21:13 +03:00
output = check_output ( ' ip address show dev veth99 scope global ' )
print ( output )
self . assertRegex ( output , r ' 192.168.5.* ' )
stop_dnsmasq ( dnsmasq_pid_file )
2020-08-28 18:21:27 +03:00
check_output ( ' systemctl stop systemd-networkd.socket ' )
check_output ( ' systemctl stop systemd-networkd.service ' )
2019-06-03 07:21:13 +03:00
output = check_output ( ' ip address show dev veth99 scope global ' )
print ( output )
self . assertRegex ( output , r ' 192.168.5.* ' )
2019-07-15 08:18:06 +03:00
restart_networkd ( 3 )
self . wait_online ( [ ' veth-peer:routable ' ] )
2019-06-03 07:21:13 +03:00
output = check_output ( ' ip address show dev veth99 scope global ' )
print ( output )
self . assertNotRegex ( output , r ' 192.168.5.* ' )
2018-09-29 15:36:25 +03:00
2019-01-17 09:38:17 +03:00
def test_dhcp_client_reuse_address_as_static ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-server-veth-peer.network ' , ' dhcp-client.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth-peer:carrier ' ] )
2019-06-05 13:08:09 +03:00
start_dnsmasq ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2019-05-24 07:59:34 +03:00
# link become 'routable' when at least one protocol provide an valid address.
2019-06-04 21:55:32 +03:00
self . wait_address ( ' veth99 ' , r ' inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic ' , ipv = ' -4 ' )
2019-10-31 19:19:23 +03:00
self . wait_address ( ' veth99 ' , r ' inet6 2600::[0-9a-f]*/128 scope global (dynamic noprefixroute|noprefixroute dynamic) ' , ipv = ' -6 ' )
2019-01-17 09:38:17 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip address show dev veth99 scope global ' )
2019-01-17 09:38:17 +03:00
print ( output )
self . assertRegex ( output , ' 192.168.5 ' )
self . assertRegex ( output , ' 2600:: ' )
2019-05-24 07:59:34 +03:00
ipv4_address = re . search ( r ' 192.168.5.[0-9]*/24 ' , output )
ipv6_address = re . search ( r ' 2600::[0-9a-f:]*/128 ' , output )
2019-01-17 09:38:17 +03:00
static_network = ' \n ' . join ( [ ' [Match] ' , ' Name=veth99 ' , ' [Network] ' , ' IPv6AcceptRA=no ' , ' Address= ' + ipv4_address . group ( ) , ' Address= ' + ipv6_address . group ( ) ] )
print ( static_network )
2019-06-05 13:08:09 +03:00
remove_unit_from_networkd_path ( [ ' dhcp-client.network ' ] )
2019-01-17 09:38:17 +03:00
with open ( os . path . join ( network_unit_file_path , ' static.network ' ) , mode = ' w ' ) as f :
f . write ( static_network )
2019-05-24 07:59:34 +03:00
# When networkd started, the links are already configured, so let's wait for 5 seconds
# the links to be re-configured.
2019-07-03 21:46:14 +03:00
restart_networkd ( 5 )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2019-01-17 09:38:17 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -4 address show dev veth99 scope global ' )
2019-01-17 09:38:17 +03:00
print ( output )
self . assertRegex ( output , ' 192.168.5 ' )
self . assertRegex ( output , ' valid_lft forever preferred_lft forever ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -6 address show dev veth99 scope global ' )
2019-01-17 09:38:17 +03:00
print ( output )
self . assertRegex ( output , ' 2600:: ' )
self . assertRegex ( output , ' valid_lft forever preferred_lft forever ' )
2019-02-12 08:42:12 +03:00
@expectedFailureIfModuleIsNotAvailable ( ' vrf ' )
def test_dhcp_client_vrf ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-server-veth-peer.network ' , ' dhcp-client-vrf.network ' ,
' 25-vrf.netdev ' , ' 25-vrf.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth-peer:carrier ' ] )
2019-06-05 13:08:09 +03:00
start_dnsmasq ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' , ' vrf99:carrier ' ] )
2019-05-24 07:59:34 +03:00
# link become 'routable' when at least one protocol provide an valid address.
2019-06-04 21:55:32 +03:00
self . wait_address ( ' veth99 ' , r ' inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic ' , ipv = ' -4 ' )
2019-10-31 19:19:23 +03:00
self . wait_address ( ' veth99 ' , r ' inet6 2600::[0-9a-f]*/128 scope global (dynamic noprefixroute|noprefixroute dynamic) ' , ipv = ' -6 ' )
2019-02-12 08:42:12 +03:00
print ( ' ## ip -d link show dev vrf99 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -d link show dev vrf99 ' )
2019-02-12 08:42:12 +03:00
print ( output )
self . assertRegex ( output , ' vrf table 42 ' )
print ( ' ## ip address show vrf vrf99 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip address show vrf vrf99 ' )
2019-06-04 21:57:21 +03:00
print ( output )
self . assertRegex ( output , ' inet 169.254.[0-9]*.[0-9]*/16 brd 169.254.255.255 scope link veth99 ' )
self . assertRegex ( output , ' inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99 ' )
2019-10-31 19:19:23 +03:00
self . assertRegex ( output , ' inet6 2600::[0-9a-f]*/128 scope global (dynamic noprefixroute|noprefixroute dynamic) ' )
2019-06-04 21:57:21 +03:00
self . assertRegex ( output , ' inet6 .* scope link ' )
2019-02-12 08:42:12 +03:00
print ( ' ## ip address show dev veth99 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip address show dev veth99 ' )
2019-02-12 08:42:12 +03:00
print ( output )
self . assertRegex ( output , ' inet 169.254.[0-9]*.[0-9]*/16 brd 169.254.255.255 scope link veth99 ' )
self . assertRegex ( output , ' inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99 ' )
2019-10-31 19:19:23 +03:00
self . assertRegex ( output , ' inet6 2600::[0-9a-f]*/128 scope global (dynamic noprefixroute|noprefixroute dynamic) ' )
2019-02-12 08:42:12 +03:00
self . assertRegex ( output , ' inet6 .* scope link ' )
print ( ' ## ip route show vrf vrf99 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip route show vrf vrf99 ' )
2019-02-12 08:42:12 +03:00
print ( output )
self . assertRegex ( output , ' default via 192.168.5.1 dev veth99 proto dhcp src 192.168.5. ' )
self . assertRegex ( output , ' 169.254.0.0/16 dev veth99 proto kernel scope link src 169.254 ' )
self . assertRegex ( output , ' 192.168.5.0/24 dev veth99 proto kernel scope link src 192.168.5 ' )
self . assertRegex ( output , ' 192.168.5.0/24 via 192.168.5.5 dev veth99 proto dhcp ' )
self . assertRegex ( output , ' 192.168.5.1 dev veth99 proto dhcp scope link src 192.168.5 ' )
print ( ' ## ip route show table main dev veth99 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip route show table main dev veth99 ' )
2019-02-12 08:42:12 +03:00
print ( output )
self . assertEqual ( output , ' ' )
2020-01-07 08:55:58 +03:00
def test_dhcp_client_gateway_ipv4 ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-server-veth-peer.network ' ,
' dhcp-client-gateway-ipv4.network ' )
start_networkd ( )
self . wait_online ( [ ' veth-peer:carrier ' ] )
start_dnsmasq ( )
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
output = check_output ( ' ip route list dev veth99 10.0.0.0/8 ' )
print ( output )
self . assertRegex ( output , ' 10.0.0.0/8 via 192.168.5.1 proto static ' )
def test_dhcp_client_gateway_ipv6 ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-server-veth-peer.network ' ,
' dhcp-client-gateway-ipv6.network ' )
start_networkd ( )
self . wait_online ( [ ' veth-peer:carrier ' ] )
start_dnsmasq ( )
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
output = check_output ( ' ip -6 route list dev veth99 2001:1234:5:9fff:ff:ff:ff:ff ' )
print ( output )
self . assertRegex ( output , ' via fe80::1034:56ff:fe78:9abd ' )
2019-02-27 13:10:47 +03:00
def test_dhcp_client_gateway_onlink_implicit ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-server-veth-peer.network ' ,
' dhcp-client-gateway-onlink-implicit.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth-peer:carrier ' ] )
2019-06-05 13:08:09 +03:00
start_dnsmasq ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2019-02-27 13:10:47 +03:00
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' veth99 ' , env = env )
2019-02-27 13:10:47 +03:00
print ( output )
self . assertRegex ( output , ' 192.168.5 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip route list dev veth99 10.0.0.0/8 ' )
2019-02-27 13:10:47 +03:00
print ( output )
self . assertRegex ( output , ' onlink ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip route list dev veth99 192.168.100.0/24 ' )
2019-02-27 13:10:47 +03:00
print ( output )
self . assertRegex ( output , ' onlink ' )
2019-05-05 18:42:05 +03:00
def test_dhcp_client_with_ipv4ll_fallback_with_dhcp_server ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-server-veth-peer.network ' ,
' dhcp-client-with-ipv4ll-fallback-with-dhcp-server.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth-peer:carrier ' ] )
2019-06-05 13:08:09 +03:00
start_dnsmasq ( lease_time = ' 2m ' )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2019-05-04 02:29:45 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip address show dev veth99 ' )
2019-05-04 02:29:45 +03:00
print ( output )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -6 address show dev veth99 scope global dynamic ' )
2019-05-04 02:29:45 +03:00
self . assertNotRegex ( output , ' inet6 2600::[0-9a-f]*/128 scope global dynamic ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -6 address show dev veth99 scope link ' )
2019-05-04 02:29:45 +03:00
self . assertRegex ( output , ' inet6 .* scope link ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -4 address show dev veth99 scope global dynamic ' )
2019-05-04 02:29:45 +03:00
self . assertRegex ( output , ' inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -4 address show dev veth99 scope link ' )
2019-05-04 02:29:45 +03:00
self . assertNotRegex ( output , ' inet .* scope link ' )
print ( ' Wait for the dynamic address to be expired ' )
time . sleep ( 130 )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip address show dev veth99 ' )
2019-05-04 02:29:45 +03:00
print ( output )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -6 address show dev veth99 scope global dynamic ' )
2019-05-04 02:29:45 +03:00
self . assertNotRegex ( output , ' inet6 2600::[0-9a-f]*/128 scope global dynamic ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -6 address show dev veth99 scope link ' )
2019-05-04 02:29:45 +03:00
self . assertRegex ( output , ' inet6 .* scope link ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -4 address show dev veth99 scope global dynamic ' )
2019-05-04 02:29:45 +03:00
self . assertRegex ( output , ' inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -4 address show dev veth99 scope link ' )
2019-05-04 02:29:45 +03:00
self . assertNotRegex ( output , ' inet .* scope link ' )
2019-06-05 13:08:09 +03:00
search_words_in_dnsmasq_log ( ' DHCPOFFER ' , show_all = True )
2019-05-04 02:29:45 +03:00
2019-05-05 18:42:05 +03:00
def test_dhcp_client_with_ipv4ll_fallback_without_dhcp_server ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-server-veth-peer.network ' ,
' dhcp-client-with-ipv4ll-fallback-without-dhcp-server.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:degraded ' , ' veth-peer:routable ' ] )
2019-05-05 18:42:05 +03:00
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip address show dev veth99 ' )
2019-05-05 18:42:05 +03:00
print ( output )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -6 address show dev veth99 scope global dynamic ' )
2019-05-05 18:42:05 +03:00
self . assertNotRegex ( output , ' inet6 2600::[0-9a-f]*/128 scope global dynamic ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -6 address show dev veth99 scope link ' )
2019-05-05 18:42:05 +03:00
self . assertRegex ( output , ' inet6 .* scope link ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -4 address show dev veth99 scope global dynamic ' )
2019-05-05 18:42:05 +03:00
self . assertNotRegex ( output , ' inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99 ' )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -4 address show dev veth99 scope link ' )
2019-05-05 18:42:05 +03:00
self . assertRegex ( output , ' inet .* scope link ' )
2019-05-24 05:39:26 +03:00
def test_dhcp_client_route_remove_on_renew ( self ) :
2019-06-05 13:08:09 +03:00
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-server-veth-peer.network ' ,
' dhcp-client-ipv4-only-ipv6-disabled.network ' )
2019-06-17 05:21:45 +03:00
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth-peer:carrier ' ] )
2019-06-05 13:08:09 +03:00
start_dnsmasq ( ipv4_range = ' 192.168.5.100,192.168.5.199 ' , lease_time = ' 2m ' )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2019-05-24 05:39:26 +03:00
# test for issue #12490
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -4 address show dev veth99 scope global dynamic ' )
2019-05-24 05:39:26 +03:00
print ( output )
self . assertRegex ( output , ' inet 192.168.5.1[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99 ' )
address1 = None
for line in output . splitlines ( ) :
if ' brd 192.168.5.255 scope global dynamic veth99 ' in line :
address1 = line . split ( ) [ 1 ] . split ( ' / ' ) [ 0 ]
break
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -4 route show dev veth99 ' )
2019-05-24 05:39:26 +03:00
print ( output )
self . assertRegex ( output , f ' default via 192.168.5.1 proto dhcp src { address1 } metric 1024 ' )
self . assertRegex ( output , f ' 192.168.5.1 proto dhcp scope link src { address1 } metric 1024 ' )
2019-06-05 13:08:09 +03:00
stop_dnsmasq ( dnsmasq_pid_file )
start_dnsmasq ( ipv4_range = ' 192.168.5.200,192.168.5.250 ' , lease_time = ' 2m ' )
2019-05-24 05:39:26 +03:00
print ( ' Wait for the dynamic address to be expired ' )
time . sleep ( 130 )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -4 address show dev veth99 scope global dynamic ' )
2019-05-24 05:39:26 +03:00
print ( output )
self . assertRegex ( output , ' inet 192.168.5.2[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99 ' )
address2 = None
for line in output . splitlines ( ) :
if ' brd 192.168.5.255 scope global dynamic veth99 ' in line :
address2 = line . split ( ) [ 1 ] . split ( ' / ' ) [ 0 ]
break
self . assertNotEqual ( address1 , address2 )
2019-06-05 12:43:28 +03:00
output = check_output ( ' ip -4 route show dev veth99 ' )
2019-05-24 05:39:26 +03:00
print ( output )
self . assertNotRegex ( output , f ' default via 192.168.5.1 proto dhcp src { address1 } metric 1024 ' )
self . assertNotRegex ( output , f ' 192.168.5.1 proto dhcp scope link src { address1 } metric 1024 ' )
self . assertRegex ( output , f ' default via 192.168.5.1 proto dhcp src { address2 } metric 1024 ' )
self . assertRegex ( output , f ' 192.168.5.1 proto dhcp scope link src { address2 } metric 1024 ' )
2019-07-03 05:55:40 +03:00
def test_dhcp_client_use_dns_yes ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-server-veth-peer.network ' , ' dhcp-client-use-dns-yes.network ' )
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth-peer:carrier ' ] )
2019-07-03 05:55:40 +03:00
start_dnsmasq ( ' --dhcp-option=option:dns-server,192.168.5.1 --dhcp-option=option6:dns-server,[2600::1] ' )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2019-07-03 05:55:40 +03:00
# link become 'routable' when at least one protocol provide an valid address.
self . wait_address ( ' veth99 ' , r ' inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic ' , ipv = ' -4 ' )
2019-10-31 19:19:23 +03:00
self . wait_address ( ' veth99 ' , r ' inet6 2600::[0-9a-f]*/128 scope global (dynamic noprefixroute|noprefixroute dynamic) ' , ipv = ' -6 ' )
2019-07-03 05:55:40 +03:00
2019-07-17 17:03:01 +03:00
time . sleep ( 3 )
2019-07-03 05:55:40 +03:00
output = check_output ( * resolvectl_cmd , ' dns ' , ' veth99 ' , env = env )
print ( output )
self . assertRegex ( output , ' 192.168.5.1 ' )
self . assertRegex ( output , ' 2600::1 ' )
def test_dhcp_client_use_dns_no ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-server-veth-peer.network ' , ' dhcp-client-use-dns-no.network ' )
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth-peer:carrier ' ] )
2019-07-03 05:55:40 +03:00
start_dnsmasq ( ' --dhcp-option=option:dns-server,192.168.5.1 --dhcp-option=option6:dns-server,[2600::1] ' )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2019-07-03 05:55:40 +03:00
# link become 'routable' when at least one protocol provide an valid address.
self . wait_address ( ' veth99 ' , r ' inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic ' , ipv = ' -4 ' )
2019-10-31 19:19:23 +03:00
self . wait_address ( ' veth99 ' , r ' inet6 2600::[0-9a-f]*/128 scope global (dynamic noprefixroute|noprefixroute dynamic) ' , ipv = ' -6 ' )
2019-07-03 05:55:40 +03:00
2019-07-17 17:03:01 +03:00
time . sleep ( 3 )
2019-07-03 05:55:40 +03:00
output = check_output ( * resolvectl_cmd , ' dns ' , ' veth99 ' , env = env )
print ( output )
self . assertNotRegex ( output , ' 192.168.5.1 ' )
self . assertNotRegex ( output , ' 2600::1 ' )
def test_dhcp_client_use_dns_ipv4 ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-server-veth-peer.network ' , ' dhcp-client-use-dns-ipv4.network ' )
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth-peer:carrier ' ] )
2019-07-03 05:55:40 +03:00
start_dnsmasq ( ' --dhcp-option=option:dns-server,192.168.5.1 --dhcp-option=option6:dns-server,[2600::1] ' )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2019-07-03 05:55:40 +03:00
# link become 'routable' when at least one protocol provide an valid address.
self . wait_address ( ' veth99 ' , r ' inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic ' , ipv = ' -4 ' )
2019-10-31 19:19:23 +03:00
self . wait_address ( ' veth99 ' , r ' inet6 2600::[0-9a-f]*/128 scope global (dynamic noprefixroute|noprefixroute dynamic) ' , ipv = ' -6 ' )
2019-07-03 05:55:40 +03:00
2019-07-17 17:03:01 +03:00
time . sleep ( 3 )
2019-07-03 05:55:40 +03:00
output = check_output ( * resolvectl_cmd , ' dns ' , ' veth99 ' , env = env )
print ( output )
self . assertRegex ( output , ' 192.168.5.1 ' )
self . assertNotRegex ( output , ' 2600::1 ' )
def test_dhcp_client_use_dns_ipv4_and_ra ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-server-veth-peer.network ' , ' dhcp-client-use-dns-ipv4-and-ra.network ' )
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth-peer:carrier ' ] )
2019-07-03 05:55:40 +03:00
start_dnsmasq ( ' --dhcp-option=option:dns-server,192.168.5.1 --dhcp-option=option6:dns-server,[2600::1] ' )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2019-07-03 05:55:40 +03:00
# link become 'routable' when at least one protocol provide an valid address.
self . wait_address ( ' veth99 ' , r ' inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic ' , ipv = ' -4 ' )
2019-10-31 19:19:23 +03:00
self . wait_address ( ' veth99 ' , r ' inet6 2600::[0-9a-f]*/128 scope global (dynamic noprefixroute|noprefixroute dynamic) ' , ipv = ' -6 ' )
2019-07-03 05:55:40 +03:00
2019-07-17 17:03:01 +03:00
time . sleep ( 3 )
2019-07-03 05:55:40 +03:00
output = check_output ( * resolvectl_cmd , ' dns ' , ' veth99 ' , env = env )
print ( output )
self . assertRegex ( output , ' 192.168.5.1 ' )
self . assertRegex ( output , ' 2600::1 ' )
2019-07-14 04:46:16 +03:00
def test_dhcp_client_use_domains ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-server-veth-peer.network ' , ' dhcp-client-use-domains.network ' )
start_networkd ( )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth-peer:carrier ' ] )
2019-07-14 04:46:16 +03:00
start_dnsmasq ( ' --dhcp-option=option:domain-search,example.com ' )
2019-07-15 08:18:06 +03:00
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2019-07-14 04:46:16 +03:00
2020-01-07 05:32:04 +03:00
output = check_output ( * networkctl_cmd , ' -n ' , ' 0 ' , ' status ' , ' veth99 ' , env = env )
2019-07-14 04:46:16 +03:00
print ( output )
self . assertRegex ( output , ' Search Domains: example.com ' )
time . sleep ( 3 )
output = check_output ( * resolvectl_cmd , ' domain ' , ' veth99 ' , env = env )
print ( output )
self . assertRegex ( output , ' example.com ' )
2019-12-20 18:25:47 +03:00
def test_dhcp_client_decline ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' dhcp-server-decline.network ' , ' dhcp-client-decline.network ' )
start_networkd ( )
self . wait_online ( [ ' veth-peer:carrier ' ] )
rc = call ( * wait_online_cmd , ' --timeout=10s ' , ' --interface=veth99:routable ' , env = env )
self . assertTrue ( rc == 1 )
2019-09-16 17:43:34 +03:00
class NetworkdIPv6PrefixTests ( unittest . TestCase , Utilities ) :
links = [ ' veth99 ' ]
units = [
' 25-veth.netdev ' ,
' ipv6ra-prefix-client.network ' ,
' ipv6ra-prefix.network '
]
def setUp ( self ) :
remove_links ( self . links )
stop_networkd ( show_logs = False )
def tearDown ( self ) :
remove_log_file ( )
remove_links ( self . links )
remove_unit_from_networkd_path ( self . units )
stop_networkd ( show_logs = True )
def test_ipv6_route_prefix ( self ) :
copy_unit_to_networkd_unit_path ( ' 25-veth.netdev ' , ' ipv6ra-prefix-client.network ' , ' ipv6ra-prefix.network ' )
start_networkd ( )
self . wait_online ( [ ' veth99:routable ' , ' veth-peer:routable ' ] )
2020-02-29 18:46:56 +03:00
output = check_output ( ' ip -6 route show dev veth-peer ' )
2019-09-16 17:43:34 +03:00
print ( output )
self . assertRegex ( output , ' 2001:db8:0:1::/64 proto ra ' )
2020-02-29 18:46:56 +03:00
output = check_output ( ' ip addr show dev veth99 ' )
print ( output )
self . assertNotRegex ( output , ' 2001:db8:0:1 ' )
self . assertRegex ( output , ' 2001:db8:0:2 ' )
2019-10-30 15:35:37 +03:00
class NetworkdMTUTests ( unittest . TestCase , Utilities ) :
links = [ ' dummy98 ' ]
units = [
' 12-dummy.netdev ' ,
' 12-dummy-mtu.netdev ' ,
' 12-dummy-mtu.link ' ,
' 12-dummy.network ' ,
]
def setUp ( self ) :
remove_links ( self . links )
stop_networkd ( show_logs = False )
def tearDown ( self ) :
remove_log_file ( )
remove_links ( self . links )
remove_unit_from_networkd_path ( self . units )
stop_networkd ( show_logs = True )
def check_mtu ( self , mtu , ipv6_mtu = None , reset = True ) :
if not ipv6_mtu :
ipv6_mtu = mtu
# test normal start
start_networkd ( )
self . wait_online ( [ ' dummy98:routable ' ] )
self . assertEqual ( read_ipv6_sysctl_attr ( ' dummy98 ' , ' mtu ' ) , ipv6_mtu )
self . assertEqual ( read_link_attr ( ' dummy98 ' , ' mtu ' ) , mtu )
# test normal restart
restart_networkd ( )
self . wait_online ( [ ' dummy98:routable ' ] )
self . assertEqual ( read_ipv6_sysctl_attr ( ' dummy98 ' , ' mtu ' ) , ipv6_mtu )
self . assertEqual ( read_link_attr ( ' dummy98 ' , ' mtu ' ) , mtu )
if reset :
self . reset_check_mtu ( mtu , ipv6_mtu )
def reset_check_mtu ( self , mtu , ipv6_mtu = None ) :
''' test setting mtu/ipv6_mtu with interface already up '''
stop_networkd ( )
# note - changing the device mtu resets the ipv6 mtu
run ( ' ip link set up mtu 1501 dev dummy98 ' )
run ( ' ip link set up mtu 1500 dev dummy98 ' )
self . assertEqual ( read_link_attr ( ' dummy98 ' , ' mtu ' ) , ' 1500 ' )
self . assertEqual ( read_ipv6_sysctl_attr ( ' dummy98 ' , ' mtu ' ) , ' 1500 ' )
self . check_mtu ( mtu , ipv6_mtu , reset = False )
def test_mtu_network ( self ) :
copy_unit_to_networkd_unit_path ( ' 12-dummy.netdev ' , ' 12-dummy.network.d/mtu.conf ' )
self . check_mtu ( ' 1600 ' )
def test_mtu_netdev ( self ) :
copy_unit_to_networkd_unit_path ( ' 12-dummy-mtu.netdev ' , ' 12-dummy.network ' , dropins = False )
# note - MTU set by .netdev happens ONLY at device creation!
self . check_mtu ( ' 1600 ' , reset = False )
def test_mtu_link ( self ) :
copy_unit_to_networkd_unit_path ( ' 12-dummy.netdev ' , ' 12-dummy-mtu.link ' , ' 12-dummy.network ' , dropins = False )
# must reload udev because it only picks up new files after 3 second delay
call ( ' udevadm control --reload ' )
# note - MTU set by .link happens ONLY at udev processing of device 'add' uevent!
self . check_mtu ( ' 1600 ' , reset = False )
def test_ipv6_mtu ( self ) :
''' set ipv6 mtu without setting device mtu '''
copy_unit_to_networkd_unit_path ( ' 12-dummy.netdev ' , ' 12-dummy.network.d/ipv6-mtu-1400.conf ' )
self . check_mtu ( ' 1500 ' , ' 1400 ' )
def test_ipv6_mtu_toolarge ( self ) :
''' try set ipv6 mtu over device mtu (it shouldn ' t work) '''
copy_unit_to_networkd_unit_path ( ' 12-dummy.netdev ' , ' 12-dummy.network.d/ipv6-mtu-1550.conf ' )
self . check_mtu ( ' 1500 ' , ' 1500 ' )
def test_mtu_network_ipv6_mtu ( self ) :
''' set ipv6 mtu and set device mtu via network file '''
copy_unit_to_networkd_unit_path ( ' 12-dummy.netdev ' , ' 12-dummy.network.d/mtu.conf ' , ' 12-dummy.network.d/ipv6-mtu-1550.conf ' )
self . check_mtu ( ' 1600 ' , ' 1550 ' )
def test_mtu_netdev_ipv6_mtu ( self ) :
''' set ipv6 mtu and set device mtu via netdev file '''
copy_unit_to_networkd_unit_path ( ' 12-dummy-mtu.netdev ' , ' 12-dummy.network.d/ipv6-mtu-1550.conf ' )
self . check_mtu ( ' 1600 ' , ' 1550 ' , reset = False )
def test_mtu_link_ipv6_mtu ( self ) :
''' set ipv6 mtu and set device mtu via link file '''
copy_unit_to_networkd_unit_path ( ' 12-dummy.netdev ' , ' 12-dummy-mtu.link ' , ' 12-dummy.network.d/ipv6-mtu-1550.conf ' )
# must reload udev because it only picks up new files after 3 second delay
call ( ' udevadm control --reload ' )
self . check_mtu ( ' 1600 ' , ' 1550 ' , reset = False )
2018-09-29 15:36:25 +03:00
if __name__ == ' __main__ ' :
2019-05-30 06:33:57 +03:00
parser = argparse . ArgumentParser ( )
parser . add_argument ( ' --build-dir ' , help = ' Path to build dir ' , dest = ' build_dir ' )
parser . add_argument ( ' --networkd ' , help = ' Path to systemd-networkd ' , dest = ' networkd_bin ' )
2019-06-04 01:05:07 +03:00
parser . add_argument ( ' --resolved ' , help = ' Path to systemd-resolved ' , dest = ' resolved_bin ' )
2020-02-04 17:51:58 +03:00
parser . add_argument ( ' --udevd ' , help = ' Path to systemd-udevd ' , dest = ' udevd_bin ' )
2019-05-30 06:33:57 +03:00
parser . add_argument ( ' --wait-online ' , help = ' Path to systemd-networkd-wait-online ' , dest = ' wait_online_bin ' )
parser . add_argument ( ' --networkctl ' , help = ' Path to networkctl ' , dest = ' networkctl_bin ' )
2019-06-04 01:05:07 +03:00
parser . add_argument ( ' --resolvectl ' , help = ' Path to resolvectl ' , dest = ' resolvectl_bin ' )
parser . add_argument ( ' --timedatectl ' , help = ' Path to timedatectl ' , dest = ' timedatectl_bin ' )
2019-05-30 06:33:57 +03:00
parser . add_argument ( ' --valgrind ' , help = ' Enable valgrind ' , dest = ' use_valgrind ' , type = bool , nargs = ' ? ' , const = True , default = use_valgrind )
parser . add_argument ( ' --debug ' , help = ' Generate debugging logs ' , dest = ' enable_debug ' , type = bool , nargs = ' ? ' , const = True , default = enable_debug )
2019-05-30 09:49:11 +03:00
parser . add_argument ( ' --asan-options ' , help = ' ASAN options ' , dest = ' asan_options ' )
2019-05-31 02:49:48 +03:00
parser . add_argument ( ' --lsan-options ' , help = ' LSAN options ' , dest = ' lsan_options ' )
2019-05-30 09:49:11 +03:00
parser . add_argument ( ' --ubsan-options ' , help = ' UBSAN options ' , dest = ' ubsan_options ' )
2019-05-30 06:33:57 +03:00
ns , args = parser . parse_known_args ( namespace = unittest )
if ns . build_dir :
2020-02-04 17:51:58 +03:00
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 :
2019-06-04 01:05:07 +03:00
print ( ' WARNING: --networkd, --resolved, --wait-online, --networkctl, --resolvectl, or --timedatectl options are ignored when --build-dir is specified. ' )
2019-05-30 06:33:57 +03:00
networkd_bin = os . path . join ( ns . build_dir , ' systemd-networkd ' )
2019-06-04 01:05:07 +03:00
resolved_bin = os . path . join ( ns . build_dir , ' systemd-resolved ' )
2020-02-04 17:51:58 +03:00
udevd_bin = os . path . join ( ns . build_dir , ' systemd-udevd ' )
2019-05-30 06:33:57 +03:00
wait_online_bin = os . path . join ( ns . build_dir , ' systemd-networkd-wait-online ' )
networkctl_bin = os . path . join ( ns . build_dir , ' networkctl ' )
2019-06-04 01:05:07 +03:00
resolvectl_bin = os . path . join ( ns . build_dir , ' resolvectl ' )
timedatectl_bin = os . path . join ( ns . build_dir , ' timedatectl ' )
2019-05-30 06:33:57 +03:00
else :
if ns . networkd_bin :
networkd_bin = ns . networkd_bin
2019-06-04 01:05:07 +03:00
if ns . resolved_bin :
resolved_bin = ns . resolved_bin
2020-02-04 17:51:58 +03:00
if ns . udevd_bin :
udevd_bin = ns . udevd_bin
2019-05-30 06:33:57 +03:00
if ns . wait_online_bin :
wait_online_bin = ns . wait_online_bin
if ns . networkctl_bin :
networkctl_bin = ns . networkctl_bin
2019-06-04 01:05:07 +03:00
if ns . resolvectl_bin :
resolvectl_bin = ns . resolvectl_bin
if ns . timedatectl_bin :
timedatectl_bin = ns . timedatectl_bin
2019-05-30 06:33:57 +03:00
use_valgrind = ns . use_valgrind
enable_debug = ns . enable_debug
2019-05-30 09:49:11 +03:00
asan_options = ns . asan_options
2019-05-31 02:49:48 +03:00
lsan_options = ns . lsan_options
2019-05-30 09:49:11 +03:00
ubsan_options = ns . ubsan_options
2019-05-30 06:33:57 +03:00
if use_valgrind :
networkctl_cmd = [ ' valgrind ' , ' --track-origins=yes ' , ' --leak-check=full ' , ' --show-leak-kinds=all ' , networkctl_bin ]
2019-06-04 01:05:07 +03:00
resolvectl_cmd = [ ' valgrind ' , ' --track-origins=yes ' , ' --leak-check=full ' , ' --show-leak-kinds=all ' , resolvectl_bin ]
timedatectl_cmd = [ ' valgrind ' , ' --track-origins=yes ' , ' --leak-check=full ' , ' --show-leak-kinds=all ' , timedatectl_bin ]
2019-05-30 06:33:57 +03:00
wait_online_cmd = [ ' valgrind ' , ' --track-origins=yes ' , ' --leak-check=full ' , ' --show-leak-kinds=all ' , wait_online_bin ]
else :
networkctl_cmd = [ networkctl_bin ]
2019-06-04 01:05:07 +03:00
resolvectl_cmd = [ resolvectl_bin ]
timedatectl_cmd = [ timedatectl_bin ]
2019-05-30 06:33:57 +03:00
wait_online_cmd = [ wait_online_bin ]
if enable_debug :
env . update ( { ' SYSTEMD_LOG_LEVEL ' : ' debug ' } )
2019-05-30 09:49:11 +03:00
if asan_options :
env . update ( { ' ASAN_OPTIONS ' : asan_options } )
2019-05-31 02:49:48 +03:00
if lsan_options :
env . update ( { ' LSAN_OPTIONS ' : lsan_options } )
2019-05-30 09:49:11 +03:00
if ubsan_options :
env . update ( { ' UBSAN_OPTIONS ' : ubsan_options } )
2019-05-30 06:33:57 +03:00
sys . argv [ 1 : ] = args
2018-09-29 15:36:25 +03:00
unittest . main ( testRunner = unittest . TextTestRunner ( stream = sys . stdout ,
verbosity = 3 ) )