Add gNMI-style JSON remediation rendering (#287) - #292
Merged
Conversation
Complete the remediation-output-matches-input-format story from #232 for OpenConfig/gNMI pipelines: WorkflowRemediation.remediation_json() (and hier_config.formats.hconfig_to_gnmi_json()) render a remediation between HConfig.from_json() trees as a gNMI-SetRequest-style structure. Negations become xpath-ish delete paths with [key=value] selectors for keyed list entries, resolved against the running config via the same key-leaf discrimination as the NETCONF renderer. Additions render into an update object through the existing JSON mapping; modified keyed entries re-gain their identity leaf so the update stays valid OpenConfig, and branches emptied by deletions are pruned.
Post-review cleanup: the NETCONF and gNMI delete renderers and the gNMI identity lookup each carried their own copy of the running-entry key probe, letting the single definition of keyed-list-entry identity drift across three sites. Extract _matching_list_key/_running_entry_key so both output formats share it. Also collapse single-name deferred imports and drop a delete-path assertion already owned by the nested-delete test.
Review flagged the fallback branch as untested: when a modified keyed entry is rendered without a running config, its remediation subtree lacks the identity leaf, so the key name cannot be resolved. Pin both consequences — the delete-path selector guesses the first list_keys name, and identity injection into the update is skipped so a guessed key never becomes applied config.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #287.
Completes the "remediation output matches input format" story from #232 for OpenConfig/gNMI pipelines:
WorkflowRemediation.remediation_json()(and the standalonehier_config.formats.hconfig_to_gnmi_json()) render a remediation betweenHConfig.from_json()trees as a gNMI-SetRequest-style structure:Design notes, mirroring the NETCONF renderer (#280) throughout:
[key=value]selectors using the same running-config key-leaf discrimination as_netconf_delete_element; scalar leaves delete by their bare path (system/config/hostname); without a running config, keyed deletes degrade to bare paths (same fallback contract as the NETCONF renderer). Selector values escape\and]; attribute-level changes raiseInvalidConfigError.from_json(). Branches emptied by deletions are pruned, and a modified keyed entry re-gains its identity leaf (e.g."name": "eth0") so the update stays valid OpenConfig.hier_config/__init__.py.Self-Review Checklist
poetry run ./scripts/build.py lint-and-testpasses locally (lint + 95% test coverage).CHANGELOG.mdhas an entry under## [Unreleased]referencing this issue/PR ((#NNN)).mkdocs build --strictpasses if docs were touched).AI-Assisted Contributions
Written with Claude Code; reviewed with the
hier-config-reviewskill (no blockers).