-
Notifications
You must be signed in to change notification settings - Fork 379
T7561: simplify op-mode-definitions XML cache generation #4562
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
base: current
Are you sure you want to change the base?
Conversation
👍 |
7ce53c5
to
03280f7
Compare
✅ No issues found in unused-imports check.. Please refer the workflow run |
1f3951d
to
533115a
Compare
Move to draft to update for recent op-mode changes. |
The original implementation of the op-mode XML cache generation resulted in a structure that was difficult to use, for example, in documentation generation. The source of complication is that, unlike the XML of interface-definitions, path names are not unique: the same path may occur as both a regular node and as a tag node. Here we simplify the underlying structure by enriching path names with type information, thus disambiguating paths. An interface to the cache is provided by explicit generator and lookup functions.
Added the following: |
8d0f03f
to
8abc42c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's ready to take out of the draft status and merge now. When all command definitions are reworked to make every path unique, we can make the ambiguity check mandatory at a later point.
CI integration 👍 passed! Details
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR simplifies the op-mode XML cache generation by refactoring the data structure to use dataclasses and adding new utility methods for traversing, looking up, and sorting op-mode definitions, which in turn facilitates documentation generation.
- Refactors NodeData from a TypedDict to a dataclass with additional fields.
- Introduces new functions for walking, sorting, and collapsing XML definition data in op_definition.py and generate_op_cache.py.
- Updates init.py to expose new API functions for accessing op-mode data.
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.
File | Description |
---|---|
python/vyos/xml_ref/op_definition.py | Refactored NodeData implementation and added lookup/walk utilities; duplicate function issue noted. |
python/vyos/xml_ref/generate_op_cache.py | Enhanced XML cache generation with sorting, consistency checks, and updated node insertion logic. |
python/vyos/xml_ref/init.py | Updated module exports and added new functions for walking and looking up op-mode data. |
Comments suppressed due to low confidence (1)
python/vyos/xml_ref/op_definition.py:56
- The function 'keys_of_name' is defined twice with different parameters; the second definition does not return the filtered result. Consider removing or renaming the duplicate definition and ensure that it returns the expected list of keys.
filter(lambda t: t[0] == s, l)
Change summary
Simplify original implementation of the op-mode XML cache generation and provide interface methods for use in, e.g., documentation generation.
While the evolution of the op-mode schema is taking place, it may be of benefit to provide a more usable structure/interface to the op-mode XML; this improves on the original implementation as follows:
(1) Disambiguate paths by enriching with node type, resulting in the simple nested dict structure familiar from the interface-definitions case.
(2) Provide generator and lookup methods to access the resulting data structure.
The above allows, for example, simple tools for documentation generation, either in bulk or on the fly.
Note one fundamental difference with the previous structure of nested lists of dicts: there is no naive dump to JSON --- nor should there be, is the position here: using the JSON representation for generation of documentation or other uses is neither needed nor desired. In it's place, the appropriate interface method into the structure should be used.
Various JSON representations may be produced from the node_data structures by simple transformations, by inserting virtual tag nodes or placeholders (as included in the
path
field of the node_data class).Simple examples:
Lookup:
Above one sees an example of path ambiguity.
One can provide hints by either including indicative tag-node values:
or by specifying the node type of the final node:
Finally, as with the original implementation, the
generate_op_cache.py
script is able to check for inconsistencies in the XML itself during cache generation. cf. the inline comments regardinggenerate_op_cache.py --check-xml-consistency
.Types of changes
Related Task(s)
Related PR(s)
How to test / Smoketest result
Checklist: