summaryrefslogtreecommitdiff
path: root/cloudinit/url_helper.py
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2018-11-13 03:14:58 +0000
committerServer Team CI Bot <josh.powers+server-team-bot@canonical.com>2018-11-13 03:14:58 +0000
commit6062595b83e08e0f12e1fe6d8e367d8db9d91ef8 (patch)
treea9d9d5096aebcb3b01c04efe2344990f0f9e24b2 /cloudinit/url_helper.py
parent6f9512049bbb594c3f01ffcd2ab25ae4e016f01e (diff)
downloadvyos-cloud-init-6062595b83e08e0f12e1fe6d8e367d8db9d91ef8.tar.gz
vyos-cloud-init-6062595b83e08e0f12e1fe6d8e367d8db9d91ef8.zip
azure: retry imds polling on requests.Timeout
There is an infrequent race when the booting instance can hit the IMDS service before it is fully available. This results in a requests.ConnectTimeout being raised. Azure's retry_callback logic now retries on either 404s or Timeouts. LP:1800223
Diffstat (limited to 'cloudinit/url_helper.py')
-rw-r--r--cloudinit/url_helper.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/cloudinit/url_helper.py b/cloudinit/url_helper.py
index cf57dbd5..396d69ae 100644
--- a/cloudinit/url_helper.py
+++ b/cloudinit/url_helper.py
@@ -554,4 +554,18 @@ def oauth_headers(url, consumer_key, token_key, token_secret, consumer_secret,
_uri, signed_headers, _body = client.sign(url)
return signed_headers
+
+def retry_on_url_exc(msg, exc):
+ """readurl exception_cb that will retry on NOT_FOUND and Timeout.
+
+ Returns False to raise the exception from readurl, True to retry.
+ """
+ if not isinstance(exc, UrlError):
+ return False
+ if exc.code == NOT_FOUND:
+ return True
+ if exc.cause and isinstance(exc.cause, requests.Timeout):
+ return True
+ return False
+
# vi: ts=4 expandtab