summaryrefslogtreecommitdiff
path: root/cloudinit/url_helper.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2015-09-29 17:17:49 -0400
committerScott Moser <smoser@ubuntu.com>2015-09-29 17:17:49 -0400
commite9e86164198993aca13148872afdeebaae751c2c (patch)
treea5cc559795c500d469db99f6b9282abb1de035fe /cloudinit/url_helper.py
parent4558922ac6d8ae129b1f47e124c6b08008e7548f (diff)
downloadvyos-cloud-init-e9e86164198993aca13148872afdeebaae751c2c.tar.gz
vyos-cloud-init-e9e86164198993aca13148872afdeebaae751c2c.zip
MAAS: fix issues with url_helper and oauth module
This would cause problems in the event that we actually had a bad clock. We add a retry in the main (for test) also, to ensure that the oauth timestamp fix gets in place. LP: #1499869
Diffstat (limited to 'cloudinit/url_helper.py')
-rw-r--r--cloudinit/url_helper.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/cloudinit/url_helper.py b/cloudinit/url_helper.py
index a93847ce..f2e1390e 100644
--- a/cloudinit/url_helper.py
+++ b/cloudinit/url_helper.py
@@ -264,7 +264,9 @@ def readurl(url, data=None, timeout=None, retries=0, sec_between=1,
# ssl exceptions are not going to get fixed by waiting a
# few seconds
break
- if exception_cb and not exception_cb(req_args.copy(), excps[-1]):
+ if exception_cb and exception_cb(req_args.copy(), excps[-1]):
+ # if an exception callback was given it should return None
+ # a true-ish value means to break and re-raise the exception
break
if i + 1 < manual_tries and sec_between > 0:
LOG.debug("Please wait %s seconds while we wait to try again",
@@ -404,7 +406,7 @@ class OauthUrlHelper(object):
def read_skew_file(self):
if self.skew_data_file and os.path.isfile(self.skew_data_file):
with open(self.skew_data_file, mode="r") as fp:
- return json.load(fp.read())
+ return json.load(fp)
return None
def update_skew_file(self, host, value):
@@ -412,6 +414,8 @@ class OauthUrlHelper(object):
if not self.skew_data_file:
return
cur = self.read_skew_file()
+ if cur is None:
+ cur = {}
cur[host] = value
with open(self.skew_data_file, mode="w") as fp:
fp.write(json.dumps(cur))