summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreb3095 <45504889+eb3095@users.noreply.github.com>2023-02-01 15:46:18 -0500
committerGitHub <noreply@github.com>2023-02-01 21:46:18 +0100
commit30a71f368bc38c37afa36e7be830dd8a6002fbe8 (patch)
treebd9b7b8829b73fe035e65b7cbbb54f2b007878be
parentf447bab61d02e78e1a10becde38219a7537d548c (diff)
downloadcloud-init-git-30a71f368bc38c37afa36e7be830dd8a6002fbe8.tar.gz
Fix Vultr cloud_interfaces usage (#1986)
cloud_interfaces is intended to be a netcfg. Change the helper function to reflect this.
-rw-r--r--cloudinit/sources/DataSourceVultr.py4
-rw-r--r--cloudinit/sources/helpers/vultr.py12
-rw-r--r--tests/unittests/sources/test_vultr.py67
3 files changed, 75 insertions, 8 deletions
diff --git a/cloudinit/sources/DataSourceVultr.py b/cloudinit/sources/DataSourceVultr.py
index a2c16991..9d7c84fb 100644
--- a/cloudinit/sources/DataSourceVultr.py
+++ b/cloudinit/sources/DataSourceVultr.py
@@ -70,10 +70,10 @@ class DataSourceVultr(sources.DataSource):
if "cloud_interfaces" in md:
# In the future we will just drop pre-configured
# network configs into the array. They need names though.
- self.netcfg = vultr.add_interface_names(md["cloud_interfaces"])
+ vultr.add_interface_names(md["cloud_interfaces"])
+ self.netcfg = md["cloud_interfaces"]
else:
self.netcfg = vultr.generate_network_config(md["interfaces"])
-
# Grab vendordata
self.vendordata_raw = md["vendor-data"]
diff --git a/cloudinit/sources/helpers/vultr.py b/cloudinit/sources/helpers/vultr.py
index 30c8cfee..836108d4 100644
--- a/cloudinit/sources/helpers/vultr.py
+++ b/cloudinit/sources/helpers/vultr.py
@@ -276,17 +276,17 @@ def generate_interface_additional_addresses(interface, netcfg):
# Make required adjustments to the network configs provided
-def add_interface_names(interfaces):
- for interface in interfaces:
- interface_name = get_interface_name(interface["mac"])
+def add_interface_names(netcfg):
+ for interface in netcfg["config"]:
+ if interface["type"] != "physical":
+ continue
+ interface_name = get_interface_name(interface["mac_address"])
if not interface_name:
raise RuntimeError(
"Interface: %s could not be found on the system"
- % interface["mac"]
+ % interface["mac_address"]
)
interface["name"] = interface_name
- return interfaces
-
# vi: ts=4 expandtab
diff --git a/tests/unittests/sources/test_vultr.py b/tests/unittests/sources/test_vultr.py
index cfd2f376..488df4f3 100644
--- a/tests/unittests/sources/test_vultr.py
+++ b/tests/unittests/sources/test_vultr.py
@@ -144,8 +144,46 @@ VULTR_V1_2 = {
],
}
+VULTR_V1_3 = None
+
SSH_KEYS_1 = ["ssh-rsa AAAAB3NzaC1y...IQQhv5PAOKaIl+mM3c= test3@key"]
+CLOUD_INTERFACES = {
+ "version": 1,
+ "config": [
+ {
+ "type": "nameserver",
+ "address": ["108.61.10.10", "2001:19f0:300:1704::6"],
+ },
+ {
+ "type": "physical",
+ "mac_address": "56:00:03:1b:4e:ca",
+ "accept-ra": 1,
+ "subnets": [
+ {"type": "dhcp", "control": "auto"},
+ {"type": "ipv6_slaac", "control": "auto"},
+ {
+ "type": "static6",
+ "control": "auto",
+ "address": "2002:19f0:5:28a7::/64",
+ },
+ ],
+ },
+ {
+ "type": "physical",
+ "mac_address": "5a:00:03:1b:4e:ca",
+ "subnets": [
+ {
+ "type": "static",
+ "control": "auto",
+ "address": "10.1.112.3",
+ "netmask": "255.255.240.0",
+ }
+ ],
+ },
+ ],
+}
+
INTERFACES = ["lo", "dummy0", "eth1", "eth0", "eth2"]
ORDERED_INTERFACES = ["eth0", "eth1", "eth2"]
@@ -246,8 +284,14 @@ def check_route(url):
class TestDataSourceVultr(CiTestCase):
def setUp(self):
+ global VULTR_V1_3
super(TestDataSourceVultr, self).setUp()
+ # Create v3
+ VULTR_V1_3 = VULTR_V1_2.copy()
+ VULTR_V1_3["cloud_interfaces"] = CLOUD_INTERFACES.copy()
+ VULTR_V1_3["interfaces"] = []
+
# Stored as a dict to make it easier to maintain
raw1 = json.dumps(VULTR_V1_1["vendor-data"][0])
raw2 = json.dumps(VULTR_V1_2["vendor-data"][0])
@@ -255,6 +299,7 @@ class TestDataSourceVultr(CiTestCase):
# Make expected format
VULTR_V1_1["vendor-data"] = [raw1]
VULTR_V1_2["vendor-data"] = [raw2]
+ VULTR_V1_3["vendor-data"] = [raw2]
self.tmp = self.tmp_dir()
@@ -302,6 +347,28 @@ class TestDataSourceVultr(CiTestCase):
# Test network config generation
self.assertEqual(EXPECTED_VULTR_NETWORK_2, source.network_config)
+ # Test the datasource with new network config type
+ @mock.patch("cloudinit.net.get_interfaces_by_mac")
+ @mock.patch("cloudinit.sources.helpers.vultr.is_vultr")
+ @mock.patch("cloudinit.sources.helpers.vultr.get_metadata")
+ def test_datasource_cloud_interfaces(
+ self, mock_getmeta, mock_isvultr, mock_netmap
+ ):
+ mock_getmeta.return_value = VULTR_V1_3
+ mock_isvultr.return_value = True
+ mock_netmap.return_value = INTERFACE_MAP
+
+ distro = mock.MagicMock()
+ distro.get_tmp_exec_path = self.tmp_dir
+ source = DataSourceVultr.DataSourceVultr(
+ settings.CFG_BUILTIN, distro, helpers.Paths({"run_dir": self.tmp})
+ )
+
+ source._get_data()
+
+ # Test network config generation
+ self.assertEqual(EXPECTED_VULTR_NETWORK_2, source.network_config)
+
# Test network config generation
@mock.patch("cloudinit.net.get_interfaces_by_mac")
def test_network_config(self, mock_netmap):