|
|
738010 |
From 635dcbf5a4a5b060ebf417c66789c59ebb28c39f Mon Sep 17 00:00:00 2001
|
|
|
738010 |
From: Eduardo Otubo <otubo@redhat.com>
|
|
|
738010 |
Date: Wed, 15 May 2019 12:15:28 +0200
|
|
|
738010 |
Subject: [PATCH 4/5] DataSourceAzure: Adjust timeout for polling IMDS
|
|
|
738010 |
|
|
|
738010 |
RH-Author: Eduardo Otubo <otubo@redhat.com>
|
|
|
738010 |
Message-id: <20190515121529.11191-5-otubo@redhat.com>
|
|
|
738010 |
Patchwork-id: 87883
|
|
|
738010 |
O-Subject: [rhel-7 cloud-init PATCHv2 4/5] DataSourceAzure: Adjust timeout for polling IMDS
|
|
|
738010 |
Bugzilla: 1687565
|
|
|
738010 |
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
|
|
|
738010 |
RH-Acked-by: Mohammed Gamal <mgamal@redhat.com>
|
|
|
738010 |
|
|
|
738010 |
From: Anh Vo <anhvo@microsoft.com>
|
|
|
738010 |
|
|
|
738010 |
BZ: 1687565
|
|
|
738010 |
BRANCH: rhel7/master-18.5
|
|
|
738010 |
UPSTREAM: ab6621d8
|
|
|
738010 |
BREW: 21696239
|
|
|
738010 |
|
|
|
738010 |
commit ab6621d849b24bb652243e88c79f6f3b446048d7
|
|
|
738010 |
Author: Anh Vo <anhvo@microsoft.com>
|
|
|
738010 |
Date: Wed May 8 14:54:03 2019 +0000
|
|
|
738010 |
|
|
|
738010 |
DataSourceAzure: Adjust timeout for polling IMDS
|
|
|
738010 |
|
|
|
738010 |
If the IMDS primary server is not available, falling back to the
|
|
|
738010 |
secondary server takes about 1s. The net result is that the
|
|
|
738010 |
expected E2E time is slightly more than 1s. This change increases
|
|
|
738010 |
the timeout to 2s to prevent the infinite loop of timeouts.
|
|
|
738010 |
|
|
|
738010 |
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
|
|
|
738010 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
738010 |
---
|
|
|
738010 |
cloudinit/sources/DataSourceAzure.py | 15 ++++++++++-----
|
|
|
738010 |
tests/unittests/test_datasource/test_azure.py | 10 +++++++---
|
|
|
738010 |
2 files changed, 17 insertions(+), 8 deletions(-)
|
|
|
738010 |
|
|
|
738010 |
diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py
|
|
|
738010 |
index c827816..5baf8da 100755
|
|
|
738010 |
--- a/cloudinit/sources/DataSourceAzure.py
|
|
|
738010 |
+++ b/cloudinit/sources/DataSourceAzure.py
|
|
|
738010 |
@@ -57,7 +57,12 @@ AZURE_CHASSIS_ASSET_TAG = '7783-7084-3265-9085-8269-3286-77'
|
|
|
738010 |
REPROVISION_MARKER_FILE = "/var/lib/cloud/data/poll_imds"
|
|
|
738010 |
REPORTED_READY_MARKER_FILE = "/var/lib/cloud/data/reported_ready"
|
|
|
738010 |
AGENT_SEED_DIR = '/var/lib/waagent'
|
|
|
738010 |
+
|
|
|
738010 |
+# In the event where the IMDS primary server is not
|
|
|
738010 |
+# available, it takes 1s to fallback to the secondary one
|
|
|
738010 |
+IMDS_TIMEOUT_IN_SECONDS = 2
|
|
|
738010 |
IMDS_URL = "http://169.254.169.254/metadata/"
|
|
|
738010 |
+
|
|
|
738010 |
PLATFORM_ENTROPY_SOURCE = "/sys/firmware/acpi/tables/OEM0"
|
|
|
738010 |
|
|
|
738010 |
# List of static scripts and network config artifacts created by
|
|
|
738010 |
@@ -582,9 +587,9 @@ class DataSourceAzure(sources.DataSource):
|
|
|
738010 |
return
|
|
|
738010 |
self._ephemeral_dhcp_ctx.clean_network()
|
|
|
738010 |
else:
|
|
|
738010 |
- return readurl(url, timeout=1, headers=headers,
|
|
|
738010 |
- exception_cb=exc_cb, infinite=True,
|
|
|
738010 |
- log_req_resp=False).contents
|
|
|
738010 |
+ return readurl(url, timeout=IMDS_TIMEOUT_IN_SECONDS,
|
|
|
738010 |
+ headers=headers, exception_cb=exc_cb,
|
|
|
738010 |
+ infinite=True, log_req_resp=False).contents
|
|
|
738010 |
except UrlError:
|
|
|
738010 |
# Teardown our EphemeralDHCPv4 context on failure as we retry
|
|
|
738010 |
self._ephemeral_dhcp_ctx.clean_network()
|
|
|
738010 |
@@ -1291,8 +1296,8 @@ def _get_metadata_from_imds(retries):
|
|
|
738010 |
headers = {"Metadata": "true"}
|
|
|
738010 |
try:
|
|
|
738010 |
response = readurl(
|
|
|
738010 |
- url, timeout=1, headers=headers, retries=retries,
|
|
|
738010 |
- exception_cb=retry_on_url_exc)
|
|
|
738010 |
+ url, timeout=IMDS_TIMEOUT_IN_SECONDS, headers=headers,
|
|
|
738010 |
+ retries=retries, exception_cb=retry_on_url_exc)
|
|
|
738010 |
except Exception as e:
|
|
|
738010 |
LOG.debug('Ignoring IMDS instance metadata: %s', e)
|
|
|
738010 |
return {}
|
|
|
738010 |
diff --git a/tests/unittests/test_datasource/test_azure.py b/tests/unittests/test_datasource/test_azure.py
|
|
|
738010 |
index eacf225..bc8b42c 100644
|
|
|
738010 |
--- a/tests/unittests/test_datasource/test_azure.py
|
|
|
738010 |
+++ b/tests/unittests/test_datasource/test_azure.py
|
|
|
738010 |
@@ -163,7 +163,8 @@ class TestGetMetadataFromIMDS(HttprettyTestCase):
|
|
|
738010 |
|
|
|
738010 |
m_readurl.assert_called_with(
|
|
|
738010 |
self.network_md_url, exception_cb=mock.ANY,
|
|
|
738010 |
- headers={'Metadata': 'true'}, retries=2, timeout=1)
|
|
|
738010 |
+ headers={'Metadata': 'true'}, retries=2,
|
|
|
738010 |
+ timeout=dsaz.IMDS_TIMEOUT_IN_SECONDS)
|
|
|
738010 |
|
|
|
738010 |
@mock.patch('cloudinit.url_helper.time.sleep')
|
|
|
738010 |
@mock.patch(MOCKPATH + 'net.is_up')
|
|
|
738010 |
@@ -1789,7 +1790,8 @@ class TestAzureDataSourcePreprovisioning(CiTestCase):
|
|
|
738010 |
headers={'Metadata': 'true',
|
|
|
738010 |
'User-Agent':
|
|
|
738010 |
'Cloud-Init/%s' % vs()
|
|
|
738010 |
- }, method='GET', timeout=1,
|
|
|
738010 |
+ }, method='GET',
|
|
|
738010 |
+ timeout=dsaz.IMDS_TIMEOUT_IN_SECONDS,
|
|
|
738010 |
url=full_url)])
|
|
|
738010 |
self.assertEqual(m_dhcp.call_count, 2)
|
|
|
738010 |
m_net.assert_any_call(
|
|
|
738010 |
@@ -1826,7 +1828,9 @@ class TestAzureDataSourcePreprovisioning(CiTestCase):
|
|
|
738010 |
headers={'Metadata': 'true',
|
|
|
738010 |
'User-Agent':
|
|
|
738010 |
'Cloud-Init/%s' % vs()},
|
|
|
738010 |
- method='GET', timeout=1, url=full_url)])
|
|
|
738010 |
+ method='GET',
|
|
|
738010 |
+ timeout=dsaz.IMDS_TIMEOUT_IN_SECONDS,
|
|
|
738010 |
+ url=full_url)])
|
|
|
738010 |
self.assertEqual(m_dhcp.call_count, 2)
|
|
|
738010 |
m_net.assert_any_call(
|
|
|
738010 |
broadcast='192.168.2.255', interface='eth9', ip='192.168.2.9',
|
|
|
738010 |
--
|
|
|
738010 |
1.8.3.1
|
|
|
738010 |
|