Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[multi-asic]: Add function to load database config #4112

Merged
merged 4 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -70,6 +71,8 @@ def get_po_names(self):
self.module.fail_json(msg=fail_msg)
else:
for po in out.split():
# load db config
load_db_config()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do load_db_config just once in the beginning, iso doing for every portchannel or every NS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed as suggested.

if 'sonic_py_common' in sys.modules and multi_asic.is_port_channel_internal(po):
continue
self.lag_names[po] = ns
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