|
|
936480 |
From f54ebeac5b95c7481718e09c4598a86bc1a8dcfb Mon Sep 17 00:00:00 2001
|
|
|
936480 |
From: Eduardo Otubo <otubo@redhat.com>
|
|
|
936480 |
Date: Wed, 3 Jul 2019 13:14:53 +0200
|
|
|
936480 |
Subject: [PATCH] Azure: Return static fallback address as if failed to find
|
|
|
936480 |
endpoint
|
|
|
936480 |
|
|
|
936480 |
RH-Author: Eduardo Otubo <otubo@redhat.com>
|
|
|
936480 |
Message-id: <20190703131453.15811-1-otubo@redhat.com>
|
|
|
936480 |
Patchwork-id: 89354
|
|
|
936480 |
O-Subject: [RHEL-7.8 cloud-init PATCH] Azure: Return static fallback address as if failed to find endpoint
|
|
|
936480 |
Bugzilla: 1726701
|
|
|
936480 |
RH-Acked-by: Bandan Das <bsd@redhat.com>
|
|
|
936480 |
RH-Acked-by: Mohammed Gamal <mgamal@redhat.com>
|
|
|
936480 |
|
|
|
936480 |
BZ: 1687565
|
|
|
936480 |
BRANCH: rhel7/master-18.5
|
|
|
936480 |
UPSTREAM: baa478546d8cac98a706010699d64f8c2f70b5bf
|
|
|
936480 |
BREW: 22476988
|
|
|
936480 |
|
|
|
936480 |
commit aefb0f1c281740ef307116509057770062d61375
|
|
|
936480 |
Author: Jason Zions (MSFT) <jasonzio@microsoft.com>
|
|
|
936480 |
Date: Fri May 10 18:38:55 2019 +0000
|
|
|
936480 |
|
|
|
936480 |
Azure: Return static fallback address as if failed to find endpoint
|
|
|
936480 |
|
|
|
936480 |
The Azure data source helper attempts to use information in the dhcp
|
|
|
936480 |
lease to find the Wireserver endpoint (IP address). Under some unusual
|
|
|
936480 |
circumstances, those attempts will fail. This change uses a static
|
|
|
936480 |
address, known to be always correct in the Azure public and sovereign
|
|
|
936480 |
clouds, when the helper fails to locate a valid dhcp lease. This
|
|
|
936480 |
address is not guaranteed to be correct in Azure Stack environments;
|
|
|
936480 |
it's still best to use the information from the lease whenever possible.
|
|
|
936480 |
|
|
|
936480 |
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
|
|
|
936480 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
936480 |
---
|
|
|
936480 |
cloudinit/sources/helpers/azure.py | 14 +++++++++++---
|
|
|
936480 |
tests/unittests/test_datasource/test_azure_helper.py | 9 +++++++--
|
|
|
936480 |
2 files changed, 18 insertions(+), 5 deletions(-)
|
|
|
936480 |
|
|
|
936480 |
diff --git a/cloudinit/sources/helpers/azure.py b/cloudinit/sources/helpers/azure.py
|
|
|
936480 |
index d3af05e..82c4c8c 100755
|
|
|
936480 |
--- a/cloudinit/sources/helpers/azure.py
|
|
|
936480 |
+++ b/cloudinit/sources/helpers/azure.py
|
|
|
936480 |
@@ -20,6 +20,9 @@ from cloudinit.reporting import events
|
|
|
936480 |
|
|
|
936480 |
LOG = logging.getLogger(__name__)
|
|
|
936480 |
|
|
|
936480 |
+# This endpoint matches the format as found in dhcp lease files, since this
|
|
|
936480 |
+# value is applied if the endpoint can't be found within a lease file
|
|
|
936480 |
+DEFAULT_WIRESERVER_ENDPOINT = "a8:3f:81:10"
|
|
|
936480 |
|
|
|
936480 |
azure_ds_reporter = events.ReportEventStack(
|
|
|
936480 |
name="azure-ds",
|
|
|
936480 |
@@ -297,7 +300,12 @@ class WALinuxAgentShim(object):
|
|
|
936480 |
@azure_ds_telemetry_reporter
|
|
|
936480 |
def _get_value_from_leases_file(fallback_lease_file):
|
|
|
936480 |
leases = []
|
|
|
936480 |
- content = util.load_file(fallback_lease_file)
|
|
|
936480 |
+ try:
|
|
|
936480 |
+ content = util.load_file(fallback_lease_file)
|
|
|
936480 |
+ except IOError as ex:
|
|
|
936480 |
+ LOG.error("Failed to read %s: %s", fallback_lease_file, ex)
|
|
|
936480 |
+ return None
|
|
|
936480 |
+
|
|
|
936480 |
LOG.debug("content is %s", content)
|
|
|
936480 |
option_name = _get_dhcp_endpoint_option_name()
|
|
|
936480 |
for line in content.splitlines():
|
|
|
936480 |
@@ -372,9 +380,9 @@ class WALinuxAgentShim(object):
|
|
|
936480 |
fallback_lease_file)
|
|
|
936480 |
value = WALinuxAgentShim._get_value_from_leases_file(
|
|
|
936480 |
fallback_lease_file)
|
|
|
936480 |
-
|
|
|
936480 |
if value is None:
|
|
|
936480 |
- raise ValueError('No endpoint found.')
|
|
|
936480 |
+ LOG.warning("No lease found; using default endpoint")
|
|
|
936480 |
+ value = DEFAULT_WIRESERVER_ENDPOINT
|
|
|
936480 |
|
|
|
936480 |
endpoint_ip_address = WALinuxAgentShim.get_ip_from_lease_value(value)
|
|
|
936480 |
LOG.debug('Azure endpoint found at %s', endpoint_ip_address)
|
|
|
936480 |
diff --git a/tests/unittests/test_datasource/test_azure_helper.py b/tests/unittests/test_datasource/test_azure_helper.py
|
|
|
936480 |
index 0255616..bd006ab 100644
|
|
|
936480 |
--- a/tests/unittests/test_datasource/test_azure_helper.py
|
|
|
936480 |
+++ b/tests/unittests/test_datasource/test_azure_helper.py
|
|
|
936480 |
@@ -67,12 +67,17 @@ class TestFindEndpoint(CiTestCase):
|
|
|
936480 |
self.networkd_leases.return_value = None
|
|
|
936480 |
|
|
|
936480 |
def test_missing_file(self):
|
|
|
936480 |
- self.assertRaises(ValueError, wa_shim.find_endpoint)
|
|
|
936480 |
+ """wa_shim find_endpoint uses default endpoint if leasefile not found
|
|
|
936480 |
+ """
|
|
|
936480 |
+ self.assertEqual(wa_shim.find_endpoint(), "168.63.129.16")
|
|
|
936480 |
|
|
|
936480 |
def test_missing_special_azure_line(self):
|
|
|
936480 |
+ """wa_shim find_endpoint uses default endpoint if leasefile is found
|
|
|
936480 |
+ but does not contain DHCP Option 245 (whose value is the endpoint)
|
|
|
936480 |
+ """
|
|
|
936480 |
self.load_file.return_value = ''
|
|
|
936480 |
self.dhcp_options.return_value = {'eth0': {'key': 'value'}}
|
|
|
936480 |
- self.assertRaises(ValueError, wa_shim.find_endpoint)
|
|
|
936480 |
+ self.assertEqual(wa_shim.find_endpoint(), "168.63.129.16")
|
|
|
936480 |
|
|
|
936480 |
@staticmethod
|
|
|
936480 |
def _build_lease_content(encoded_address):
|
|
|
936480 |
--
|
|
|
936480 |
1.8.3.1
|
|
|
936480 |
|