diff options
6 files changed, 72 insertions, 1 deletions
diff --git a/test/test-network/conf/dhcp-client-ipv4-ipv6ra-prefix-client-with-delay.network b/test/test-network/conf/dhcp-client-ipv4-ipv6ra-prefix-client-with-delay.network new file mode 100644 index 0000000000..448cfb0e59 --- /dev/null +++ b/test/test-network/conf/dhcp-client-ipv4-ipv6ra-prefix-client-with-delay.network @@ -0,0 +1,9 @@ +[Match] +Name=veth99 + +[NetworkEmulator] +DelaySec=9 + +[Network] +DHCP=ipv4 +IPv6AcceptRA=true diff --git a/test/test-network/conf/dhcp-server-with-ipv6-prefix.network b/test/test-network/conf/dhcp-server-with-ipv6-prefix.network new file mode 100644 index 0000000000..05ebe3e7e2 --- /dev/null +++ b/test/test-network/conf/dhcp-server-with-ipv6-prefix.network @@ -0,0 +1,11 @@ +[Match] +Name=veth-peer + +[Network] +Address=192.168.5.1/24 +IPv6AcceptRA=no +DHCPServer=yes +IPv6SendRA=yes + +[IPv6Prefix] +Prefix=2002:da8:1:0::/64 diff --git a/test/test-network/conf/ipv6-prefix-with-delay.network b/test/test-network/conf/ipv6-prefix-with-delay.network new file mode 100644 index 0000000000..4fe3c9a04b --- /dev/null +++ b/test/test-network/conf/ipv6-prefix-with-delay.network @@ -0,0 +1,12 @@ +[Match] +Name=veth-peer + +[NetworkEmulator] +DelaySec=15 + +[Network] +IPv6AcceptRA=no +IPv6SendRA=yes + +[IPv6Prefix] +Prefix=2002:da8:1:0::/64 diff --git a/test/test-network/conf/ipv6ra-prefix-client-with-static-ipv4-address.network b/test/test-network/conf/ipv6ra-prefix-client-with-static-ipv4-address.network new file mode 100644 index 0000000000..13fd0adeff --- /dev/null +++ b/test/test-network/conf/ipv6ra-prefix-client-with-static-ipv4-address.network @@ -0,0 +1,6 @@ +[Match] +Name=veth99 + +[Network] +IPv6AcceptRA=true +Address=192.168.5.1/24 diff --git a/test/test-network/conf/state-file-tests.network b/test/test-network/conf/state-file-tests.network index 1f7e7d16f0..d9db9a9ab9 100644 --- a/test/test-network/conf/state-file-tests.network +++ b/test/test-network/conf/state-file-tests.network @@ -3,6 +3,7 @@ Name=dummy98 [Link] RequiredForOnline=routable +RequiredFamilyForOnline=both [Network] IPv6AcceptRA=no @@ -14,3 +15,4 @@ MulticastDNS=yes DNSSEC=no Address=192.168.10.10/24 Address=192.168.12.12/24 +Address=2002:da8:1:0:1034:56ff:fe78:9abc/64 diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py index fc88fefd0f..28ffe3d8ba 100755 --- a/test/test-network/systemd-networkd-tests.py +++ b/test/test-network/systemd-networkd-tests.py @@ -555,7 +555,7 @@ class Utilities(): self.fail(f'Timed out waiting for {link} to reach state {operstate}/{setup_state}') return False - def wait_online(self, links_with_operstate, timeout='20s', bool_any=False, setup_state='configured', setup_timeout=5): + def wait_online(self, links_with_operstate, timeout='20s', bool_any=False, ipv4=False, ipv6=False, setup_state='configured', setup_timeout=5): """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, @@ -569,6 +569,9 @@ class Utilities(): 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. + Set 'ipv4' or 'ipv6' to True to wait for IPv4 address or IPv6 address, respectively, of each of the given links. + This is applied only for the operational state 'degraded' or above. + 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*. @@ -578,6 +581,10 @@ class Utilities(): args = wait_online_cmd + [f'--timeout={timeout}'] + [f'--interface={link}' for link in links_with_operstate] if bool_any: args += ['--any'] + if ipv4: + args += ['--ipv4'] + if ipv6: + args += ['--ipv6'] try: check_output(*args, env=env) except subprocess.CalledProcessError: @@ -1781,6 +1788,7 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities): 'gretun97', 'ip6gretun97', 'test1', + 'veth-peer', 'veth99', 'vrf99', ] @@ -1842,6 +1850,10 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities): '25-vrf.netdev', '25-vrf.network', '26-link-local-addressing-ipv6.network', + 'dhcp-client-ipv4-ipv6ra-prefix-client-with-delay.network', + 'dhcp-server-with-ipv6-prefix.network', + 'ipv6ra-prefix-client-with-static-ipv4-address.network', + 'ipv6-prefix-with-delay.network', 'routing-policy-rule-dummy98.network', 'routing-policy-rule-test1.network', 'routing-policy-rule-reconfigure1.network', @@ -3099,6 +3111,22 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities): call('rmmod netdevsim', stderr=subprocess.DEVNULL) + def test_wait_online_ipv4(self): + copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-with-ipv6-prefix.network', 'dhcp-client-ipv4-ipv6ra-prefix-client-with-delay.network') + start_networkd() + + self.wait_online(['veth99:routable'], ipv4=True) + + self.wait_address('veth99', r'192.168.5.[0-9]+', ipv='-4', timeout_sec=1) + + def test_wait_online_ipv6(self): + copy_unit_to_networkd_unit_path('25-veth.netdev', 'ipv6-prefix-with-delay.network', 'ipv6ra-prefix-client-with-static-ipv4-address.network') + start_networkd() + + self.wait_online(['veth99:routable'], ipv6=True) + + self.wait_address('veth99', r'2002:da8:1:0:1034:56ff:fe78:9abc', ipv='-6', timeout_sec=1) + class NetworkdStateFileTests(unittest.TestCase, Utilities): links = [ 'dummy98', @@ -3135,10 +3163,13 @@ class NetworkdStateFileTests(unittest.TestCase, Utilities): with open(path) as f: data = f.read() + self.assertRegex(data, r'IPV4_ADDRESS_STATE=routable') + self.assertRegex(data, r'IPV6_ADDRESS_STATE=routable') 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'REQUIRED_FAMILY_FOR_ONLINE=both') self.assertRegex(data, r'ACTIVATION_POLICY=up') self.assertRegex(data, r'NETWORK_FILE=/run/systemd/network/state-file-tests.network') self.assertRegex(data, r'DNS=10.10.10.10#aaa.com 10.10.10.11:1111#bbb.com \[1111:2222::3333\]:1234#ccc.com') |