mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-28 18:03:04 +00:00
cloud-init: add patch for vultr
This patch fixes the DataSourceVultr logic so cloud-init works properly on Vultr.
This commit is contained in:
parent
a28301d4a1
commit
4c97c79eb7
@ -0,0 +1,110 @@
|
||||
From 6df2a198013ebed9aeff119ee0d15cb2d616474c Mon Sep 17 00:00:00 2001
|
||||
From: zimbatm <zimbatm@zimbatm.com>
|
||||
Date: Sun, 30 Apr 2023 12:13:54 +0200
|
||||
Subject: [PATCH] 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 | 22 ----------------------
|
||||
tests/unittests/sources/test_vultr.py | 12 ------------
|
||||
2 files changed, 34 deletions(-)
|
||||
|
||||
diff --git a/cloudinit/sources/helpers/vultr.py b/cloudinit/sources/helpers/vultr.py
|
||||
index 71676bb1..aac2a610 100644
|
||||
--- a/cloudinit/sources/helpers/vultr.py
|
||||
+++ b/cloudinit/sources/helpers/vultr.py
|
||||
@@ -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 ba21ae24..7fa02b1c 100644
|
||||
--- a/tests/unittests/sources/test_vultr.py
|
||||
+++ b/tests/unittests/sources/test_vultr.py
|
||||
@@ -274,14 +274,6 @@ INTERFACE_MAP = {
|
||||
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 @@ class TestDataSourceVultr(CiTestCase):
|
||||
@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 @@ class TestDataSourceVultr(CiTestCase):
|
||||
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 @@ class TestDataSourceVultr(CiTestCase):
|
||||
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,
|
||||
--
|
||||
2.40.0
|
||||
|
@ -26,7 +26,13 @@ python3.pkgs.buildPythonApplication rec {
|
||||
hash = "sha256-tn4flcrf04hVWhqkmK4qDenXcnV93pP+C+8J63b6FXQ=";
|
||||
};
|
||||
|
||||
patches = [ ./0001-add-nixos-support.patch ./0002-Add-Udhcpc-support.patch ];
|
||||
patches = [
|
||||
./0001-add-nixos-support.patch
|
||||
# upstream: https://github.com/canonical/cloud-init/pull/2125
|
||||
./0002-Add-Udhcpc-support.patch
|
||||
# upstream: https://github.com/canonical/cloud-init/pull/2151
|
||||
./0003-vultr-remove-check_route-check.patch
|
||||
];
|
||||
|
||||
prePatch = ''
|
||||
substituteInPlace setup.py \
|
||||
|
Loading…
Reference in New Issue
Block a user