Skip to content

Validate rendered cloud-init templates against official schema#63

Merged
ret2libc merged 4 commits intomainfrom
feat/cloudinit-schema-validation
Apr 13, 2026
Merged

Validate rendered cloud-init templates against official schema#63
ret2libc merged 4 commits intomainfrom
feat/cloudinit-schema-validation

Conversation

@ret2libc
Copy link
Copy Markdown
Collaborator

Summary

  • Add jsonschema as a dev dependency
  • Add two new tests that render the default Jinja2 cloud-init template (with/without Tailscale) and validate the output against the official cloud-init JSON schema
  • Schema is fetched at test time via a module-scoped fixture; tests skip gracefully if the network is unavailable

Test plan

  • uv run pytest tests/test_cloudinit.py -v — all 6 tests pass
  • uv run pytest -v — full suite (291 tests) passes with coverage above threshold
  • prek run — all pre-commit hooks pass
  • Verify tests skip correctly when offline (disconnect network, run tests)

🤖 Generated with Claude Code

@ret2libc ret2libc force-pushed the feat/cloudinit-schema-validation branch from e7410fe to bc121e8 Compare March 31, 2026 12:30
Add jsonschema dev dependency and two new tests that render the Jinja2
cloud-init template (with and without Tailscale) then validate the
output against canonical/cloud-init's JSON schema. Tests skip gracefully
when the network is unavailable.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ret2libc ret2libc force-pushed the feat/cloudinit-schema-validation branch from bc121e8 to 7a37172 Compare March 31, 2026 12:32
@ret2libc ret2libc requested review from BradSwain and DarkaMaul March 31, 2026 12:32
@ret2libc
Copy link
Copy Markdown
Collaborator Author

JFYI:

Context

PR #63 (feat/cloudinit-schema-validation) adds tests that validate rendered cloud-init templates against the official cloud-init JSON schema. Currently, the schema is fetched from GitHub main branch at test time. Three reviewers raised concerns:

  1. BradSwain: Fetching from main means we validate against the latest schema, but older distros may not support newer keys. Should pin to the lowest cloud-init version among supported DO distros. Commit schema to repo to avoid network dependency.
  2. DarkaMaul: Agrees — schema should be in the repo, with a GH Action to update periodically. Prefers running tests offline.
  3. ret2libc: Minor formatting fix (already applied in f49a471).

Research findings

Lowest cloud-init version on current DigitalOcean images:

Distro DO Slug cloud-init version
Debian 12 debian-12-x64 22.4.2 (lowest)
Rocky/Alma/CentOS 8-9 various 23.4
Ubuntu 22.04 ubuntu-22-04-x64 24.x+ (updated via apt)
Ubuntu 24.04 ubuntu-24-04-x64 24.1+
Fedora 42+ fedora-42-x64 24.2+

Minimum: 22.4.2 (Debian 12 bookworm, which freezes packages).

The schema at tag 22.4.2 uses JSON Schema Draft 4 ($schema: http://json-schema.org/draft-04/schema#), same as current main. The file is ~130KB.

Replace the network-fetched schema (from cloud-init main) with a local
copy pinned to version 22.4.2 — the oldest cloud-init shipped by any
currently supported DigitalOcean image (Debian 12 bookworm). This
addresses review feedback to avoid validating against a schema newer
than what target distros actually support, and removes the network
dependency so tests work offline.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ret2libc ret2libc requested a review from BradSwain April 13, 2026 14:15
@ret2libc ret2libc merged commit 111a6cd into main Apr 13, 2026
7 checks passed
@ret2libc ret2libc deleted the feat/cloudinit-schema-validation branch April 13, 2026 15:03
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