diff options
author | Scott Moser <smoser@ubuntu.com> | 2018-04-20 20:25:48 -0400 |
---|---|---|
committer | Scott Moser <smoser@brickies.net> | 2018-04-20 20:25:48 -0400 |
commit | 5037252ca5dc54c6d978b23dba063ac5fabc98fa (patch) | |
tree | d39ee7c87b9d471a10a300766570a838c04cbc24 /cloudinit/tests | |
parent | 4952a8545b61ceb2fe26a933d2f64020d0281703 (diff) | |
download | vyos-cloud-init-5037252ca5dc54c6d978b23dba063ac5fabc98fa.tar.gz vyos-cloud-init-5037252ca5dc54c6d978b23dba063ac5fabc98fa.zip |
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.
Diffstat (limited to 'cloudinit/tests')
-rw-r--r-- | cloudinit/tests/helpers.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/cloudinit/tests/helpers.py b/cloudinit/tests/helpers.py index 5aada6e7..4999f1f6 100644 --- a/cloudinit/tests/helpers.py +++ b/cloudinit/tests/helpers.py @@ -24,6 +24,8 @@ try: except ImportError: from ConfigParser import ConfigParser +from cloudinit.config.schema import ( + SchemaValidationError, validate_cloudconfig_schema) from cloudinit import helpers as ch from cloudinit import util @@ -312,6 +314,23 @@ class HttprettyTestCase(CiTestCase): super(HttprettyTestCase, self).tearDown() +class SchemaTestCaseMixin(unittest2.TestCase): + + def assertSchemaValid(self, cfg, msg="Valid Schema failed validation."): + """Assert the config is valid per self.schema. + + If there is only one top level key in the schema properties, then + the cfg will be put under that key.""" + props = list(self.schema.get('properties')) + # put cfg under top level key if there is only one in the schema + if len(props) == 1: + cfg = {props[0]: cfg} + try: + validate_cloudconfig_schema(cfg, self.schema, strict=True) + except SchemaValidationError: + self.fail(msg) + + def populate_dir(path, files): if not os.path.exists(path): os.makedirs(path) |