canonical / canonical/cloud-init

[enhancement]: Query for schema failures

Open
#5,100 2 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
3.8k
Forks
1.1k
Avg merge
2d 23h
Merged PRs (30d)
18

Description

# Enhancement

It would be really great if there was a dedicated method to query cloud-init for schema validation errors, particularly in a machine readable format such as the json format option for `cloud-init status`. At minimum, I am interested in *top-level keys* that failed to validate and only their names. Although I'm sure there's some uses for further information I haven't thought of yet!

## Use case example

In Subiquity, new users may confuse cloud-config with autoinstall and provide autoinstall directives in cloud-config mistakenly. This means the directives never make it to Subiquity and the behavior does not match their expectation. To avoid this silent failure, we query cloud-init for schema validation errors and halt the install if a recognized autoinstall directive was the cause of a cloud-init schema failure.

The [current method](https://github.com/canonical/subiquity/pull/1954) for this is to:
1. Read the output of `cloud-init status --format=json` and look for the line "Invalid cloud-config provided: Please run 'sudo cloud-init schema --system' to see the schema errors." in the `recoverable_errors` section.
2. Use regex to match the "Additional properties are now allowed ('key1', 'key2', ... , 'keyN' were unexpected)" line printed to stderr by said command and parse out the key names.

This implementation is fragile to output format changes and requires coordinating multiple calls to cloud-init. If instead we could make one call to (for example) `cloud-init schema --system --format=json` and get a response that lists all of the unrecognized keys, has per-key validation error information, or some other format that would allow parsing the key-names reliably, it would help a lot!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.