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

support show interface commands for multi ASIC platforms #1006

Merged
merged 7 commits into from
Aug 21, 2020

Conversation

arlakshm
Copy link
Contributor

@arlakshm arlakshm commented Jul 25, 2020

Support show interface commands for multi ASIC platforms

Depends on the following PRs

Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan arlakshm@microsoft.com

- What I did
Support the following commands for multi ASIC

  • show interface status
  • show interface description

2 new options have added

  • [-n, --namespace] to allow user to display the information for given namespaces
    If this option is not present the information from all the namespaces will be displayed

  • [-d, --display] to allow user to display information related both internal and external interfaces
    If this option is not present only external interfaces/neighbors will be display

One single ASIC platform, this options ignored, so the behavior remains unchanged

- How I did it

  • Add argparse intfutil script
  • Change the IntfDescription and IntfStatus classes to get the information from all namespaces.
  • Add changes to filter out the internal ports from display
  • Add support for -n and -d click options

- How to verify it
Help menu

root@sonic:/home/admin# show interface description -h
Usage: show interface description [OPTIONS] [INTERFACENAME]

  Show interface status, protocol and description

Options:
  -d, --display [all|frontend]    Show internal interfaces  [default:
                                  frontend]
  -n, --namespace [asic0|asic1|asic2|asic3|asic4|asic5]
                                  Namespace name or all
  --verbose                       Enable verbose output
  -?, -h, --help                  Show this message and exit.
root@sonic:/home/admin# show interface status -h
Usage: show interface status [OPTIONS] [INTERFACENAME]

  Show Interface status information

Options:
  -d, --display [all|frontend]    Show internal interfaces  [default:
                                  frontend]
  -n, --namespace [asic0|asic1|asic2|asic3|asic4|asic5]
                                  Namespace name or all
  --verbose                       Enable verbose output
  -?, -h, --help                  Show this message and exit.

Handling for invalid namespaces

root@sonic:/home/admin# show interface description -n asic -d all
Usage: show interface description [OPTIONS] [INTERFACENAME]

Error: Invalid value for "--namespace" / "-n": invalid choice: asic. (choose from asic0, asic1, asic2, asic3, asic4, asic5)

Sample output

root@sonic:/home/admin# show interface description -n asic0
  Interface    Oper    Admin         Alias               Description
-----------  ------  -------  ------------  ------------------------
  Ethernet0      up       up   Ethernet1/1  ARISTA01T2:Ethernet3/1/1
  Ethernet4      up       up   Ethernet1/2  ARISTA01T2:Ethernet3/2/1
  Ethernet8    down     down   Ethernet1/3               Ethernet1/3
 Ethernet12    down     down   Ethernet1/4               Ethernet1/4
 Ethernet16      up       up   Ethernet1/5  ARISTA03T2:Ethernet3/1/1
 Ethernet20      up       up   Ethernet1/6  ARISTA03T2:Ethernet3/2/1
 Ethernet24    down     down   Ethernet1/7               Ethernet1/7
 Ethernet28    down     down   Ethernet1/8               Ethernet1/8
 Ethernet32    down     down   Ethernet1/9               Ethernet1/9
 Ethernet36    down     down  Ethernet1/10              Ethernet1/10
 Ethernet40    down     down  Ethernet1/11              Ethernet1/11
 Ethernet44    down     down  Ethernet1/12              Ethernet1/12
 Ethernet48    down     down  Ethernet1/13              Ethernet1/13
 Ethernet52    down     down  Ethernet1/14              Ethernet1/14
 Ethernet56    down     down  Ethernet1/15              Ethernet1/15
 Ethernet60    down     down  Ethernet1/16              Ethernet1/16
root@sonic:/home/admin# show interface description -n asic0 -d all
    Interface    Oper    Admin          Alias               Description
-------------  ------  -------  -------------  ------------------------
    Ethernet0      up       up    Ethernet1/1  ARISTA01T2:Ethernet3/1/1
    Ethernet4      up       up    Ethernet1/2  ARISTA01T2:Ethernet3/2/1
    Ethernet8    down     down    Ethernet1/3               Ethernet1/3
   Ethernet12    down     down    Ethernet1/4               Ethernet1/4
   Ethernet16      up       up    Ethernet1/5  ARISTA03T2:Ethernet3/1/1
   Ethernet20      up       up    Ethernet1/6  ARISTA03T2:Ethernet3/2/1
   Ethernet24    down     down    Ethernet1/7               Ethernet1/7
   Ethernet28    down     down    Ethernet1/8               Ethernet1/8
   Ethernet32    down     down    Ethernet1/9               Ethernet1/9
   Ethernet36    down     down   Ethernet1/10              Ethernet1/10
   Ethernet40    down     down   Ethernet1/11              Ethernet1/11
   Ethernet44    down     down   Ethernet1/12              Ethernet1/12
   Ethernet48    down     down   Ethernet1/13              Ethernet1/13
   Ethernet52    down     down   Ethernet1/14              Ethernet1/14
   Ethernet56    down     down   Ethernet1/15              Ethernet1/15
   Ethernet60    down     down   Ethernet1/16              Ethernet1/16
 Ethernet-BP0      up       up   Ethernet-BP0          ASIC4:Eth0-ASIC4
 Ethernet-BP4      up       up   Ethernet-BP4          ASIC4:Eth1-ASIC4
 Ethernet-BP8      up       up   Ethernet-BP8          ASIC4:Eth2-ASIC4
