← Back to team overview

cloud-init-dev team mailing list archive

[Merge] lp:~harlowja/cloud-init/simple-traverse into lp:cloud-init

 

Joshua Harlow has proposed merging lp:~harlowja/cloud-init/simple-traverse into lp:cloud-init.

Requested reviews:
  cloud init development team (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~harlowja/cloud-init/simple-traverse/+merge/134174

Even when using boto < 2.6 force the unlazying to occur

It seems like its possible that boto 2.5.2 and below have
the lazy loading metadata dictionary so as a precaution
we will always take the hit of unlazying the metadata dictionary
by traversing it which in the non-lazy dictionary case has
no effect (its marginal). This also removes the need to check
the boto version and the dependency on setup tools just for
this case.

-- 
https://code.launchpad.net/~harlowja/cloud-init/simple-traverse/+merge/134174
Your team cloud init development team is requested to review the proposed merge of lp:~harlowja/cloud-init/simple-traverse into lp:cloud-init.
=== modified file 'cloudinit/ec2_utils.py'
--- cloudinit/ec2_utils.py	2012-11-12 17:23:44 +0000
+++ cloudinit/ec2_utils.py	2012-11-13 19:05:25 +0000
@@ -16,34 +16,26 @@
 #    You should have received a copy of the GNU General Public License
 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-import pkg_resources
-from pkg_resources import parse_version as pver
-
 import boto.utils as boto_utils
 
-# Versions of boto >= 2.6.0 try to lazily load
-# the metadata backing, which doesn't work so well
-# in cloud-init especially since the metadata is
-# serialized and actions are performed where the
-# metadata server may be blocked (thus the datasource
-# will start failing) resulting in url exceptions
-# when fields that do exist (or would have existed)
-# do not exist due to the blocking that occurred.
-
-BOTO_LAZY = False
-try:
-    _boto_lib = pkg_resources.get_distribution('boto')
-    if _boto_lib.parsed_version > pver("2.5.2"):  # pylint: disable=E1103
-        BOTO_LAZY = True
-except pkg_resources.DistributionNotFound:
-    pass
+# Versions of boto >= 2.6.0 (and possibly 2.5.2)
+# try to lazily load the metadata backing, which
+# doesn't work so well in cloud-init especially
+# since the metadata is serialized and actions are
+# performed where the metadata server may be blocked
+# (thus the datasource will start failing) resulting
+# in url exceptions when fields that do exist (or
+# would have existed) do not exist due to the blocking
+# that occurred.
 
 
 def _unlazy_dict(mp):
     if not isinstance(mp, (dict)):
         return mp
-    if not BOTO_LAZY:
-        return mp
+    # Walk over the keys/values which
+    # forces boto to unlazy itself and
+    # has no effect on dictionaries that
+    # already have there items.
     for (_k, v) in mp.items():
         _unlazy_dict(v)
     return mp


Follow ups