[storm-control] Fixed show storm-control interface command display #4122
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixed show storm-control interface command failure with error message "missing 2 required positional arguments: 'namespace' and 'display'".
Type of change
Bug fix - Corrected parameter handling in Click command structure
Approach
The "interface" subcommand function expected "namespace" parameter in its signature, but these were defined as options on the parent "storm_control" group. Click doesn't automatically pass parent group options to subcommands.
Solution:
How did you do it?
Used Click's context system to access parent parameters: Added @click.pass_context decorator
Modified function to accept ctx as parameter
What is the motivation for this PR?
Users couldn't execute show storm-control interface <interface_name> command due to TypeError, blocking storm control troubleshooting functionality.
How to verify it
Added a new UT case for verifying storm control show per interface
Previous command output (if the output of a command-line utility has changed)
root@sonic:/home/admin# show storm-control interface Ethernet184
Traceback (most recent call last):
File "/usr/local/bin/show", line 8, in
sys.exit(cli())
^^^^^
File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 764, in call
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: interface() missing 2 required positional arguments: 'namespace' and 'display'
root@sonic:/home/admin#
New command output (if the output of a command-line utility has changed)
admin@str-marvell-tl10-01:~$ show storm-control interface Ethernet0
+------------------+--------------+---------------+
| Interface Name | Storm Type | Rate (kbps) |
+==================+==============+===============+
| Ethernet0 | broadcast | 24000 |
+------------------+--------------+---------------+
Any platform specific information:
NA