Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 3 additions & 18 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,23 +260,16 @@ def parse_png(png, hname, dpg_ecmp_content = None):
if child.tag == str(QName(ns, "Devices")):
for device in child.findall(str(QName(ns, "Device"))):
(lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, name, hwsku, d_type, deployment_id, cluster, d_subtype) = parse_device(device)
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

device_data = {'lo_addr': lo_prefix, 'type': d_type, 'mgmt_addr': mgmt_prefix, 'hwsku': hwsku}
if cluster != None:
device_data['cluster'] = cluster
if deployment_id != None:
device_data['deployment_id'] = deployment_id
if lo_prefix != None:
device_data['lo_addr'] = lo_prefix
if lo_prefix_v6 != None:
device_data['lo_addr_v6'] = lo_prefix_v6
if mgmt_prefix != None:
device_data['mgmt_addr'] = mgmt_prefix
if mgmt_prefix_v6 != None:
device_data['mgmt_addr_v6'] = mgmt_prefix_v6
if d_type != None:
device_data['type'] = d_type
if d_subtype != None:
device_data['subtype'] = d_subtype
devices[name] = device_data
Expand Down Expand Up @@ -403,23 +396,15 @@ def parse_asic_png(png, asic_name, hostname):
if child.tag == str(QName(ns, "Devices")):
for device in child.findall(str(QName(ns, "Device"))):
(lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, name, hwsku, d_type, deployment_id, cluster, _) = parse_device(device)
device_data = {}
if hwsku != None:
device_data['hwsku'] = hwsku
device_data = {'lo_addr': lo_prefix, 'type': d_type, 'mgmt_addr': mgmt_prefix, 'hwsku': hwsku}
if cluster != None:
device_data['cluster'] = cluster
if deployment_id != None:
device_data['deployment_id'] = deployment_id
if lo_prefix != None:
device_data['lo_addr'] = lo_prefix
if lo_prefix_v6 != None:
device_data['lo_addr_v6'] = lo_prefix_v6
if mgmt_prefix != None:
device_data['mgmt_addr'] = mgmt_prefix
if mgmt_prefix_v6 != None:
device_data['mgmt_addr_v6'] = mgmt_prefix_v6
if d_type != None:
device_data['type'] = d_type
devices[name] = device_data

return (neighbors, devices, port_speeds)
Expand Down
2 changes: 1 addition & 1 deletion src/sonic-config-engine/tests/test_multinpu_cfggen.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def test_frontend_asic_device_neigh_metadata(self):
output = json.loads(self.run_script(argument))
print(output)
self.assertDictEqual(output, \
{'01T2': {'mgmt_addr': '89.139.132.40', 'hwsku': 'VM', 'type': 'SpineRouter'},
{'01T2': {'lo_addr': None, 'type': 'SpineRouter', 'mgmt_addr': '89.139.132.40', 'hwsku': 'VM'},
'ASIC3': {'lo_addr_v6': '::/0', 'mgmt_addr': '0.0.0.0/0', 'hwsku': 'multi-npu-asic', 'lo_addr': '0.0.0.0/0', 'type': 'Asic', 'mgmt_addr_v6': '::/0'},
'ASIC2': {'lo_addr_v6': '::/0', 'mgmt_addr': '0.0.0.0/0', 'hwsku': 'multi-npu-asic', 'lo_addr': '0.0.0.0/0', 'type': 'Asic', 'mgmt_addr_v6': '::/0'}})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ module sonic-device_neighbor_metadata {
type union {
type inet:ipv4-prefix;
type inet:ipv4-address;
type string {
pattern "None";
}
}
}

Expand All @@ -68,6 +71,9 @@ module sonic-device_neighbor_metadata {
type union {
type inet:ipv4-prefix;
type inet:ipv4-address;
type string {
pattern "None";
}
}
}

Expand Down