diff options
author | Douglas Jordan <dojordan@microsoft.com> | 2018-03-23 12:04:18 -0600 |
---|---|---|
committer | Chad Smith <chad.smith@canonical.com> | 2018-03-23 12:04:18 -0600 |
commit | 2d618e27687470a8a3649f44598819bdee8cdb03 (patch) | |
tree | 396a821b2ac2e332695ec72b909b54d39c124312 /cloudinit/url_helper.py | |
parent | 097a2967abd6c78edfbdc035e7141f2d142f17ae (diff) | |
download | vyos-cloud-init-2d618e27687470a8a3649f44598819bdee8cdb03.tar.gz vyos-cloud-init-2d618e27687470a8a3649f44598819bdee8cdb03.zip |
Reduce AzurePreprovisioning HTTP timeouts.
Reducing timeout to 1 second as IMDS responds within a handful
of milliseconds. Also get rid of max_retries to prevent exiting
out of polling loop early due to IMDS outage / upgrade.
Reduce Azure PreProvisioning HTTP timeouts during polling to
avoid waiting an extra minute.
LP: #1752977
Diffstat (limited to 'cloudinit/url_helper.py')
-rw-r--r-- | cloudinit/url_helper.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/cloudinit/url_helper.py b/cloudinit/url_helper.py index 36289af5..03a573af 100644 --- a/cloudinit/url_helper.py +++ b/cloudinit/url_helper.py @@ -16,7 +16,7 @@ import time from email.utils import parsedate from functools import partial - +from itertools import count from requests import exceptions from six.moves.urllib.parse import ( @@ -172,7 +172,7 @@ def _get_ssl_args(url, ssl_details): def readurl(url, data=None, timeout=None, retries=0, sec_between=1, headers=None, headers_cb=None, ssl_details=None, check_status=True, allow_redirects=True, exception_cb=None, - session=None): + session=None, infinite=False): url = _cleanurl(url) req_args = { 'url': url, @@ -220,7 +220,8 @@ def readurl(url, data=None, timeout=None, retries=0, sec_between=1, excps = [] # Handle retrying ourselves since the built-in support # doesn't handle sleeping between tries... - for i in range(0, manual_tries): + # Infinitely retry if infinite is True + for i in count() if infinite else range(0, manual_tries): req_args['headers'] = headers_cb(url) filtered_req_args = {} for (k, v) in req_args.items(): @@ -229,7 +230,8 @@ def readurl(url, data=None, timeout=None, retries=0, sec_between=1, filtered_req_args[k] = v try: LOG.debug("[%s/%s] open '%s' with %s configuration", i, - manual_tries, url, filtered_req_args) + "infinite" if infinite else manual_tries, url, + filtered_req_args) if session is None: session = requests.Session() @@ -263,7 +265,8 @@ def readurl(url, data=None, timeout=None, retries=0, sec_between=1, # to continue retrying and False to break and re-raise the # exception break - if i + 1 < manual_tries and sec_between > 0: + if (infinite and sec_between > 0) or \ + (i + 1 < manual_tries and sec_between > 0): LOG.debug("Please wait %s seconds while we wait to try again", sec_between) time.sleep(sec_between) |