diff options
author | Chad Smith <chad.smith@canonical.com> | 2017-10-23 14:46:12 -0600 |
---|---|---|
committer | Chad Smith <chad.smith@canonical.com> | 2017-10-23 14:46:12 -0600 |
commit | a7f478aafa570abde940037014fabcb0eab16502 (patch) | |
tree | d838e40b26684f33b3b05c24ead267e28bb1b5a3 /tests/unittests/test_handler/test_schema.py | |
parent | 5443ede5e90c0be56f25ac729c5f341cdb4ad31c (diff) | |
parent | 17a15f9e0ae78e4fc4e24fab0caebdf78f06ef66 (diff) | |
download | vyos-cloud-init-a7f478aafa570abde940037014fabcb0eab16502.tar.gz vyos-cloud-init-a7f478aafa570abde940037014fabcb0eab16502.zip |
merge from master at 17.1-25-g17a15f9e
Diffstat (limited to 'tests/unittests/test_handler/test_schema.py')
-rw-r--r-- | tests/unittests/test_handler/test_schema.py | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/tests/unittests/test_handler/test_schema.py b/tests/unittests/test_handler/test_schema.py index b8fc8930..648573f6 100644 --- a/tests/unittests/test_handler/test_schema.py +++ b/tests/unittests/test_handler/test_schema.py @@ -4,11 +4,12 @@ from cloudinit.config.schema import ( CLOUD_CONFIG_HEADER, SchemaValidationError, annotated_cloudconfig_file, get_schema_doc, get_schema, validate_cloudconfig_file, validate_cloudconfig_schema, main) -from cloudinit.util import write_file +from cloudinit.util import subp, write_file from cloudinit.tests.helpers import CiTestCase, mock, skipIf from copy import copy +import os from six import StringIO from textwrap import dedent from yaml import safe_load @@ -364,4 +365,38 @@ class MainTest(CiTestCase): self.assertIn( 'Valid cloud-config file {0}'.format(myyaml), m_stdout.getvalue()) + +class CloudTestsIntegrationTest(CiTestCase): + """Validate all cloud-config yaml schema provided in integration tests. + + It is less expensive to have unittests validate schema of all cloud-config + yaml provided to integration tests, than to run an integration test which + raises Warnings or errors on invalid cloud-config schema. + """ + + @skipIf(_missing_jsonschema_dep, "No python-jsonschema dependency") + def test_all_integration_test_cloud_config_schema(self): + """Validate schema of cloud_tests yaml files looking for warnings.""" + schema = get_schema() + testsdir = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + integration_testdir = os.path.sep.join( + [testsdir, 'cloud_tests', 'testcases']) + errors = [] + out, _ = subp(['find', integration_testdir, '-name', '*yaml']) + for filename in out.splitlines(): + test_cfg = safe_load(open(filename)) + cloud_config = test_cfg.get('cloud_config') + if cloud_config: + cloud_config = safe_load( + cloud_config.replace("#cloud-config\n", "")) + try: + validate_cloudconfig_schema( + cloud_config, schema, strict=True) + except SchemaValidationError as e: + errors.append( + '{0}: {1}'.format( + filename, e)) + if errors: + raise AssertionError(', '.join(errors)) + # vi: ts=4 expandtab syntax=python |