From efa200c63a962766b1800e071693435ba35c70ff Mon Sep 17 00:00:00 2001 From: zimbatm Date: Tue, 9 May 2023 13:19:57 +0200 Subject: [PATCH 1/2] add "zimbatm" as contributor --- tools/.github-cla-signers | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/.github-cla-signers b/tools/.github-cla-signers index 4e617741e47..c7c4b5c9c5d 100644 --- a/tools/.github-cla-signers +++ b/tools/.github-cla-signers @@ -158,4 +158,5 @@ yangzz-97 yawkat zhan9san zhuzaifangxuele +zimbatm zykovd From 3c62b73bb5ec98ecfe7f69ceb62883323da03c42 Mon Sep 17 00:00:00 2001 From: zimbatm Date: Sun, 30 Apr 2023 12:13:54 +0200 Subject: [PATCH 2/2] vultr: remove check_route check The heuristic is assuming that the URL will contain an IP, and that the route explicitly lists that IP (eg: 0.0.0.0/0 should match but doesn't). In order for the heuristic to be 100% reliable, it would have to replicate exactly what the system is doing both in terms of DNS and route resolution. Because the HTTP request below is already exercising the python nd system resolution, it is simpler to just remove this check and lean on the HTTP request to provide the answer if the network is up or not. --- cloudinit/sources/helpers/vultr.py | 24 +----------------------- tests/unittests/sources/test_vultr.py | 12 ------------ 2 files changed, 1 insertion(+), 35 deletions(-) diff --git a/cloudinit/sources/helpers/vultr.py b/cloudinit/sources/helpers/vultr.py index 71676bb154b..1bdeeaae0bc 100644 --- a/cloudinit/sources/helpers/vultr.py +++ b/cloudinit/sources/helpers/vultr.py @@ -9,7 +9,7 @@ from cloudinit import dmi from cloudinit import log as log -from cloudinit import net, netinfo, subp, url_helper, util +from cloudinit import net, subp, url_helper, util from cloudinit.net.dhcp import NoDHCPLeaseError from cloudinit.net.ephemeral import EphemeralDHCPv4 @@ -32,10 +32,6 @@ def get_metadata( iface=iface, connectivity_url_data={"url": url}, ): - # Check for the metadata route, skip if not there - if not check_route(url): - continue - # Fetch the metadata v1 = read_metadata(url, timeout, retries, sec_between, agent) @@ -75,24 +71,6 @@ def get_interface_list(): return ifaces -# Check for /32 route that our dhcp servers inject -# in order to determine if this a customer-run dhcp server -def check_route(url): - # Get routes, confirm entry exists - routes = netinfo.route_info() - - # If no tools exist and empty dict is returned - if "ipv4" not in routes: - return False - - # Parse each route into a more searchable format - for route in routes["ipv4"]: - if route.get("destination", None) in url: - return True - - return False - - # Read the system information from SMBIOS def get_sysinfo(): return { diff --git a/tests/unittests/sources/test_vultr.py b/tests/unittests/sources/test_vultr.py index ba21ae24cda..7fa02b1c9bb 100644 --- a/tests/unittests/sources/test_vultr.py +++ b/tests/unittests/sources/test_vultr.py @@ -274,14 +274,6 @@ FINAL_INTERFACE_USED = "" -# Static override, pylint doesnt like this in -# classes without self -def check_route(url): - if FINAL_INTERFACE_USED == "eth0": - return True - return False - - class TestDataSourceVultr(CiTestCase): def setUp(self): global VULTR_V1_3 @@ -431,7 +423,6 @@ def override_exit(self, excp_type, excp_value, excp_traceback): @mock.patch( "cloudinit.net.ephemeral.EphemeralDHCPv4.__exit__", override_exit ) - @mock.patch("cloudinit.sources.helpers.vultr.check_route") @mock.patch("cloudinit.sources.helpers.vultr.is_vultr") @mock.patch("cloudinit.sources.helpers.vultr.read_metadata") @mock.patch("cloudinit.sources.helpers.vultr.get_interface_list") @@ -440,12 +431,10 @@ def test_interface_seek( mock_interface_list, mock_read_metadata, mock_isvultr, - mock_check_route, ): mock_read_metadata.return_value = {} mock_isvultr.return_value = True mock_interface_list.return_value = FILTERED_INTERFACES - mock_check_route.return_value = True distro = mock.MagicMock() distro.get_tmp_exec_path = self.tmp_dir @@ -461,7 +450,6 @@ def test_interface_seek( self.assertEqual(FINAL_INTERFACE_USED, INTERFACES[3]) # Test route checking sucessful DHCPs - @mock.patch("cloudinit.sources.helpers.vultr.check_route", check_route) @mock.patch( "cloudinit.net.ephemeral.EphemeralDHCPv4.__init__", ephemeral_init_always,