-
Notifications
You must be signed in to change notification settings - Fork 666
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
Make PFC commands use a class #3057
Conversation
001c9c9
to
3f80da0
Compare
/azpw run Azure.sonic-utilities |
/azpw run |
/azpw run Azure.sonic-utilities |
/azp run Azure.sonic-utilities |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
pfc/main.py
Outdated
@@ -1,160 +1,182 @@ | |||
#!/usr/bin/env python3 | |||
|
|||
import os |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please sort imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
||
class TestPfc(TestPfcBase): | ||
@classmethod | ||
def setup_class(cls): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
teardown needs to be called for TestPfc to set the UTILITIES_UNIT_TESTING
to zero
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
teardown_class
is defined in the base class TestPfcBase
, it should inherit that method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the latest revision, I removed the need for the environment variable UTILITIES_UNIT_TESTING
.
pfc/main.py
Outdated
PFC handler to display asymmetric PFC information. | ||
""" | ||
header = ('Interface', 'Asymmetric') | ||
if "UTILITIES_UNIT_TESTING" in os.environ and os.environ["UTILITIES_UNIT_TESTING"] == "2": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do need this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need it, it looks like it was just to make writing the test easier but we can just as easily call the config command followed by the show command in the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this and changed the way we validate the test case. Please see latest posted change.
tests/pfc_test.py
Outdated
|
||
def test_pfc_config_priority(self): | ||
self.executor(pfc.cli, ['config', 'priority', 'on', 'Ethernet0', '5'], | ||
expected_output=pfc_config_priority_on) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add test for showPfcPrio ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like there already is one for showPfcPrio
see test_pfc_show_priority_all
, test_pfc_show_priority_intf
and test_pfc_show_asymmetric_intf_fake
3f80da0
to
49590ab
Compare
expected_output=pfc_config_asymmetric) | ||
|
||
def test_pfc_config_priority(self): | ||
self.executor(pfc.cli, ['config', 'priority', 'on', 'Ethernet0', '5'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bktsim-arista Can we add "show pfc counter" test as well ? Also, Could we test this change on pizza box as well as chassis ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vmittal-msft Adding a test for show pfc counter
is out of scope for this PR as show pfc counter
is implemented in the pfcstat
script. See
Lines 637 to 644 in d5287d4
def counters(namespace, display, verbose): | |
"""Show pfc counters""" | |
cmd = ['pfcstat', '-s', str(display)] | |
if namespace is not None: | |
cmd += ['-n', str(namespace)] | |
run_command(cmd, display_cmd=verbose) |
Also, Could we test this change on pizza box as well as chassis ?
This can be done. Though this PR is about refactoring main.py
to implement the config/show methods in a class. New unit tests are added as there were no tests prior to this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I confirmed on a T0 switch that the config/show commands in pfc/main.py
work as expected. This is not surprising as there is no functional product change in this PR. This PR encapsulates globals methods into a class and adds missing UTs.
This change puts contents originally in pfc/main.py into a class, to support the usage of the multi-asic helper in a future change. This change is required, as multi-asic helper relies on certain members of the class to exist. The multi-asic class helper will be used to add multi-asic support to pfc commands.
335772e
to
8566ef7
Compare
Because of the conversion of global methods to class methods, there are lots of white space changes. The best way to review this PR is to ignore whitespace. |
28dc1d5
to
bad2beb
Compare
Removed the use of the environment variable to test `config asymmetric on`. Instead replaced the validation method with a direct check for the expected CONFIG_DB entry. Also removed the unnecessary classmethods in TestPfcBase.
bad2beb
to
cc424b4
Compare
What I did This change puts contents originally in pfc/main.py into a class, to support the usage of the multi-asic helper in a future change. This change is required, as multi-asic helper being used expects members self.config_db and self.db to exist when a function with the decorator run_on_multi_asic is called. The multi-asic class helper will be used to add multi-asic support to pfc commands in a following pull request. This is a part of the set of changes being pushed for sonic-net/sonic-buildimage#15148 How I did it Moved contents of PFC commands into a class. There are no functional changes. Co-authored-by: rdjeric <[email protected]> Co-authored-by: Kenneth Cheung <[email protected]>
@bktsim-arista Please file a direct PR to 202405 branch to address the conflict. |
There's no need to cherry-pick this PR into 202405 because commit 6447308 is already included. 😄 Can you change the label to already included in 202405? |
What I did
This change puts contents originally in pfc/main.py into a class, to support the usage of the multi-asic helper in a future change. This change is required, as multi-asic helper being used expects members
self.config_db
andself.db
to exist when a function with the decoratorrun_on_multi_asic
is called. The multi-asic class helper will be used to add multi-asic support to pfc commands in a following pull request.This is a part of the set of changes being pushed for sonic-net/sonic-buildimage#15148
How I did it
Moved contents of PFC commands into a class. There are no functional changes.