From: Yu Watanabe Date: Mon, 31 Jul 2023 08:52:09 +0000 (+0900) Subject: test-network: add more tests for address properties X-Git-Tag: v255-rc1~868^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f2bcd3245a948871fa3eef86bba395ffd66f28d3;p=thirdparty%2Fsystemd.git test-network: add more tests for address properties --- diff --git a/test/test-network/conf/25-address-static.network b/test/test-network/conf/25-address-static.network index 2a96491b52f..a406aab7e48 100644 --- a/test/test-network/conf/25-address-static.network +++ b/test/test-network/conf/25-address-static.network @@ -14,102 +14,166 @@ Address=2001:db8:0:f102::15/64 Address=hogehoge Address=foofoo +## With Label= [Address] -Address=10.3.2.3/16 -Label=32 +Address=10.3.1.1/24 +Label=label1 [Address] -Address=10.4.2.3/16 -Peer=10.4.2.4/16 -Label=33 +Address=10.3.2.1/24 +Label=label2 [Address] -Address=0.0.0.0/24 -Label=34 +Address=10.3.3.1/24 +Label= +## With Broadcast= [Address] -Address=0.0.0.0/16 -Label=35 +Address=10.4.1.1/24 +Broadcast=no [Address] -# this section must be ignored -Peer=hoge -Address=10.10.0.1/16 -Label=30 +Address=10.4.2.1/24 +Broadcast=yes [Address] -# this section must be ignored -Label=30 -Peer=hoge -Address=10.10.0.2/16 +Address=10.4.3.1/24 +Broadcast=10.4.3.63 [Address] -# address and peer must be in the same family -Address=10.10.0.3/16 -Peer=2001:db8:0:f103::10/128 +# Invalid broadcast +Address=10.4.4.1/24 +Broadcast=yes +Broadcast= +Broadcast=::1 + +[Address] +# broadcast cannot set for IPv6 address +Address=2001:db8:0:f101::2/64 +Broadcast=::1 +## With/without Peer= [Address] -Address=2001:db8:0:f102::16/64 +Address=10.5.1.1/24 +Peer=10.5.1.101/24 [Address] -Address=2001:db8:0:f103::20/128 +Address=10.5.2.1/24 +Peer=10.5.2.101/24 + +[Address] +Address=10.5.3.1/24 +#Peer= (no-peer) + +[Address] +Address=2001:db8:0:f103::1/128 +Peer=2001:db8:0:f103::101/128 + +[Address] +Address=2001:db8:0:f103::2/128 +Peer=2001:db8:0:f103::102/128 + +[Address] +Address=2001:db8:0:f103::3/128 +#Peer= (no-peer) + +[Address] +# address and peer must be in the same family +Address=10.5.4.1/24 Peer=2001:db8:0:f103::10/128 [Address] -Address=2001:db8:0:f104::16/64 -RouteMetric=128 +# address and peer must be in the same family +Address=2001:db8:0:f103::4/64 +Peer=192.168.0.1 [Address] -Address=::/64 +# invalid peer, this section will be ignored +Address=10.5.5.1/24 +Peer=hoge -[Network] -# this will later deduped by the following section -Address=10.7.8.9/16 +## With Scope= +[Address] +Address=10.6.1.1/24 +Scope=global [Address] -Address=10.7.8.9/16 -PreferredLifetime=0 +Address=10.6.2.1/24 Scope=link +## For lifetime [Address] -# this will also deduped -Address=2001:0db8:1:f101::1/64 +Address=10.7.1.1/24 PreferredLifetime=infinity [Address] -Address=2001:0db8:1:f101::1/64 +Address=10.7.2.1/24 PreferredLifetime=0 [Address] -Address=10.8.8.1/16 -Broadcast=yes -Broadcast= -Broadcast=no +Address=2001:db8:0:f104::1/64 +PreferredLifetime=infinity [Address] -Address=10.8.8.2/16 -Broadcast=10.8.8.128 +Address=2001:db8:0:f104::2/64 +PreferredLifetime=0 +## For RouteMetric= [Address] -# Invalid broadcast -Address=10.8.8.2/16 -Broadcast=::1 +Address=10.8.1.1/24 +RouteMetric=128 [Address] -# broadcast cannot set for IPv6 address -Address=2001:0db8:1:f101::2/64 -Broadcast=::1 +# invalid metric +Address=10.8.2.1/24 +RouteMetric=hoge [Address] -Address=10.9.0.1/16 +Address=2001:db8:0:f105::1/64 RouteMetric=128 +## For flags [Address] -# invalid metric -Address=10.9.0.1/16 -RouteMetric=hoge +Address=10.9.1.1/24 +AddPrefixRoute=no + +[Address] +Address=10.9.2.1/24 +AddPrefixRoute=yes + +[Address] +# invalid flags for IPv4 address +Address=10.9.3.1/24 +HomeAddress=yes +ManageTemporaryAddress=yes + +[Address] +Address=2001:db8:0:f106::1/64 +HomeAddress=no +ManageTemporaryAddress=no +AddPrefixRoute=no + +[Address] +Address=2001:db8:0:f106::2/64 +HomeAddress=yes +ManageTemporaryAddress=yes +AddPrefixRoute=yes + +# TODO: add tests for AutoJoin= + +## null address +[Address] +Address=0.0.0.0/16 +Label=subnet16 + +[Address] +Address=0.0.0.0/24 +Label=subnet24 + +[Address] +Address=::/73 [Address] -Address=10.4.3.2/24 +Address=10.10.1.1/24 # just a random label which should exist NetLabel=system_u:object_r:root_t:s0 diff --git a/test/test-network/conf/25-address-static.network.d/10-override-route-metric.conf b/test/test-network/conf/25-address-static.network.d/10-override-route-metric.conf deleted file mode 100644 index da5bec2a34d..00000000000 --- a/test/test-network/conf/25-address-static.network.d/10-override-route-metric.conf +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later - -[Address] -Address=10.9.0.1/16 -RouteMetric=256 - -[Address] -Address=2001:db8:0:f104::16/64 -RouteMetric=256 diff --git a/test/test-network/conf/25-address-static.network.d/10-override.conf b/test/test-network/conf/25-address-static.network.d/10-override.conf new file mode 100644 index 00000000000..0c87809b4a4 --- /dev/null +++ b/test/test-network/conf/25-address-static.network.d/10-override.conf @@ -0,0 +1,139 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +# For checking if each address property is correctly updated. +# Comments are previous values + +## For Label= +[Address] +Address=10.3.1.1/24 +#Label=label1 +Label=new-label1 + +[Address] +Address=10.3.2.1/24 +#Label=label2 +Label= + +[Address] +Address=10.3.3.1/24 +#Label= +Label=new-label3 + +## For Broadcast= +[Address] +Address=10.4.1.1/24 +#Broadcast=no +Broadcast=yes + +[Address] +Address=10.4.2.1/24 +#Broadcast=yes +Broadcast=no + +[Address] +Address=10.4.3.1/24 +#Broadcast=10.4.3.63 +Broadcast=10.4.3.31 + +## For Peer= +[Address] +Address=10.5.1.1/24 +#Peer=10.5.1.101/24 +Peer=10.5.1.102/24 + +[Address] +Address=10.5.2.1/24 +#Peer=10.5.2.101/24 +#Peer= (no-peer) + +[Address] +Address=10.5.3.1/24 +#Peer= (no-peer) +Peer=10.5.3.102/24 + +[Address] +Address=2001:db8:0:f103::1/128 +#Peer=2001:db8:0:f103::101/128 +Peer=2001:db8:0:f103::201/128 + +[Address] +Address=2001:db8:0:f103::2/128 +#Peer=2001:db8:0:f103::102/128 +#Peer= (no-peer) + +[Address] +Address=2001:db8:0:f103::3/128 +#Peer= (no-peer) +Peer=2001:db8:0:f103::203/128 + +## For Scope= +[Address] +Address=10.6.1.1/24 +#Scope=global +Scope=link + +[Address] +Address=10.6.2.1/24 +#Scope=link +Scope=global + +## For lifetime +[Address] +Address=10.7.1.1/24 +#PreferredLifetime=infinity +PreferredLifetime=0 + +[Address] +Address=10.7.2.1/24 +#PreferredLifetime=0 +PreferredLifetime=infinity + +[Address] +Address=2001:db8:0:f104::1/64 +#PreferredLifetime=infinity +PreferredLifetime=0 + +[Address] +Address=2001:db8:0:f104::2/64 +#PreferredLifetime=0 +PreferredLifetime=infinity + +## For RouteMetric= +[Address] +Address=10.8.1.1/24 +# RouteMetric=128 +RouteMetric=256 + +[Address] +Address=2001:db8:0:f105::1/64 +# RouteMetric=128 +RouteMetric=256 + +## For flags +[Address] +Address=10.9.1.1/24 +#AddPrefixRoute=no +AddPrefixRoute=yes + +[Address] +Address=10.9.2.1/24 +#AddPrefixRoute=yes +AddPrefixRoute=no + +[Address] +Address=2001:db8:0:f106::1/64 +#HomeAddress=no +#ManageTemporaryAddress=no +#AddPrefixRoute=no +HomeAddress=yes +ManageTemporaryAddress=yes +AddPrefixRoute=yes + +[Address] +Address=2001:db8:0:f106::2/64 +#HomeAddress=yes +#ManageTemporaryAddress=yes +#AddPrefixRoute=yes +HomeAddress=no +ManageTemporaryAddress=no +AddPrefixRoute=no diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py index 7c13af58e83..7f922b46f6c 100755 --- a/test/test-network/systemd-networkd-tests.py +++ b/test/test-network/systemd-networkd-tests.py @@ -2329,107 +2329,234 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities): def tearDown(self): tear_down_common() - def verify_address_static(self, route_metric): - # IPv4 addresses - output = check_output('ip -4 address show dev dummy98') + def verify_address_static( + self, + label1: str, + label2: str, + label3: str, + broadcast1: str, + broadcast2: str, + broadcast3: str, + peer1: str, + peer2: str, + peer3: str, + peer4: str, + peer5: str, + peer6: str, + scope1: str, + scope2: str, + deprecated1: str, + deprecated2: str, + deprecated3: str, + deprecated4: str, + route_metric: int, + flag1: str, + flag2: str, + flag3: str, + flag4: str, + ): + output = check_output('ip address show dev dummy98') print(output) + + # simple settings self.assertIn('inet 10.1.2.3/16 brd 10.1.255.255 scope global dummy98', output) self.assertIn('inet 10.1.2.4/16 brd 10.1.255.255 scope global secondary dummy98', output) self.assertIn('inet 10.2.2.4/16 brd 10.2.255.255 scope global dummy98', output) - self.assertIn('inet 10.7.8.9/16 brd 10.7.255.255 scope link deprecated dummy98', output) - self.assertIn('inet 10.8.8.1/16 scope global dummy98', output) - self.assertIn('inet 10.8.8.2/16 brd 10.8.8.128 scope global secondary dummy98', output) - self.assertRegex(output, rf'inet 10.9.0.1/16 (metric {route_metric} |)brd 10.9.255.255 scope global dummy98') - - # invalid sections - self.assertNotIn('10.10.0.1/16', output) - self.assertNotIn('10.10.0.2/16', output) - - # address labels - output = check_output('ip -4 address show dev dummy98 label 32') - self.assertIn('inet 10.3.2.3/16 brd 10.3.255.255 scope global 32', output) - - output = check_output('ip -4 address show dev dummy98 label 33') - self.assertIn('inet 10.4.2.3 peer 10.4.2.4/16 scope global 33', output) - - output = check_output('ip -4 address show dev dummy98 label 34') - self.assertRegex(output, r'inet 192.168.[0-9]*.1/24 brd 192.168.[0-9]*.255 scope global 34') - - output = check_output('ip -4 address show dev dummy98 label 35') - self.assertRegex(output, r'inet 172.[0-9]*.0.1/16 brd 172.[0-9]*.255.255 scope global 35') - - # check metric of prefix route - output = check_output('ip -4 route show dev dummy98 10.9.0.0/16') - print(output) - self.assertIn(f'10.9.0.0/16 proto kernel scope link src 10.9.0.1 metric {route_metric}', output) - output = check_output('ip -6 route show dev dummy98 2001:db8:0:f104::/64') - print(output) - self.assertIn(f'2001:db8:0:f104::/64 proto kernel metric {route_metric}', output) - - # IPv6 addresses - output = check_output('ip -6 address show dev dummy98') - print(output) self.assertIn('inet6 2001:db8:0:f101::15/64 scope global', output) self.assertIn('inet6 2001:db8:0:f101::16/64 scope global', output) self.assertIn('inet6 2001:db8:0:f102::15/64 scope global', output) - self.assertIn('inet6 2001:db8:0:f102::16/64 scope global', output) - self.assertIn('inet6 2001:db8:0:f103::20 peer 2001:db8:0:f103::10/128 scope global', output) - self.assertRegex(output, rf'inet6 2001:db8:0:f104::16/64 (metric {route_metric} |)scope global') - self.assertIn('inet6 2001:db8:1:f101::1/64 scope global deprecated', output) - self.assertRegex(output, r'inet6 fd[0-9a-f:]*1/64 scope global') + + # label + self.assertIn(f'inet 10.3.1.1/24 brd 10.3.1.255 scope global {label1}', output) + self.assertIn(f'inet 10.3.2.1/24 brd 10.3.2.255 scope global {label2}', output) + self.assertIn(f'inet 10.3.3.1/24 brd 10.3.3.255 scope global {label3}', output) + + # broadcast + self.assertIn(f'inet 10.4.1.1/24{broadcast1} scope global dummy98', output) + self.assertIn(f'inet 10.4.2.1/24{broadcast2} scope global dummy98', output) + self.assertIn(f'inet 10.4.3.1/24{broadcast3} scope global dummy98', output) + + # peer + self.assertIn(f'inet 10.5.1.1{peer1} scope global dummy98', output) + self.assertIn(f'inet 10.5.2.1{peer2} scope global dummy98', output) + self.assertIn(f'inet 10.5.3.1{peer3} scope global dummy98', output) + self.assertIn(f'inet6 2001:db8:0:f103::1{peer4} scope global', output) + self.assertIn(f'inet6 2001:db8:0:f103::2{peer5} scope global', output) + self.assertIn(f'inet6 2001:db8:0:f103::3{peer6} scope global', output) + + # scope + self.assertIn(f'inet 10.6.1.1/24 brd 10.6.1.255 scope {scope1} dummy98', output) + self.assertIn(f'inet 10.6.2.1/24 brd 10.6.2.255 scope {scope2} dummy98', output) + + # lifetime + self.assertIn(f'inet 10.7.1.1/24 brd 10.7.1.255 scope global{deprecated1} dummy98', output) + self.assertIn(f'inet 10.7.2.1/24 brd 10.7.2.255 scope global{deprecated2} dummy98', output) + self.assertIn(f'inet6 2001:db8:0:f104::1/64 scope global{deprecated3}', output) + self.assertIn(f'inet6 2001:db8:0:f104::2/64 scope global{deprecated4}', output) + + # route metric + self.assertRegex(output, rf'inet 10.8.1.1/24 (metric {route_metric} |)brd 10.8.1.255 scope global dummy98') + self.assertRegex(output, rf'inet6 2001:db8:0:f105::1/64 (metric {route_metric} |)scope global') + + output_route = check_output('ip -4 route show dev dummy98 10.8.1.0/24') + print(output_route) + self.assertIn(f'10.8.1.0/24 proto kernel scope link src 10.8.1.1 metric {route_metric}', output_route) + + output_route = check_output('ip -6 route show dev dummy98 2001:db8:0:f105::/64') + print(output_route) + self.assertIn(f'2001:db8:0:f105::/64 proto kernel metric {route_metric}', output_route) + + # flags + self.assertIn(f'inet 10.9.1.1/24 brd 10.9.1.255 scope global{flag1} dummy98', output) + self.assertIn(f'inet 10.9.2.1/24 brd 10.9.2.255 scope global{flag2} dummy98', output) + self.assertIn(f'inet6 2001:db8:0:f106::1/64 scope global{flag3}', output) + self.assertIn(f'inet6 2001:db8:0:f106::2/64 scope global{flag4}', output) + + # null address + self.assertRegex(output, r'inet [0-9]*.[0-9]*.0.1/16 brd [0-9]*.[0-9]*.255.255 scope global subnet16') + self.assertRegex(output, r'inet [0-9]*.[0-9]*.[0-9]*.1/24 brd [0-9]*.[0-9]*.[0-9]*.255 scope global subnet24') + self.assertRegex(output, r'inet6 [0-9a-f:]*:1/73 scope global') + + # invalid sections + self.assertNotIn('10.4.4.1', output) + self.assertNotIn('10.5.4.1', output) + self.assertNotIn('10.5.5.1', output) + self.assertNotIn('10.8.2.1', output) + self.assertNotIn('10.9.3.1', output) + self.assertNotIn('2001:db8:0:f101::2', output) + self.assertNotIn('2001:db8:0:f103::4', output) # netlabel - self.check_netlabel('dummy98', r'10\.4\.3\.0/24') + self.check_netlabel('dummy98', r'10\.10\.1\.0/24') output = check_output(*networkctl_cmd, '--json=short', 'status', env=env) check_json(output) def test_address_static(self): - # test for #22515. The address will be removed and replaced with /64 prefix. - check_output('ip link add dummy98 type dummy') - check_output('ip link set dev dummy98 up') - check_output('ip -6 address add 2001:db8:0:f101::15/128 dev dummy98') - self.wait_address('dummy98', '2001:db8:0:f101::15/128', ipv='-6') - check_output('ip -4 address add 10.3.2.3/16 brd 10.3.255.250 scope global label dummy98:hoge dev dummy98') - self.wait_address('dummy98', '10.3.2.3/16 brd 10.3.255.250', ipv='-4') - copy_network_unit('25-address-static.network', '12-dummy.netdev', copy_dropins=False) start_networkd() self.wait_online(['dummy98:routable']) - self.verify_address_static(route_metric=128) - - copy_network_unit('25-address-static.network.d/10-override-route-metric.conf') + self.verify_address_static( + label1='label1', + label2='label2', + label3='dummy98', + broadcast1='', + broadcast2=' brd 10.4.2.255', + broadcast3=' brd 10.4.3.63', + peer1=' peer 10.5.1.101/24', + peer2=' peer 10.5.2.101/24', + peer3='/24 brd 10.5.3.255', + peer4=' peer 2001:db8:0:f103::101/128', + peer5=' peer 2001:db8:0:f103::102/128', + peer6='/128', + scope1='global', + scope2='link', + deprecated1='', + deprecated2=' deprecated', + deprecated3='', + deprecated4=' deprecated', + route_metric=128, + flag1=' noprefixroute', + flag2='', + flag3=' noprefixroute', + flag4=' home mngtmpaddr', + ) + + copy_network_unit('25-address-static.network.d/10-override.conf') networkctl_reload() self.wait_online(['dummy98:routable']) - self.verify_address_static(route_metric=256) + self.verify_address_static( + label1='new-label1', + label2='dummy98', + label3='new-label3', + broadcast1=' brd 10.4.1.255', + broadcast2='', + broadcast3=' brd 10.4.3.31', + peer1=' peer 10.5.1.102/24', + peer2='/24 brd 10.5.2.255', + peer3=' peer 10.5.3.102/24', + peer4=' peer 2001:db8:0:f103::201/128', + peer5='/128', + peer6=' peer 2001:db8:0:f103::203/128', + scope1='link', + scope2='global', + deprecated1=' deprecated', + deprecated2='', + deprecated3=' deprecated', + deprecated4='', + route_metric=256, + flag1='', + flag2=' noprefixroute', + flag3=' home mngtmpaddr', + flag4=' noprefixroute', + ) networkctl_reconfigure('dummy98') self.wait_online(['dummy98:routable']) - self.verify_address_static(route_metric=256) + self.verify_address_static( + label1='new-label1', + label2='dummy98', + label3='new-label3', + broadcast1=' brd 10.4.1.255', + broadcast2='', + broadcast3=' brd 10.4.3.31', + peer1=' peer 10.5.1.102/24', + peer2='/24 brd 10.5.2.255', + peer3=' peer 10.5.3.102/24', + peer4=' peer 2001:db8:0:f103::201/128', + peer5='/128', + peer6=' peer 2001:db8:0:f103::203/128', + scope1='link', + scope2='global', + deprecated1=' deprecated', + deprecated2='', + deprecated3=' deprecated', + deprecated4='', + route_metric=256, + flag1='', + flag2=' noprefixroute', + flag3=' home mngtmpaddr', + flag4=' noprefixroute', + ) # Tests for #20891. # 1. set preferred lifetime forever to drop the deprecated flag for testing #20891. - check_output('ip address change 10.7.8.9/16 dev dummy98 preferred_lft forever') - check_output('ip address change 2001:db8:1:f101::1/64 dev dummy98 preferred_lft forever') - output = check_output('ip -4 address show dev dummy98') - print(output) - self.assertNotIn('deprecated', output) - output = check_output('ip -6 address show dev dummy98') + check_output('ip address change 10.7.1.1/24 dev dummy98 preferred_lft forever') + check_output('ip address change 2001:db8:0:f104::1/64 dev dummy98 preferred_lft forever') + output = check_output('ip address show dev dummy98') print(output) - self.assertNotIn('deprecated', output) + self.assertNotRegex(output, '10.7.1.1/24 .* deprecated') + self.assertNotRegex(output, '2001:db8:0:f104::1/64 .* deprecated') - # 2. reconfigure the interface. + # 2. reconfigure the interface, and check the deprecated flag is set again networkctl_reconfigure('dummy98') self.wait_online(['dummy98:routable']) - - # 3. check the deprecated flag is set for the address configured with PreferredLifetime=0 - output = check_output('ip -4 address show dev dummy98') - print(output) - self.assertIn('inet 10.7.8.9/16 brd 10.7.255.255 scope link deprecated dummy98', output) - output = check_output('ip -6 address show dev dummy98') - print(output) - self.assertIn('inet6 2001:db8:1:f101::1/64 scope global deprecated', output) + self.verify_address_static( + label1='new-label1', + label2='dummy98', + label3='new-label3', + broadcast1=' brd 10.4.1.255', + broadcast2='', + broadcast3=' brd 10.4.3.31', + peer1=' peer 10.5.1.102/24', + peer2='/24 brd 10.5.2.255', + peer3=' peer 10.5.3.102/24', + peer4=' peer 2001:db8:0:f103::201/128', + peer5='/128', + peer6=' peer 2001:db8:0:f103::203/128', + scope1='link', + scope2='global', + deprecated1=' deprecated', + deprecated2='', + deprecated3=' deprecated', + deprecated4='', + route_metric=256, + flag1='', + flag2=' noprefixroute', + flag3=' home mngtmpaddr', + flag4=' noprefixroute', + ) # test for ENOBUFS issue #17012 (with reload) copy_network_unit('25-address-static.network.d/10-many-address.conf')