Skip to content

Commit

Permalink
Merge branch 'master' into dev/liuh/improve-reinit
Browse files Browse the repository at this point in the history
  • Loading branch information
qiluo-msft authored Oct 28, 2023
2 parents 523ebb5 + bdaddca commit c9fc25c
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 8 deletions.
3 changes: 2 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ stages:
- script: |
set -ex
sudo apt-get -y purge libhiredis-dev libnl-3-dev libnl-route-3-dev
sudo dpkg -i ../target/debs/buster/{libyang_1.0.73_amd64.deb,libswsscommon_1.0.0_amd64.deb,python3-swsscommon_1.0.0_amd64.deb,libnl-3-200_*.deb,libnl-genl-3-200_*.deb,libnl-nf-3-200_*.deb,libnl-route-3-200_*.deb,libhiredis0.14_*.deb}
sudo apt-get -y install libhiredis0.14
sudo dpkg -i ../target/debs/buster/{libyang_1.0.73_amd64.deb,libswsscommon_1.0.0_amd64.deb,python3-swsscommon_1.0.0_amd64.deb,libnl-3-200_*.deb,libnl-genl-3-200_*.deb,libnl-nf-3-200_*.deb,libnl-route-3-200_*.deb}
sudo python3 -m pip install ../target/python-wheels/buster/swsssdk*-py3-*.whl
sudo python3 -m pip install ../target/python-wheels/buster/sonic_py_common-1.0-py3-none-any.whl
python3 setup.py bdist_wheel
Expand Down
26 changes: 19 additions & 7 deletions src/sonic_ax_impl/mibs/ietf/rfc2863.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,11 @@ def interface_alias(self, sub_id):
:param sub_id: The 1-based sub-identifier query.
:return: The SONiC interface description, empty string if not defined.
"""
entry = self._get_if_entry(sub_id)
oid = self.get_oid(sub_id)
if not oid:
return

entry = self._get_if_entry(oid)
if not entry:
return

Expand Down Expand Up @@ -262,15 +266,11 @@ def _get_counter(self, oid, table_name, mask):
mibs.logger.warning("SyncD 'COUNTERS_DB' missing attribute '{}'.".format(e))
return None

def _get_if_entry(self, sub_id):
def _get_if_entry(self, oid):
"""
:param oid: The 1-based sub-identifier query.
:return: the DB entry for the respective sub_id.
"""
oid = self.get_oid(sub_id)
if not oid:
return

if_table = ""
# Once PORT_TABLE will be moved to CONFIG DB
# we will get entry from CONFIG_DB for all cases
Expand All @@ -294,7 +294,19 @@ def get_high_speed(self, sub_id):
:param sub_id: The 1-based sub-identifier query.
:return: speed value for the respective sub_id or 40000 if not defined.
"""
entry = self._get_if_entry(sub_id)
oid = self.get_oid(sub_id)
if not oid:
return

if oid in self.oid_lag_name_map:
speed = 0
for lag_member in self.lag_name_if_name_map[self.oid_lag_name_map[oid]]:
entry = self._get_if_entry(mibs.get_index_from_str(lag_member))
if entry:
speed += int(entry.get("speed", 0))
return speed

entry = self._get_if_entry(oid)
if not entry:
return

Expand Down
3 changes: 3 additions & 0 deletions tests/mock_tables/appl_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,9 @@
"nexthop": "",
"ifname": "lo"
},
"LAG_MEMBER_TABLE:PortChannel01:Ethernet108": {
"status": "enabled"
},
"LAG_MEMBER_TABLE:PortChannel01:Ethernet112": {
"status": "enabled"
},
Expand Down
19 changes: 19 additions & 0 deletions tests/test_hc_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,25 @@ def test_no_speed(self):
self.assertEqual(str(value0.name), str(ObjectIdentifier(12, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 15, 121))))
self.assertEqual(value0.data, 40000)

def test_portchannel_speed(self):
"""
For a portchannel, the speed should be the sum of all members' speeds
"""
oid = ObjectIdentifier(12, 0, 0, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 15, 1000))
get_pdu = GetNextPDU(
header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
oids=[oid]
)

encoded = get_pdu.encode()
response = get_pdu.make_response(self.lut)
print(response)

value0 = response.values[0]
self.assertEqual(value0.type_, ValueType.GAUGE_32)
self.assertEqual(str(value0.name), str(ObjectIdentifier(12, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 15, 1001))))
self.assertEqual(value0.data, 200000)

def test_no_description(self):
"""
For a port with no speed in the db the result should be 40000
Expand Down
68 changes: 68 additions & 0 deletions tests/test_rfc2863.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import os
import sys
import sonic_ax_impl
from unittest import TestCase

if sys.version_info.major == 3:
from unittest import mock
else:
import mock

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.mibs.ietf.rfc2863 import InterfaceMIBUpdater

class TestInterfaceMIBUpdater(TestCase):

def mock_get_sync_d_from_all_namespace(per_namespace_func, dbs):
if per_namespace_func == sonic_ax_impl.mibs.init_sync_d_lag_tables:
return [{'PortChannel999': [], 'PortChannel103': ['Ethernet120']}, # lag_name_if_name_map
{},
{1999: 'PortChannel999', 1103: 'PortChannel103'}, # oid_lag_name_map
{},
{}]

if per_namespace_func == sonic_ax_impl.mibs.init_sync_d_interface_tables:
return [{},
{},
{},
{121: 'Ethernet120'}]

return [{},{},{}]

def mock_lag_entry_table(lag_name):
if lag_name == "PortChannel103":
return "PORT_TABLE:Ethernet120"

return

def mock_dbs_get_all(dbs, db_name, hash, *args, **kwargs):
if hash == "PORT_TABLE:Ethernet120":
return {'admin_status': 'up', 'alias': 'fortyGigE0/120', 'description': 'ARISTA03T1:Ethernet1', 'index': '30', 'lanes': '101,102,103,104', 'mtu': '9100', 'oper_status': 'up', 'pfc_asym': 'off', 'speed': '40000', 'tpid': '0x8100'}

return

def mock_init_mgmt_interface_tables(db_conn):
return [{},{}]

@mock.patch('sonic_ax_impl.mibs.Namespace.get_sync_d_from_all_namespace', mock_get_sync_d_from_all_namespace)
@mock.patch('sonic_ax_impl.mibs.Namespace.dbs_get_all', mock_dbs_get_all)
@mock.patch('sonic_ax_impl.mibs.lag_entry_table', mock_lag_entry_table)
@mock.patch('sonic_ax_impl.mibs.init_mgmt_interface_tables', mock_init_mgmt_interface_tables)
def test_InterfaceMIBUpdater_get_high_speed(self):
updater = InterfaceMIBUpdater()

with mock.patch('sonic_ax_impl.mibs.logger.warning') as mocked_warning:
updater.reinit_data()
updater.update_data()

# get speed of port-channel 103, OID is 1103
speed = updater.get_high_speed((1103,))
print("103 speed: {}".format(speed))
self.assertTrue(speed == 40000)

# get speed of port-channel 999, OID is 1999
speed = updater.get_high_speed((1999,))
print("999 speed: {}".format(speed))
self.assertTrue(speed == 0)

0 comments on commit c9fc25c

Please sign in to comment.