← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~chad.smith/cloud-init:bug/1803598-dont-retry-on-timeout-in-imds-poll into cloud-init:master

 

Chad Smith has proposed merging ~chad.smith/cloud-init:bug/1803598-dont-retry-on-timeout-in-imds-poll into cloud-init:master.

Commit message:
azure: _poll_imds only retry on 404. Fail on Timeout

Upon URL timeout, _poll_imds is expected to re-dhcp to get updated
IP configuration. We don't want to indefinitely retry because the
instance likely has invalid IP configuration.

LP: #1803598

Requested reviews:
  cloud-init commiters (cloud-init-dev)
Related bugs:
  Bug #1803598 in cloud-init: "Do not retry polling IMDS for reprovisiondata during timeout"
  https://bugs.launchpad.net/cloud-init/+bug/1803598

For more details, see:
https://code.launchpad.net/~chad.smith/cloud-init/+git/cloud-init/+merge/358872
-- 
Your team cloud-init commiters is requested to review the proposed merge of ~chad.smith/cloud-init:bug/1803598-dont-retry-on-timeout-in-imds-poll into cloud-init:master.
diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py
index 9e8a1a8..2a3e567 100644
--- a/cloudinit/sources/DataSourceAzure.py
+++ b/cloudinit/sources/DataSourceAzure.py
@@ -526,6 +526,13 @@ class DataSourceAzure(sources.DataSource):
         report_ready = bool(not os.path.isfile(REPORTED_READY_MARKER_FILE))
         LOG.debug("Start polling IMDS")
 
+        def exc_cb(msg, exception):
+            if isinstance(exception, UrlError) and exception.code == 404:
+                return True
+            # If we get an exception while trying to call IMDS, we
+            # call DHCP and setup the ephemeral network to acquire the new IP.
+            return False
+
         while True:
             try:
                 # Save our EphemeralDHCPv4 context so we avoid repeated dhcp
@@ -540,7 +547,7 @@ class DataSourceAzure(sources.DataSource):
                     self._report_ready(lease=lease)
                     report_ready = False
                 return readurl(url, timeout=1, headers=headers,
-                               exception_cb=retry_on_url_exc, infinite=True,
+                               exception_cb=exc_cb, infinite=True,
                                log_req_resp=False).contents
             except UrlError:
                 # Teardown our EphemeralDHCPv4 context on failure as we retry

Follow ups