-
Notifications
You must be signed in to change notification settings - Fork 661
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
Enhancement of 'show' commands, addition of 'Clear', 'debug', 'undebug'. #98
Conversation
scripts/aclshow
Outdated
@@ -229,7 +229,7 @@ class AclStat(object): | |||
if not display_all and (self.get_counter_value(rule_key, 'packets') == '0' or \ | |||
self.get_counter_value(rule_key, 'packets') == 'N/A'): | |||
continue | |||
rule = self.acl_rules[rule_key] | |||
rule = self.acl_rules[rule_key] |
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.
This appears to be an accidental change. Revert?
Clear/main.py
Outdated
from click_default_group import DefaultGroup | ||
|
||
try: | ||
# noinspection PyPep8Naming |
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.
These # noinspection
markups are specific to the PyCharm IDE. Please remove them.
Clear/main.py
Outdated
# noinspection PyPep8Naming | ||
import ConfigParser as configparser | ||
except ImportError: | ||
# noinspection PyUnresolvedReferences |
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.
Remove markup, as above.
debug/main.py
Outdated
from click_default_group import DefaultGroup | ||
|
||
try: | ||
# noinspection PyPep8Naming |
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.
Remove markup, as above.
debug/main.py
Outdated
# noinspection PyPep8Naming | ||
import ConfigParser as configparser | ||
except ImportError: | ||
# noinspection PyUnresolvedReferences |
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.
Remove markup, as above.
undebug/main.py
Outdated
# noinspection PyPep8Naming | ||
import ConfigParser as configparser | ||
except ImportError: | ||
# noinspection PyUnresolvedReferences |
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.
Remove markup, as above.
undebug/main.py
Outdated
from click_default_group import DefaultGroup | ||
|
||
try: | ||
# noinspection PyPep8Naming |
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.
Remove markup, as above.
Clear/main.py
Outdated
@@ -0,0 +1,337 @@ | |||
#! /usr/bin/python -u |
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 understand that you've named this program Clear
with a capital "C" to distinguish it from the standard Linux clear
command. I feel as though it would be better off with a different, all-lowercase name to avoid confusion. Suggestions?
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.
Alternative is to alias "clear" with some script. In that script, if clear does not have arguments, invoke system clear command, otherwise invoke corresponding sonic clear command.
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.
maybe "clearcmd" ?
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.
The best way to address this is by having a small script with name "clear" installed under /usr/local/bin/ that redirects user input to system clear command (/usr/bin/clear) & SONiC Clear commands (/usr/bin/Clear).
The user will not see the upper case Clear & the redirection will transparent to the user.
Since, that script change has go to sonic-buildimage repo, I can commit that change in a separate pull.
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.
can we rename /usr/bin/clear to /usr/bin/clear_screen
then, when we do 'clear screen', we invoke this /usr/bin/clear_screen
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.
This isn't a backwards compatible suggestion if we ever decide to change in the future the cli framework. The Linux cmds shouldn't be touched.
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.
if there is no argument, we can still call linux "clear", there is no backwards compatibility issue.
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.
/usr/bin/clear is the linux clear screen command. It should not be replaced and it should not be renamed. There needs to be a sonic-clear and a clear in /usr/local/bin. In the user's path /usr/local/bin comes first. The clear in /usr/local/bin with no arguments should call /usr/bin/clear and with arguments it should call /usr/local/bin/sonic-clear.
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.
The only issue I have with Ravi's solution of a /usr/local/bin/clear script is that it will make the SONiC clear
command behave inconsistently with the other CLI commands. For instance, calling show
or config
with no arguments will present the user with the usage statement, but calling clear
with no arguments will clear the user's screen.
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 is unfortunate that sonic presents the user with usage statement when show or config are called with no arguments. Sounds like that decision needs to be revisited. Nevertheless, we need to move forward with this commit. I agree with the point you made that we should come up with a better way than a capitalized command. Sort of introducing a cli shell for all sonic commands (show, clear, config), this is the next best thing which is not interfering with the linux clear command in any way.
Clear/main.py
Outdated
|
||
def run_command(command, pager=False): | ||
if pager is True: | ||
#click.echo(click.style("Command: ", fg='cyan') + click.style(command, fg='green')) |
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 these two lines are commented out?
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.
You mean the last line?
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.
He's referring to both of the click.echo(click.style("Command: ", fg='cyan') + click.style(command, fg='green'))
lines (lines 86 and 90). These are carried over from our show
command, in which they display the underlying wrapped command that is being called. In our config
command, I added a "verbose" flag to enable this print, leaving it disabled by default. I have not yet got around to modifying show
to match. I believe this utility should either follow the same format or these lines should be deleted altogether.
Clear/main.py
Outdated
# 'cli' group (root group) ### | ||
# | ||
|
||
# THis is our entrypoint - the main "Clear" command |
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.
h
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.
Looks like this was missed: THis
-> This
.
This was a copy-paste of a typo I made in the show
command. I have since fixed it there.
Clear/main.py
Outdated
|
||
# We use the "click.group()" decorator because we want to add this group | ||
# to more than one group, which we do using the "add_command() methods below. | ||
@click.group(cls=AliasedGroup,default_if_no_args=True) |
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 have made changes to the group/command hierarchy in the show
command, so this should be updated to match. My changes are here for your reference: #102
The bgp
group should now only be a member of the ip
group, NOT the cli
group. Thus, line 125 should change to @ip.group(cls=AliasedGroup, default_if_no_args=False)
and you can subsequently remove lines 131-133.
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.
The change made in #102 regarding BGP is not necessarily the right approach. BGP has many address families (l2vpn, ls etc) and they are certainly not ipv4 or ipv6. BGP should either have "show ip bgp ..." or "show bgp ..." or both. BGP should not appear under ipv6.
Clear/main.py
Outdated
|
||
|
||
# 'bgp' command | ||
@click.group(cls=AliasedGroup,default_if_no_args=True) |
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.
Same as above. This bgp
command is only a member of the ipv6
group, so you can change line 224 to @ipv6.group(cls=AliasedGroup,default_if_no_args=True)
and subsequently remove line 229.
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.
See comment above.
Clear/main.py
Outdated
def neighbor(): | ||
pass | ||
|
||
bgp.add_command(neighbor) |
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.
This line is unnecessary, as neighbor is added to the bgp
group via the decorator on line 239.
Clear/main.py
Outdated
def soft(): | ||
pass | ||
|
||
neighbor.add_command(soft) |
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.
This line is unnecessary, as neighbor is added to the neighbor
group via the decorator on line 179.
Clear/main.py
Outdated
def soft(): | ||
pass | ||
|
||
neighbor.add_command(soft) |
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.
This line is unnecessary, as neighbor is added to the neighbor
group via the decorator on line 275.
Clear/main.py
Outdated
# 'arp' command #### | ||
# | ||
|
||
@click.command() |
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.
For now, only add arp
command to the root cli
group, so you can change line 320 to @cli.command()
and subsequently remove lines 330-332.
Please also address all the conflicts. |
show/main.py
Outdated
if e.errno == errno.EPIPE: | ||
sys.exit(0) | ||
else: | ||
raise |
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.
Revert back to spaces from tabs (lines 98-102).
show/main.py
Outdated
if interfacename is not None: | ||
cmd += " -p {}".format(interfacename) | ||
cmd += " -p {}".format(interfacename) |
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.
Revert back to spaces from tabs.
show/main.py
Outdated
@click.argument('interfacename', required=True) | ||
def details(interfacename): | ||
command="sudo sfputil --port {} --dom".format(interfacename) | ||
run_command(command) |
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.
Replace spaces with tabs (lines 184-185).
show/main.py
Outdated
t = p1.stdout.readlines()[0] | ||
command2 = "cat {}/port_config.ini".format(t.rstrip()) | ||
p2 = subprocess.Popen(command2, shell=True, stdout=subprocess.PIPE) | ||
click.echo(p2.stdout.read()) |
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.
Replace spaces with tabs (lines 242-259).
show/main.py
Outdated
@neighbor.command('advertised-routes') | ||
@click.argument('ipaddress') | ||
def advertised_routes(ipaddress): | ||
command = 'sudo vtysh -c "show ip bgp neighbor {} advertised-routes"'.format(ipaddress) |
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.
Replace spaces with tabs.
show/main.py
Outdated
@cli.command('system-memory') | ||
def system_memory(): | ||
"""Show memory information""" | ||
comm="free -m" |
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.
Change to command = "..."
for consistency ("comm" -> "command" and add spaces around equals sign).
show/main.py
Outdated
@click.argument('bridge_name', required=True) | ||
def id(bridge_name): | ||
"""Show list of learned MAC addresses for particular bridge""" | ||
comm="sudo brctl showmacs {}".format(bridge_name) |
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.
Change to command = "..."
for consistency ("comm" -> "command" and add spaces around equals sign).
show/main.py
Outdated
@cli.command('services') | ||
def services(): | ||
"""Show all daemon services""" | ||
comm = "sudo docker ps --format '{{.Names}}'" |
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.
Change to command = "..."
for consistency ("comm" -> "command").
show/main.py
Outdated
if line != '': | ||
print(line.rstrip()+'\t'+"docker") | ||
print("---------------------------") | ||
comm1 = "sudo docker exec -it {} ps -ef | sed '$d'".format(line.rstrip()) |
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.
Reuse command
instead of creating comm1
?
show/main.py
Outdated
run_command("interface_stat") | ||
|
||
@interface.command() | ||
def portmap(): |
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.
Remove portmap
command as no it is redundant with show interfaces alias
.
aaa1ce6
to
150c8a6
Compare
Fix `Failed to update PSU data - global name 'self' is not defined` Signed-off-by: Volodymyr Boyko <volodymyrx.boiko@intel.com>
[sfp_base] Update return value documentation of channel-specific methods (sonic-net#98) [SfpBase] Fix key name typo in docstring (sonic-net#99) [sfp] Tweak key names of some transceiver info fields (sonic-net#97) [sfputil] Make SfpUtilHelper.get_physical_to_logical noexcept as in SfpUtilBase (sonic-net#96)
a1830c1761087bdc1f7433ebbb8d0bdc419da0d3 (HEAD -> 201911, origin/master, origin/HEAD, origin/201911) Fix OpenAPI spec to be readable by autorest (sonic-net#101) 94805a39ac0712219f7dc08faa2cfdbf371dd177 Identify and report Vnet GUID for conflicting VNI (sonic-net#99) 4832dfd677de72edc44d4eb8c1b60cfad79a3355 Static route expiry if not specified as persistent (sonic-net#98) 5cc4358fb67b9e2a0da9a6691064e41f97ebebc2 (master) Add support for overlay ECMP (sonic-net#96) 6822a46197daef060b4d00dba5153b04b163c43f [CI] Set diff cover threshold to 50% (sonic-net#97) dcc826a1503060b9a07e4510b4f48331c49e87dd Add PR diff coverage (sonic-net#95) e842c5ff317c67919dcbcab3358143cb9a16c9dd Generate code coverage for Unit Tests (sonic-net#94) f9bbed3cb86a3bab9a07745096835dbdbe5a4db6 Convert Unit Tests from unittest framework to pytest framework (sonic-net#93) Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>
…ods (sonic-net#98) Update docstrings of `get_rx_los()`, `get_tx_fault()` and `get_tx_disable()` methods to reflect that they should return a list of values where each value reflect the status of an individual SFP channel. Also add more detail to other channel-specific method docstrings.
List of changes: