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

[multi-asic] show ip interface changes for multi asic #1396

Merged
merged 7 commits into from
Feb 11, 2021

Conversation

arlakshm
Copy link
Contributor

@arlakshm arlakshm commented Feb 2, 2021

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

- What I did
The PR has changes to support command show ip interface for multi asic platform.

- How I did it
The following changes are done in this PR

  • The code for show ip interface has been moved from show/main.py to scripts\ipintutil
  • Modify the code to support both single and multi asic platform
    • To do this the library pyroute2 is used to get interface information in each namespace
  • Add the following options for multi asic
    • [-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

  • Add unit tests for single and multi asic

- How to verify it
Verify on single and multi asic

admin@sonic:~$ show ip interface
Interface        Master    IPv4 address/mask    Admin/Oper    BGP Neighbor    Neighbor IP
---------------  --------  -------------------  ------------  --------------  -------------
Loopback0                  10.1.0.32/32         up/up         N/A             N/A
PortChannel0001            10.0.0.32/31         up/up         ARISTA01T0      10.0.0.33
PortChannel0002            10.0.0.0/31          up/up         ARISTA01T2      10.0.0.1
PortChannel0003            10.0.0.34/31         up/up         ARISTA02T0      10.0.0.35
PortChannel0004            10.0.0.36/31         up/up         ARISTA03T0      10.0.0.37
PortChannel0005            10.0.0.4/31          up/up         ARISTA03T2      10.0.0.5
PortChannel0006            10.0.0.38/31         up/up         ARISTA04T0      10.0.0.39
PortChannel0007            10.0.0.40/31         up/up         ARISTA05T0      10.0.0.41
PortChannel0008            10.0.0.8/31          up/up         ARISTA05T2      10.0.0.9
PortChannel0009            10.0.0.42/31         up/up         ARISTA06T0      10.0.0.43
PortChannel0010            10.0.0.44/31         up/up         ARISTA07T0      10.0.0.45
PortChannel0011            10.0.0.12/31         up/up         ARISTA07T2      10.0.0.13
PortChannel0012            10.0.0.46/31         up/up         ARISTA08T0      10.0.0.47
PortChannel0013            10.0.0.48/31         up/up         ARISTA09T0      10.0.0.49
PortChannel0014            10.0.0.50/31         up/up         ARISTA10T0      10.0.0.51
PortChannel0015            10.0.0.52/31         up/up         ARISTA11T0      10.0.0.53
PortChannel0016            10.0.0.54/31         up/up         ARISTA12T0      10.0.0.55
PortChannel0017            10.0.0.56/31         up/up         ARISTA13T0      10.0.0.57
PortChannel0018            10.0.0.58/31         up/up         ARISTA14T0      10.0.0.59
PortChannel0019            10.0.0.60/31         up/up         ARISTA15T0      10.0.0.61
PortChannel0020            10.0.0.62/31         up/up         ARISTA16T0      10.0.0.63
PortChannel0021            10.0.0.64/31         up/up         ARISTA17T0      10.0.0.65
PortChannel0022            10.0.0.66/31         up/up         ARISTA18T0      10.0.0.67
PortChannel0023            10.0.0.68/31         up/up         ARISTA19T0      10.0.0.69
PortChannel0024            10.0.0.70/31         up/up         ARISTA20T0      10.0.0.71
docker0                    240.127.1.1/24       up/up         N/A             N/A
eth0                       10.3.147.150/23      up/up         N/A             N/A
lo                         127.0.0.1/8          up/up         N/A             N/A
admin@sonic:~$ 

Code Coverage

============================= test session starts ==============================
platform linux -- Python 3.7.3, 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 521 items

tests/acl_loader_test.py ....                                            [  0%]
tests/aclshow_test.py ...........                                        [  2%]
tests/bgp_commands_test.py ...                                           [  3%]
tests/buffer_test.py .......                                             [  4%]
tests/chassis_modules_test.py ..............                             [  7%]
tests/config_dpb_test.py .....                                           [  8%]
tests/config_mgmt_test.py ....                                           [  9%]
tests/config_test.py ....                                                [  9%]
tests/console_test.py .................................................. [ 19%]
.........                                                                [ 21%]
tests/counterpoll_test.py .....                                          [ 22%]
tests/crm_test.py ...................................................... [ 32%]
........                                                                 [ 34%]
tests/drops_group_test.py .......                                        [ 35%]
tests/ecn_test.py ................                                       [ 38%]
tests/fan_test.py .                                                      [ 38%]
tests/feature_test.py ......................                             [ 42%]
tests/fgnhg_test.py ......                                               [ 44%]
tests/filter_fdb_entries_test.py ..........                              [ 46%]
tests/gearbox_test.py ..                                                 [ 46%]
tests/interfaces_test.py ................                                [ 49%]
tests/intfstat_test.py ........                                          [ 51%]
tests/intfutil_test.py ...............                                   [ 53%]
tests/ip_show_routes_multi_asic_test.py ..............                   [ 56%]
tests/ip_show_routes_test.py ......                                      [ 57%]
tests/kube_test.py ..........                                            [ 59%]
tests/multi_asic_intfutil_test.py .........                              [ 61%]
tests/muxcable_test.py ............................                      [ 66%]
tests/neighbor_advertiser_test.py .                                      [ 66%]
tests/pcieutil_test.py ......                                            [ 68%]
tests/pfcstat_test.py .......                                            [ 69%]
tests/pfcwd_test.py ..................                                   [ 72%]
tests/port2alias_test.py ....                                            [ 73%]
tests/portchannel_test.py ............                                   [ 76%]
tests/portstat_test.py ....................                              [ 79%]
tests/psu_test.py ...                                                    [ 80%]
tests/reboot_cause_test.py ....                                          [ 81%]
tests/route_check_test.py .                                              [ 81%]
tests/sflow_test.py ..........                                           [ 83%]
tests/sfp_test.py ...........                                            [ 85%]
tests/show_breakout_test.py ..                                           [ 85%]
tests/show_ip_int_test.py ..........                                     [ 87%]
tests/show_platform_test.py .                                            [ 87%]
tests/sku_create_test.py .                                               [ 88%]
tests/synchronous_mode_test.py .                                         [ 88%]
tests/system_health_test.py ...                                          [ 88%]
tests/vlan_test.py ...................................                   [ 95%]
tests/vxlan_test.py ...........                                          [ 97%]
tests/watermarkstat_test.py ............                                 [100%]
----------- coverage: platform linux, python 3.7.3-final-0 -----------
Name                                          Stmts   Miss  Cover
-----------------------------------------------------------------
acl_loader/__init__.py                            0      0   100%
acl_loader/main.py                              539    364    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                                   193    114    41%
config/__init__.py                                0      0   100%
config/aaa.py                                   122     74    39%
config/chassis_modules.py                        18      1    94%
config/config_mgmt.py                           356    115    68%
config/console.py                               110      1    99%
config/feature.py                                59      1    98%
config/kdump.py                                  29     18    38%
config/kube.py                                   81      3    96%
config/main.py                                 2578   1566    39%
config/mlnx.py                                  124     85    31%
config/muxcable.py                              116     15    87%
config/nat.py                                   678    569    16%
config/utils.py                                   3      0   100%
config/vlan.py                                  163     17    90%
config/vxlan.py                                 202     65    68%
connect/__init__.py                               0      0   100%
connect/main.py                                  56     56     0%
consutil/__init__.py                              0      0   100%
consutil/lib.py                                 221      8    96%
consutil/main.py                                 73      3    96%
counterpoll/__init__.py                           0      0   100%
counterpoll/main.py                             173     86    50%
crm/__init__.py                                   0      0   100%
crm/main.py                                     368     21    94%
debug/__init__.py                                 0      0   100%
debug/main.py                                   153    153     0%
fdbutil/__init__.py                               0      0   100%
fdbutil/filter_fdb_entries.py                    79      7    91%
fwutil/__init__.py                                5      5     0%
fwutil/lib.py                                   465    465     0%
fwutil/log.py                                    45     45     0%
fwutil/main.py                                  243    243     0%
pcieutil/__init__.py                              0      0   100%
pcieutil/main.py                                166     65    61%
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                                   282     92    67%
psuutil/__init__.py                               0      0   100%
psuutil/main.py                                  66     66     0%
scripts/aclshow                                 127     13    90%
scripts/db_migrator.py                          310    310     0%
scripts/dropconfig                              219    104    53%
scripts/dropstat                                222     21    91%
scripts/dump_nat_entries.py                      12     12     0%
scripts/ecnconfig                               234     58    75%
scripts/fanshow                                  63     10    84%
scripts/fast-reboot-dump.py                     216    216     0%
scripts/gearboxutil                             131     21    84%
scripts/intfstat                                195     42    78%
scripts/intfutil                                304     13    96%
scripts/ipintutil                               174     18    90%
scripts/mellanox_buffer_migrator.py             140    140     0%
scripts/mmuconfig                               104     29    72%
scripts/neighbor_advertiser                     301    155    49%
scripts/pfcstat                                 157     23    85%
scripts/port2alias                               32      5    84%
scripts/portstat                                309     54    83%
scripts/psushow                                  60      9    85%
scripts/route_check.py                          230      5    98%
scripts/sfpshow                                 215     35    84%
scripts/sonic_sku_create.py                     592    413    30%
scripts/update_json.py                           35     35     0%
scripts/watermarkstat                           184     32    83%
sfputil/__init__.py                               0      0   100%
sfputil/main.py                                 342    342     0%
show/__init__.py                                  0      0   100%
show/acl.py                                      21     11    48%
show/bgp_common.py                              275     11    96%
show/bgp_frr_v4.py                               38     21    45%
show/bgp_frr_v6.py                               35     18    49%
show/bgp_quagga_v4.py                            21     21     0%
show/bgp_quagga_v6.py                            16     16     0%
show/chassis_modules.py                          73      7    90%
show/dropcounters.py                             25      1    96%
show/feature.py                                 105      1    99%
show/fgnhg.py                                   125      1    99%
show/gearbox.py                                  14      3    79%
show/interfaces/__init__.py                     278     88    68%
show/interfaces/portchannel.py                  102      6    94%
show/kdump.py                                    59     47    20%
show/kube.py                                     41      2    95%
show/main.py                                    712    391    45%
show/mlnx.py                                     80     62    22%
show/muxcable.py                                222     19    91%
show/nat.py                                      56     34    39%
show/platform.py                                 71     30    58%
show/processes.py                                16      7    56%
show/reboot_cause.py                             48      4    92%
show/sflow.py                                    59      5    92%
show/system_health.py                           179     46    74%
show/vlan.py                                     97      5    95%
show/vnet.py                                    181    164     9%
show/vxlan.py                                   226     89    61%
show/warm_restart.py                             94     84    11%
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                         416    416     0%
ssdutil/__init__.py                               0      0   100%
ssdutil/main.py                                  50     50     0%
utilities_common/__init__.py                      0      0   100%
utilities_common/bgp_util.py                    181     68    62%
utilities_common/cli.py                         326    109    67%
utilities_common/constants.py                     8      0   100%
utilities_common/db.py                           23      2    91%
utilities_common/intf_filter.py                  30     18    40%
utilities_common/multi_asic.py                   92      7    92%
utilities_common/netstat.py                      37     11    70%
utilities_common/platform_sfputil_helper.py      23     17    26%
utilities_common/util_base.py                    32     32     0%
watchdogutil/__init__.py                          0      0   100%
watchdogutil/main.py                             54     54     0%
-----------------------------------------------------------------
TOTAL                                         18244   9445    48%
Coverage HTML written to dir htmlcov
Coverage XML written to file coverage.xml


========================= 521 passed in 128.10 seconds =========================

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

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

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>
scripts/ipintutil Outdated Show resolved Hide resolved
@lgtm-com

This comment has been minimized.

scripts/ipintutil Outdated Show resolved Hide resolved
scripts/ipintutil Outdated Show resolved Hide resolved
scripts/ipintutil Outdated Show resolved Hide resolved
scripts/ipintutil Outdated Show resolved Hide resolved
utilities_common/cli.py Outdated Show resolved Hide resolved
utilities_common/multi_asic.py Outdated Show resolved Hide resolved
Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <arlakshm@microsoft.com>
Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <arlakshm@microsoft.com>
scripts/ipintutil Outdated Show resolved Hide resolved
scripts/ipintutil Outdated Show resolved Hide resolved
tests/mock_tables/mock_multi_asic.py Outdated Show resolved Hide resolved
tests/mock_tables/mock_multi_asic.py Outdated Show resolved Hide resolved
tests/mock_tables/mock_multi_asic.py Outdated Show resolved Hide resolved
'sudo ip link del Vlan100',
'sudo sysctl -w net.ipv6.conf.default.addr_gen_mode=1',
'sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1'

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this blank line

Copy link
Contributor

Choose a reason for hiding this comment

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

looks like we have an issue with using sysctl in docker, @jleveque ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. Good catch. Discussion is here: #1406. We need to figure out a solution.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jleveque , @prsunny
I am able to use the sysctl commands in the slave docker.

arlakshm@a0b00d89505a:/sonic/src/sonic-utilities$ sudo sysctl net.ipv6.conf.all.disable_ipv6
net.ipv6.conf.all.disable_ipv6 = 1
arlakshm@a0b00d89505a:/sonic/src/sonic-utilities$ sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0
net.ipv6.conf.all.disable_ipv6 = 0
arlakshm@a0b00d89505a:/sonic/src/sonic-utilities$ sudo sysctl net.ipv6.conf.all.disable_ipv6
net.ipv6.conf.all.disable_ipv6 = 0
arlakshm@a0b00d89505a:/sonic/src/sonic-utilities$ sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.all.disable_ipv6 = 1
arlakshm@a0b00d89505a:/sonic/src/sonic-utilities$ sudo sysctl net.ipv6.conf.all.disable_ipv6
net.ipv6.conf.all.disable_ipv6 = 1
arlakshm@a0b00d89505a:/sonic/src/sonic-utilities$

We do similar configuration for the ptf docker in sonic-mgmt

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to use 'netifaces' apis in the tests instead of mocking the data. If this might cause as issue, let me know I can rewrite the tests

Copy link
Contributor

Choose a reason for hiding this comment

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

@jleveque , @prsunny
I am able to use the sysctl commands in the slave docker

Interesting. I wonder what the difference is compared to #1406. Maybe because Azure Pipelines doesn't run the container in privileged mode?

Copy link
Contributor

Choose a reason for hiding this comment

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

@arlakshm: I have confirmed that "privileged" mode is the difference. However, please see the comments here. Tests which rely on interacting with the system should be reserved for sonic-mgmt tests. For unit testing, you should simply mock any system calls and return contrived output that you can test against.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jleveque, update the unit tests to use mock data in the latest commit.

tests/show_ip_int_test.py Outdated Show resolved Hide resolved
tests/show_ip_int_test.py Outdated Show resolved Hide resolved
tests/show_ip_int_test.py Outdated Show resolved Hide resolved
tests/show_ip_int_test.py Outdated Show resolved Hide resolved
@lgtm-com
Copy link

lgtm-com bot commented Feb 8, 2021

This pull request introduces 3 alerts when merging 67de06f into 794cdd3 - view on LGTM.com

new alerts:

  • 2 for Unused import
  • 1 for Except block handles 'BaseException'

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.

Also please fix LGTM alerts

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

arlakshm commented Feb 8, 2021

Also please fix LGTM alerts

Fixed the LGTMs warnings

tests/mock_tables/mock_multi_asic.py Outdated Show resolved Hide resolved
tests/mock_tables/mock_multi_asic.py Outdated Show resolved Hide resolved
tests/mock_tables/config_db.json Show resolved Hide resolved
tests/show_ip_int_test.py Outdated Show resolved Hide resolved
Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <arlakshm@microsoft.com>
Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <arlakshm@microsoft.com>
@arlakshm arlakshm merged commit 23fa39c into sonic-net:master Feb 11, 2021
@arlakshm arlakshm deleted the masic_show_ip_int branch February 11, 2021 00:05
arlakshm added a commit to sonic-net/sonic-buildimage that referenced this pull request Feb 23, 2021
show ip interfaces is enhanced recently to support multi ASIC platforms in this PR- sonic-net/sonic-utilities#1396 .
The ipintutil script as to run as sudo user, to get the ip interface from each namespace.
Add this script to the sudoer file so that show ip interface command is available for user with read-only permissions

Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <arlakshm@microsoft.com>
anand-kumar-subramanian pushed a commit to anand-kumar-subramanian/sonic-utilities that referenced this pull request Mar 2, 2021
Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <arlakshm@microsoft.com>
- What I did
The PR has changes to support command show ip interface for multi asic platform.

- How I did it
The following changes are done in this PR

The code for show ip interface has been moved from show/main.py to scripts\ipintutil
  -  Modify the code to support both single and multi asic platform
  - To do this the library pyroute2 is used to get interface information in each namespace
  - Add the following options for multi asic
     [-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

- Add unit tests for single and multi asic
from tabulate import tabulate

from sonic_py_common import multi_asic
from swsssdk import ConfigDBConnector, SonicDBConfig
Copy link
Contributor

Choose a reason for hiding this comment

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

swsssdk is deprecated largely in sonic-utilities. Could you adapt the new ConfigDBConnector as in latest code?

lguohan pushed a commit to sonic-net/sonic-buildimage that referenced this pull request Mar 14, 2021
show ip interfaces is enhanced recently to support multi ASIC platforms in this PR- sonic-net/sonic-utilities#1396 .
The ipintutil script as to run as sudo user, to get the ip interface from each namespace.
Add this script to the sudoer file so that show ip interface command is available for user with read-only permissions

Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <arlakshm@microsoft.com>
carl-nokia pushed a commit to carl-nokia/sonic-buildimage that referenced this pull request Aug 7, 2021
show ip interfaces is enhanced recently to support multi ASIC platforms in this PR- sonic-net/sonic-utilities#1396 .
The ipintutil script as to run as sudo user, to get the ip interface from each namespace.
Add this script to the sudoer file so that show ip interface command is available for user with read-only permissions

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

This PR could not be cleanly cherry-pick to 202012. Please submit another PR.

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.

5 participants