Skip to content

Commit

Permalink
[PSU]: Return number of PSU as zero for Chassis Linecard
Browse files Browse the repository at this point in the history
Signed-off-by: Suvarna Meenakshi <sumeenak@microsoft.com>
  • Loading branch information
SuvarnaMeenakshi committed Jul 9, 2024
1 parent f652948 commit 2b4da4f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from enum import Enum, unique
from sonic_ax_impl import mibs
from ax_interface import MIBMeta, ValueType, SubtreeMIBEntry
from sonic_py_common.device_info import is_chassis, is_supervisor

CHASSIS_INFO_KEY_TEMPLATE = 'chassis {}'
PSU_INFO_KEY_TEMPLATE = 'PSU {}'
Expand Down Expand Up @@ -59,6 +60,9 @@ def _get_num_psus(self):
Get PSU number
:return: the number of supported PSU
"""
if is_chassis() and not is_supervisor():
return 0

chassis_name = CHASSIS_INFO_KEY_TEMPLATE.format(1)
chassis_info = self.statedb.get_all(self.statedb.STATE_DB, mibs.chassis_info_table(chassis_name))
num_psus = get_chassis_data(chassis_info)
Expand Down
48 changes: 48 additions & 0 deletions tests/test_psu.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

from unittest import TestCase

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

from ax_interface import ValueType
from ax_interface.pdu_implementations import GetPDU, GetNextPDU
from ax_interface.encodings import ObjectIdentifier
Expand Down Expand Up @@ -115,3 +120,46 @@ def test_getMissedPsu(self):
self.assertEqual(value0.type_, ValueType.END_OF_MIB_VIEW)
self.assertEqual(str(value0.name), str(oid))
self.assertEqual(value0.data, None)

@mock.patch('sonic_ax_impl.mibs.vendor.cisco.ciscoEntityFruControlMIB.is_chassis', mock.MagicMock(return_value=True))
@mock.patch('sonic_ax_impl.mibs.vendor.cisco.ciscoEntityFruControlMIB.is_supervisor', mock.MagicMock(return_value=False))
@mock.patch('sonic_ax_impl.mibs.vendor.cisco.ciscoEntityFruControlMIB.get_chassis_data', mock.MagicMock(return_value=(('',))))
def test_getNoPsuChassisLineCard(self):
# is_chassis is True and is_supervisor is False
# Expect no PSU in Linecard of Chassis
# Fail if Exception is caught, no exception should be caught for Linecard with no PSU
oid = ObjectIdentifier(2, 0, 0, 0, (1, 3, 6, 1, 4, 1, 9, 9, 117, 1, 1, 2, 1, 2, 1))
expected_oid = None
try:
ciscoEntityFruControlMIB.cefcFruPowerStatusTable.power_status_handler._get_num_psus()
except Exception as e:
self.fail(f"Caught unexpected exception: {type(e).__name__}: {str(e)}")


@mock.patch('sonic_ax_impl.mibs.vendor.cisco.ciscoEntityFruControlMIB.is_chassis', mock.MagicMock(return_value=True))
@mock.patch('sonic_ax_impl.mibs.vendor.cisco.ciscoEntityFruControlMIB.is_supervisor', mock.MagicMock(return_value=True))
@mock.patch('sonic_ax_impl.mibs.vendor.cisco.ciscoEntityFruControlMIB.get_chassis_data', mock.MagicMock(return_value=(('',))))
def test_getNoPsuChassisSupervisor(self):
# is_chassis is True and is_supervisor is True
# get_chassis_data() should return num_psu
# Exception will be caught on supervisory if num_psu is empty
oid = ObjectIdentifier(2, 0, 0, 0, (1, 3, 6, 1, 4, 1, 9, 9, 117, 1, 1, 2, 1, 2, 1))
expected_oid = None

with self.assertRaises(Exception):
ciscoEntityFruControlMIB.cefcFruPowerStatusTable.power_status_handler._get_num_psus()

@mock.patch('sonic_ax_impl.mibs.vendor.cisco.ciscoEntityFruControlMIB.is_chassis', mock.MagicMock(return_value=True))
@mock.patch('sonic_ax_impl.mibs.vendor.cisco.ciscoEntityFruControlMIB.is_supervisor', mock.MagicMock(return_value=True))
@mock.patch('sonic_ax_impl.mibs.vendor.cisco.ciscoEntityFruControlMIB.get_chassis_data', mock.MagicMock(return_value=(('8',))))
def test_getPsuPresentChassisSupervisor(self):
# is_chassis is True and is_supervisor is True
# get_chassis_data() should return num_psu
# no exception should be caught and number of psus should be returned
oid = ObjectIdentifier(2, 0, 0, 0, (1, 3, 6, 1, 4, 1, 9, 9, 117, 1, 1, 2, 1, 2, 1))
expected_oid = None
try:
num_psus = ciscoEntityFruControlMIB.cefcFruPowerStatusTable.power_status_handler._get_num_psus()
self.assertEqual(num_psus, 8)
except Exception as e:
self.fail(f"Caught unexpected exception: {type(e).__name__}: {str(e)}")

0 comments on commit 2b4da4f

Please sign in to comment.