From 470b4a574514cf87f90682ac2bdd71b5fbbe6139 Mon Sep 17 00:00:00 2001 From: eb3095 <45504889+eb3095@users.noreply.github.com> Date: Mon, 14 Feb 2022 12:00:12 -0500 Subject: Fix extra ipv6 issues, code reduction and simplification (#1243) Eliminated the duplicate code and now run the entire configuration routine against both public and private interfaces. Also addressed an inconsistency from our metadata api for ipv6 address configuration. --- tests/unittests/sources/test_vultr.py | 53 ++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) (limited to 'tests/unittests') diff --git a/tests/unittests/sources/test_vultr.py b/tests/unittests/sources/test_vultr.py index 21d5bc17..18b2c084 100644 --- a/tests/unittests/sources/test_vultr.py +++ b/tests/unittests/sources/test_vultr.py @@ -8,6 +8,7 @@ import json from cloudinit import helpers, settings +from cloudinit.net.dhcp import NoDHCPLeaseError from cloudinit.sources import DataSourceVultr from cloudinit.sources.helpers import vultr from tests.unittests.helpers import CiTestCase, mock @@ -95,7 +96,9 @@ VULTR_V1_2 = { "netmask": "255.255.254.0", }, "ipv6": { - "additional": [], + "additional": [ + {"network": "2002:19f0:5:28a7::", "prefix": "64"} + ], "address": "2001:19f0:5:28a7:5400:03ff:fe1b:4eca", "network": "2001:19f0:5:28a7::", "prefix": "64", @@ -138,6 +141,14 @@ VULTR_V1_2 = { SSH_KEYS_1 = ["ssh-rsa AAAAB3NzaC1y...IQQhv5PAOKaIl+mM3c= test3@key"] +INTERFACES = [ + ["lo", "56:00:03:15:c4:00", "drv", "devid0"], + ["dummy0", "56:00:03:15:c4:01", "drv", "devid1"], + ["eth1", "56:00:03:15:c4:02", "drv", "devid2"], + ["eth0", "56:00:03:15:c4:04", "drv", "devid4"], + ["eth2", "56:00:03:15:c4:03", "drv", "devid3"], +] + # Expected generated objects # Expected config @@ -182,6 +193,11 @@ EXPECTED_VULTR_NETWORK_2 = { "subnets": [ {"type": "dhcp", "control": "auto"}, {"type": "ipv6_slaac", "control": "auto"}, + { + "type": "static6", + "control": "auto", + "address": "2002:19f0:5:28a7::/64", + }, ], }, { @@ -208,6 +224,9 @@ INTERFACE_MAP = { } +EPHERMERAL_USED = "" + + class TestDataSourceVultr(CiTestCase): def setUp(self): super(TestDataSourceVultr, self).setUp() @@ -284,5 +303,37 @@ class TestDataSourceVultr(CiTestCase): EXPECTED_VULTR_NETWORK_2, vultr.generate_network_config(interf) ) + def ephemeral_init(self, iface="", connectivity_url_data=None): + global EPHERMERAL_USED + EPHERMERAL_USED = iface + if iface == "eth0": + return + raise NoDHCPLeaseError("Generic for testing") + + # Test interface seeking to ensure we are able to find the correct one + @mock.patch("cloudinit.net.dhcp.EphemeralDHCPv4.__init__", ephemeral_init) + @mock.patch("cloudinit.sources.helpers.vultr.is_vultr") + @mock.patch("cloudinit.sources.helpers.vultr.read_metadata") + @mock.patch("cloudinit.net.get_interfaces") + def test_interface_seek( + self, mock_get_interfaces, mock_read_metadata, mock_isvultr + ): + mock_read_metadata.side_effect = NoDHCPLeaseError( + "Generic for testing" + ) + mock_isvultr.return_value = True + mock_get_interfaces.return_value = INTERFACES + + source = DataSourceVultr.DataSourceVultr( + settings.CFG_BUILTIN, None, helpers.Paths({"run_dir": self.tmp}) + ) + + try: + source._get_data() + except Exception: + pass + + self.assertEqual(EPHERMERAL_USED, INTERFACES[3][0]) + # vi: ts=4 expandtab -- cgit v1.2.3