Skip to content

Commit

Permalink
[sonic-package-manager] do not mod_config for whole config db when se…
Browse files Browse the repository at this point in the history
…tting 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 <stepanb@nvidia.com>
  • Loading branch information
stepanblyschak authored Mar 20, 2022
1 parent bf55ceb commit 968900c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
12 changes: 11 additions & 1 deletion sonic_package_manager/service_creator/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,22 @@ def set_initial_config(self, package):
if not init_cfg:
return

def update_config_with_init_cfg(cfg, conn):
for table, content in init_cfg.items():
if not isinstance(content, dict):
continue

for key, fvs in content.items():
key_cfg = cfg.get(table, {}).get(key, {})
key_cfg.update(fvs)
conn.mod_entry(table, key, key_cfg)

for conn in self.sonic_db.get_connectors():
cfg = conn.get_config()
new_cfg = init_cfg.copy()
utils.deep_update(new_cfg, cfg)
self.validate_config(new_cfg)
conn.mod_config(new_cfg)
update_config_with_init_cfg(cfg, conn)

def remove_config(self, package):
""" Remove configuration based on package YANG module.
Expand Down
15 changes: 5 additions & 10 deletions tests/sonic_package_manager/test_service_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ def test_service_creator_yang(sonic_fs, manifest, mock_sonic_db,
mock_sonic_db.get_connectors = Mock(return_value=[mock_connector])
mock_connector.get_table = Mock(return_value={'key_a': {'field_1': 'value_1'}})
mock_connector.get_config = Mock(return_value={
'TABLE_A': mock_connector.get_table('')
'TABLE_A': mock_connector.get_table(''),
'TABLE_B': mock_connector.get_table(''),
'TABLE_C': mock_connector.get_table(''),
})

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

mock_config_mgmt.add_module.assert_called_with(test_yang)

mock_connector.mod_config.assert_called_with(
{
'TABLE_A': {
'key_a': {
'field_1': 'value_1',
'field_2': 'value_2',
},
},
}
mock_connector.mod_entry.assert_called_once_with(
'TABLE_A', 'key_a', {'field_1': 'value_1', 'field_2': 'value_2'}
)

mock_config_mgmt.sy.confDbYangMap = {
Expand Down

0 comments on commit 968900c

Please sign in to comment.