Skip to content

Commit 6e0ff93

Browse files
Updating SNMP implementation to handle change of PSU Keys (#312)
- What I did Modified snmp implementation of Cisco MIB to use updated format for psu keys instead of index of PSU - How I did it Used a consistently sorted list of keys to allow for the modified statedb key naming for psus - How to verify it Ran the associated sonic-mgmt tests for PSUs (phy_entity and snmp_psu) - Description for the changelog Modifies SNMP implementation of Cisco PSUs to use key names instead of simple indexing Related PRs: sonic-net/sonic-mgmt#11944 sonic-net/sonic-utilities#3208 sonic-net/sonic-platform-daemons#446
1 parent 25f9e4f commit 6e0ff93

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/sonic_ax_impl/mibs/vendor/cisco/ciscoEntityFruControlMIB.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from enum import Enum, unique
22
from sonic_ax_impl import mibs
33
from ax_interface import MIBMeta, ValueType, SubtreeMIBEntry
4+
from natsort import natsorted
45

56
CHASSIS_INFO_KEY_TEMPLATE = 'chassis {}'
67
PSU_INFO_KEY_TEMPLATE = 'PSU {}'
@@ -70,8 +71,8 @@ def _get_psu_presence(self, psu_index):
7071
Get PSU presence
7172
:return: the presence of particular PSU
7273
"""
73-
psu_name = PSU_INFO_KEY_TEMPLATE.format(psu_index)
74-
psu_info = self.statedb.get_all(self.statedb.STATE_DB, mibs.psu_info_table(psu_name))
74+
psu_keys = natsorted(self.statedb.keys(self.statedb.STATE_DB, "PSU_INFO|*"))
75+
psu_info = self.statedb.get_all(self.statedb.STATE_DB, psu_keys[psu_index-1])
7576
presence, status = get_psu_data(psu_info)
7677

7778
return presence == PSU_PRESENCE_OK
@@ -81,8 +82,8 @@ def _get_psu_status(self, psu_index):
8182
Get PSU status
8283
:return: the status of particular PSU
8384
"""
84-
psu_name = PSU_INFO_KEY_TEMPLATE.format(psu_index)
85-
psu_info = self.statedb.get_all(self.statedb.STATE_DB, mibs.psu_info_table(psu_name))
85+
psu_keys = natsorted(self.statedb.keys(self.statedb.STATE_DB, "PSU_INFO|*"))
86+
psu_info = self.statedb.get_all(self.statedb.STATE_DB, psu_keys[psu_index-1])
8687
presence, status = get_psu_data(psu_info)
8788

8889
return status == PSU_STATUS_OK

0 commit comments

Comments
 (0)