~oddbloke/cloud-init/lp1506187

« back to all changes in this revision

Viewing changes to cloudinit/sources/DataSourceMAAS.py

  • Committer: Scott Moser
  • Date: 2015-09-29 21:17:49 UTC
  • Revision ID: smoser@ubuntu.com-20150929211749-n1ya5495kqjk7wou
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.

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
            return False
89
89
 
90
90
        try:
 
91
            # doing this here actually has a side affect of
 
92
            # getting oauth time-fix in place.  As no where else would
 
93
            # retry by default, so even if we could fix the timestamp
 
94
            # we would not.
91
95
            if not self.wait_for_metadata_service(url):
92
96
                return False
93
97
 
95
99
 
96
100
            (userdata, metadata) = read_maas_seed_url(
97
101
                self.base_url, read_file_or_url=self.oauth_helper.readurl,
98
 
                paths=self.paths)
 
102
                paths=self.paths, retries=1)
99
103
            self.userdata_raw = userdata
100
104
            self.metadata = metadata
101
105
            return True
161
165
 
162
166
 
163
167
def read_maas_seed_url(seed_url, read_file_or_url=None, timeout=None,
164
 
                       version=MD_VERSION, paths=None):
 
168
                       version=MD_VERSION, paths=None, retries=None):
165
169
    """
166
170
    Read the maas datasource at seed_url.
167
171
      read_file_or_url is a method that should provide an interface
193
197
    for name in file_order:
194
198
        url = files.get(name)
195
199
        if name == 'user-data':
196
 
            retries = 0
 
200
            item_retries = 0
197
201
        else:
198
 
            retries = None
 
202
            item_retries = retries
199
203
 
200
204
        try:
201
205
            ssl_details = util.fetch_ssl_details(paths)
202
 
            resp = read_file_or_url(url, retries=retries,
 
206
            resp = read_file_or_url(url, retries=item_retries,
203
207
                                    timeout=timeout, ssl_details=ssl_details)
204
208
            if resp.ok():
205
209
                if name in BINARY_FIELDS:
306
310
        oauth_helper = url_helper.OauthUrlHelper(**creds)
307
311
 
308
312
        def geturl(url):
309
 
            return oauth_helper.readurl(url).contents
 
313
            # the retry is to ensure that oauth timestamp gets fixed
 
314
            return oauth_helper.readurl(url, retries=1).contents
310
315
 
311
316
        def printurl(url):
312
317
            print("== %s ==\n%s\n" % (url, geturl(url).decode()))
329
334
            if args.url[0] == "/" or args.url.startswith("file://"):
330
335
                readurl = None
331
336
            (userdata, metadata) = read_maas_seed_url(
332
 
                args.url, version=args.apiver, read_file_or_url=readurl)
 
337
                args.url, version=args.apiver, read_file_or_url=readurl,
 
338
                retries=2)
333
339
            print("=== userdata ===")
334
340
            print(userdata.decode())
335
341
            print("=== metadata ===")