Skip to content
Open
Changes from 1 commit
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
30 changes: 27 additions & 3 deletions sonic-psud/scripts/psud
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,40 @@ def _wrapper_get_num_psus():
return platform_psuutil.get_num_psus()


def _wrapper_get_psu(psu_index):
"""
Get PSU object from platform chassis
Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring is missing the logger parameter description. Add ':param logger: Logger instance for error/warning messages' to document the logger parameter.

Suggested change
Get PSU object from platform chassis
Get PSU object from platform chassis
:param logger: Logger instance for error/warning messages

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LinJin23 Pls fix this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

:param psu_index: PSU index (1-based)
:return: PSU object if available, None otherwise
"""
if platform_chassis is not None:
try:
return platform_chassis.get_psu(psu_index - 1)
except NotImplementedError: # TODO: Is NotImplementedError sufficient?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log a warning for this exception and return None, Also add a general exception to make the code robust.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

pass # TODO: When caught, what should we do here?
# TODO: If platform_chassis is None, should we return None or add logging and return None?
return None


def _wrapper_get_psu_presence(psu_index):
if platform_chassis is not None:
psu = _wrapper_get_psu(psu_index)
if not psu:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if psu returned is None here, add exception here to log error and returning false.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return False # TODO: What should we do when PSU object is not available?
try:
return platform_chassis.get_psu(psu_index - 1).get_presence()
return psu.get_presence()
except NotImplementedError:
pass
return platform_psuutil.get_psu_presence(psu_index)


def _wrapper_get_psu_status(psu_index):
if platform_chassis is not None:
psu = _wrapper_get_psu(psu_index)
if not psu:
return False # TODO: What should we do when PSU object is not available?
try:
return platform_chassis.get_psu(psu_index - 1).get_powergood_status()
return psu.get_powergood_status()
except NotImplementedError:
pass
return platform_psuutil.get_psu_status(psu_index)
Expand All @@ -123,8 +144,11 @@ def _wrapper_get_psu_status(psu_index):

def get_psu_key(psu_index):
if platform_chassis is not None:
psu = _wrapper_get_psu(psu_index)
if not psu:
return "" # TODO: What should we do when PSU object is not available?
try:
return platform_chassis.get_psu(psu_index - 1).get_name()
return psu.get_name()
except NotImplementedError:
pass
except IndexError:
Expand Down
Loading