Ethernet-BP12      up       up  Ethernet-BP12          ASIC4:Eth3-ASIC4
Ethernet-BP16      up       up  Ethernet-BP16          ASIC4:Eth4-ASIC4
Ethernet-BP20      up       up  Ethernet-BP20          ASIC4:Eth5-ASIC4
Ethernet-BP24      up       up  Ethernet-BP24          ASIC4:Eth6-ASIC4
Ethernet-BP28      up       up  Ethernet-BP28          ASIC4:Eth7-ASIC4
Ethernet-BP32      up       up  Ethernet-BP32          ASIC5:Eth0-ASIC5
Ethernet-BP36      up       up  Ethernet-BP36          ASIC5:Eth1-ASIC5
Ethernet-BP40      up       up  Ethernet-BP40          ASIC5:Eth2-ASIC5
Ethernet-BP44      up       up  Ethernet-BP44          ASIC5:Eth3-ASIC5
Ethernet-BP48      up       up  Ethernet-BP48          ASIC5:Eth4-ASIC5
Ethernet-BP52      up       up  Ethernet-BP52          ASIC5:Eth5-ASIC5
Ethernet-BP56      up       up  Ethernet-BP56          ASIC5:Eth6-ASIC5
Ethernet-BP60      up       up  Ethernet-BP60          ASIC5:Eth7-ASIC5

UT results

============================= test session starts ==============================
platform linux2 -- Python 2.7.16, pytest-3.10.1, py-1.7.0, pluggy-0.8.0
rootdir: /sonic/src/sonic-utilities, inifile: pytest.ini
plugins: cov-2.6.0
collected 137 items

tests/acl_loader_test.py ....                                            [  2%]
tests/aclshow_test.py ...........                                        [ 10%]
tests/config_mgmt_test.py ....                                           [ 13%]
tests/config_test.py ..                                                  [ 15%]
tests/drops_group_test.py .......                                        [ 20%]
tests/feature_test.py ..........                                         [ 27%]
tests/filter_fdb_entries_test.py ..........                              [ 35%]
tests/gearbox_test.py ..                                                 [ 36%]
tests/interfaces_test.py .............                                   [ 45%]
tests/intfstat_test.py ........                                          [ 51%]
tests/intfutil_test.py ...............                                   [ 62%]
tests/multi_asic_intfutil_test.py ........                               [ 68%]
tests/port2alias_test.py ....                                            [ 71%]
tests/psu_test.py ...                                                    [ 73%]
tests/sflow_test.py ..                                                   [ 75%]
tests/sfp_test.py ...                                                    [ 77%]
tests/show_breakout_test.py ..                                           [ 78%]
tests/show_platform_test.py .                                            [ 79%]
tests/vlan_test.py ............................                          [100%]

---------- coverage: platform linux2, python 2.7.16-final-0 ----------
Name                                       Stmts   Miss  Cover
--------------------------------------------------------------
acl_loader/__init__.py                         0      0   100%
acl_loader/main.py                           541    367    32%
clear/__init__.py                              0      0   100%
clear/bgp_frr_v6.py                           44     44     0%
clear/bgp_quagga_v4.py                        44     44     0%
clear/bgp_quagga_v6.py                        44     44     0%
clear/main.py                                179    106    41%
config/__init__.py                             0      0   100%
config/aaa.py                                124     75    40%
config/config_mgmt.py                        345    116    66%
config/feature.py                             25      5    80%
config/main.py                              2107   1547    27%
config/mlnx.py                               124     85    31%
config/nat.py                                680    570    16%
config/utils.py                                3      0   100%
config/vlan.py                               132     14    89%
connect/__init__.py                            0      0   100%
connect/main.py                               55     55     0%
consutil/__init__.py                           0      0   100%
consutil/lib.py                               79     79     0%
consutil/main.py                              70     70     0%
counterpoll/__init__.py                        0      0   100%
counterpoll/main.py                          126    126     0%
crm/__init__.py                                0      0   100%
crm/main.py                                  289    289     0%
debug/__init__.py                              0      0   100%
debug/main.py                                153    153     0%
fdbutil/__init__.py                            0      0   100%
fdbutil/filter_fdb_entries.py                 77      7    91%
fwutil/__init__.py                             5      5     0%
fwutil/lib.py                                474    474     0%
fwutil/log.py                                 44     44     0%
fwutil/main.py                               243    243     0%
pcieutil/__init__.py                           0      0   100%
pcieutil/main.py                              75     75     0%
pddf_fanutil/__init__.py                       0      0   100%
pddf_fanutil/main.py                         182    182     0%
pddf_ledutil/__init__.py                       0      0   100%
pddf_ledutil/main.py                          60     60     0%
pddf_psuutil/__init__.py                       0      0   100%
pddf_psuutil/main.py                         203    203     0%
pddf_thermalutil/__init__.py                   0      0   100%
pddf_thermalutil/main.py                     104    104     0%
pfcwd/__init__.py                              0      0   100%
pfcwd/main.py                                197    197     0%
psuutil/__init__.py                            0      0   100%
psuutil/main.py                               66     66     0%
scripts/aclshow                              127     13    90%
scripts/db_migrator.py                       154    154     0%
scripts/dropconfig                           215    103    52%
scripts/dropstat                             216     21    90%
scripts/dump_nat_entries.py                   12     12     0%
scripts/fast-reboot-dump.py                  204    204     0%
scripts/gearboxutil                          131     21    84%
scripts/intfstat                             194     42    78%
scripts/intfutil                             308     13    96%
scripts/mellanox_buffer_migrator.py           90     90     0%
scripts/port2alias                            32      5    84%
scripts/psushow                               59      9    85%
scripts/route_check.py                       172    172     0%
scripts/sfpshow                              168     36    79%
scripts/update_json.py                        35     35     0%
sfputil/__init__.py                            0      0   100%
sfputil/main.py                              338    338     0%
show/__init__.py                               0      0   100%
show/bgp_frr_v4.py                            37     37     0%
show/bgp_frr_v6.py                            34     34     0%
show/bgp_quagga_v4.py                         20     20     0%
show/bgp_quagga_v6.py                         15     15     0%
show/feature.py                               34      0   100%
show/interfaces/__init__.py                  227     74    67%
show/interfaces/portchannel.py                92      5    95%
show/main.py                                1420   1005    29%
show/mlnx.py                                  80     62    23%
show/vlan.py                                  91      5    95%
sonic_installer/__init__.py                    0      0   100%
sonic_installer/bootloader/__init__.py         9      9     0%
sonic_installer/bootloader/aboot.py          136    136     0%
sonic_installer/bootloader/bootloader.py      32     32     0%
sonic_installer/bootloader/grub.py            60     60     0%
sonic_installer/bootloader/onie.py            27     27     0%
sonic_installer/bootloader/uboot.py           61     61     0%
sonic_installer/common.py                     21     21     0%
sonic_installer/exception.py                   2      2     0%
sonic_installer/main.py                      412    412     0%
ssdutil/__init__.py                            0      0   100%
ssdutil/main.py                               50     50     0%
utilities_common/__init__.py                   0      0   100%
utilities_common/cli.py                      297    105    65%
utilities_common/constants.py                  6      0   100%
utilities_common/db.py                         9      0   100%
utilities_common/intf_filter.py               30     18    40%
utilities_common/multi_asic.py                70      8    89%
utilities_common/netstat.py                   35     15    57%
utilities_common/util_base.py                 32     32     0%
watchdogutil/__init__.py                       0      0   100%
watchdogutil/main.py                          54     54     0%
--------------------------------------------------------------
TOTAL                                      12742   9016    29%
Coverage HTML written to dir htmlcov
Coverage XML written to file coverage.xml

- Previous command output (if the output of a command-line utility has changed)
NA
- New command output (if the output of a command-line utility has changed)
NA

Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <arlakshm@microsoft.com>
@lgtm-com

This comment has been minimized.

scripts/intfutil Outdated
Comment on lines 16 to 20
from utilities_common.constants import PORT_CHANNEL_OBJ
from utilities_common.constants import PORT_OBJ
from utilities_common.multi_asic import MultiAsic
from utilities_common.multi_asic import multi_asic_args
from utilities_common.multi_asic import run_on_all_asics
Copy link
Contributor

Choose a reason for hiding this comment

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

group imports.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in latest commit

scripts/intfutil Outdated
appl_db_sub_intf_status_get(self.db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_OPTICS_TYPE)))
return table

def __init__(self, intf_name, namespace_option, display_option):
Copy link
Contributor

