-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Single JSON schema validation in early boot #1175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
blackboxsw
merged 20 commits into
canonical:main
from
blackboxsw:single-schema-validation
Jan 18, 2022
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e0c6725
schema: perform validate_cloudcfg_schema once in early boot
blackboxsw feb5c5e
schema: deliver single JSON schema file and Paths.schema_dir
blackboxsw 5c66261
schema: support legacy module schema and compisite global schema
blackboxsw 12b9504
schema: define schema meta for cc_apt_pipelining
blackboxsw b1cf0aa
schema: annotation fixes for lists and empty schema
blackboxsw cfaf67b
schema: clarify schema warning message
blackboxsw 5e8ff02
integration test
blackboxsw 2ea7fce
schema: warn when multiple schema files present, but use the first one
blackboxsw cf10af4
tests
blackboxsw dd7e363
tests: apt_pipelining schema tests
blackboxsw 1710170
tests: apt_pipelining spelling
blackboxsw 3bf0220
schema: migrate cc_apk_configure and add schema tests
blackboxsw 2b43a2e
schema: allow CLOUD_INIT_SCHEMA_DIR env override for Paths.schema_dir
blackboxsw 392db85
rebase includes keyboard legacy schema
blackboxsw 8c40933
tox: use setenv in tox so tox -e doc includes defines schema docs
blackboxsw 3473609
schema: deliver cloud-init-schema.json with python modules. Drop path…
blackboxsw d47ebc3
schema: do not version cloud-init-schema.json yet
blackboxsw bbbbc43
drop now-irrelevant paths.schema_dir from tests
blackboxsw a77e879
setup.py: include schema json data file in packaging
blackboxsw 4ff1b3c
testing: no longer mkdir schema_dir
blackboxsw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ | |
|
|
||
| from cloudinit import log as logging | ||
| from cloudinit import temp_utils, templater, util | ||
| from cloudinit.config.schema import get_meta_doc, validate_cloudconfig_schema | ||
| from cloudinit.config.schema import get_meta_doc | ||
| from cloudinit.settings import PER_INSTANCE | ||
|
|
||
| LOG = logging.getLogger(__name__) | ||
|
|
@@ -102,104 +102,7 @@ | |
| "frequency": frequency, | ||
| } | ||
|
|
||
| schema = { | ||
| "type": "object", | ||
| "properties": { | ||
| "apk_repos": { | ||
| "type": "object", | ||
| "properties": { | ||
| "preserve_repositories": { | ||
| "type": "boolean", | ||
| "default": False, | ||
| "description": dedent( | ||
| """\ | ||
| By default, cloud-init will generate a new repositories | ||
| file ``/etc/apk/repositories`` based on any valid | ||
| configuration settings specified within a apk_repos | ||
| section of cloud config. To disable this behavior and | ||
| preserve the repositories file from the pristine image, | ||
| set ``preserve_repositories`` to ``true``. | ||
|
|
||
| The ``preserve_repositories`` option overrides | ||
| all other config keys that would alter | ||
| ``/etc/apk/repositories``. | ||
| """ | ||
| ), | ||
| }, | ||
| "alpine_repo": { | ||
| "type": ["object", "null"], | ||
| "properties": { | ||
| "base_url": { | ||
| "type": "string", | ||
| "default": DEFAULT_MIRROR, | ||
| "description": dedent( | ||
| """\ | ||
| The base URL of an Alpine repository, or | ||
| mirror, to download official packages from. | ||
| If not specified then it defaults to ``{}`` | ||
| """.format( | ||
| DEFAULT_MIRROR | ||
| ) | ||
| ), | ||
| }, | ||
| "community_enabled": { | ||
| "type": "boolean", | ||
| "default": False, | ||
| "description": dedent( | ||
| """\ | ||
| Whether to add the Community repo to the | ||
| repositories file. By default the Community | ||
| repo is not included. | ||
| """ | ||
| ), | ||
| }, | ||
| "testing_enabled": { | ||
| "type": "boolean", | ||
| "default": False, | ||
| "description": dedent( | ||
| """\ | ||
| Whether to add the Testing repo to the | ||
| repositories file. By default the Testing | ||
| repo is not included. It is only recommended | ||
| to use the Testing repo on a machine running | ||
| the ``Edge`` version of Alpine as packages | ||
| installed from Testing may have dependancies | ||
| that conflict with those in non-Edge Main or | ||
| Community repos." | ||
| """ | ||
| ), | ||
| }, | ||
| "version": { | ||
| "type": "string", | ||
| "description": dedent( | ||
| """\ | ||
| The Alpine version to use (e.g. ``v3.12`` or | ||
| ``edge``) | ||
| """ | ||
| ), | ||
| }, | ||
| }, | ||
| "required": ["version"], | ||
| "minProperties": 1, | ||
| "additionalProperties": False, | ||
| }, | ||
| "local_repo_base_url": { | ||
| "type": "string", | ||
| "description": dedent( | ||
| """\ | ||
| The base URL of an Alpine repository containing | ||
| unofficial packages | ||
| """ | ||
| ), | ||
| }, | ||
| }, | ||
| "minProperties": 1, # Either preserve_repositories or alpine_repo | ||
| "additionalProperties": False, | ||
| } | ||
| }, | ||
| } | ||
|
|
||
| __doc__ = get_meta_doc(meta, schema) | ||
| __doc__ = get_meta_doc(meta) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. _get_meta_doc now makes schema param optional and will construct docs based on sub-schema matching meta['id'] for the "new-style" cc_ modules. |
||
|
|
||
|
|
||
| def handle(name, cfg, cloud, log, _args): | ||
|
|
@@ -222,8 +125,6 @@ def handle(name, cfg, cloud, log, _args): | |
| ) | ||
| return | ||
|
|
||
| validate_cloudconfig_schema(cfg, schema) | ||
|
|
||
| # If "preserve_repositories" is explicitly set to True in | ||
| # the configuration do nothing. | ||
| if util.get_cfg_option_bool(apk_section, "preserve_repositories", False): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-04/schema#", | ||
| "$defs": { | ||
| "cc_apk_configure": { | ||
| "type": "object", | ||
| "properties": { | ||
| "apk_repos": { | ||
| "type": "object", | ||
| "properties": { | ||
| "preserve_repositories": { | ||
| "type": "boolean", | ||
| "default": false, | ||
| "description": "By default, cloud-init will generate a new repositories file ``/etc/apk/repositories`` based on any valid configuration settings specified within a apk_repos section of cloud config. To disable this behavior and preserve the repositories file from the pristine image, set ``preserve_repositories`` to ``true``.\n\n The ``preserve_repositories`` option overrides all other config keys that would alter ``/etc/apk/repositories``." | ||
| }, | ||
| "alpine_repo": { | ||
| "type": ["object", "null"], | ||
| "properties": { | ||
| "base_url": { | ||
| "type": "string", | ||
| "default": "https://alpine.global.ssl.fastly.net/alpine", | ||
| "description": "The base URL of an Alpine repository, or mirror, to download official packages from. If not specified then it defaults to ``https://alpine.global.ssl.fastly.net/alpine``" | ||
| }, | ||
| "community_enabled": { | ||
| "type": "boolean", | ||
| "default": false, | ||
| "description": "Whether to add the Community repo to the repositories file. By default the Community repo is not included." | ||
| }, | ||
| "testing_enabled": { | ||
| "type": "boolean", | ||
| "default": false, | ||
| "description": "Whether to add the Testing repo to the repositories file. By default the Testing repo is not included. It is only recommended to use the Testing repo on a machine running the ``Edge`` version of Alpine as packages installed from Testing may have dependancies that conflict with those in non-Edge Main or Community repos." | ||
| }, | ||
| "version": { | ||
| "type": "string", | ||
| "description": "The Alpine version to use (e.g. ``v3.12`` or ``edge``)" | ||
| } | ||
| }, | ||
| "required": ["version"], | ||
| "minProperties": 1, | ||
| "additionalProperties": false | ||
| }, | ||
| "local_repo_base_url": { | ||
| "type": "string", | ||
| "description": "The base URL of an Alpine repository containing unofficial packages" | ||
| } | ||
| }, | ||
| "minProperties": 1, | ||
| "additionalProperties": false | ||
| } | ||
| } | ||
| }, | ||
| "cc_apt_pipelining": { | ||
| "type": "object", | ||
| "properties": { | ||
| "apt_pipelining": { | ||
| "oneOf": [ | ||
| {"type": "integer"}, | ||
| {"type": "boolean"}, | ||
| {"type": "string", "enum": ["none", "unchanged", "os"]} | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "allOf": [ | ||
| { "$ref": "#/$defs/cc_apk_configure" }, | ||
| { "$ref": "#/$defs/cc_apt_pipelining" } | ||
| ] | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Migrated schema modules will no longer define "schema" attribute or run validate_cloudconfig_schema since we run schema validation one-time against the full schema after the user-data is processed in main.py:480