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>