Skip to content

Commit 968900c

Browse files
[sonic-package-manager] do not mod_config for whole config db when setting init_cfg (#2055)
What I did conn.mod_config(new_cfg) modifies entries which where not changed in new_cfg. This causes errors when installing/upgrading extension like, because mod_config pushes the same configuration again: "ERR swss#orchagent: :- addOperation: Vxlan tunnel 'tunnel1' is already exists” in syslog I made a change so that when setting init configuration for an extension we are not modifying the whole DB. How I did it Perform a conn.mod_entry for entries from init configuration of the package. How to verify it Run UT. Make sure no errors when installing extension and having vxlan configuration in config db. Signed-off-by: Stepan Blyschak <[email protected]>
1 parent bf55ceb commit 968900c

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

sonic_package_manager/service_creator/creator.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -491,12 +491,22 @@ def set_initial_config(self, package):
491491
if not init_cfg:
492492
return
493493

494+
def update_config_with_init_cfg(cfg, conn):
495+
for table, content in init_cfg.items():
496+
if not isinstance(content, dict):
497+
continue
498+
499+
for key, fvs in content.items():
500+
key_cfg = cfg.get(table, {}).get(key, {})
501+
key_cfg.update(fvs)
502+
conn.mod_entry(table, key, key_cfg)
503+
494504
for conn in self.sonic_db.get_connectors():
495505
cfg = conn.get_config()
496506
new_cfg = init_cfg.copy()
497507
utils.deep_update(new_cfg, cfg)
498508
self.validate_config(new_cfg)
499-
conn.mod_config(new_cfg)
509+
update_config_with_init_cfg(cfg, conn)
500510

501511
def remove_config(self, package):
502512
""" Remove configuration based on package YANG module.

tests/sonic_package_manager/test_service_creator.py

+5-10
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ def test_service_creator_yang(sonic_fs, manifest, mock_sonic_db,
131131
mock_sonic_db.get_connectors = Mock(return_value=[mock_connector])
132132
mock_connector.get_table = Mock(return_value={'key_a': {'field_1': 'value_1'}})
133133
mock_connector.get_config = Mock(return_value={
134-
'TABLE_A': mock_connector.get_table('')
134+
'TABLE_A': mock_connector.get_table(''),
135+
'TABLE_B': mock_connector.get_table(''),
136+
'TABLE_C': mock_connector.get_table(''),
135137
})
136138

137139
entry = PackageEntry('test', 'azure/sonic-test')
@@ -155,15 +157,8 @@ def test_service_creator_yang(sonic_fs, manifest, mock_sonic_db,
155157

156158
mock_config_mgmt.add_module.assert_called_with(test_yang)
157159

158-
mock_connector.mod_config.assert_called_with(
159-
{
160-
'TABLE_A': {
161-
'key_a': {
162-
'field_1': 'value_1',
163-
'field_2': 'value_2',
164-
},
165-
},
166-
}
160+
mock_connector.mod_entry.assert_called_once_with(
161+
'TABLE_A', 'key_a', {'field_1': 'value_1', 'field_2': 'value_2'}
167162
)
168163

169164
mock_config_mgmt.sy.confDbYangMap = {

0 commit comments

Comments
 (0)