summaryrefslogtreecommitdiff
path: root/cloudinit/config/schema.py
AgeCommit message (Collapse)Author
2020-05-14cloudinit: remove unneeded __future__ imports (#362)Daniel Watkins
We live in the future now.
2020-05-13Add schema to apt configure config (#357)lucasmoura
Create a schema object for the `apt_configure` module and validate this schema in the `handle` function of the module. There are some considerations regarding this PR: * The `primary` and `security` keys have the exact same properties. I tried to eliminate this redundancy by moving their properties to a common place and then just referencing it for both security and primary. Similar to what is documented here: https://json-schema.org/understanding-json-schema/structuring.html under the `Reuse` paragraph. However, this approach does not work, because the `#` pointer goes to the beginning of the file, which is a python module instead of a json file, not allowing the pointer to find the correct definition. What I did was to create a separate dict for the mirror config and reuse it for primary and security, but maybe there are better approaches to do that. * There was no documentation for the config `debconf_selections`. I tried to infer what it supposed to do by looking at the code and the `debconf-set-selections` manpage, but my description may not be accurate or complete. * Add a _parse_description function to schema.py to render multi-line preformatted content instead of squashing all whitespace LP: #1858884
2020-04-27schema: ignore spurious pylint error (#332)Daniel Watkins
The line in question is in the code path handling older versions of jsonschema. In that context it _is_ correct, but when pylint analyses it against the latest jsonschema it (incorrectly) detects an error.
2020-04-24schema: add json schema for write_files module (#152)Chad Smith
Add schema definition to cc_write_files.py Cloud-config containing write_files config directives will now emit warnings for invalid config keys or values for the write_files module. Add an extension to JSON schema's draft4validator to permit either binary or text values for 'string' objects. This allows for JSON schema validating the YAML declaration of binary valiues in cloud-config using YAML's '!!binary' syntax. Add the ability to pass a specific module name to `cloud-init devel schema --docs <module_name>|all` to optionally limit doc output during development to a single schema doc.
2019-01-30Resolve flake8 comparison and pycodestyle over-ident issuesParide Legovini
Fixes: - flake8: use ==/!= to compare str, bytes, and int literals - pycodestyle: E117 over-indented
2018-05-23yaml_load/schema: Add invalid line and column nums to error messageChad Smith
Yaml tracebacks are generally hard to read for average users. Add a bit of logic to util.yaml_load and schema validation to look for YAMLError.context_marker or problem_marker line and column counts. No longer log the full exceeption traceback from the yaml_load error, instead just LOG.warning for the specific error and point to the offending line and column where the problem exists.
2018-05-17read_file_or_url: move to url_helper, fix bug in its FileResponse.Scott Moser
The result of a read_file_or_url on a file and on a url would differ in behavior. str(UrlResponse) would return UrlResponse.contents.decode('utf-8') while str(FileResponse) would return str(FileResponse.contents) The difference being "b'foo'" versus "foo". As part of the general goal of cleaning util, move read_file_or_url into url_helper.
2018-04-19pylint: pay attention to unused variable warnings.Scott Moser
This enables warnings produced by pylint for unused variables (W0612), and fixes the existing errors.
2017-10-18schema: Log debug instead of warning when jsonschema is not available.Scott Moser
When operating in expected path, cloud-init should avoid logging with warning. That causes 'WARNING' messages in /var/log/cloud-init.log. By default, warnings also go to the console. Since jsonschema is a optional dependency, and not present on xenial and zesty, cloud-init should not warn there. Also here: * Add a test to integration tests to assert that there are no warnings in /var/log/cloud-init.log. * Update one integration test that did show warning and the related documentation and examples. LP: #1724354
2017-09-20docs: fix sphinx module schema documentationChad Smith
Create a copy of each modules schema attribute when generating sphinx docs to avoid altering the actual module dict in memory. This avoids illegible rendering of module examples and distros where each character of a list was represented on a separate line by itself. Fixes ntp, resizefs, runcmd and bootcmd docs.
2017-09-13schema and docs: Add jsonschema to resizefs and bootcmd modulesChad Smith
Add schema definitions to both cc_resizefs and cc_bootcmd modules. Extend schema.py to parse and document enumerated json types. Schema definitions are used to generate module documention and log warnings for schema infractions. This branch also does the following: - drops vestigial 'resize_rootfs_tmp' option from cc_resizefs. That option only created the specified directory and didn't make use of that directory for any resize operations. - Drop yaml.dumps calls from schema documentation generation to avoid yaml import costs on module load - Add __doc__ = get_schema_doc(schema) definitions it each module to supplement python help() calls for cc_runcmd, cc_bootcmd, cc_ntp and cc_resizefs - Add a SCHEMA_EXAMPLES_SPACER_TEMPLATE string to docs for modules which contain more than one example
2017-08-22schema cli: Add schema subcommand to cloud-init cli and cc_runcmd schemaChad Smith
This branch does a few things: - Add 'schema' subcommand to cloud-init CLI for validating cloud-config files against strict module jsonschema definitions - Add --annotate parameter to 'cloud-init schema' to annotate existing cloud-config file content with validation errors - Add jsonschema definition to cc_runcmd - Add unit test coverage for cc_runcmd - Update CLI capabilities documentation This branch only imports development (and analyze) subparsers when the specific subcommand is provided on the CLI to avoid adding costly unused file imports during cloud-init system boot. The schema command allows a person to quickly validate a cloud-config text file against cloud-init's known module schemas to avoid costly roundtrips deploying instances in their cloud of choice. As of this branch, only cc_ntp and cc_runcmd cloud-config modules define schemas. Schema validation will ignore all undefined config keys until all modules define a strict schema. To perform validation of runcmd and ntp sections of a cloud-config file: $ cat > cloud.cfg <<EOF runcmd: bogus EOF $ python -m cloudinit.cmd.main schema --config-file cloud.cfg $ python -m cloudinit.cmd.main schema --config-file cloud.cfg \ --annotate Once jsonschema is defined for all ~55 cc modules, we will move this schema subcommand up as a proper subcommand of the cloud-init CLI.
2017-05-31ntp: Add schema definition and passive schema validation.Chad Smith
cloud-config files are very flexible and permissive. This adds a jsonsschema definition to the cc_ntp module and validation functions in cloudinit/config/schema which will log warnings about invalid configuration values in the ntp section. A cmdline tools/cloudconfig-schema is added which can be used in our dev environments to quickly attempt to exercise the ntp schema. It is also exposed as a main in cloudinit.config.schema. (python3 -m cloudinit.config.schema) LP: #1692916