Skip to content
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

schema: version schema-cloud-config-v1.json #1424

Merged
merged 6 commits into from
May 16, 2022

Conversation

blackboxsw
Copy link
Collaborator

@blackboxsw blackboxsw commented May 3, 2022

Provide top-level versions.schema.cloud-config.json which will be
published to https://github.com/SchemaStore/schemastore/ and provided
for external json validator tools.

Move static JSON schema files into cloudinit/config/schemas/.
Rename cloud-init-schema.json to schema-cloud-config-v1.json to allow
space for providing static scoped schema definitions for vendor-data,
meta-data and network-config in the future.

Proposed Commit Message

Provide top-level version.schema.cloud-config.json which will be
consumed by https://github.com/SchemaStore/schemastore/ and provided
for json validator tooling.

Rename cloud-init-schema.json to schema-cloud-config-v1.json to allow
space for providing static scoped schema definitions for vendor-data,
meta-data and network-config in the future.

Additional Context

This PR follows the suggested naming conventions and versioning best-practices for adding an out-of-tree
schema definition for schemastore.org.

It attempts to follow the contributing guidelines for non-local schema definitions as well as guidance for multi-version support

Test Steps

tox -e py3
PYTHONPATH=. python3 -m cloudinit.cmd.main schema --docs all
echo > bogus.yaml << EOF
#cloud-config
users: somethingbroken
EOF
PYTHONPATH=. python3 -m cloudinit.cmd.main schema --annotate -c bogus.yaml

Checklist:

  • My code follows the process laid out in the documentation
  • I have updated or added any unit tests accordingly
  • I have updated or added any documentation accordingly

@blackboxsw blackboxsw force-pushed the publish-schema branch 2 times, most recently from 4068a96 to 17ddf05 Compare May 13, 2022 03:24
@blackboxsw blackboxsw marked this pull request as draft May 13, 2022 16:31
@blackboxsw blackboxsw marked this pull request as ready for review May 13, 2022 17:39
Provide top-level version.schema.cloud-config.json which will be
consumed by https://github.com/SchemaStore/schemastore/ and provided
for json validator tooling.

Rename cloud-init-schema.json to schema-cloud-config-v1.json to allow
space for providing static scoped schema definitions for vendor-data,
meta-data and network-config in the future.
- Move static schema files into cloudinit/config/schemas.
- versions.schema.cloud-config.json to use correct raw github
  URL as $id
- add get_schema_dir for use in testing
@blackboxsw
Copy link
Collaborator Author

Thanks for the review @BigBlueHundids.

Copy link
Member

@TheRealFalcon TheRealFalcon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@TheRealFalcon TheRealFalcon merged commit 53e1ccf into canonical:main May 16, 2022
Copy link
Contributor

@aciba90 aciba90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thank you.

As an optional nit, I think it would be more clear and concise if we refactor test_versioned_cloud_config_schema_is_valid_json to something like:

diff --git a/tests/unittests/config/test_schema.py b/tests/unittests/config/test_schema.py
index c75b7227..5a7cafce 100644
--- a/tests/unittests/config/test_schema.py
+++ b/tests/unittests/config/test_schema.py
@@ -106,11 +106,25 @@ class TestVersionedSchemas:
         full_path_schema["oneOf"][0]["allOf"][1]["$ref"] = file_ref
         return full_path_schema
 
+    def validate_cloudconfig_schema_safe(self, schema, version_schema):
+        try:
+            validate_cloudconfig_schema(
+                schema, schema=version_schema, strict=True
+            )
+        except jsonschema.exceptions.RefResolutionError:
+            full_path_schema = self._relative_ref_to_local_file_path(
+                version_schema
+            )
+            validate_cloudconfig_schema(
+                schema, schema=full_path_schema, strict=True
+            )
+
     @pytest.mark.parametrize(
         "schema,error_msg",
         (
             ({}, None),
             ({"version": "v1"}, None),
             ({"version": "v2"}, "is not valid"),
             ({"version": "v1", "final_message": -1}, "is not valid"),
             ({"version": "v1", "final_message": "some msg"}, None),
@@ -128,30 +142,10 @@ class TestVersionedSchemas:
         version_schema["$id"] = f"file://{version_schemafile}"
         if error_msg:
             with pytest.raises(SchemaValidationError) as context_mgr:
-                try:
-                    validate_cloudconfig_schema(
-                        schema, schema=version_schema, strict=True
-                    )
-                except jsonschema.exceptions.RefResolutionError:
-                    full_path_schema = self._relative_ref_to_local_file_path(
-                        version_schema
-                    )
-                    validate_cloudconfig_schema(
-                        schema, schema=full_path_schema, strict=True
-                    )
+                self.validate_cloudconfig_schema_safe(schema, version_schema)
             assert error_msg in str(context_mgr.value)
         else:
-            try:
-                validate_cloudconfig_schema(
-                    schema, schema=version_schema, strict=True
-                )
-            except jsonschema.exceptions.RefResolutionError:
-                full_path_schema = self._relative_ref_to_local_file_path(
-                    version_schema
-                )
-                validate_cloudconfig_schema(
-                    schema, schema=full_path_schema, strict=True
-                )
+            self.validate_cloudconfig_schema_safe(schema, version_schema)

"schema,error_msg",
(
({}, None),
({"version": "v1"}, None),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also tests version == 22.2 please?

Suggested change
({"version": "v1"}, None),
({"version": "v1"}, None),
({"version": "22.2"}, None),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants