Skip to content

Commit

Permalink
Bug fixes and merge repair for unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Raphael Tryster <raphaelt@nvidia.com>
  • Loading branch information
raphaelt-nvidia committed May 20, 2021
1 parent da3c648 commit 8842851
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 41 deletions.
3 changes: 2 additions & 1 deletion src/sonic_ax_impl/mibs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
import os


from swsscommon.swsscommon import SonicV2Connector
from swsssdk import SonicDBConfig
from swsssdk import port_util
Expand Down Expand Up @@ -379,7 +380,7 @@ def init_sync_d_lag_tables(db_conn):
lag_entries = db_conn.keys(APPL_DB, "LAG_TABLE:*")

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

db_conn.connect(COUNTERS_DB)
lag_sai_map = db_conn.get_all(COUNTERS_DB, "COUNTERS_LAG_NAME_MAP")
Expand Down
3 changes: 2 additions & 1 deletion src/sonic_ax_impl/mibs/ietf/rfc1213.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ def __init__(self):

self.namespace_db_map = Namespace.get_namespace_db_map(self.db_conn)


def reinit_data(self):
"""
Subclass update interface information
Expand Down Expand Up @@ -249,7 +250,7 @@ def update_data(self):
self.lag_name_if_name_map, \
self.if_name_lag_name_map, \
self.oid_lag_name_map, \
self.lag_sai_map, _ = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_lag_tables, self.db_conn)
self.lag_sai_map, self.sai_lag_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_lag_tables, self.db_conn)

self.if_range = sorted(list(self.oid_name_map.keys()) +
list(self.oid_lag_name_map.keys()) +
Expand Down
5 changes: 5 additions & 0 deletions tests/mock_tables/asic0/asic_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@
},
"ASIC_STATE:SAI_OBJECT_TYPE_LAG:oid:0x1000000000007": {
"NULL": "NULL"
},
"ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE:oid:0x6000000001abc": {
"SAI_ROUTER_INTERFACE_ATTR_OUTER_VLAN_ID": "101",
"SAI_ROUTER_INTERFACE_ATTR_PORT_ID": "oid:0x1000000000017",
"SAI_ROUTER_INTERFACE_ATTR_TYPE": "SAI_ROUTER_INTERFACE_TYPE_SUB_PORT"
}
}
75 changes: 74 additions & 1 deletion tests/mock_tables/asic0/counters_db.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
{
"COUNTERS:oid:0x6000000000006": {
"SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "106",
"SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "116",
"SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "106",
"SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "226",
"SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "12",
"SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "212",
"SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "6",
"SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "336"
},
"COUNTERS:oid:0x6000000001abc": {
"SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "101",
"SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "101",
"SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "101",
"SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "101",
"SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "101",
"SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "101",
"SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "101",
"SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "101"
},
"COUNTERS:oid:0x1000000000007": {
"SAI_PORT_STAT_ETHER_STATS_TX_NO_ERRORS": "0",
"SAI_PORT_STAT_ETHER_STATS_OVERSIZE_PKTS": "0",
Expand Down Expand Up @@ -881,4 +901,57 @@
"SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4",
"SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5",
"SAI_QUEUE_STAT_WATERMARK_BYTES": "6"
}}
},
"COUNTERS_RIF_NAME_MAP": {
"Ethernet0": "oid:0x6000000000015",
"Ethernet8.101": "oid:0x6000000001abc",
"Ethernet8.102": "oid:0x6000000001abd",
"PortChannel01": "oid:0x6000000000006",
"PortChannel02": "oid:0x6000000000005",
"PortChannel03": "oid:0x6000000000004",
"PortChannel04": "oid:0x6000000000003",
"PortChannel101": "oid:0x6000000000002",
"Vlan1000": "oid:0x60000000005d0"
},
"COUNTERS_RIF_TYPE_MAP": {
"oid:0x6000000000015": "SAI_ROUTER_INTERFACE_TYPE_PORT",
"oid:0x6000000001abc": "SAI_ROUTER_INTERFACE_TYPE_SUB_PORT",
"oid:0x6000000001abd": "SAI_ROUTER_INTERFACE_TYPE_SUB_PORT",
"oid:0x6000000000006": "SAI_ROUTER_INTERFACE_TYPE_PORT",
"oid:0x6000000000005": "SAI_ROUTER_INTERFACE_TYPE_PORT",
"oid:0x6000000000004": "SAI_ROUTER_INTERFACE_TYPE_PORT",
"oid:0x6000000000003": "SAI_ROUTER_INTERFACE_TYPE_PORT",
"oid:0x6000000000002": "SAI_ROUTER_INTERFACE_TYPE_PORT",
"oid:0x60000000005d0": "SAI_ROUTER_INTERFACE_TYPE_VLAN"
},
"COUNTERS:oid:0x6000000000006": {
"SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "6",
"SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "116",
"SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "6",
"SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "226",
"SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "12",
"SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "212",
"SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "6",
"SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "336"
},
"COUNTERS:oid:0x6000000000015": {
"SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "10",
"SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "2048",
"SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "1",
"SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "55",
"SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "20",
"SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "4096",
"SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "2",
"SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "110"
},
"COUNTERS:oid:0x60000000005d0": {
"SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "10",
"SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "2048",
"SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "1",
"SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "55",
"SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "20",
"SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "4096",
"SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "2",
"SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "110"
}
}
24 changes: 23 additions & 1 deletion tests/mock_tables/asic1/counters_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@
"Ethernet12": "oid:0x1000000000004",
"Ethernet-BP8": "oid:0x1000000000005",
"Ethernet-BP12": "oid:0x1000000000006",
"Ethernet16": "oid:0x1000000000010"
"Ethernet16": "oid:0x1000000000010"
},
"COUNTERS_LAG_NAME_MAP": {
"PortChannel02": "oid:0x1000000000007"
Expand Down Expand Up @@ -988,4 +988,26 @@
"SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4",
"SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5",
"SAI_QUEUE_STAT_WATERMARK_BYTES": "6"
},
"COUNTERS_RIF_NAME_MAP": {
"Ethernet20": "oid:0x6000000000015",
"Ethernet8.101": "oid:0x6000000001abc",
"Ethernet8.102": "oid:0x6000000001abd",
"PortChannel01": "oid:0x6000000000006",
"PortChannel02": "oid:0x6000000000005",
"PortChannel03": "oid:0x6000000000004",
"PortChannel04": "oid:0x6000000000003",
"PortChannel101": "oid:0x6000000000002",
"Vlan1000": "oid:0x60000000005d0"
},
"COUNTERS_RIF_TYPE_MAP": {
"oid:0x6000000000015": "SAI_ROUTER_INTERFACE_TYPE_PORT",
"oid:0x6000000001abc": "SAI_ROUTER_INTERFACE_TYPE_SUB_PORT",
"oid:0x6000000001abd": "SAI_ROUTER_INTERFACE_TYPE_SUB_PORT",
"oid:0x6000000000006": "SAI_ROUTER_INTERFACE_TYPE_PORT",
"oid:0x6000000000005": "SAI_ROUTER_INTERFACE_TYPE_PORT",
"oid:0x6000000000004": "SAI_ROUTER_INTERFACE_TYPE_PORT",
"oid:0x6000000000003": "SAI_ROUTER_INTERFACE_TYPE_PORT",
"oid:0x6000000000002": "SAI_ROUTER_INTERFACE_TYPE_PORT",
"oid:0x60000000005d0": "SAI_ROUTER_INTERFACE_TYPE_VLAN"
}}
22 changes: 22 additions & 0 deletions tests/mock_tables/asic2/counters_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -950,4 +950,26 @@
"SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4",
"SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5",
"SAI_QUEUE_STAT_WATERMARK_BYTES": "6"
},
"COUNTERS_RIF_NAME_MAP": {
"Ethernet20": "oid:0x6000000000015",
"Ethernet8.101": "oid:0x6000000001abc",
"Ethernet8.102": "oid:0x6000000001abd",
"PortChannel01": "oid:0x6000000000006",
"PortChannel02": "oid:0x6000000000005",
"PortChannel03": "oid:0x6000000000004",
"PortChannel04": "oid:0x6000000000003",
"PortChannel101": "oid:0x6000000000002",
"Vlan1000": "oid:0x60000000005d0"
},
"COUNTERS_RIF_TYPE_MAP": {
"oid:0x6000000000015": "SAI_ROUTER_INTERFACE_TYPE_PORT",
"oid:0x6000000001abc": "SAI_ROUTER_INTERFACE_TYPE_SUB_PORT",
"oid:0x6000000001abd": "SAI_ROUTER_INTERFACE_TYPE_SUB_PORT",
"oid:0x6000000000006": "SAI_ROUTER_INTERFACE_TYPE_PORT",
"oid:0x6000000000005": "SAI_ROUTER_INTERFACE_TYPE_PORT",
"oid:0x6000000000004": "SAI_ROUTER_INTERFACE_TYPE_PORT",
"oid:0x6000000000003": "SAI_ROUTER_INTERFACE_TYPE_PORT",
"oid:0x6000000000002": "SAI_ROUTER_INTERFACE_TYPE_PORT",
"oid:0x60000000005d0": "SAI_ROUTER_INTERFACE_TYPE_VLAN"
}}
36 changes: 8 additions & 28 deletions tests/mock_tables/counters_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -2284,26 +2284,6 @@
"PortChannel04": "oid:0x2000000000003",
"PortChannel101": "oid:0x2000000000a14"
},
"COUNTERS_RIF_NAME_MAP": {
"Ethernet20": "oid:0x6000000000015",
"Ethernet8.101": "oid:0x6000000001abc",
"Ethernet8.102": "oid:0x6000000001abd",
"PortChannel01": "oid:0x6000000000006",
"PortChannel02": "oid:0x6000000000005",
"PortChannel03": "oid:0x6000000000004",
"PortChannel04": "oid:0x6000000000003",
"Vlan1000": "oid:0x60000000005d0"
},
"COUNTERS_RIF_TYPE_MAP": {
"oid:0x6000000000015": "SAI_ROUTER_INTERFACE_TYPE_PORT",
"oid:0x6000000001abc": "SAI_ROUTER_INTERFACE_TYPE_SUB_PORT",
"oid:0x6000000001abd": "SAI_ROUTER_INTERFACE_TYPE_SUB_PORT",
"oid:0x6000000000006": "SAI_ROUTER_INTERFACE_TYPE_PORT",
"oid:0x6000000000005": "SAI_ROUTER_INTERFACE_TYPE_PORT",
"oid:0x6000000000004": "SAI_ROUTER_INTERFACE_TYPE_PORT",
"oid:0x6000000000003": "SAI_ROUTER_INTERFACE_TYPE_PORT",
"oid:0x60000000005d0": "SAI_ROUTER_INTERFACE_TYPE_VLAN"
},
"COUNTERS:oid:0x6000000000015": {
"SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "10",
"SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "2048",
Expand Down Expand Up @@ -2355,14 +2335,14 @@
"SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "0"
},
"COUNTERS:oid:0x6000000001abc": {
"SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "101",
"SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "101",
"SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "101",
"SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "101",
"SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "101",
"SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "101",
"SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "101",
"SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "101"
"SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "1011",
"SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "1012",
"SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "1013",
"SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "1014",
"SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "1015",
"SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "1016",
"SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "1017",
"SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "1018"
},
"COUNTERS:oid:0x6000000001abd": {
"SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "102",
Expand Down
11 changes: 7 additions & 4 deletions tests/namespace/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
import sys
import importlib

# noinspection PyUnresolvedReferences
import tests.mock_tables.dbconnector
# 3 directory levels above sonic-snmpagent/tests/namespace/test_interfaces.py = sonic-snmpagent
modules_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

modules_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Insert sonic-snmpagent and sonic-snmpagent/src to path
sys.path.insert(0, modules_path)
sys.path.insert(0, os.path.join(modules_path, 'src'))

from unittest import TestCase

# noinspection PyUnresolvedReferences
import tests.mock_tables.dbconnector

from ax_interface import ValueType
from ax_interface.pdu_implementations import GetPDU, GetNextPDU
from ax_interface.encodings import ObjectIdentifier
Expand Down
2 changes: 1 addition & 1 deletion tests/namespace/test_mibs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_init_namespace_sync_d_lag_tables(self):
lag_name_if_name_map, \
if_name_lag_name_map, \
oid_lag_name_map, \
lag_sai_map, _ = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_lag_tables, dbs)
lag_sai_map, sai_lag_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_lag_tables, dbs)
#PortChannel in asic0 Namespace
self.assertTrue("PortChannel01" in lag_name_if_name_map)
self.assertTrue("Ethernet-BP0" in lag_name_if_name_map["PortChannel01"])
Expand Down
7 changes: 3 additions & 4 deletions tests/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
import sys
import importlib

# noinspection PyUnresolvedReferences
import tests.mock_tables.dbconnector

modules_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.join(modules_path, 'src'))

from unittest import TestCase

# noinspection PyUnresolvedReferences
import tests.mock_tables.dbconnector

from ax_interface import ValueType
from ax_interface.pdu_implementations import GetPDU, GetNextPDU
from ax_interface.encodings import ObjectIdentifier
Expand Down

0 comments on commit 8842851

Please sign in to comment.