[sonic-cfggen]: Fix generated deployment_id (#10154)
Why I did it Config db schema generated by minigraph can’t pass yang validation, deployment_id can’t be none for yang validation. How I did it Update minigraph.py, skip deployment_id with None value How to verify it Run UT for sonic-config-enginue. Run command 'sonic-cfggen -m tests/multi_npu_data/sample-minigraph-noportchannel.xml -p tests/multi_npu_data/sample_port_config-3.ini -n asic3 --print-data'. Signed-off-by: Gang Lv ganglv@microsoft.com
This commit is contained in:
parent
9e7dbffca2
commit
d224315292
@ -1281,7 +1281,6 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
|
||||
results = {}
|
||||
results['DEVICE_METADATA'] = {'localhost': {
|
||||
'bgp_asn': bgp_asn,
|
||||
'deployment_id': deployment_id,
|
||||
'region': region,
|
||||
'cloudtype': cloudtype,
|
||||
'docker_routing_config_mode': docker_routing_config_mode,
|
||||
@ -1292,6 +1291,9 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
|
||||
}
|
||||
}
|
||||
|
||||
if deployment_id is not None:
|
||||
results['DEVICE_METADATA']['localhost']['deployment_id'] = deployment_id
|
||||
|
||||
cluster = [devices[key] for key in devices if key.lower() == hostname.lower()][0].get('cluster', "")
|
||||
if cluster:
|
||||
results['DEVICE_METADATA']['localhost']['cluster'] = cluster
|
||||
|
347
src/sonic-config-engine/tests/t0-sample-deployment-id.xml
Normal file
347
src/sonic-config-engine/tests/t0-sample-deployment-id.xml
Normal file
@ -0,0 +1,347 @@
|
||||
<DeviceMiniGraph xmlns="Microsoft.Search.Autopilot.Evolution" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<CpgDec>
|
||||
<IsisRouters xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution"/>
|
||||
<PeeringSessions>
|
||||
<BGPSession>
|
||||
<MacSec>false</MacSec>
|
||||
<StartRouter>switch-t0</StartRouter>
|
||||
<StartPeer>10.0.0.56</StartPeer>
|
||||
<EndRouter>ARISTA01T1</EndRouter>
|
||||
<EndPeer>10.0.0.57</EndPeer>
|
||||
<Multihop>1</Multihop>
|
||||
<HoldTime>180</HoldTime>
|
||||
<KeepAliveTime>60</KeepAliveTime>
|
||||
</BGPSession>
|
||||
<BGPSession>
|
||||
<StartRouter>switch-t0</StartRouter>
|
||||
<StartPeer>FC00::71</StartPeer>
|
||||
<EndRouter>ARISTA01T1</EndRouter>
|
||||
<EndPeer>FC00::72</EndPeer>
|
||||
<Multihop>1</Multihop>
|
||||
<HoldTime>180</HoldTime>
|
||||
<KeepAliveTime>60</KeepAliveTime>
|
||||
</BGPSession>
|
||||
<BGPSession>
|
||||
<MacSec>false</MacSec>
|
||||
<StartRouter>switch-t0</StartRouter>
|
||||
<StartPeer>10.0.0.58</StartPeer>
|
||||
<EndRouter>ARISTA02T1</EndRouter>
|
||||
<EndPeer>10.0.0.59</EndPeer>
|
||||
<Multihop>1</Multihop>
|
||||
<HoldTime>180</HoldTime>
|
||||
<KeepAliveTime>60</KeepAliveTime>
|
||||
</BGPSession>
|
||||
<BGPSession>
|
||||
<StartRouter>switch-t0</StartRouter>
|
||||
<StartPeer>FC00::75</StartPeer>
|
||||
<EndRouter>ARISTA02T1</EndRouter>
|
||||
<EndPeer>FC00::76</EndPeer>
|
||||
<Multihop>1</Multihop>
|
||||
<HoldTime>180</HoldTime>
|
||||
<KeepAliveTime>60</KeepAliveTime>
|
||||
</BGPSession>
|
||||
<BGPSession>
|
||||
<MacSec>false</MacSec>
|
||||
<StartRouter>switch-t0</StartRouter>
|
||||
<StartPeer>10.0.0.60</StartPeer>
|
||||
<EndRouter>ARISTA03T1</EndRouter>
|
||||
<EndPeer>10.0.0.61</EndPeer>
|
||||
<Multihop>1</Multihop>
|
||||
<HoldTime>180</HoldTime>
|
||||
<KeepAliveTime>60</KeepAliveTime>
|
||||
</BGPSession>
|
||||
<BGPSession>
|
||||
<StartRouter>switch-t0</StartRouter>
|
||||
<StartPeer>FC00::79</StartPeer>
|
||||
<EndRouter>ARISTA03T1</EndRouter>
|
||||
<EndPeer>FC00::7A</EndPeer>
|
||||
<Multihop>1</Multihop>
|
||||
<HoldTime>180</HoldTime>
|
||||
<KeepAliveTime>60</KeepAliveTime>
|
||||
</BGPSession>
|
||||
<BGPSession>
|
||||
<MacSec>false</MacSec>
|
||||
<StartRouter>switch-t0</StartRouter>
|
||||
<StartPeer>10.0.0.62</StartPeer>
|
||||
<EndRouter>ARISTA04T1</EndRouter>
|
||||
<EndPeer>10.0.0.63</EndPeer>
|
||||
<Multihop>1</Multihop>
|
||||
<HoldTime>180</HoldTime>
|
||||
<KeepAliveTime>60</KeepAliveTime>
|
||||
</BGPSession>
|
||||
<BGPSession>
|
||||
<StartRouter>switch-t0</StartRouter>
|
||||
<StartPeer>FC00::7D</StartPeer>
|
||||
<EndRouter>ARISTA04T1</EndRouter>
|
||||
<EndPeer>FC00::7E</EndPeer>
|
||||
<Multihop>1</Multihop>
|
||||
<HoldTime>180</HoldTime>
|
||||
<KeepAliveTime>60</KeepAliveTime>
|
||||
</BGPSession>
|
||||
</PeeringSessions>
|
||||
<Routers xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution">
|
||||
<a:BGPRouterDeclaration>
|
||||
<a:ASN>65100</a:ASN>
|
||||
<a:Hostname>switch-t0</a:Hostname>
|
||||
<a:Peers>
|
||||
<BGPPeer>
|
||||
<Address>10.0.0.57</Address>
|
||||
<RouteMapIn i:nil="true"/>
|
||||
<RouteMapOut i:nil="true"/>
|
||||
<Vrf i:nil="true"/>
|
||||
</BGPPeer>
|
||||
<BGPPeer>
|
||||
<Address>10.0.0.59</Address>
|
||||
<RouteMapIn i:nil="true"/>
|
||||
<RouteMapOut i:nil="true"/>
|
||||
<Vrf i:nil="true"/>
|
||||
</BGPPeer>
|
||||
<BGPPeer>
|
||||
<Address>10.0.0.61</Address>
|
||||
<RouteMapIn i:nil="true"/>
|
||||
<RouteMapOut i:nil="true"/>
|
||||
<Vrf i:nil="true"/>
|
||||
</BGPPeer>
|
||||
<BGPPeer>
|
||||
<Address>10.0.0.63</Address>
|
||||
<RouteMapIn i:nil="true"/>
|
||||
<RouteMapOut i:nil="true"/>
|
||||
<Vrf i:nil="true"/>
|
||||
</BGPPeer>
|
||||
<BGPPeer>
|
||||
<Address>10.1.0.32</Address>
|
||||
<a:Name>BGPSLBPassive</a:Name>
|
||||
<a:PeersRange>10.10.10.10/26;100.100.100.100/26</a:PeersRange>
|
||||
</BGPPeer>
|
||||
</a:Peers>
|
||||
<a:RouteMaps/>
|
||||
</a:BGPRouterDeclaration>
|
||||
<a:BGPRouterDeclaration>
|
||||
<a:ASN>64600</a:ASN>
|
||||
<a:Hostname>ARISTA01T1</a:Hostname>
|
||||
<a:RouteMaps/>
|
||||
</a:BGPRouterDeclaration>
|
||||
<a:BGPRouterDeclaration>
|
||||
<a:ASN>64600</a:ASN>
|
||||
<a:Hostname>ARISTA02T1</a:Hostname>
|
||||
<a:RouteMaps/>
|
||||
</a:BGPRouterDeclaration>
|
||||
<a:BGPRouterDeclaration>
|
||||
<a:ASN>64600</a:ASN>
|
||||
<a:Hostname>ARISTA03T1</a:Hostname>
|
||||
<a:RouteMaps/>
|
||||
</a:BGPRouterDeclaration>
|
||||
<a:BGPRouterDeclaration>
|
||||
<a:ASN>64600</a:ASN>
|
||||
<a:Hostname>ARISTA04T1</a:Hostname>
|
||||
<a:RouteMaps/>
|
||||
</a:BGPRouterDeclaration>
|
||||
</Routers>
|
||||
</CpgDec>
|
||||
<DpgDec>
|
||||
<DeviceDataPlaneInfo>
|
||||
<IPSecTunnels/>
|
||||
<LoopbackIPInterfaces xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution">
|
||||
<a:LoopbackIPInterface>
|
||||
<Name>HostIP</Name>
|
||||
<AttachTo>Loopback0</AttachTo>
|
||||
<a:Prefix xmlns:b="Microsoft.Search.Autopilot.Evolution">
|
||||
<b:IPPrefix>10.1.0.32/32</b:IPPrefix>
|
||||
</a:Prefix>
|
||||
<a:PrefixStr>10.1.0.32/32</a:PrefixStr>
|
||||
</a:LoopbackIPInterface>
|
||||
<a:LoopbackIPInterface>
|
||||
<Name>HostIP1</Name>
|
||||
<AttachTo>Loopback0</AttachTo>
|
||||
<a:Prefix xmlns:b="Microsoft.Search.Autopilot.Evolution">
|
||||
<b:IPPrefix>FC00:1::32/128</b:IPPrefix>
|
||||
</a:Prefix>
|
||||
<a:PrefixStr>FC00:1::32/128</a:PrefixStr>
|
||||
</a:LoopbackIPInterface>
|
||||
</LoopbackIPInterfaces>
|
||||
<ManagementIPInterfaces xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution">
|
||||
<a:ManagementIPInterface>
|
||||
<Name>HostIP</Name>
|
||||
<AttachTo>eth0</AttachTo>
|
||||
<a:Prefix xmlns:b="Microsoft.Search.Autopilot.Evolution">
|
||||
<b:IPPrefix>10.0.0.100/24</b:IPPrefix>
|
||||
</a:Prefix>
|
||||
<a:PrefixStr>10.0.0.100/24</a:PrefixStr>
|
||||
</a:ManagementIPInterface>
|
||||
</ManagementIPInterfaces>
|
||||
<ManagementVIPInterfaces xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution"/>
|
||||
<MplsInterfaces/>
|
||||
<MplsTeInterfaces/>
|
||||
<RsvpInterfaces/>
|
||||
<Hostname>switch-t0</Hostname>
|
||||
<PortChannelInterfaces>
|
||||
<PortChannel>
|
||||
<Name>PortChannel01</Name>
|
||||
<AttachTo>fortyGigE0/112</AttachTo>
|
||||
<SubInterface/>
|
||||
</PortChannel>
|
||||
<PortChannel>
|
||||
<Name>PortChannel02</Name>
|
||||
<AttachTo>fortyGigE0/116</AttachTo>
|
||||
<SubInterface/>
|
||||
</PortChannel>
|
||||
<PortChannel>
|
||||
<Name>PortChannel03</Name>
|
||||
<AttachTo>fortyGigE0/120</AttachTo>
|
||||
<SubInterface/>
|
||||
</PortChannel>
|
||||
<PortChannel>
|
||||
<Name>PortChannel04</Name>
|
||||
<AttachTo>fortyGigE0/124</AttachTo>
|
||||
<SubInterface/>
|
||||
</PortChannel>
|
||||
</PortChannelInterfaces>
|
||||
<VlanInterfaces>
|
||||
<VlanInterface>
|
||||
<Name>Vlan1000</Name>
|
||||
<AttachTo>fortyGigE0/4;fortyGigE0/8;fortyGigE0/12;fortyGigE0/16;fortyGigE0/20;fortyGigE0/24;fortyGigE0/28;fortyGigE0/32;fortyGigE0/36;fortyGigE0/40;fortyGigE0/44;fortyGigE0/48;fortyGigE0/52;fortyGigE0/56;fortyGigE0/60;fortyGigE0/64;fortyGigE0/68;fortyGigE0/72;fortyGigE0/76;fortyGigE0/80;fortyGigE0/84;fortyGigE0/88;fortyGigE0/92;fortyGigE0/96</AttachTo>
|
||||
<NoDhcpRelay>False</NoDhcpRelay>
|
||||
<StaticDHCPRelay>0.0.0.0/0</StaticDHCPRelay>
|
||||
<Type i:nil="true"/>
|
||||
<DhcpRelays>192.0.0.1;192.0.0.2</DhcpRelays>
|
||||
<VlanID>1000</VlanID>
|
||||
<Tag>1000</Tag>
|
||||
<Subnets>192.168.0.0/27</Subnets>
|
||||
</VlanInterface>
|
||||
</VlanInterfaces>
|
||||
<IPInterfaces>
|
||||
<IPInterface>
|
||||
<Name i:nil="true"/>
|
||||
<AttachTo>PortChannel01</AttachTo>
|
||||
<Prefix>10.0.0.56/31</Prefix>
|
||||
</IPInterface>
|
||||
<IPInterface>
|
||||
<Name i:Name="true"/>
|
||||
<AttachTo>PortChannel01</AttachTo>
|
||||
<Prefix>FC00::71/126</Prefix>
|
||||
</IPInterface>
|
||||
<IPInterface>
|
||||
<Name i:nil="true"/>
|
||||
<AttachTo>PortChannel02</AttachTo>
|
||||
<Prefix>10.0.0.58/31</Prefix>
|
||||
</IPInterface>
|
||||
<IPInterface>
|
||||
<Name i:Name="true"/>
|
||||
<AttachTo>PortChannel02</AttachTo>
|
||||
<Prefix>FC00::75/126</Prefix>
|
||||
</IPInterface>
|
||||
<IPInterface>
|
||||
<Name i:nil="true"/>
|
||||
<AttachTo>PortChannel03</AttachTo>
|
||||
<Prefix>10.0.0.60/31</Prefix>
|
||||
</IPInterface>
|
||||
<IPInterface>
|
||||
<Name i:Name="true"/>
|
||||
<AttachTo>PortChannel03</AttachTo>
|
||||
<Prefix>FC00::79/126</Prefix>
|
||||
</IPInterface>
|
||||
<IPInterface>
|
||||
<Name i:nil="true"/>
|
||||
<AttachTo>PortChannel04</AttachTo>
|
||||
<Prefix>10.0.0.62/31</Prefix>
|
||||
</IPInterface>
|
||||
<IPInterface>
|
||||
<Name i:Name="true"/>
|
||||
<AttachTo>PortChannel04</AttachTo>
|
||||
<Prefix>FC00::7D/126</Prefix>
|
||||
</IPInterface>
|
||||
<IPInterface>
|
||||
<Name i:nil="true"/>
|
||||
<AttachTo>Vlan1000</AttachTo>
|
||||
<Prefix>192.168.0.1/27</Prefix>
|
||||
</IPInterface>
|
||||
</IPInterfaces>
|
||||
<DataAcls/>
|
||||
<AclInterfaces>
|
||||
<AclInterface>
|
||||
<AttachTo>PortChannel01;PortChannel02;PortChannel03;PortChannel04</AttachTo>
|
||||
<InAcl>DataAcl</InAcl>
|
||||
<Type>DataPlane</Type>
|
||||
</AclInterface>
|
||||
<AclInterface>
|
||||
<AttachTo>SNMP</AttachTo>
|
||||
<InAcl>SNMP_ACL</InAcl>
|
||||
<Type>SNMP</Type>
|
||||
</AclInterface>
|
||||
</AclInterfaces>
|
||||
<DownstreamSummaries/>
|
||||
<DownstreamSummarySet xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution"/>
|
||||
</DeviceDataPlaneInfo>
|
||||
</DpgDec>
|
||||
<PngDec>
|
||||
<DeviceInterfaceLinks>
|
||||
<DeviceLinkBase>
|
||||
<ElementType>DeviceInterfaceLink</ElementType>
|
||||
<EndDevice>ARISTA01T1</EndDevice>
|
||||
<EndPort>Ethernet1/1</EndPort>
|
||||
<StartDevice>switch-t0</StartDevice>
|
||||
<StartPort>fortyGigE0/112</StartPort>
|
||||
</DeviceLinkBase>
|
||||
<DeviceLinkBase>
|
||||
<ElementType>DeviceInterfaceLink</ElementType>
|
||||
<EndDevice>ARISTA02T1</EndDevice>
|
||||
<EndPort>Ethernet1/1</EndPort>
|
||||
<StartDevice>switch-t0</StartDevice>
|
||||
<StartPort>fortyGigE0/116</StartPort>
|
||||
</DeviceLinkBase>
|
||||
<DeviceLinkBase>
|
||||
<ElementType>DeviceInterfaceLink</ElementType>
|
||||
<EndDevice>ARISTA03T1</EndDevice>
|
||||
<EndPort>Ethernet1/1</EndPort>
|
||||
<StartDevice>switch-t0</StartDevice>
|
||||
<StartPort>fortyGigE0/120</StartPort>
|
||||
</DeviceLinkBase>
|
||||
<DeviceLinkBase>
|
||||
<ElementType>DeviceInterfaceLink</ElementType>
|
||||
<EndDevice>ARISTA04T1</EndDevice>
|
||||
<EndPort>Ethernet1/1</EndPort>
|
||||
<StartDevice>switch-t0</StartDevice>
|
||||
<StartPort>fortyGigE0/124</StartPort>
|
||||
</DeviceLinkBase>
|
||||
</DeviceInterfaceLinks>
|
||||
<Devices>
|
||||
<Device i:type="ToRRouter">
|
||||
<Hostname>switch-t0</Hostname>
|
||||
<HwSku>Force10-S6000</HwSku>
|
||||
</Device>
|
||||
<Device i:type="LeafRouter">
|
||||
<Hostname>ARISTA01T1</Hostname>
|
||||
<HwSku>Arista</HwSku>
|
||||
</Device>
|
||||
<Device i:type="LeafRouter">
|
||||
<Hostname>ARISTA02T1</Hostname>
|
||||
<HwSku>Arista</HwSku>
|
||||
</Device>
|
||||
<Device i:type="LeafRouter">
|
||||
<Hostname>ARISTA03T1</Hostname>
|
||||
<HwSku>Arista</HwSku>
|
||||
</Device>
|
||||
<Device i:type="LeafRouter">
|
||||
<Hostname>ARISTA04T1</Hostname>
|
||||
<HwSku>Arista</HwSku>
|
||||
</Device>
|
||||
</Devices>
|
||||
</PngDec>
|
||||
<MetadataDeclaration>
|
||||
<Devices xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution">
|
||||
<a:DeviceMetadata>
|
||||
<a:Name>switch-t0</a:Name>
|
||||
<a:Properties>
|
||||
<a:DeviceProperty>
|
||||
<a:Name>ErspanDestinationIpv4</a:Name>
|
||||
<a:Reference i:nil="true"/>
|
||||
<a:Value>2.2.2.2</a:Value>
|
||||
</a:DeviceProperty>
|
||||
</a:Properties>
|
||||
</a:DeviceMetadata>
|
||||
</Devices>
|
||||
<Properties xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution"/>
|
||||
</MetadataDeclaration>
|
||||
<Hostname>switch-t0</Hostname>
|
||||
<HwSku>Force10-S6000</HwSku>
|
||||
</DeviceMiniGraph>
|
@ -23,6 +23,7 @@ class TestCfgGen(TestCase):
|
||||
self.sample_graph_metadata = os.path.join(self.test_dir, 'simple-sample-graph-metadata.xml')
|
||||
self.sample_graph_pc_test = os.path.join(self.test_dir, 'pc-test-graph.xml')
|
||||
self.sample_graph_bgp_speaker = os.path.join(self.test_dir, 't0-sample-bgp-speaker.xml')
|
||||
self.sample_graph_deployment_id = os.path.join(self.test_dir, 't0-sample-deployment-id.xml')
|
||||
self.sample_graph_voq = os.path.join(self.test_dir, 'sample-voq-graph.xml')
|
||||
self.sample_device_desc = os.path.join(self.test_dir, 'device.xml')
|
||||
self.port_config = os.path.join(self.test_dir, 't0-sample-port-config.ini')
|
||||
@ -498,6 +499,11 @@ class TestCfgGen(TestCase):
|
||||
output = self.run_script(argument)
|
||||
self.assertEqual(output.strip(), "1")
|
||||
|
||||
def test_minigraph_deployment_id_null(self):
|
||||
argument = '-m "' + self.sample_graph_deployment_id + '" -p "' + self.port_config + '" -v "DEVICE_METADATA[\'localhost\']"'
|
||||
output = self.run_script(argument)
|
||||
self.assertNotIn('deployment_id', output.strip())
|
||||
|
||||
def test_minigraph_ethernet_interfaces(self, **kwargs):
|
||||
graph_file = kwargs.get('graph_file', self.sample_graph_simple)
|
||||
argument = '-m "' + graph_file + '" -p "' + self.port_config + '" -v "PORT[\'Ethernet8\']"'
|
||||
|
Loading…
Reference in New Issue
Block a user