Skip to content

Add missing sys imports to psu_base and fan_drawer_base#343

Merged
gechiang merged 1 commit intosonic-net:masterfrom
spilkey-cisco:spilkey/psu_base_master
Jan 30, 2023
Merged

Add missing sys imports to psu_base and fan_drawer_base#343
gechiang merged 1 commit intosonic-net:masterfrom
spilkey-cisco:spilkey/psu_base_master

Conversation

@spilkey-cisco
Copy link
Copy Markdown
Contributor

Description

Import sys in modules where it was missing and attempted to be referenced. Found it missing in psu_base.py and fan_drawer_base.py.

Motivation and Context

sys.stderr.write is used in default API definitions within psu_base.py and fan_drawer_base.py. When an exception is caught within these APIs, they will throw NameError: name 'sys' is not defined when trying to use the sys module without first importing it. Issue was originally found for PSUs, but also exists within fan_drawer_base.

How Has This Been Tested?

Test code demonstrating the issue and the fix after importing sys

>>> def test(index):
...     l = []
...     try:
...         return l[index]
...     except IndexError:
...         sys.stderr.write('Index out of range\n')
...     return None
...
>>> test(1)
Traceback (most recent call last):
  File "<stdin>", line 4, in test
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 6, in test
NameError: name 'sys' is not defined
>>> import sys
>>> test(1)
Index out of range

Additional Information (Optional)

This fix should go into all active branches, especially master, 202205, and 202012.

@gechiang gechiang self-requested a review January 30, 2023 19:29
Copy link
Copy Markdown

@gechiang gechiang left a comment

Choose a reason for hiding this comment

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

LGTM

@gechiang gechiang merged commit 01ef800 into sonic-net:master Jan 30, 2023
dprital added a commit to dprital/sonic-buildimage that referenced this pull request Jan 30, 2023
Update sonic-platform-common submodule pointer to include the following:
* 01ef800 Add missing sys imports ([sonic-net#343](sonic-net/sonic-platform-common#343))

Signed-off-by: dprital <drorp@nvidia.com>
liat-grozovik pushed a commit to sonic-net/sonic-buildimage that referenced this pull request Feb 1, 2023
Update sonic-platform-common submodule pointer to include the following:
* 01ef800 Add missing sys imports ([#343](sonic-net/sonic-platform-common#343))

Signed-off-by: dprital <drorp@nvidia.com>
yxieca pushed a commit that referenced this pull request Feb 2, 2023
qiluo-msft pushed a commit that referenced this pull request Feb 2, 2023
@spilkey-cisco spilkey-cisco deleted the spilkey/psu_base_master branch May 23, 2023 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants