Skip to content

sonic/validator: replace sonic-yang-mgmt+libyang with generated Pydan…#2253

Merged
berendt merged 1 commit intomainfrom
change-sonic-validate
May 4, 2026
Merged

sonic/validator: replace sonic-yang-mgmt+libyang with generated Pydan…#2253
berendt merged 1 commit intomainfrom
change-sonic-validate

Conversation

@berendt
Copy link
Copy Markdown
Member

@berendt berendt commented May 4, 2026

…tic schemas

The previous validator imported sonic_yang (a SWIG binding to libyang1) which is not packaged for Alpine and is not available on the runtime image. Replace it with a build-time YANG→Pydantic transpiler whose committed output is the runtime schema source — runtime needs only pydantic, no native dependencies.

  • tools/sonic_yang_to_pydantic.py walks pyang's AST over files/sonic/yang_models/ and emits one Pydantic v2 model per ConfigDB table.
  • osism/tasks/conductor/sonic/_generated/_schemas.py is the committed output (205 tables); regenerated via the tool when YANG models are refreshed.
  • Validator API stays stable for callers; ValidatorUnavailable / load_yang_context are dropped along with the --yang-dir flag and SONIC_YANG_MODELS_DIR setting.
  • Tables not yet covered by upstream YANG are reported as warnings, not errors.
  • Containerfile drops libyang apk and the yang_models COPY; requirements.sonic.txt switches from the sonic-yang-mgmt VCS pin to pydantic; pyang moves out of runtime requirements (only needed when regenerating).

Cross-table leafref enforcement is intentionally out of scope here and tracked in #2252.

AI-assisted: Claude Code

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Sorry @berendt, your pull request is larger than the review limit of 150000 diff characters

@berendt berendt force-pushed the change-sonic-validate branch from 71e5dd2 to a50fbe9 Compare May 4, 2026 20:02
…tic schemas

The previous validator imported sonic_yang (a SWIG binding to libyang1) which
is not packaged for Alpine and is not available on the runtime image. Replace
it with a build-time YANG→Pydantic transpiler whose committed output is the
runtime schema source — runtime needs only pydantic, no native dependencies.

- tools/sonic_yang_to_pydantic.py walks pyang's AST over files/sonic/yang_models/
  and emits one Pydantic v2 model per ConfigDB table.
- osism/tasks/conductor/sonic/_generated/_schemas.py is the committed output
  (205 tables); regenerated via the tool when YANG models are refreshed.
- Validator API stays stable for callers; ValidatorUnavailable / load_yang_context
  are dropped along with the --yang-dir flag and SONIC_YANG_MODELS_DIR setting.
- Tables not yet covered by upstream YANG are reported as warnings, not errors.
- Containerfile drops libyang apk and the yang_models COPY; requirements.sonic.txt
  switches from the sonic-yang-mgmt VCS pin to pydantic; pyang moves out of
  runtime requirements (only needed when regenerating).

Cross-table leafref enforcement is intentionally out of scope here and tracked
in #2252.

AI-assisted: Claude Code

Signed-off-by: Christian Berendt <berendt@osism.tech>
@berendt berendt force-pushed the change-sonic-validate branch from a50fbe9 to e235a7d Compare May 4, 2026 20:04
@berendt berendt merged commit 0b94020 into main May 4, 2026
3 checks passed
@berendt berendt deleted the change-sonic-validate branch May 4, 2026 20:23
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.

1 participant