Skip to content
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

[CLI][Multi ASIC] Allow commands that don't support "-n" option to be run with "sudo ip netns.." option. #5446

Merged
merged 1 commit into from
Sep 24, 2020

Conversation

smaheshm
Copy link
Contributor

@smaheshm smaheshm commented Sep 23, 2020

- Why I did it

In multi ASIC platforms, CLIs commands can be under a namespace using the following command, which is now broken.

sudo ip netns exec asic0 show ....

NOTE: CLI commands that support "-n" option will still give an error when run with "sudo ip netns exec ... " option. This behavior is intended to encourage users to use "-n" option.

The preferred way of running a CLI command for a namespace is using "-n" option of the CLI command. At this point not all 'show' CLIs have the support of specifying "-n" option. "sudo ip netns exec asicX" is the only way run a command for a namespace.

- How I did it

The command was failing as it was trying to connect to DB in different namespace. Made change so that get namespace API returns the current namespace if it is run under a non default namespace.

- How to verify it

Verified manually on multi ASIC platform.

Before:

admin@str-n3164-acs-2:~$ sudo ip netns exec asic1 show --help
Traceback (most recent call last):       
  File "/usr/bin/show", line 8, in <module>    
    from show.main import cli                           
  File "/usr/lib/python2.7/dist-packages/show/main.py", line 233, in <module>
    iface_alias_converter = InterfaceAliasConverter()        
  File "/usr/lib/python2.7/dist-packages/show/main.py", line 58, in __init__
    self.port_dict = multi_asic.get_port_table()                   
  File "/usr/local/lib/python2.7/dist-packages/sonic_py_common/multi_asic.py", line 236, in get_port_table
.
.
  File "/usr/local/lib/python2.7/dist-packages/redis/connection.py", line 610, in send_command
    self.send_packed_command(self.pack_command(*args))
  File "/usr/local/lib/python2.7/dist-packages/redis/connection.py", line 585, in send_packed_command
    self.connect()                    
  File "/usr/local/lib/python2.7/dist-packages/redis/connection.py", line 489, in connect
    raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 113 connecting to 240.127.1.2:6379. No route to host.

After:

admin@str-n3164-acs-2:~$ sudo ip netns exec asic0 show --help
Usage: show [OPTIONS] COMMAND [ARGS]...

  SONiC command line - 'show' command

Options:
  -?, -h, --help  Show this message and exit.

Commands:
  aaa                   Show AAA configuration
  acl                   Show ACL related information
  arp                   Show IP ARP table
  boot                  Show boot configuration

.
.

admin@str-n3164-acs-2:/etc/sonic$ sudo ip netns exec asic0 show priority-group  watermark shared                                                                                      
Ingress shared pool occupancy per PG:                                                                                                                                                 
         Port    PG0    PG1    PG2    PG3    PG4    PG5    PG6    PG7                                                                                                                 
-------------  -----  -----  -----  -----  -----  -----  -----  -----                                                                                                                 
    Ethernet0    416      0      0      0      0      0      0      0                                                                                                                 
    Ethernet4   1664      0      0      0      0      0      0      0                                                                                                                 
    Ethernet8      0      0      0      0      0      0      0      0                                                                                                                 
   Ethernet12      0      0      0      0      0      0      0      0                                                                                                                 
   Ethernet16   1664      0      0      0      0      0      0      0                                                                                                                 
   Ethernet20    416      0      0      0      0      0      0      0                                                                                                                 
   Ethernet24      0      0      0      0      0      0      0      0      
.
.
.                                                                                                           
Ethernet-BP44    416      0      0      0      0      0      0      0                                                                                                                 
Ethernet-BP48   9360      0      0      0      0      0      0      0                                                                                                                 
Ethernet-BP52    416      0      0      0      0      0      0      0                                                                                                                 
Ethernet-BP56    416      0      0      0      0      0      0      0                                                                                                                 
Ethernet-BP60    416      0      0      0      0      0      0      0    

- Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006

- Description for the changelog

Update get_all_linux_namespaces() API to return the current namespace

- A picture of a cute animal (not mandatory but encouraged)

@smaheshm
Copy link
Contributor Author

NOTE: CLI commands that support "-n" option will still give an error when run with "sudo ip netns exec ... " option. This behavior is intended to encourage users to use "-n" option.

@smaheshm smaheshm changed the title update get_all_namespace to return current namespace [CLI][Multi ASIC] Allow commands that don't support "-n" option to be run with "sudo ip netns.." option. Sep 23, 2020
@rlhui
Copy link
Contributor

rlhui commented Sep 23, 2020

Dont' see "Which release branch to backport (provide reason below if selected)" marked? Is this PR needed for backporting to 201911?

@smaheshm
Copy link
Contributor Author

Dont' see "Which release branch to backport (provide reason below if selected)" marked? Is this PR needed for backporting to 201911?

I selected and saved, not sure why it didn't save.

@smaheshm
Copy link
Contributor Author

retest vsimage please

Copy link
Contributor

@arlakshm arlakshm left a comment

Choose a reason for hiding this comment

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

lgtm

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