Skip to content

Commit

Permalink
Merge branch 'master' into rfc2863_counters
Browse files Browse the repository at this point in the history
  • Loading branch information
abdosi authored Jul 11, 2020
2 parents ff5d7b8 + 1d210d9 commit 5a54bdb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
38 changes: 23 additions & 15 deletions src/sonic_ax_impl/mibs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,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 @@ -282,7 +279,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 Down Expand Up @@ -353,13 +349,11 @@ def init_sync_d_lag_tables(db_conn):
# { lag_name (SONiC) -> lag_oid (SAI) }
lag_sai_map = {}

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

if not lag_entries:
return lag_name_if_name_map, if_name_lag_name_map, oid_lag_name_map, lag_sai_map

db_conn.connect(COUNTERS_DB)
lag_sai_map = db_conn.get_all(COUNTERS_DB, b"COUNTERS_LAG_NAME_MAP")
lag_sai_map = {name: sai_id.lstrip(b"oid:0x") for name, sai_id in lag_sai_map.items()}

Expand Down Expand Up @@ -391,9 +385,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 @@ -554,6 +545,7 @@ 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
Expand All @@ -566,6 +558,12 @@ def get_namespace_db_map(dbs):
db_map[db_conn.namespace] = db_conn
return db_map

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 @@ -578,7 +576,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 @@ -590,12 +587,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 @@ -627,6 +630,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 @@ -655,6 +659,7 @@ 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, \
Expand All @@ -672,6 +677,7 @@ def init_namespace_sync_d_rif_tables(dbs):
rif_port_map = {}
port_rif_map = {}

Namespace.connect_namespace_dbs(dbs)
for db_conn in Namespace.get_non_host_dbs(dbs):
rif_port_map_ns, \
port_rif_map_ns = init_sync_d_rif_tables(db_conn)
Expand All @@ -686,6 +692,7 @@ def init_namespace_sync_d_vlan_tables(dbs):
oid_sai_map = {}
oid_name_map = {}

Namespace.connect_namespace_dbs(dbs)
for db_conn in Namespace.get_non_host_dbs(dbs):
vlan_name_map_ns, \
oid_sai_map_ns, \
Expand All @@ -708,6 +715,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,12 +16,12 @@ 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, \
lag_sai_map = mibs.init_sync_d_lag_tables(db_conn)
lag_sai_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 5a54bdb

Please sign in to comment.