Skip to content

Commit

Permalink
[show] Fix 'show int neigh expected' (sonic-net#1189)
Browse files Browse the repository at this point in the history
`show int neighbor expected` only show one member interface for
portchannel with multiple member interfaces. This is because
`device2interface_dict` only stores mapping from one device to one
port.

Signed-off-by: Longxiang Lyu <lolv@microsoft.com>
  • Loading branch information
lolyu committed Nov 8, 2020
1 parent 29e4469 commit 4585be1
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,34 +695,38 @@ def expected(interfacename):
print("DEVICE_NEIGHBOR_METADATA information is not present.")
return

#Swap Key and Value from interface: name to name: interface
device2interface_dict = {}
for port in natsorted(neighbor_dict.keys()):
temp_port = port
if get_interface_mode() == "alias":
port = iface_alias_converter.name_to_alias(port)
neighbor_dict[port] = neighbor_dict.pop(temp_port)
device2interface_dict[neighbor_dict[port]['name']] = {'localPort': port, 'neighborPort': neighbor_dict[port]['port']}

header = ['LocalPort', 'Neighbor', 'NeighborPort', 'NeighborLoopback', 'NeighborMgmt', 'NeighborType']
body = []
if interfacename:
for device in natsorted(neighbor_metadata_dict.keys()):
if device2interface_dict[device]['localPort'] == interfacename:
body.append([device2interface_dict[device]['localPort'],
device,
device2interface_dict[device]['neighborPort'],
neighbor_metadata_dict[device]['lo_addr'],
neighbor_metadata_dict[device]['mgmt_addr'],
neighbor_metadata_dict[device]['type']])
else:
for device in natsorted(neighbor_metadata_dict.keys()):
body.append([device2interface_dict[device]['localPort'],
try:
device = neighbor_dict[interfacename]['name']
body.append([interfacename,
device,
device2interface_dict[device]['neighborPort'],
neighbor_dict[interfacename]['port'],
neighbor_metadata_dict[device]['lo_addr'],
neighbor_metadata_dict[device]['mgmt_addr'],
neighbor_metadata_dict[device]['type']])
except KeyError:
click.echo("No neighbor information available for interface {}".format(interfacename))
return
else:
for port in natsorted(neighbor_dict.keys()):
try:
device = neighbor_dict[port]['name']
body.append([port,
device,
neighbor_dict[port]['port'],
neighbor_metadata_dict[device]['lo_addr'],
neighbor_metadata_dict[device]['mgmt_addr'],
neighbor_metadata_dict[device]['type']])
except KeyError:
pass

click.echo(tabulate(body, header))

Expand Down

0 comments on commit 4585be1

Please sign in to comment.