← 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:
  Server Team CI bot (server-team-bot): continuous-integration
  cloud-init commiters (cloud-init-dev)

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

This needs 
 https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/343609
-- 
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 76826e0..e3c4725 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..3c22aac 100644
--- a/tests/unittests/test_handler/test_schema.py
+++ b/tests/unittests/test_handler/test_schema.py
@@ -79,10 +79,10 @@ class ValidateCloudConfigSchemaTest(CiTestCase):
 
     @skipUnlessJsonSchema()
     def test_validateconfig_schema_emits_warning_on_missing_jsonschema(self):
-        """Warning from validate_cloudconfig_schema when missing jsonschema."""
+        """Message logged from validate_cloudconfig_schema if no jsonschema."""
         schema = {'properties': {'p1': {'type': 'string'}}}
         with mock.patch.dict('sys.modules', **{'jsonschema': ImportError()}):
-            validate_cloudconfig_schema({'p1': -1}, schema, strict=True)
+            validate_cloudconfig_schema({'p1': -1}, schema, strict=False)
         self.assertIn(
             'Ignoring schema validation. python-jsonschema is not present',
             self.logs.getvalue())
@@ -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