From fdf22ddc2eb362ac22e79b4433ff863519fcfb85 Mon Sep 17 00:00:00 2001 From: ebenner Date: Mon, 21 Mar 2022 09:56:31 -0400 Subject: [PATCH] Use find_candidate_nics, use ipv6 dns --- cloudinit/sources/helpers/vultr.py | 22 +++++++------- tests/unittests/sources/test_vultr.py | 44 +++++++++------------------ 2 files changed, 26 insertions(+), 40 deletions(-) diff --git a/cloudinit/sources/helpers/vultr.py b/cloudinit/sources/helpers/vultr.py index 1a7008aaf23..c8fb8420b12 100644 --- a/cloudinit/sources/helpers/vultr.py +++ b/cloudinit/sources/helpers/vultr.py @@ -25,7 +25,7 @@ def get_metadata(url, timeout, retries, sec_between, agent): for iface in get_interface_list(): try: with EphemeralDHCPv4( - iface=iface[0], connectivity_url_data={"url": url} + iface=iface, connectivity_url_data={"url": url} ): # Check for the metadata route, skip if not there if not check_route(url): @@ -47,20 +47,15 @@ def get_metadata(url, timeout, retries, sec_between, agent): # Get interface list, sort, and clean -# Should be replaced with find_candidate_nics -# Dummy and lo will remain to need to be removed def get_interface_list(): ifaces = [] - for iface in net.get_interfaces(): - # Skip dummy, lo interfaces - if "dummy" in iface[0]: - continue - if "lo" == iface[0]: + for iface in net.find_candidate_nics(): + # Skip dummy + if "dummy" in iface: continue ifaces.append(iface) - # Sort alphabetically - return sorted(ifaces, key=lambda i: i[0]) + return ifaces # Check for /32 route that our dhcp servers inject @@ -155,7 +150,12 @@ def get_interface_name(mac): def generate_network_config(interfaces): network = { "version": 1, - "config": [{"type": "nameserver", "address": ["108.61.10.10"]}], + "config": [ + { + "type": "nameserver", + "address": ["108.61.10.10", "2001:19f0:300:1704::6"], + } + ], } # Prepare interface 0, public diff --git a/tests/unittests/sources/test_vultr.py b/tests/unittests/sources/test_vultr.py index d2d2938ca2c..c8398579d27 100644 --- a/tests/unittests/sources/test_vultr.py +++ b/tests/unittests/sources/test_vultr.py @@ -141,25 +141,11 @@ 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"], -] - -ORDERED_INTERFACES = [ - ["eth0", "56:00:03:15:c4:04", "drv", "devid4"], - ["eth1", "56:00:03:15:c4:02", "drv", "devid2"], - ["eth2", "56:00:03:15:c4:03", "drv", "devid3"], -] - -FILTERED_INTERFACES = [ - ["eth1", "56:00:03:15:c4:02", "drv", "devid2"], - ["eth2", "56:00:03:15:c4:03", "drv", "devid3"], - ["eth0", "56:00:03:15:c4:04", "drv", "devid4"], -] +INTERFACES = ["lo", "dummy0", "eth1", "eth0", "eth2"] + +ORDERED_INTERFACES = ["eth0", "eth1", "eth2"] + +FILTERED_INTERFACES = ["eth1", "eth2", "eth0"] # Expected generated objects @@ -179,7 +165,10 @@ EXPECTED_VULTR_NETWORK_1 = { "version": 1, "config": [ - {"type": "nameserver", "address": ["108.61.10.10"]}, + { + "type": "nameserver", + "address": ["108.61.10.10", "2001:19f0:300:1704::6"], + }, { "name": "eth0", "type": "physical", @@ -196,7 +185,10 @@ EXPECTED_VULTR_NETWORK_2 = { "version": 1, "config": [ - {"type": "nameserver", "address": ["108.61.10.10"]}, + { + "type": "nameserver", + "address": ["108.61.10.10", "2001:19f0:300:1704::6"], + }, { "name": "eth0", "type": "physical", @@ -380,7 +372,7 @@ def test_interface_seek( except Exception: pass - self.assertEqual(FINAL_INTERFACE_USED, INTERFACES[3][0]) + self.assertEqual(FINAL_INTERFACE_USED, INTERFACES[3]) # Test route checking sucessful DHCPs @mock.patch("cloudinit.sources.helpers.vultr.check_route", check_route) @@ -408,13 +400,7 @@ def test_interface_seek_route_check( except Exception: pass - self.assertEqual(FINAL_INTERFACE_USED, INTERFACES[3][0]) - - # Test interface list to ensure alphabetical and cleaned - @mock.patch("cloudinit.net.get_interfaces") - def test_interface_list(self, mock_get_interfaces): - mock_get_interfaces.return_value = INTERFACES - self.assertEqual(ORDERED_INTERFACES, vultr.get_interface_list()) + self.assertEqual(FINAL_INTERFACE_USED, INTERFACES[3]) # vi: ts=4 expandtab