From e2d5aab32afa25d1bb54f4022213edd166199c50 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 3 Jul 2019 11:55:40 +0900 Subject: test-network: add tests for UseDNS= in [DHCP] section --- .../conf/dhcp-client-use-dns-ipv4-and-ra.network | 11 ++++ .../conf/dhcp-client-use-dns-ipv4.network | 14 ++++ .../conf/dhcp-client-use-dns-no.network | 11 ++++ .../conf/dhcp-client-use-dns-yes.network | 11 ++++ test/test-network/systemd-networkd-tests.py | 76 ++++++++++++++++++++++ 5 files changed, 123 insertions(+) create mode 100644 test/test-network/conf/dhcp-client-use-dns-ipv4-and-ra.network create mode 100644 test/test-network/conf/dhcp-client-use-dns-ipv4.network create mode 100644 test/test-network/conf/dhcp-client-use-dns-no.network create mode 100644 test/test-network/conf/dhcp-client-use-dns-yes.network (limited to 'test') diff --git a/test/test-network/conf/dhcp-client-use-dns-ipv4-and-ra.network b/test/test-network/conf/dhcp-client-use-dns-ipv4-and-ra.network new file mode 100644 index 0000000000..ed5989555c --- /dev/null +++ b/test/test-network/conf/dhcp-client-use-dns-ipv4-and-ra.network @@ -0,0 +1,11 @@ +[Match] +Name=veth99 + +[Network] +DHCP=ipv4 + +[DHCP] +UseDNS=yes + +[IPv6AcceptRA] +UseDNS=yes diff --git a/test/test-network/conf/dhcp-client-use-dns-ipv4.network b/test/test-network/conf/dhcp-client-use-dns-ipv4.network new file mode 100644 index 0000000000..dbd0f7f3fe --- /dev/null +++ b/test/test-network/conf/dhcp-client-use-dns-ipv4.network @@ -0,0 +1,14 @@ +[Match] +Name=veth99 + +[Network] +DHCP=ipv4 + +[DHCPv4] +UseDNS=yes + +[DHCPv6] +UseDNS=no + +[IPv6AcceptRA] +UseDNS=no diff --git a/test/test-network/conf/dhcp-client-use-dns-no.network b/test/test-network/conf/dhcp-client-use-dns-no.network new file mode 100644 index 0000000000..891efdbe12 --- /dev/null +++ b/test/test-network/conf/dhcp-client-use-dns-no.network @@ -0,0 +1,11 @@ +[Match] +Name=veth99 + +[Network] +DHCP=yes + +[DHCP] +UseDNS=no + +[IPv6AcceptRA] +UseDNS=no diff --git a/test/test-network/conf/dhcp-client-use-dns-yes.network b/test/test-network/conf/dhcp-client-use-dns-yes.network new file mode 100644 index 0000000000..f38ffe36e3 --- /dev/null +++ b/test/test-network/conf/dhcp-client-use-dns-yes.network @@ -0,0 +1,11 @@ +[Match] +Name=veth99 + +[Network] +DHCP=yes + +[DHCP] +UseDNS=yes + +[IPv6AcceptRA] +UseDNS=no diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py index e2b4aae6ef..2e6ac2896d 100755 --- a/test/test-network/systemd-networkd-tests.py +++ b/test/test-network/systemd-networkd-tests.py @@ -2153,6 +2153,10 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities): 'dhcp-client-listen-port.network', 'dhcp-client-route-metric.network', 'dhcp-client-route-table.network', + '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', 'dhcp-client-use-routes-no.network', 'dhcp-client-vrf.network', 'dhcp-client-with-ipv4ll-fallback-with-dhcp-server.network', @@ -2674,6 +2678,78 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities): 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') + 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() + wait_online(['veth-peer:carrier']) + start_dnsmasq('--dhcp-option=option:dns-server,192.168.5.1 --dhcp-option=option6:dns-server,[2600::1]') + wait_online(['veth99:routable', 'veth-peer:routable']) + + # 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') + self.wait_address('veth99', r'inet6 2600::[0-9a-f]*/128 scope global (?:dynamic noprefixroute|noprefixroute dynamic)', ipv='-6') + + time.sleep(3) + 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() + wait_online(['veth-peer:carrier']) + start_dnsmasq('--dhcp-option=option:dns-server,192.168.5.1 --dhcp-option=option6:dns-server,[2600::1]') + wait_online(['veth99:routable', 'veth-peer:routable']) + + # 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') + self.wait_address('veth99', r'inet6 2600::[0-9a-f]*/128 scope global (?:dynamic noprefixroute|noprefixroute dynamic)', ipv='-6') + + time.sleep(3) + 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() + wait_online(['veth-peer:carrier']) + start_dnsmasq('--dhcp-option=option:dns-server,192.168.5.1 --dhcp-option=option6:dns-server,[2600::1]') + wait_online(['veth99:routable', 'veth-peer:routable']) + + # 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') + self.wait_address('veth99', r'inet6 2600::[0-9a-f]*/128 scope global (?:dynamic noprefixroute|noprefixroute dynamic)', ipv='-6') + + time.sleep(3) + 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() + wait_online(['veth-peer:carrier']) + start_dnsmasq('--dhcp-option=option:dns-server,192.168.5.1 --dhcp-option=option6:dns-server,[2600::1]') + wait_online(['veth99:routable', 'veth-peer:routable']) + + # 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') + self.wait_address('veth99', r'inet6 2600::[0-9a-f]*/128 scope global (?:dynamic noprefixroute|noprefixroute dynamic)', ipv='-6') + + time.sleep(3) + output = check_output(*resolvectl_cmd, 'dns', 'veth99', env=env) + print(output) + self.assertRegex(output, '192.168.5.1') + self.assertRegex(output, '2600::1') + if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--build-dir', help='Path to build dir', dest='build_dir') -- cgit v1.2.3