summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2015-03-02 15:48:42 -0500
committerScott Moser <smoser@ubuntu.com>2015-03-02 15:48:42 -0500
commit086fd973ea489dad5f680ce18fdacf61077fa82b (patch)
tree5250e06c3cddb31448220bd507b8e23f9c3a2bca
parentf0388cfffadc0596faeda9e11775597444bff25d (diff)
downloadvyos-cloud-init-086fd973ea489dad5f680ce18fdacf61077fa82b.tar.gz
vyos-cloud-init-086fd973ea489dad5f680ce18fdacf61077fa82b.zip
url_helper.py: fix undefined variable
python2 scoping is different and running wait_for_url in python3 results in a use of undeclared variable 'e'. $ python3 -c 'from cloudinit import url_helper; \ url_helper.wait_for_url("o", max_wait=3,timeout=1, exception_cb=print)' Traceback (most recent call last): File "<string>", line 1, in <module> File "cloudinit/url_helper.py", line 358, in wait_for_url exception_cb(msg=status_msg, exception=e)
-rw-r--r--cloudinit/url_helper.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/cloudinit/url_helper.py b/cloudinit/url_helper.py
index 2d81a062..0e65f431 100644
--- a/cloudinit/url_helper.py
+++ b/cloudinit/url_helper.py
@@ -321,7 +321,7 @@ def wait_for_url(urls, max_wait=None, timeout=None,
timeout = int((start_time + max_wait) - now)
reason = ""
- e = None
+ url_exc = None
try:
if headers_cb is not None:
headers = headers_cb(url)
@@ -332,18 +332,20 @@ def wait_for_url(urls, max_wait=None, timeout=None,
check_status=False)
if not response.contents:
reason = "empty response [%s]" % (response.code)
- e = UrlError(ValueError(reason),
- code=response.code, headers=response.headers)
+ url_exc = UrlError(ValueError(reason), code=response.code,
+ headers=response.headers)
elif not response.ok():
reason = "bad status code [%s]" % (response.code)
- e = UrlError(ValueError(reason),
- code=response.code, headers=response.headers)
+ url_exc = UrlError(ValueError(reason), code=response.code,
+ headers=response.headers)
else:
return url
except UrlError as e:
reason = "request error [%s]" % e
+ url_exc = e
except Exception as e:
reason = "unexpected error [%s]" % e
+ url_exc = e
time_taken = int(time.time() - start_time)
status_msg = "Calling '%s' failed [%s/%ss]: %s" % (url,
@@ -355,7 +357,7 @@ def wait_for_url(urls, max_wait=None, timeout=None,
# This can be used to alter the headers that will be sent
# in the future, for example this is what the MAAS datasource
# does.
- exception_cb(msg=status_msg, exception=e)
+ exception_cb(msg=status_msg, exception=url_exc)
if timeup(max_wait, start_time):
break