Skip to content

Commit f289374

Browse files
authored
[202405][GCU] Don't remove all entries in a table when just adding/modifying keys within an existing table
What I did Fixed an issue in config apply-patch where adding a new entry to a table (e.g., INTERFACE) incorrectly removes all existing entries in that table before adding them back, causing unnecessary disruption. Fixes: sonic-net/sonic-buildimage#24464 for 202405-msft How I did it Made two changes to generic_config_updater/patch_sorter.py: KeyLevelMoveGenerator: Added check to prevent deleting entire table when it has a single key if that table will continue to exist in the target config. Now only deletes the whole table when table not in diff.target_config. UpperLevelMoveExtender: Added logic to prevent key-level ADD/REPLACE operations from being extended to table-level operations when the table exists in both current and target configs. This keeps operations at the key level, avoiding unnecessary removal of unaffected entries. How to verify it Create a config with an INTERFACE table containing one entry (e.g., Ethernet0) Apply a patch that adds a new entry (e.g., Ethernet10) to the INTERFACE table Verify that only the new entry is added and the existing Ethernet0 entry is NOT removed during the operation Check logs to confirm no REMOVE operations are generated for unaffected entries
2 parents db36ebf + 840896f commit f289374

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

generic_config_updater/patch_sorter.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,8 @@ def generate(self, diff):
10751075
for tokens in self._get_non_existing_keys_tokens(diff.current_config, diff.target_config):
10761076
table = tokens[0]
10771077
# if table has a single key, delete the whole table because empty tables are not allowed in ConfigDB
1078-
if len(diff.current_config[table]) == 1:
1078+
# BUT only if the table won't exist in target config (i.e., not adding new keys to it)
1079+
if len(diff.current_config[table]) == 1 and table not in diff.target_config:
10791080
yield JsonMove(diff, OperationType.REMOVE, [table])
10801081
else:
10811082
yield JsonMove(diff, OperationType.REMOVE, tokens)
@@ -1477,6 +1478,18 @@ def extend(self, move, diff):
14771478
return
14781479

14791480
upper_current_tokens = move.current_config_tokens[:-1]
1481+
1482+
# Don't extend key-level ADD/REPLACE operations to table-level when just adding/modifying keys within an existing table
1483+
# This prevents incorrectly replacing/removing entire tables when only adding/updating individual keys
1484+
# We still allow REMOVE operations to be extended to handle dependency cleanup properly
1485+
if len(upper_current_tokens) == 1: # This would be a table-level operation
1486+
table = upper_current_tokens[0]
1487+
# If table exists in both current and target, don't extend ADD/REPLACE to table level
1488+
# The key-level operation is sufficient for additions/modifications
1489+
if table in diff.current_config and table in diff.target_config:
1490+
if move.op_type in [OperationType.ADD, OperationType.REPLACE]:
1491+
return
1492+
14801493
operation_type = self._get_upper_operation(upper_current_tokens, diff)
14811494

14821495
upper_target_tokens = None

0 commit comments

Comments
 (0)