Skip to content

Commit

Permalink
[minigraph] populate bgp_asn in DEVICE_METADATA only if it is valid. (s…
Browse files Browse the repository at this point in the history
…onic-net#19413)

What I did:-
Populate bgp_asn in DEVICE_METADATA only if is present/valid.

Why I did:
Without this it causes Yang Validation failure for Systems that are Pure
L2/Chassis Supervisor (no BGP) as Yang expects bgp_asn as valid
as_number

---------

Signed-off-by: Abhishek Dosi <[email protected]>
  • Loading branch information
abdosi authored Jul 2, 2024
1 parent 0114373 commit dda96cf
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2120,7 +2120,6 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw

results = {}
results['DEVICE_METADATA'] = {'localhost': {
'bgp_asn': bgp_asn,
'region': region,
'cloudtype': cloudtype,
'docker_routing_config_mode': docker_routing_config_mode,
Expand All @@ -2132,6 +2131,9 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
}
}

if bgp_asn:
results['DEVICE_METADATA']['localhost']['bgp_asn'] = bgp_asn

if chassis_hostname:
results['DEVICE_METADATA']['localhost']['chassis_hostname'] = chassis_hostname

Expand Down
9 changes: 1 addition & 8 deletions src/sonic-config-engine/tests/sample-voq-graph.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
<DeviceMiniGraph xmlns="Microsoft.Search.Autopilot.Evolution" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<CpgDec>
<PeeringSessions/>
<Routers xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution">
<a:BGPRouterDeclaration>
<a:ASN>65100</a:ASN>
<a:Hostname>linecard-1</a:Hostname>
<a:Peers/>
<a:RouteMaps/>
</a:BGPRouterDeclaration>
</Routers>
<Routers xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution"/>
</CpgDec>
<DpgDec>
<DeviceDataPlaneInfo>
Expand Down
5 changes: 0 additions & 5 deletions src/sonic-config-engine/tests/test_chassis_cfggen.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,6 @@ def test_device_metadata(self):
output = json.loads(self.run_script(argument))
print(output['localhost'])
self.assertDictEqual(output['localhost'], {
'bgp_asn': None,
'region': 'test',
'cloudtype': 'Public',
'docker_routing_config_mode': 'separated',
Expand Down Expand Up @@ -910,7 +909,6 @@ def test_device_metadata(self):
print(output['localhost'])
self.assertDictEqual(output['localhost'],
{
"bgp_asn": None,
"region": "test",
"cloudtype": "Public",
"docker_routing_config_mode": "separated",
Expand Down Expand Up @@ -938,7 +936,6 @@ def test_device_metadata_for_namespace(self):
print(output['localhost'])
self.assertDictEqual(output['localhost'],
{
"bgp_asn": None,
"region": "test",
"cloudtype": None,
"docker_routing_config_mode": "separated",
Expand Down Expand Up @@ -1046,7 +1043,6 @@ def test_device_metadata(self):
print(output['localhost'])
self.assertDictEqual(output['localhost'],
{
"bgp_asn": None,
"region": "test",
"cloudtype": "Public",
"docker_routing_config_mode": "separated",
Expand Down Expand Up @@ -1074,7 +1070,6 @@ def test_device_metadata_for_namespace(self):
print(output['localhost'])
self.assertDictEqual(output['localhost'],
{
"bgp_asn": None,
"region": "test",
"cloudtype": None,
"docker_routing_config_mode": "separated",
Expand Down

0 comments on commit dda96cf

Please sign in to comment.