Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Namespace]: Simplify sync_d functions to use higher order #154

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 15 additions & 74 deletions src/sonic_ax_impl/mibs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,82 +554,23 @@ def get_non_host_dbs(dbs):
else:
return dbs[1:]


@staticmethod
def init_namespace_sync_d_interface_tables(dbs):
if_name_map = {}
if_alias_map = {}
if_id_map = {}
oid_sai_map = {}
oid_name_map = {}

"""
all_ns_db - will have db_conn to all namespace DBs and
global db. First db in the list is global db.
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, \
if_id_map_ns, \
oid_sai_map_ns, \
oid_name_map_ns = init_sync_d_interface_tables(db_conn)
if_name_map.update(if_name_map_ns)
if_alias_map.update(if_alias_map_ns)
if_id_map.update(if_id_map_ns)
oid_sai_map.update(oid_sai_map_ns)
oid_name_map.update(oid_name_map_ns)

return if_name_map, if_alias_map, if_id_map, oid_sai_map, oid_name_map

@staticmethod
def init_namespace_sync_d_lag_tables(dbs):

lag_name_if_name_map = {}
if_name_lag_name_map = {}
oid_lag_name_map = {}

"""
all_ns_db - will have db_conn to all namespace DBs and
global db. First db in the list is global db.
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
def init_namespace_sync_d_queue_tables(dbs):
port_queues_map = {}
queue_stat_map = {}
port_queue_list_map = {}

"""
all_ns_db - will have db_conn to all namespace DBs and
global db. First db in the list is global db.
Ignore first global db to get queue tables if there
are multiple namespaces.
"""
Namespace.connect_namespace_dbs(dbs)
def get_sync_d_from_all_namespace(per_namespace_func, dbs):
# return merged tuple of dictionaries retrieved from per
# namespace functions.
result_map = {}
# list of return values
result_list = []
for db_conn in Namespace.get_non_host_dbs(dbs):
port_queues_map_ns, \
queue_stat_map_ns, \
port_queue_list_map_ns = init_sync_d_queue_tables(db_conn)
port_queues_map.update(port_queues_map_ns)
queue_stat_map.update(queue_stat_map_ns)
port_queue_list_map.update(port_queue_list_map_ns)

return port_queues_map, queue_stat_map, port_queue_list_map
ns_tuple = per_namespace_func(db_conn)
for idx in range(len(ns_tuple)):
if idx not in result_map:
result_map[idx] = ns_tuple[idx]
else:
result_map[idx].update(ns_tuple[idx])
for idx, ns_tuple_dict in result_map.items():
result_list.append(ns_tuple_dict)
return result_list

@staticmethod
def dbs_get_bridge_port_map(dbs, db_name):
Expand Down
6 changes: 3 additions & 3 deletions src/sonic_ax_impl/mibs/ieee802_1ab.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def reinit_data(self):
self.if_alias_map, \
self.if_id_map, \
self.oid_sai_map, \
self.oid_name_map = Namespace.init_namespace_sync_d_interface_tables(self.db_conn)
self.oid_name_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_interface_tables, self.db_conn)

self.mgmt_oid_name_map, \
self.mgmt_alias_map = mibs.init_mgmt_interface_tables(self.db_conn[0])
Expand Down Expand Up @@ -401,7 +401,7 @@ def reinit_data(self):
self.if_alias_map, \
self.if_id_map, \
self.oid_sai_map, \
self.oid_name_map = Namespace.init_namespace_sync_d_interface_tables(self.db_conn)
self.oid_name_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_interface_tables, self.db_conn)

self.mgmt_oid_name_map, _ = mibs.init_mgmt_interface_tables(self.db_conn[0])

Expand Down Expand Up @@ -561,7 +561,7 @@ def reinit_data(self):
"""
Subclass reinit data routine.
"""
_, _, _, _, self.oid_name_map = Namespace.init_namespace_sync_d_interface_tables(self.db_conn)
_, _, _, _, self.oid_name_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_interface_tables, self.db_conn)

self.mgmt_oid_name_map, _ = mibs.init_mgmt_interface_tables(self.db_conn[0])

Expand Down
4 changes: 2 additions & 2 deletions src/sonic_ax_impl/mibs/ietf/rfc1213.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def reinit_data(self):
self.if_alias_map, \
self.if_id_map, \
self.oid_sai_map, \
self.oid_name_map = Namespace.init_namespace_sync_d_interface_tables(self.db_conn)
self.oid_name_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_interface_tables, self.db_conn)
"""
db_conn - will have db_conn to all namespace DBs and
global db. First db in the list is global db.
Expand All @@ -200,7 +200,7 @@ def update_data(self):

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

self.if_range = sorted(list(self.oid_sai_map.keys()) +
list(self.oid_lag_name_map.keys()) +
Expand Down
2 changes: 1 addition & 1 deletion src/sonic_ax_impl/mibs/ietf/rfc2737.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def reinit_data(self):

# update interface maps
_, self.if_alias_map, _, _, _ = \
Namespace.init_namespace_sync_d_interface_tables(Namespace.init_namespace_dbs())
Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_interface_tables, Namespace.init_namespace_dbs())

device_metadata = mibs.get_device_metadata(self.statedb[0])
chassis_sub_id = (self.CHASSIS_ID, )
Expand Down
4 changes: 2 additions & 2 deletions src/sonic_ax_impl/mibs/ietf/rfc2863.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ def reinit_data(self):
self.if_alias_map, \
self.if_id_map, \
self.oid_sai_map, \
self.oid_name_map = Namespace.init_namespace_sync_d_interface_tables(self.db_conn)
self.oid_name_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_interface_tables, self.db_conn)

self.lag_name_if_name_map, \
self.if_name_lag_name_map, \
self.oid_lag_name_map = Namespace.init_namespace_sync_d_lag_tables(self.db_conn)
self.oid_lag_name_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_lag_tables, self.db_conn)
"""
db_conn - will have db_conn to all namespace DBs and
global db. First db in the list is global db.
Expand Down
2 changes: 1 addition & 1 deletion src/sonic_ax_impl/mibs/ietf/rfc4363.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def reinit_data(self):
self.if_alias_map, \
self.if_id_map, \
self.oid_sai_map, \
self.oid_name_map = Namespace.init_namespace_sync_d_interface_tables(self.db_conn)
self.oid_name_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_interface_tables, self.db_conn)

self.if_bpid_map = Namespace.dbs_get_bridge_port_map(self.db_conn, mibs.ASIC_DB)
self.bvid_vlan_map.clear()
Expand Down
4 changes: 2 additions & 2 deletions src/sonic_ax_impl/mibs/vendor/cisco/ciscoPfcExtMIB.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def reinit_data(self):
self.if_alias_map, \
self.if_id_map, \
self.oid_sai_map, \
self.oid_name_map = Namespace.init_namespace_sync_d_interface_tables(self.db_conn)
self.oid_name_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_interface_tables, self.db_conn)

self.update_data()

Expand All @@ -51,7 +51,7 @@ def update_data(self):

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

self.if_range = sorted(list(self.oid_sai_map.keys()) + list(self.oid_lag_name_map.keys()))
self.if_range = [(i,) for i in self.if_range]
Expand Down
4 changes: 2 additions & 2 deletions src/sonic_ax_impl/mibs/vendor/cisco/ciscoSwitchQosMIB.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ def reinit_data(self):
self.if_alias_map, \
self.if_id_map, \
self.oid_sai_map, \
self.oid_name_map = Namespace.init_namespace_sync_d_interface_tables(self.db_conn)
self.oid_name_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_interface_tables, self.db_conn)

self.port_queues_map, self.queue_stat_map, self.port_queue_list_map = \
Namespace.init_namespace_sync_d_queue_tables(self.db_conn)
Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_queue_tables, self.db_conn)

self.queue_type_map = Namespace.dbs_get_all(self.db_conn, mibs.COUNTERS_DB, "COUNTERS_QUEUE_TYPE_MAP", blocking=False)

Expand Down
3 changes: 2 additions & 1 deletion tests/namespace/test_mibs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import tests.mock_tables.dbconnector
from sonic_ax_impl.mibs import Namespace
from sonic_ax_impl import mibs

modules_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.join(modules_path, 'src'))
Expand All @@ -20,7 +21,7 @@ def test_init_namespace_sync_d_lag_tables(self):

lag_name_if_name_map, \
if_name_lag_name_map, \
oid_lag_name_map = Namespace.init_namespace_sync_d_lag_tables(dbs)
oid_lag_name_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_lag_tables, dbs)
#PortChannel in asic0 Namespace
self.assertTrue(b"PortChannel01" in lag_name_if_name_map)
self.assertTrue(b"Ethernet-BP0" in lag_name_if_name_map[b"PortChannel01"])
Expand Down
3 changes: 2 additions & 1 deletion tests/test_mibs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
sys.path.insert(0, os.path.join(modules_path, 'src'))

from sonic_ax_impl.mibs import Namespace
from sonic_ax_impl import mibs

class TestGetNextPDU(TestCase):
@classmethod
Expand All @@ -20,7 +21,7 @@ def test_init_sync_d_lag_tables(self):

lag_name_if_name_map, \
if_name_lag_name_map, \
oid_lag_name_map = Namespace.init_namespace_sync_d_lag_tables(db_conn)
oid_lag_name_map = Namespace.get_sync_d_from_all_namespace(mibs.init_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