Skip to content

Commit e0f36a5

Browse files
[multi-asic]: Udpate to use SonicDBConfig from swsscommon (sonic-net#219)
**- 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" ...
1 parent 266bd15 commit e0f36a5

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/sonic_ax_impl/mibs/__init__.py

+21-5
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
import os
44

55
from swsscommon.swsscommon import SonicV2Connector
6-
from swsssdk import SonicDBConfig
6+
from swsscommon.swsscommon import SonicDBConfig
77
from swsssdk import port_util
88
from swsssdk.port_util import get_index_from_str
99
from ax_interface.mib import MIBUpdater
1010
from ax_interface.util import oid2tuple
1111
from sonic_ax_impl import logger
12+
from sonic_py_common import multi_asic
1213

1314
COUNTERS_PORT_NAME_MAP = 'COUNTERS_PORT_NAME_MAP'
1415
COUNTERS_QUEUE_NAME_MAP = 'COUNTERS_QUEUE_NAME_MAP'
@@ -218,7 +219,12 @@ def init_db():
218219
Connects to DB
219220
:return: db_conn
220221
"""
221-
SonicDBConfig.load_sonic_global_db_config()
222+
if not SonicDBConfig.isInit():
223+
if multi_asic.is_multi_asic():
224+
# Load the global config file database_global.json once.
225+
SonicDBConfig.load_sonic_global_db_config()
226+
else:
227+
SonicDBConfig.load_sonic_db_config()
222228
# SyncD database connector. THIS MUST BE INITIALIZED ON A PER-THREAD BASIS.
223229
# Redis PubSub objects (such as those within swsssdk) are NOT thread-safe.
224230
db_conn = SonicV2Connector(**redis_kwargs)
@@ -538,10 +544,20 @@ class Namespace:
538544
@staticmethod
539545
def init_namespace_dbs():
540546
db_conn = []
541-
SonicDBConfig.load_sonic_global_db_config()
542-
for namespace in SonicDBConfig.get_ns_list():
543-
db = SonicV2Connector(use_unix_socket_path=True, namespace=namespace, decode_responses=True)
547+
if not SonicDBConfig.isInit():
548+
if multi_asic.is_multi_asic():
549+
SonicDBConfig.load_sonic_global_db_config()
550+
else:
551+
SonicDBConfig.load_sonic_db_config()
552+
host_namespace_idx = 0
553+
for idx, namespace in enumerate(SonicDBConfig.get_ns_list()):
554+
if namespace == multi_asic.DEFAULT_NAMESPACE:
555+
host_namespace_idx = idx
556+
db = SonicV2Connector(use_unix_socket_path=True, namespace=namespace)
544557
db_conn.append(db)
558+
# Ensure that db connector of default namespace is the first element of
559+
# db_conn list.
560+
db_conn[0], db_conn[host_namespace_idx] = db_conn[host_namespace_idx], db_conn[0]
545561

546562
Namespace.connect_namespace_dbs(db_conn)
547563
return db_conn

tests/mock_tables/dbconnector.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from swsssdk import SonicDBConfig
1010
from swsssdk.interface import DBInterface
1111
from swsscommon import swsscommon
12+
from sonic_py_common import multi_asic
1213

1314

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

136-
137137
DBInterface._subscribe_keyspace_notification = _subscribe_keyspace_notification
138138
mockredis.MockRedis.config_set = config_set
139139
redis.StrictRedis = SwssSyncClient
140140
SonicV2Connector.connect = connect_SonicV2Connector
141141
swsscommon.SonicV2Connector = SonicV2Connector
142+
swsscommon.SonicDBConfig = SonicDBConfig
142143

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

0 commit comments

Comments
 (0)