← Back to team overview

cloud-init-dev team mailing list archive

[Merge] lp:~smoser/cloud-init/lp1172742 into lp:cloud-init

 

Scott Moser has proposed merging lp:~smoser/cloud-init/lp1172742 into lp:cloud-init.

Requested reviews:
  cloud init development team (cloud-init-dev)
Related bugs:
  Bug #1172742 in cloud-init: "maas datasource fails if no user-data"
  https://bugs.launchpad.net/cloud-init/+bug/1172742

For more details, see:
https://code.launchpad.net/~smoser/cloud-init/lp1172742/+merge/160944
-- 
https://code.launchpad.net/~smoser/cloud-init/lp1172742/+merge/160944
Your team cloud init development team is requested to review the proposed merge of lp:~smoser/cloud-init/lp1172742 into lp:cloud-init.
=== modified file 'cloudinit/sources/DataSourceMAAS.py'
--- cloudinit/sources/DataSourceMAAS.py	2013-03-19 12:22:30 +0000
+++ cloudinit/sources/DataSourceMAAS.py	2013-04-25 16:07:33 +0000
@@ -218,14 +218,20 @@
     md = {}
     for name in file_order:
         url = files.get(name)
-        if header_cb:
-            headers = header_cb(url)
+        if not header_cb:
+            def _cb(url):
+                return {}
+            header_cb = _cb
+
+        if name == 'user-data':
+            retries = 0
         else:
-            headers = {}
+            retries = None
+
         try:
             ssl_details = util.fetch_ssl_details(paths)
-            resp = util.read_file_or_url(url,
-                                         headers=headers,
+            resp = util.read_file_or_url(url, retries=retries,
+                                         headers_cb=header_cb,
                                          timeout=timeout,
                                          ssl_details=ssl_details)
             if resp.ok():

=== modified file 'cloudinit/url_helper.py'
--- cloudinit/url_helper.py	2013-03-19 14:05:51 +0000
+++ cloudinit/url_helper.py	2013-04-25 16:07:33 +0000
@@ -102,8 +102,8 @@
 
 
 def readurl(url, data=None, timeout=None, retries=0, sec_between=1,
-            headers=None, ssl_details=None, check_status=True,
-            allow_redirects=True):
+            headers=None, headers_cb=None, ssl_details=None,
+            check_status=True, allow_redirects=True):
     url = _cleanurl(url)
     req_args = {
         'url': url,
@@ -149,8 +149,11 @@
         headers = {
             'User-Agent': 'Cloud-Init/%s' % (version.version_string()),
         }
-    req_args['headers'] = headers
-    LOG.debug("Attempting to open '%s' with %s configuration", url, req_args)
+    if not headers_cb:
+        def _cb(url):
+            return headers
+        headers_cb = _cb
+
     if data:
         # Do this after the log (it might be large)
         req_args['data'] = data
@@ -161,6 +164,11 @@
     # doesn't handle sleeping between tries...
     for i in range(0, manual_tries):
         try:
+            req_args['headers'] = headers_cb(url)
+            LOG.debug("[%s/%s] open '%s' with %s configuration", i,
+                      manual_tries, url,
+                      {k: req_args[k] for k in req_args if k != 'data'})
+
             r = requests.request(**req_args)
             if check_status:
                 r.raise_for_status()  # pylint: disable=E1103
@@ -174,7 +182,7 @@
         except exceptions.RequestException as e:
             if (isinstance(e, (exceptions.HTTPError))
                 and hasattr(e, 'response')  # This appeared in v 0.10.8
-                and e.response):
+                and hasattr(e.response, 'status_code')):
                 excps.append(UrlError(e, code=e.response.status_code,
                                       headers=e.response.headers))
             else:

=== modified file 'cloudinit/util.py'
--- cloudinit/util.py	2013-03-26 21:48:40 +0000
+++ cloudinit/util.py	2013-04-25 16:07:33 +0000
@@ -671,7 +671,8 @@
 
 
 def read_file_or_url(url, timeout=5, retries=10,
-                     headers=None, data=None, sec_between=1, ssl_details=None):
+                     headers=None, data=None, sec_between=1, ssl_details=None,
+                     headers_cb=None):
     url = url.lstrip()
     if url.startswith("/"):
         url = "file://%s" % url
@@ -685,6 +686,7 @@
                                   timeout=timeout,
                                   retries=retries,
                                   headers=headers,
+                                  headers_cb=headers_cb,
                                   data=data,
                                   sec_between=sec_between,
                                   ssl_details=ssl_details)


Follow ups