Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions cloudinit/sources/helpers/vultr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
44 changes: 15 additions & 29 deletions tests/unittests/sources/test_vultr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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