← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~smoser/cloud-init:cleanup/schema-raise-import-error-if-validate-strict into cloud-init:master

 

Scott Moser has proposed merging ~smoser/cloud-init:cleanup/schema-raise-import-error-if-validate-strict into cloud-init:master.

Commit message:
schema: in validation, raise ImportError if strict but no jsonschema.

validate_cloudconfig_schema with strict=True would not actually validate
if there was no jsonschema available.  That seems kind of strange.
The change here is to make it raise an exception if strict was passed in.
And then to fix the one test that needed a skipIfJsonSchema wrapper.

Requested reviews:
  cloud-init commiters (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/343610

see commit message
-- 
Your team cloud-init commiters is requested to review the proposed merge of ~smoser/cloud-init:cleanup/schema-raise-import-error-if-validate-strict into cloud-init:master.
diff --git a/cloudinit/config/schema.py b/cloudinit/config/schema.py
index ca7d0d5..49ada0b 100644
--- a/cloudinit/config/schema.py
+++ b/cloudinit/config/schema.py
@@ -74,6 +74,8 @@ def validate_cloudconfig_schema(config, schema, strict=False):
     try:
         from jsonschema import Draft4Validator, FormatChecker
     except ImportError:
+        if strict:
+            raise
         logging.debug(
             'Ignoring schema validation. python-jsonschema is not present')
         return
diff --git a/tests/unittests/test_handler/test_schema.py b/tests/unittests/test_handler/test_schema.py
index ac41f12..6791c56 100644
--- a/tests/unittests/test_handler/test_schema.py
+++ b/tests/unittests/test_handler/test_schema.py
@@ -351,6 +351,7 @@ class MainTest(CiTestCase):
         self.assertIn('\nNTP\n---\n', m_stdout.getvalue())
         self.assertIn('\nRuncmd\n------\n', m_stdout.getvalue())
 
+    @skipUnlessJsonSchema()
     def test_main_validates_config_file(self):
         """When --config-file parameter is provided, main validates schema."""
         myyaml = self.tmp_path('my.yaml')

Follow ups