Skip to content

Commit

Permalink
[master]Fix show ip interface neighbor info not correct when add seco…
Browse files Browse the repository at this point in the history
…nd ip (sonic-net#1134)

**- What I did**
Fix sonic-net/sonic-buildimage#5423
**- How I did it**
store neighbor info into array for later showing.
**- How to verify it**
config interface ip add Ethernet49 xxx secondary many times
show ip interface
**- Previous command output (if the output of a command-line utility has changed)**
```
root@sonic:/home/admin# show ip interfaces
Interface        Master    IPv4 address/mask    Admin/Oper    BGP Neighbor    Neighbor IP
---------------  --------  -------------------  ------------  --------------  -------------
Ethernet49                 10.0.0.96/31         up/up         N/A             N/A
                           10.10.49.1/24
```
**- New command output (if the output of a command-line utility has changed)**
```
root@sonic:/usr/lib/python2.7/dist-packages/show# show ip interfaces
Interface    Master           IPv4 address/mask    Admin/Oper    BGP Neighbor    Neighbor IP
-----------  ---------------  -------------------  ------------  --------------  -------------
Ethernet49                    10.0.0.96/31         up/up         ARISTA21T0      10.0.0.97
                              10.10.49.1/24        up/up         N/A             N/A
```

Co-authored-by: shaoshouping <shaoshouping@ruijie.com.cn>
  • Loading branch information
tim-rj and shaoshouping authored Oct 7, 2020
1 parent 6e58dff commit 068f37f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ def interfaces():

if netifaces.AF_INET in ipaddresses:
ifaddresses = []
neighbor_info = []
for ipaddr in ipaddresses[netifaces.AF_INET]:
neighbor_name = 'N/A'
neighbor_ip = 'N/A'
Expand All @@ -732,6 +733,7 @@ def interfaces():
neighbor_ip = bgp_peer[local_ip][1]
except Exception:
pass
neighbor_info.append([neighbor_name, neighbor_ip])

if len(ifaddresses) > 0:
admin = get_if_admin_state(iface)
Expand All @@ -743,10 +745,12 @@ def interfaces():
if clicommon.get_interface_naming_mode() == "alias":
iface = iface_alias_converter.name_to_alias(iface)

data.append([iface, master, ifaddresses[0][1], admin + "/" + oper, neighbor_name, neighbor_ip])
data.append([iface, master, ifaddresses[0][1], admin + "/" + oper, neighbor_info[0][0], neighbor_info[0][1]])
neighbor_info.pop(0)

for ifaddr in ifaddresses[1:]:
data.append(["", "", ifaddr[1], ""])
for ifaddr in ifaddresses[1:]:
data.append(["", "", ifaddr[1], admin + "/" + oper, neighbor_info[0][0], neighbor_info[0][1]])
neighbor_info.pop(0)

print(tabulate(data, header, tablefmt="simple", stralign='left', missingval=""))

Expand Down

0 comments on commit 068f37f

Please sign in to comment.