Skip to content

fix show interface neighbor exp issue#12468

Closed
jcaiMR wants to merge 2 commits intosonic-net:masterfrom
jcaiMR:yang/device_neighbor_fix
Closed

fix show interface neighbor exp issue#12468
jcaiMR wants to merge 2 commits intosonic-net:masterfrom
jcaiMR:yang/device_neighbor_fix

Conversation

@jcaiMR
Copy link
Copy Markdown
Contributor

@jcaiMR jcaiMR commented Oct 21, 2022

Why I did it

With the commit of #11894.
device neighbor metadata in config_db.json changed a little bit when "lo_addr"/"mgmt_addr" are None.

dfa09cf3-b9f5-4da1-b998-ff750ef6ab12

CLI parse code for "show interface neighbor expected" is not strong enough to handle None case.
It always assume 'lo_addr' and 'mgmt_addr' exists, and will finally cause KeyError, show command will not print the information.

for port in natsorted(list(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

How I did it

Since in code many places don't check the existence of 'lo_addr' and 'mgmt_addr', for safety always add 'lo_addr' and 'mgmt_addr' in minigraph.py

How to verify it

"show interface neighbor expected" with fix image

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

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106
  • 202111
  • 202205

fixes #12301

@jcaiMR jcaiMR requested a review from qiluo-msft as a code owner October 21, 2022 13:04
@qiluo-msft qiluo-msft requested a review from ganglyu October 21, 2022 21:24
device_data = {}
if hwsku != None:
device_data['hwsku'] = hwsku
# 'lo_addr', 'mgmt_addr', 'type', 'hwsku' are must fields in config db
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are they must fields?
And we should use "mandatory true" in yang models for must field.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for comments, maybe can't say must fields. Seems for historical reason, code never check if 'lo_addr' and 'mgmt_addr' keys are exists or not. In minigraph, 'lo_addr' and 'mgmt_addr' sometime may not exists, but after deploy mg we generated config_db.json, code parse config_db.json will access 'lo_addr' and 'mgmt_addr' without confirm if keys are exists.
Another fix may find all places referring 'lo_addr' and 'mgmt_addr', but they are many places and for safety I decided to change the behavior back.

The description "# 'lo_addr', ..." here seems a little bit confuse, I will remove this description.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When 'lo_addr' and 'mgmt_addr' keys do not exists in minigraph, the value in config_db will be ‘None’.
How does consumer for this table handle this value?

Copy link
Copy Markdown
Contributor Author

@jcaiMR jcaiMR Oct 26, 2022

Choose a reason for hiding this comment

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

minigraph.py will first save 'lo_addr':None to DEVICE_NEIGHBOE_METADATA

if asic_name is None:
        results['DEVICE_NEIGHBOR_METADATA'] = { key:devices[key] for key in devices if key.lower() != hostname.lower() }
    else:
        results['DEVICE_NEIGHBOR_METADATA'] = { key:devices[key] for key in devices if key in {device['name'] for device in neighbors.values()} }

Then results to json will treat None as "None" in final config_db.json, and in show cli python code, it will access the value in config_db.json, that is "lo_addr":"None". So the final show result is something like this:

admin@str-dx010-acs-5:~$ show interface neighbor exp
LocalPort    Neighbor    NeighborPort    NeighborLoopback    NeighborMgmt    NeighborType
-----------  ----------  --------------  ------------------  --------------  --------------
Ethernet112  ARISTA01T1  Ethernet1       None                10.64.247.220   LeafRouter
Ethernet116  ARISTA02T1  Ethernet1       None                10.64.247.221   LeafRouter
Ethernet120  ARISTA03T1  Ethernet1       None                10.64.247.222   LeafRouter
Ethernet124  ARISTA04T1  Ethernet1       None                10.64.247.223   LeafRouter

@StormLiangMS
Copy link
Copy Markdown
Contributor

/azp run sonic-buildimage

@azure-pipelines
Copy link
Copy Markdown

No pipelines are associated with this pull request.

@jcaiMR jcaiMR requested a review from ganglyu October 26, 2022 06:05
@jcaiMR
Copy link
Copy Markdown
Contributor Author

jcaiMR commented Oct 31, 2022

Hold on the commit, team make a discussion to have another solution which will make code change in sonic-utilities repo.
Related PR:
https://github.com/sonic-net/sonic-utilities/pull/2465/files

@jcaiMR
Copy link
Copy Markdown
Contributor Author

jcaiMR commented Nov 15, 2022

@jcaiMR jcaiMR closed this Nov 15, 2022
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.

show interfaces neighbor expected returns empty output

4 participants