Skip to content

Commit

Permalink
[multi-asic]: Udpate to use SonicDBConfig from swsscommon (sonic-net#219
Browse files Browse the repository at this point in the history
)

**- What I did**
Update snmpagent to use SonicDBConfig from swsscommon.

**- How I did it**
- Update import of SonicDBConfig 
- init_namespace_dbs should return list of all namespace connector classes. Ensure that the list ordering is maintained such that the first element of the list is of the default namespace.
 
**- How to verify it**
Tested on single asic VS; SNMP service starts without any error log.
Execute snmpwalk on one of the OIDs:
admin@vlab-01:~$ docker exec -it snmp snmpwalk -v2c -c public 127.0.0.1 iso.3.6.1.2.1.2.2.1.2
iso.3.6.1.2.1.2.2.1.2.1 = STRING: "fortyGigE0/0"
iso.3.6.1.2.1.2.2.1.2.5 = STRING: "fortyGigE0/4"
iso.3.6.1.2.1.2.2.1.2.9 = STRING: "fortyGigE0/8"
iso.3.6.1.2.1.2.2.1.2.13 = STRING: "fortyGigE0/12"
iso.3.6.1.2.1.2.2.1.2.17 = STRING: "fortyGigE0/16"
iso.3.6.1.2.1.2.2.1.2.21 = STRING: "fortyGigE0/20"
iso.3.6.1.2.1.2.2.1.2.25 = STRING: "fortyGigE0/24"
iso.3.6.1.2.1.2.2.1.2.29 = STRING: "fortyGigE0/28"
..
iso.3.6.1.2.1.2.2.1.2.10000 = STRING: "eth0"

Tested on multi asic VS; SNMP service starts without any error log.
admin@vlab-08:~$ docker exec -it snmp snmpwalk -v2c -c public 127.0.0.1 iso.3.6.1.2.1.2.2.1.2
Execute snmpwalk on one of the OIDs:
iso.3.6.1.2.1.2.2.1.2.1 = STRING: "Ethernet1/1"
iso.3.6.1.2.1.2.2.1.2.5 = STRING: "Ethernet1/2"
iso.3.6.1.2.1.2.2.1.2.9 = STRING: "Ethernet1/3"
iso.3.6.1.2.1.2.2.1.2.13 = STRING: "Ethernet1/4"
iso.3.6.1.2.1.2.2.1.2.17 = STRING: "Ethernet1/5"
iso.3.6.1.2.1.2.2.1.2.21 = STRING: "Ethernet1/6"
iso.3.6.1.2.1.2.2.1.2.25 = STRING: "Ethernet1/7"
iso.3.6.1.2.1.2.2.1.2.29 = STRING: "Ethernet1/8"
iso.3.6.1.2.1.2.2.1.2.1001 = STRING: "PortChannel0001"
..
iso.3.6.1.2.1.2.2.1.2.9000 = STRING: "Eth4-ASIC0"
iso.3.6.1.2.1.2.2.1.2.9004 = STRING: "Eth5-ASIC0"
iso.3.6.1.2.1.2.2.1.2.9008 = STRING: "Eth6-ASIC0"
iso.3.6.1.2.1.2.2.1.2.9012 = STRING: "Eth7-ASIC0"
...
  • Loading branch information
SuvarnaMeenakshi authored Jun 30, 2021
1 parent 266bd15 commit e0f36a5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
26 changes: 21 additions & 5 deletions src/sonic_ax_impl/mibs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import os

from swsscommon.swsscommon import SonicV2Connector
from swsssdk import SonicDBConfig
from swsscommon.swsscommon import SonicDBConfig
from swsssdk import port_util
from swsssdk.port_util import get_index_from_str
from ax_interface.mib import MIBUpdater
from ax_interface.util import oid2tuple
from sonic_ax_impl import logger
from sonic_py_common import multi_asic

COUNTERS_PORT_NAME_MAP = 'COUNTERS_PORT_NAME_MAP'
COUNTERS_QUEUE_NAME_MAP = 'COUNTERS_QUEUE_NAME_MAP'
Expand Down Expand Up @@ -218,7 +219,12 @@ def init_db():
Connects to DB
:return: db_conn
"""
SonicDBConfig.load_sonic_global_db_config()
if not SonicDBConfig.isInit():
if multi_asic.is_multi_asic():
# Load the global config file database_global.json once.
SonicDBConfig.load_sonic_global_db_config()
else:
SonicDBConfig.load_sonic_db_config()
# SyncD database connector. THIS MUST BE INITIALIZED ON A PER-THREAD BASIS.
# Redis PubSub objects (such as those within swsssdk) are NOT thread-safe.
db_conn = SonicV2Connector(**redis_kwargs)
Expand Down Expand Up @@ -538,10 +544,20 @@ class Namespace:
@staticmethod
def init_namespace_dbs():
db_conn = []
SonicDBConfig.load_sonic_global_db_config()
for namespace in SonicDBConfig.get_ns_list():
db = SonicV2Connector(use_unix_socket_path=True, namespace=namespace, decode_responses=True)
if not SonicDBConfig.isInit():
if multi_asic.is_multi_asic():
SonicDBConfig.load_sonic_global_db_config()
else:
SonicDBConfig.load_sonic_db_config()
host_namespace_idx = 0
for idx, namespace in enumerate(SonicDBConfig.get_ns_list()):
if namespace == multi_asic.DEFAULT_NAMESPACE:
host_namespace_idx = idx
db = SonicV2Connector(use_unix_socket_path=True, namespace=namespace)
db_conn.append(db)
# Ensure that db connector of default namespace is the first element of
# db_conn list.
db_conn[0], db_conn[host_namespace_idx] = db_conn[host_namespace_idx], db_conn[0]

Namespace.connect_namespace_dbs(db_conn)
return db_conn
Expand Down
3 changes: 2 additions & 1 deletion tests/mock_tables/dbconnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from swsssdk import SonicDBConfig
from swsssdk.interface import DBInterface
from swsscommon import swsscommon
from sonic_py_common import multi_asic


if sys.version_info >= (3, 0):
Expand Down Expand Up @@ -133,12 +134,12 @@ def keys(self, pattern='*'):
# Find every key that matches the pattern
return [key for key in self.redis.keys() if regex.match(key)]


DBInterface._subscribe_keyspace_notification = _subscribe_keyspace_notification
mockredis.MockRedis.config_set = config_set
redis.StrictRedis = SwssSyncClient
SonicV2Connector.connect = connect_SonicV2Connector
swsscommon.SonicV2Connector = SonicV2Connector
swsscommon.SonicDBConfig = SonicDBConfig

# pytest case collecting will import some module before monkey patch, so reload
from importlib import reload
Expand Down

0 comments on commit e0f36a5

Please sign in to comment.