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

[PSU]: Return number of PSU as zero for Chassis Linecard #323

Closed
wants to merge 1 commit into from
Closed
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
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)}")
Loading