Skip to content

Commit

Permalink
[Namespace]: Fix SNMP AgentX socket connection timeout when using Nam…
Browse files Browse the repository at this point in the history
…espace.get_all() (#140)

* [Namespace]: Remove key exists check in dbs_get_all
to reduce time taken.

Signed-off-by: SuvarnaMeenakshi <[email protected]>

* Fix as per review comment.

Signed-off-by: SuvarnaMeenakshi <[email protected]>

* Minor fix.

Signed-off-by: SuvarnaMeenakshi <[email protected]>

* Connect to all required namespace dbs during init and periodic
sync_d functions to reduce time taken in dbs_get_all.

Signed-off-by: SuvarnaMeenakshi <[email protected]>

* Change test_mibs to use generic wrapper function added.
The Namespace functions will be used for both single
and multi-asic platforms.

Signed-off-by: SuvarnaMeenakshi <[email protected]>

* Fix review comment.

Signed-off-by: SuvarnaMeenakshi <[email protected]>

* Fix as per review comment.

Signed-off-by: SuvarnaMeenakshi <[email protected]>

* Remove whitespace.

Signed-off-by: SuvarnaMeenakshi <[email protected]>

* Fix review comment. Avoid modifying mutable object kwargs,
do a shallow copy instead.

Signed-off-by: SuvarnaMeenakshi <[email protected]>
  • Loading branch information
SuvarnaMeenakshi authored and abdosi committed Jul 11, 2020
1 parent c70df53 commit cd83dbc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
37 changes: 22 additions & 15 deletions src/sonic_ax_impl/mibs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,6 @@ def init_sync_d_interface_tables(db_conn):
:return: tuple(if_name_map, if_id_map, oid_map, if_alias_map)
"""

# Make sure we're connected to COUNTERS_DB
db_conn.connect(COUNTERS_DB)

# { if_name (SONiC) -> sai_id }
# ex: { "Ethernet76" : "1000000000023" }
if_name_map, if_id_map = port_util.get_interface_oid_map(db_conn)
Expand Down Expand Up @@ -232,7 +229,6 @@ def init_sync_d_interface_tables(db_conn):
.format(port_util.SONIC_ETHERNET_RE_PATTERN))
logger.warning("Port name map:\n" + pprint.pformat(if_name_map, indent=2))

db_conn.connect(APPL_DB)

if_alias_map = dict()

Expand All @@ -259,7 +255,6 @@ def init_sync_d_lag_tables(db_conn):
# { OID -> lag_name (SONiC) }
oid_lag_name_map = {}

db_conn.connect(APPL_DB)

lag_entries = db_conn.keys(APPL_DB, b"LAG_TABLE:*")

Expand Down Expand Up @@ -294,9 +289,6 @@ def init_sync_d_queue_tables(db_conn):
:return: tuple(port_queues_map, queue_stat_map)
"""

# Make sure we're connected to COUNTERS_DB
db_conn.connect(COUNTERS_DB)

# { Port index : Queue index (SONiC) -> sai_id }
# ex: { "1:2" : "1000000000023" }
queue_name_map = db_conn.get_all(COUNTERS_DB, COUNTERS_QUEUE_NAME_MAP, blocking=True)
Expand Down Expand Up @@ -457,8 +449,15 @@ def init_namespace_dbs():
db = SonicV2Connector(use_unix_socket_path=True, namespace=namespace)
db_conn.append(db)

Namespace.connect_namespace_dbs(db_conn)
return db_conn

@staticmethod
def connect_namespace_dbs(dbs):
list_of_dbs = [APPL_DB, COUNTERS_DB, CONFIG_DB, STATE_DB, ASIC_DB, SNMP_OVERLAY_DB]
for db_name in list_of_dbs:
Namespace.connect_all_dbs(dbs, db_name)

@staticmethod
def connect_all_dbs(dbs, db_name):
for db_conn in dbs:
Expand All @@ -471,7 +470,6 @@ def dbs_keys(dbs, db_name, pattern='*'):
"""
result_keys=[]
for db_conn in dbs:
db_conn.connect(db_name)
keys = db_conn.keys(db_name, pattern)
if keys is not None:
result_keys.extend(keys)
Expand All @@ -483,12 +481,18 @@ def dbs_get_all(dbs, db_name, _hash, *args, **kwargs):
db get_all function executed on global and all namespace DBs.
"""
result = {}
# If there are multiple namespaces, _hash might not be
# present in all namespace, ignore if not present in a
# specfic namespace.
if len(dbs) > 1:
tmp_kwargs = kwargs.copy()
tmp_kwargs['blocking'] = False
else:
tmp_kwargs = kwargs
for db_conn in dbs:
db_conn.connect(db_name)
if(db_conn.exists(db_name, _hash)):
ns_result = db_conn.get_all(db_name, _hash, *args, **kwargs)
if ns_result is not None:
result.update(ns_result)
ns_result = db_conn.get_all(db_name, _hash, *args, **tmp_kwargs)
if ns_result is not None:
result.update(ns_result)
return result

@staticmethod
Expand Down Expand Up @@ -520,6 +524,7 @@ def init_namespace_sync_d_interface_tables(dbs):
Ignore first global db to get interface tables if there
are multiple namespaces.
"""
Namespace.connect_namespace_dbs(dbs)
for db_conn in Namespace.get_non_host_dbs(dbs):
if_name_map_ns, \
if_alias_map_ns, \
Expand Down Expand Up @@ -547,14 +552,15 @@ def init_namespace_sync_d_lag_tables(dbs):
Ignore first global db to get lag tables if
there are multiple namespaces.
"""
Namespace.connect_namespace_dbs(dbs)
for db_conn in Namespace.get_non_host_dbs(dbs):
lag_name_if_name_map_ns, \
if_name_lag_name_map_ns, \
oid_lag_name_map_ns = init_sync_d_lag_tables(db_conn)
lag_name_if_name_map.update(lag_name_if_name_map_ns)
if_name_lag_name_map.update(if_name_lag_name_map_ns)
oid_lag_name_map.update(oid_lag_name_map_ns)

return lag_name_if_name_map, if_name_lag_name_map, oid_lag_name_map

@staticmethod
Expand All @@ -569,6 +575,7 @@ def init_namespace_sync_d_queue_tables(dbs):
Ignore first global db to get queue tables if there
are multiple namespaces.
"""
Namespace.connect_namespace_dbs(dbs)
for db_conn in Namespace.get_non_host_dbs(dbs):
port_queues_map_ns, \
queue_stat_map_ns, \
Expand Down
6 changes: 3 additions & 3 deletions tests/test_mibs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
modules_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.join(modules_path, 'src'))

from sonic_ax_impl import mibs
from sonic_ax_impl.mibs import Namespace

class TestGetNextPDU(TestCase):
@classmethod
Expand All @@ -16,11 +16,11 @@ def setUpClass(cls):
tests.mock_tables.dbconnector.load_database_config()

def test_init_sync_d_lag_tables(self):
db_conn = mibs.init_db()
db_conn = Namespace.init_namespace_dbs()

lag_name_if_name_map, \
if_name_lag_name_map, \
oid_lag_name_map = mibs.init_sync_d_lag_tables(db_conn)
oid_lag_name_map = Namespace.init_namespace_sync_d_lag_tables(db_conn)

self.assertTrue(b"PortChannel04" in lag_name_if_name_map)
self.assertTrue(lag_name_if_name_map[b"PortChannel04"] == [b"Ethernet124"])
Expand Down

0 comments on commit cd83dbc

Please sign in to comment.