← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~chad.smith/cloud-init:cyaml-loading into cloud-init:master

 

Chad Smith has proposed merging ~chad.smith/cloud-init:cyaml-loading into cloud-init:master.

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

For more details, see:
https://code.launchpad.net/~chad.smith/cloud-init/+git/cloud-init/+merge/323088

Use CSafeLoader C-bindings instead of python for a faster yaml.load when processing yaml files.

For faster yaml processing import CSafeLoader in cloudinit/safeyaml.py during yaml loads. Also adds a comment to requirements.txt about the libyaml-dev packages required for unit tests to properly build. Previous test deployments may need to run tox -r to rebuild the virtual env cache if necessary libyaml-dev python-dev packages were absent.

LP: # 1685939

To test:
 tox -r
 tox
-- 
Your team cloud init development team is requested to review the proposed merge of ~chad.smith/cloud-init:cyaml-loading into cloud-init:master.
diff --git a/cloudinit/safeyaml.py b/cloudinit/safeyaml.py
index 7bcf9dd..4dd9fb4 100644
--- a/cloudinit/safeyaml.py
+++ b/cloudinit/safeyaml.py
@@ -4,10 +4,12 @@
 #
 # This file is part of cloud-init. See LICENSE file for license information.
 
-import yaml
+from yaml import (
+    CSafeLoader,
+    load as yaml_load)
 
 
-class _CustomSafeLoader(yaml.SafeLoader):
+class _CustomSafeLoader(CSafeLoader):
     def construct_python_unicode(self, node):
         return self.construct_scalar(node)
 
@@ -18,6 +20,6 @@ _CustomSafeLoader.add_constructor(
 
 
 def load(blob):
-    return(yaml.load(blob, Loader=_CustomSafeLoader))
+    return(yaml_load(blob, Loader=_CustomSafeLoader))
 
 # vi: ts=4 expandtab
diff --git a/requirements.txt b/requirements.txt
index 0c4951f..157592a 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -24,10 +24,14 @@ oauthlib
 # section)...
 configobj>=5.0.2
 
-# All new style configurations are in the yaml format
+# cloudinit/safeyaml.py depends on libyaml c-bindings which are built by tox
+# when libyaml-(dev|devel), libpython2.7-(dev|devel) and libpython3-(dev|devel)
+# headers packages are installed. If tox fails importing CSafeLoader, we need
+# these dev packages.
+# All new style configurations are in the yaml format.
 pyyaml
 
-# The new main entrypoint uses argparse instead of optparse
+# The new main entrypoint uses argparse instead of optparse 
 argparse
 
 # Requests handles ssl correctly!

Follow ups