@smaheshm smaheshm Jul 31, 2020

Choose a reason for hiding this comment

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

move init to top?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

scripts/intfutil Outdated

def __init__(self, intf_name):
def __init__(self, intf_name, namespace_option, display_option):
Copy link
Contributor

Choose a reason for hiding this comment

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

move init to top?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

@jleveque jleveque left a comment

Choose a reason for hiding this comment

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

Please also add/modify unit tests as necessary to add coverage for intfutil: https://github.com/Azure/sonic-utilities/blob/master/sonic-utilities-tests/intfutil_test.py

Copy link
Contributor

@smaheshm smaheshm left a comment

Choose a reason for hiding this comment

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

Looks good. Minor comments.

@lguohan
Copy link
Contributor

lguohan commented Jul 31, 2020

i think we need to add new unit test to cover the new functions.

Copy link
Contributor

@lguohan lguohan left a comment

Choose a reason for hiding this comment

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

need to add new unit test to cover the new functions.

Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <arlakshm@microsoft.com>
@lgtm-com

This comment has been minimized.

Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <arlakshm@microsoft.com>
@arlakshm
Copy link
Contributor Author

need to add new unit test to cover the new functions.

@lguohan, @jleveque , @smaheshm. Added the multi asic Unit tests in the latest commit.

@lgtm-com

This comment has been minimized.

@arlakshm
Copy link
Contributor Author

retest this please

Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <arlakshm@microsoft.com>
@lgtm-com
Copy link

lgtm-com bot commented Aug 18, 2020

This pull request fixes 3 alerts when merging da04d1a into 8768580 - view on LGTM.com

fixed alerts:

  • 2 for Unused local variable
  • 1 for Unused import

show/interfaces/__init__.py Outdated Show resolved Hide resolved
utilities_common/cli.py Outdated Show resolved Hide resolved
Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <arlakshm@microsoft.com>
@arlakshm arlakshm requested a review from jleveque August 19, 2020 00:32
@lgtm-com
Copy link

lgtm-com bot commented Aug 19, 2020

This pull request fixes 3 alerts when merging 99f0741 into 8768580 - view on LGTM.com

fixed alerts:

  • 2 for Unused local variable
  • 1 for Unused import

scripts/intfutil Outdated
modules_path = os.path.join(os.path.dirname(__file__), "..")
tests_path = os.path.join(modules_path, "tests")
sys.path.insert(0, modules_path)
sys.path.insert(0, tests_path)
import mock_tables.dbconnector
if os.environ["UTILITIES_UNIT_TESTING"] == "3":
Copy link
Contributor

Choose a reason for hiding this comment

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

i think we need to keep this as '2': but maybe we can introduce a new environmental variable, "UTILITIES_UNIT_TESTING_TOPOLOGY"="multi-asic"

@lguohan
Copy link
Contributor

lguohan commented Aug 20, 2020

in the unit test, we do have backend asic v.s. frontend asic?

result = subprocess.check_output(
'intfutil -c description -n asic0 -d all', stderr=subprocess.STDOUT, shell=True)
print(result)
assert result == intf_description_asic0_all
Copy link
Contributor

@lguohan lguohan Aug 20, 2020

Choose a reason for hiding this comment

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

please assert exit_code for all cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in latest commit

@arlakshm
Copy link
Contributor Author

arlakshm commented Aug 20, 2020

in the unit test, we do have backend asic v.s. frontend asic?

The cli command is implementation is same for backend or frontend asic. For any asic either the internal or all the interfaces are displayed

assert result == intf_description_asic0_all


def teardown_class(cls):
Copy link
Contributor

Choose a reason for hiding this comment

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

i do not see any negative unit test cases, for example, check an asic name that does not exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

add negative cases for invalid asic-id

Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <arlakshm@microsoft.com>
@arlakshm arlakshm requested a review from lguohan August 20, 2020 22:16
@lgtm-com
Copy link

lgtm-com bot commented Aug 20, 2020

This pull request fixes 3 alerts when merging ee66cc5 into 5263b54 - view on LGTM.com

fixed alerts:

  • 2 for Unused local variable
  • 1 for Unused import

Comment on lines +96 to +106
def get_result_and_return_code(self, cmd):
return_code = 0
try:
output = subprocess.check_output(
cmd, stderr=subprocess.STDOUT, shell=True)
except subprocess.CalledProcessError as e:
return_code = e.returncode
#store only the error, no need for the traceback
output = e.output.strip().split("\n")[-1]

return(return_code, output)
Copy link
Contributor

@jleveque jleveque Aug 20, 2020

Choose a reason for hiding this comment

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

This is a good candidate to be a shared function between many tests. In the future, we can maybe consider creating a base class and adding this to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants