Skip to content

loaders: add YAML partition source with schema validation - #155

Open
Igor Opaniuk (igoropaniuk) wants to merge 4 commits into
qualcomm-linux:mainfrom
igoropaniuk:feat/yaml-loader
Open

loaders: add YAML partition source with schema validation#155
Igor Opaniuk (igoropaniuk) wants to merge 4 commits into
qualcomm-linux:mainfrom
igoropaniuk:feat/yaml-loader

Conversation

@igoropaniuk

Copy link
Copy Markdown
Contributor

Second step of the partition-source rework [1], building on the loaders package: this adds the structured YAML input format for a single storage device.

The .conf line format cannot be validated: sizes are parsed by best-effort regex, GUIDs are bare strings, booleans are ad-hoc, and mistakes only surface when a device fails to boot. A structured, schema-validated source catches these errors at build time and is the foundation for everything that follows in [1] - shared partition groups, board variants, and multi-storage boards.

A new loaders/yaml.py loads a disk mapping plus partitions list, validates it against a packaged JSON Schema, and normalises it into the same LoadedSpec the .conf loader produces - so both formats emit byte-identical XML, which the test suite pins with an equivalence test against a real board layout and an end-to-end XML comparison. The schema enforces the known YAML footguns up front: GUIDs and sizes must be quoted strings, unknown keys are rejected, disk types are constrained. PyYAML and jsonschema become the project's first runtime dependencies; the dispatcher late-imports them, so the .conf path never pays for either.

No board is migrated and nothing consumes YAML in the build yet: every generated artifact is unchanged, as CI proves via the pinned checksum manifest.

[1] #124

The YAML partition source introduced in [1] needs a YAML parser and a
schema validator at runtime. Declare PyYAML and jsonschema as install
dependencies so pip pulls them in automatically.

No code imports these yet; this only prepares the ground for the YAML
loader. Build, lint, unit tests and the pinned checksum manifest are
unaffected.

[1] qualcomm-linux#124

Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
The Dependencies section still claimed the tool ran on the standard
library alone. Update it to note the two runtime dependencies now
declared in pyproject.toml (PyYAML and jsonschema) and that pip
installs them automatically.

Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
Introduce the structured YAML source format from [1] for a single
storage device. loaders/yaml.py loads a `disk` mapping and `partitions`
list, validates it against a packaged JSON Schema, and normalises it
into the same LoadedSpec the .conf loader produces, so both formats emit
byte-identical XML.

Normalisation mirrors loaders/conf.py field for field: defaults are
copied in the same key order, partition_size_in_kb is reused and the
attribute bits are decoded identically. YAML booleans are rendered as
lowercase "true"/"false" so they match the legacy strings. The schema
enforces the YAML footgun mitigations: GUIDs and sizes must be quoted
strings, unknown keys are rejected, and the disk type is constrained to
the known storage classes.

Register .yaml/.yml in the loaders dispatcher behind a late import so
the .conf path never pays for PyYAML or jsonschema, and ship the schema
as package data.

[1] qualcomm-linux#124

Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
Pin the load-bearing property that the YAML and .conf loaders produce
the same LoadedSpec: an equivalence test against the real
glymur-crd/nvme board, a synthetic multi-LUN spec exercising attribute
bits, and an end-to-end assertion that both formats emit byte-identical
XML through the shared emitter.

Add schema-rejection cases for the documented footguns (unquoted
all-digit GUID, unquoted size, unknown key, missing type-guid,
malformed size, unknown disk type) and a non-mapping top-level
document.

Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
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.

2 participants