Blame SOURCES/ci-DataSourceAzure-Adjust-timeout-for-polling-IMDS.patch

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