diff options
Diffstat (limited to 'tests/unittests/sources/test_vultr.py')
-rw-r--r-- | tests/unittests/sources/test_vultr.py | 67 |
1 files changed, 67 insertions, 0 deletions
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): |