=== modified file 'cloudinit/sources/DataSourceMAAS.py' --- cloudinit/sources/DataSourceMAAS.py 2015-08-25 19:03:35 +0000 +++ cloudinit/sources/DataSourceMAAS.py 2015-09-29 21:07:30 +0000 @@ -161,7 +161,7 @@ def read_maas_seed_url(seed_url, read_file_or_url=None, timeout=None, - version=MD_VERSION, paths=None): + version=MD_VERSION, paths=None, retries=None): """ Read the maas datasource at seed_url. read_file_or_url is a method that should provide an interface @@ -193,13 +193,13 @@ for name in file_order: url = files.get(name) if name == 'user-data': - retries = 0 + item_retries = 0 else: - retries = None + item_retries = retries try: ssl_details = util.fetch_ssl_details(paths) - resp = read_file_or_url(url, retries=retries, + resp = read_file_or_url(url, retries=item_retries, timeout=timeout, ssl_details=ssl_details) if resp.ok(): if name in BINARY_FIELDS: @@ -306,7 +306,8 @@ oauth_helper = url_helper.OauthUrlHelper(**creds) def geturl(url): - return oauth_helper.readurl(url).contents + # the retry is to ensure that oauth timestamp gets fixed + return oauth_helper.readurl(url, retries=1).contents def printurl(url): print("== %s ==\n%s\n" % (url, geturl(url).decode())) @@ -329,7 +330,8 @@ if args.url[0] == "/" or args.url.startswith("file://"): readurl = None (userdata, metadata) = read_maas_seed_url( - args.url, version=args.apiver, read_file_or_url=readurl) + args.url, version=args.apiver, read_file_or_url=readurl, + retries=2) print("=== userdata ===") print(userdata.decode()) print("=== metadata ===") === modified file 'cloudinit/url_helper.py' --- cloudinit/url_helper.py 2015-08-31 16:28:09 +0000 +++ cloudinit/url_helper.py 2015-09-29 21:09:25 +0000 @@ -264,7 +264,9 @@ # 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 @@ 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 @@ 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))