Skip to content

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

Merged
SuvarnaMeenakshi merged 4 commits intosonic-net:masterfrom
SuvarnaMeenakshi:load_db
Sep 1, 2021
Merged

[multi-asic]: Add function to load database config #4112
SuvarnaMeenakshi merged 4 commits intosonic-net:masterfrom
SuvarnaMeenakshi:load_db

Conversation

@SuvarnaMeenakshi
Copy link
Contributor

Description of PR

Summary:
Fixes # (issue)

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • Test case(new/improvement)

Back port request

  • 201911

Approach

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

./run_tests.sh -c "$tests" -d vlab-08 -f vtestbed.csv -i veos_vtb -n vms-kvm-four-asic-t1-lag -e --disable_loganalyzer -u
        if (res.is_failed or 'exception' in res) and not module_ignore_errors:
>           raise RunAnsibleModuleFail("run module {} failed".format(self.module_name), res)
E           RunAnsibleModuleFail: run module minigraph_facts failed, Ansible Results =>
E           {
E               "changed": false, 
E               "failed": true, 
E               "invocation": {
E                   "module_args": {
E                       "filename": null, 
E                       "host": "vlab-08", 
E                       "namespace": null
E                   }
E               }, 
E               "msg": ":- validateNamespace: Initialize global DB config using API SonicDBConfig::initializeGlobalConfig\nTraceback (most recent call last):\n  File \"/tmp/ansible_minigraph_facts_payload_XTvxQr/__main__.py\", line 823, in main\n    results = parse_xml(filename, m_args['host'], namespace)\n  File \"/tmp/ansible_minigraph_facts_payload_XTvxQr/__main__.py\", line 636, in parse_xml\n    port_alias_to_name_map, port_alias_asic_map = get_port_alias_to_name_map(hwsku, asic_id)\n  File \"/tmp/ansible_minigraph_facts_payload_XTvxQr/ansible_minigraph_facts_payload.zip/ansible/module_utils/port_utils.py\", line 18, in get_port_alias_to_name_map\n    namespace_list = multi_asic.get_all_namespaces()\n  File \"/usr/local/lib/python2.7/dist-packages/sonic_py_common/multi_asic.py\", line 226, in get_all_namespaces\n    config_db = connect_config_db_for_ns(namespace)\n  File \"/usr/local/lib/python2.7/dist-packages/sonic_py_common/multi_asic.py\", line 40, in connect_config_db_for_ns\n    config_db = swsscommon.ConfigDBConnector(namespace=namespace)\n  File \"/usr/lib/python2.7/dist-packages/swsscommon/swsscommon.py\", line 2076, in __init__\n    super(ConfigDBConnector, self).__init__(use_unix_socket_path = use_unix_socket_path, namespace = namespace)\n  File \"/usr/lib/python2.7/dist-packages/swsscommon/swsscommon.py\", line 1698, in __init__\n    for db_name in self.get_db_list():\n  File \"/usr/lib/python2.7/dist-packages/swsscommon/swsscommon.py\", line 1634, in get_db_list\n    return _swsscommon.SonicV2Connector_Native_get_db_list(self)\nRuntimeError: :- validateNamespace: Initialize global DB config using API SonicDBConfig::initializeGlobalConfig\n"
E           }

complex_args = {'host': 'vlab-08', 'namespace': None}
filename   = '/data/sonic-mgmt/tests/common/devices/sonic.py'
function_name = 'get_extended_minigraph_facts'
index      = 0
line_number = 1210
lines      = ["        mg_facts = self.minigraph_facts(host = self.hostname, namespace = namespace)['ansible_facts']\n"]
module_args = ()
module_async = False
module_ignore_errors = False
previous_frame = <frame object at 0x555b4ff69d30>
res        = {u'failed': True, u'exception': u'WARNING: The below traceback may *not* be re...Initialize global DB config using API SonicDBConfig::initializeGlobalConfig\n'}
self       = <SonicHost> vlab-08
verbose    = True

After fix:
=== Running tests individually ===

/usr/local/lib/python2.7/dist-packages/ansible/parsing/vault/__init__.py:44: CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in a future release.
  from cryptography.exceptions import InvalidSignature
========================================= test session starts =========================================
platform linux2 -- Python 2.7.17, pytest-4.6.5, py-1.9.0, pluggy-0.13.1
ansible: 2.8.12
rootdir: /data/sonic-mgmt/tests, inifile: pytest.ini
plugins: metadata-1.10.0, forked-1.3.0, html-1.22.1, repeat-0.9.1, xdist-1.28.0, ansible-2.2.2
collected 4 items                                                                                     

bgp/test_bgp_fact.py::test_bgp_facts[vlab-08-0] PASSED                                          [ 25%]
bgp/test_bgp_fact.py::test_bgp_facts[vlab-08-1] PASSED                                          [ 50%]
bgp/test_bgp_fact.py::test_bgp_facts[vlab-08-2] PASSED                                          [ 75%]
bgp/test_bgp_fact.py::test_bgp_facts[vlab-08-3] PASSED                                          [100%]

Tested the same with 201911 VS image to ensure that changes do not impact test cases running on 201911 image.

Any platform specific information?

Supported testbed topology if it's a new test case?

Documentation

on single asic or multi-asic platform.

Signed-off-by: Suvarna Meenakshi <sumeenak@microsoft.com>
functions that connect to db.

Signed-off-by: Suvarna Meenakshi <sumeenak@microsoft.com>
@SuvarnaMeenakshi SuvarnaMeenakshi requested a review from a team as a code owner August 24, 2021 01:01
Signed-off-by: Suvarna Meenakshi <sumeenak@microsoft.com>
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.

Copy link
Contributor

@arlakshm arlakshm left a comment

Choose a reason for hiding this comment

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

as comments

Signed-off-by: Suvarna Meenakshi <sumeenak@microsoft.com>
@arlakshm
Copy link
Contributor

/Azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@SuvarnaMeenakshi SuvarnaMeenakshi merged commit f6586d6 into sonic-net:master Sep 1, 2021
@SuvarnaMeenakshi SuvarnaMeenakshi deleted the load_db branch September 1, 2021 00:19
vmittal-msft pushed a commit to vmittal-msft/sonic-mgmt that referenced this pull request Sep 28, 2021
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants