sonic: document config ownership regimes#2371
Open
ideaship wants to merge 1 commit into
Open
Conversation
SONiC config is written to two stores with deliberately different ownership disciplines, and only one was documented. config_db.json uses table-level ownership: the generator owns whole tables and rebuilds them every regen, which is safe because the file has no external co-owner. The NetBox device local_context_data is co-owned with other generators (frr_parameters, netplan_parameters), so save_config_to_netbox owns only its sonic_config key: it carries the existing context forward and overwrites just that key, so the value written back always still holds the siblings -- a distinct regime, partitioned key ownership. The contrast was implicit, inviting a future change to "simplify" the exporter into writing back a context that holds only sonic_config and drops the siblings. The sibling preservation is already enforced by tests in test_exporter.py, but that lock was not discoverable: the tests asserted a bare dict equality, so a regression failed with only a dict diff. An author who did not already know the contract could read the test as stale and weaken it instead of recognizing the broken behavior, exactly the regression the test guards against. Make the lock teach at the point of failure. Add the regime, its reason, and the deciding factor (an external co-owner) to the save_config_to_netbox docstring, and name both regimes in the generate_sonic_config ownership-model docstring so the two read as one model. Give the sibling-preservation assertions an explanatory message that states the partitioned-key-ownership contract and points to the docstring, so a regression surfaces the reasoning rather than a bare diff. Documentation and test messages only; no behavior change. Assisted-by: Claude:claude-fable-5 Signed-off-by: Roger Luethi <luethi@osism.tech>
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The
_PARTITIONED_KEY_OWNERSHIPmessage largely restates thesave_config_to_netboxdocstring; consider shortening it and explicitly referencing the docstring instead of duplicating the reasoning, to reduce future drift between the two. - The
save_config_to_netboxdocstring is now quite dense; consider breaking the ownership explanation into a short summary plus a bulleted or clearly separated rationale so future readers can quickly grasp the key rule (only ownsonic_config) without wading through the full background each time.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `_PARTITIONED_KEY_OWNERSHIP` message largely restates the `save_config_to_netbox` docstring; consider shortening it and explicitly referencing the docstring instead of duplicating the reasoning, to reduce future drift between the two.
- The `save_config_to_netbox` docstring is now quite dense; consider breaking the ownership explanation into a short summary plus a bulleted or clearly separated rationale so future readers can quickly grasp the key rule (only own `sonic_config`) without wading through the full background each time.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
Problem
SONiC config is written to two stores with deliberately different ownership disciplines, and only one was documented:
config_db.json— table-level ownership: the generator owns whole tables and drops-and-rebuilds them every regen. Safe because the file has no external co-owner.local_context_data— co-owned with other generators (frr_parameters,netplan_parameters), sosave_config_to_netboxowns only itssonic_configkey: it carries the existing context forward and overwrites just that key, so the value written back always still holds the siblings. A distinct regime — partitioned key ownership.The contrast was implicit, inviting a future change to "simplify" the exporter into writing back a context that holds only
sonic_configand drops the siblings.Why the existing lock wasn't enough
The sibling preservation is already enforced by tests in
test_exporter.py. But that lock wasn't discoverable: the tests asserted a bare dict equality, so a regression failed with only a dict diff. An author who didn't already know the contract could read the test as stale and weaken it — instead of recognizing the broken behavior, which is exactly the regression the test guards against.Change
Make the lock teach at the point of failure (docs and test messages only — no behavior change):
save_config_to_netboxdocstring.generate_sonic_configownership-model docstring, so the two read as one model.Related