Skip to content

Commit

Permalink
[multi-asic]: Add function to load database config (sonic-net#4112)
Browse files Browse the repository at this point in the history
What is the motivation for this PR?
With the changes in sonic-net/sonic-buildimage#8173, the applications that connect to namespace dbs have to load global database configuration. Due to this change, the sonic-py-common.multi_asic functions that connect to database will fail if database configuration is not loaded in ansible library functions.

How did you do it?
Add a new module_utility library function to load the right db configuration based on single or multi-asic platform.
Invoke this function in port_util and lag_facts where mutli_asic library function is invoked which connects to db.

How did you verify/test it?
Bring up a multi-asic VS testbed.
./testbed-cli.sh -t vtestbed.csv -m veos_vtb -k ceos add-topo vms-kvm-four-asic-t1-lag password.txt
Before adding this change, failure seen while running test_bgp_fact.py
  • Loading branch information
SuvarnaMeenakshi authored and vmittal-msft committed Sep 28, 2021
1 parent ef9bd43 commit 21a9d1e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ansible/library/lag_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import sys
from ansible.module_utils.basic import *
from ansible.module_utils.multi_asic_utils import load_db_config
try:
from sonic_py_common import multi_asic
NAMESPACE_LIST = multi_asic.get_namespace_list()
Expand Down Expand Up @@ -63,6 +64,8 @@ def get_po_names(self):
'''
Collect configured lag interface names
'''
# load db config
load_db_config()
for ns in NAMESPACE_LIST:
rt, out, err = self.module.run_command("sonic-cfggen -m /etc/sonic/minigraph.xml {} -v \"PORTCHANNEL.keys() | join(' ')\"".format('-n ' + ns if ns else ''))
if rt != 0:
Expand Down
22 changes: 22 additions & 0 deletions ansible/module_utils/multi_asic_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
def load_db_config():
'''
Load the correct database config file:
- database_global.json for multi asic
- database_config.json for single asic
Loading database config file is not required for
201911 images so ignore import error or function
name error.
'''
try:
from sonic_py_common import multi_asic
from swsscommon import swsscommon
if multi_asic.is_multi_asic():
if not swsscommon.SonicDBConfig.isGlobalInit():
swsscommon.SonicDBConfig.load_sonic_global_db_config()
else:
if not swsscommon.SonicDBConfig.isInit():
swsscommon.SonicDBConfig.load_sonic_db_config()
except ImportError:
pass
except NameError:
pass
2 changes: 2 additions & 0 deletions ansible/module_utils/port_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def _port_alias_to_name_map_50G(all_ports, s100G_ports,):
def get_port_alias_to_name_map(hwsku, asic_id=None):
try:
from sonic_py_common import multi_asic
from ansible.module_utils.multi_asic_utils import load_db_config
load_db_config()
namespace_list = multi_asic.get_all_namespaces()
for key, list in namespace_list.items():
asic_ids = []
Expand Down

0 comments on commit 21a9d1e

Please sign in to comment.