Skip to content

Commit 3bd3549

Browse files
taoyl-mslguohan
authored andcommitted
[cfggen] Fix a bug when portchannel has >2 members (#493)
1 parent 884bd2d commit 3bd3549

File tree

3 files changed

+210
-2
lines changed

3 files changed

+210
-2
lines changed

src/sonic-config-engine/minigraph.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def parse_dpg(dpg, hname):
197197
for pcintf in pcintfs.findall(str(QName(ns, "PortChannel"))):
198198
pcintfname = pcintf.find(str(QName(ns, "Name"))).text
199199
pcintfmbr = pcintf.find(str(QName(ns, "AttachTo"))).text
200-
pcmbr_list = pcintfmbr.split(';', 1)
200+
pcmbr_list = pcintfmbr.split(';')
201201
for i, member in enumerate(pcmbr_list):
202202
pcmbr_list[i] = port_alias_map[member]
203203
pcs[pcintfname] = {'name': pcintfname, 'members': pcmbr_list}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
<DeviceMiniGraph xmlns="Microsoft.Search.Autopilot.Evolution" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
2+
<CpgDec>
3+
<IsisRouters xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution"/>
4+
<PeeringSessions>
5+
<BGPSession>
6+
<MacSec>false</MacSec>
7+
<StartRouter>switch-t0</StartRouter>
8+
<StartPeer>10.0.0.56</StartPeer>
9+
<EndRouter>ARISTA01T1</EndRouter>
10+
<EndPeer>10.0.0.57</EndPeer>
11+
<Multihop>1</Multihop>
12+
<HoldTime>180</HoldTime>
13+
<KeepAliveTime>60</KeepAliveTime>
14+
</BGPSession>
15+
<BGPSession>
16+
<StartRouter>switch-t0</StartRouter>
17+
<StartPeer>FC00::71</StartPeer>
18+
<EndRouter>ARISTA01T1</EndRouter>
19+
<EndPeer>FC00::72</EndPeer>
20+
<Multihop>1</Multihop>
21+
<HoldTime>180</HoldTime>
22+
<KeepAliveTime>60</KeepAliveTime>
23+
</BGPSession>
24+
</PeeringSessions>
25+
<Routers xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution">
26+
<a:BGPRouterDeclaration>
27+
<a:ASN>65100</a:ASN>
28+
<a:Hostname>switch-t0</a:Hostname>
29+
<a:Peers>
30+
<BGPPeer>
31+
<Address>10.0.0.57</Address>
32+
<RouteMapIn i:nil="true"/>
33+
<RouteMapOut i:nil="true"/>
34+
<Vrf i:nil="true"/>
35+
</BGPPeer>
36+
</a:Peers>
37+
<a:RouteMaps/>
38+
</a:BGPRouterDeclaration>
39+
<a:BGPRouterDeclaration>
40+
<a:ASN>64600</a:ASN>
41+
<a:Hostname>ARISTA01T1</a:Hostname>
42+
<a:RouteMaps/>
43+
</a:BGPRouterDeclaration>
44+
<a:BGPRouterDeclaration>
45+
<a:ASN>64600</a:ASN>
46+
<a:Hostname>ARISTA02T1</a:Hostname>
47+
<a:RouteMaps/>
48+
</a:BGPRouterDeclaration>
49+
<a:BGPRouterDeclaration>
50+
<a:ASN>64600</a:ASN>
51+
<a:Hostname>ARISTA03T1</a:Hostname>
52+
<a:RouteMaps/>
53+
</a:BGPRouterDeclaration>
54+
<a:BGPRouterDeclaration>
55+
<a:ASN>64600</a:ASN>
56+
<a:Hostname>ARISTA04T1</a:Hostname>
57+
<a:RouteMaps/>
58+
</a:BGPRouterDeclaration>
59+
</Routers>
60+
</CpgDec>
61+
<DpgDec>
62+
<DeviceDataPlaneInfo>
63+
<IPSecTunnels/>
64+
<LoopbackIPInterfaces xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution">
65+
<a:LoopbackIPInterface>
66+
<Name>HostIP</Name>
67+
<AttachTo>Loopback0</AttachTo>
68+
<a:Prefix xmlns:b="Microsoft.Search.Autopilot.Evolution">
69+
<b:IPPrefix>10.1.0.32/32</b:IPPrefix>
70+
</a:Prefix>
71+
<a:PrefixStr>10.1.0.32/32</a:PrefixStr>
72+
</a:LoopbackIPInterface>
73+
<a:LoopbackIPInterface>
74+
<Name>HostIP1</Name>
75+
<AttachTo>Loopback0</AttachTo>
76+
<a:Prefix xmlns:b="Microsoft.Search.Autopilot.Evolution">
77+
<b:IPPrefix>FC00:1::32/128</b:IPPrefix>
78+
</a:Prefix>
79+
<a:PrefixStr>FC00:1::32/128</a:PrefixStr>
80+
</a:LoopbackIPInterface>
81+
</LoopbackIPInterfaces>
82+
<ManagementIPInterfaces xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution">
83+
<a:ManagementIPInterface>
84+
<Name>HostIP</Name>
85+
<AttachTo>eth0</AttachTo>
86+
<a:Prefix xmlns:b="Microsoft.Search.Autopilot.Evolution">
87+
<b:IPPrefix>10.0.0.100/24</b:IPPrefix>
88+
</a:Prefix>
89+
<a:PrefixStr>10.0.0.100/24</a:PrefixStr>
90+
</a:ManagementIPInterface>
91+
</ManagementIPInterfaces>
92+
<ManagementVIPInterfaces xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution"/>
93+
<MplsInterfaces/>
94+
<MplsTeInterfaces/>
95+
<RsvpInterfaces/>
96+
<Hostname>switch-t0</Hostname>
97+
<PortChannelInterfaces>
98+
<PortChannel>
99+
<Name>PortChannel01</Name>
100+
<AttachTo>fortyGigE0/112;fortyGigE0/116;fortyGigE0/120;fortyGigE0/124</AttachTo>
101+
<SubInterface/>
102+
</PortChannel>
103+
</PortChannelInterfaces>
104+
<VlanInterfaces>
105+
<VlanInterface>
106+
<Name>Vlan1000</Name>
107+
<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>
108+
<NoDhcpRelay>False</NoDhcpRelay>
109+
<StaticDHCPRelay>0.0.0.0/0</StaticDHCPRelay>
110+
<Type i:nil="true"/>
111+
<VlanID>1000</VlanID>
112+
<Tag>1000</Tag>
113+
<Subnets>192.168.0.0/27</Subnets>
114+
</VlanInterface>
115+
</VlanInterfaces>
116+
<IPInterfaces>
117+
<IPInterface>
118+
<Name i:nil="true"/>
119+
<AttachTo>PortChannel01</AttachTo>
120+
<Prefix>10.0.0.56/31</Prefix>
121+
</IPInterface>
122+
<IPInterface>
123+
<Name i:Name="true"/>
124+
<AttachTo>PortChannel01</AttachTo>
125+
<Prefix>FC00::71/126</Prefix>
126+
</IPInterface>
127+
<IPInterface>
128+
<Name i:nil="true"/>
129+
<AttachTo>Vlan1000</AttachTo>
130+
<Prefix>192.168.0.1/27</Prefix>
131+
</IPInterface>
132+
</IPInterfaces>
133+
<DataAcls/>
134+
<AclInterfaces>
135+
<AclInterface>
136+
<AttachTo>
137+
PortChannel01;PortChannel02;PortChannel03;PortChannel04
138+
</AttachTo>
139+
<InAcl>DataAcl</InAcl>
140+
</AclInterface>
141+
</AclInterfaces>
142+
<DownstreamSummaries/>
143+
<DownstreamSummarySet xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution"/>
144+
</DeviceDataPlaneInfo>
145+
</DpgDec>
146+
<PngDec>
147+
<DeviceInterfaceLinks>
148+
<DeviceLinkBase>
149+
<ElementType>DeviceInterfaceLink</ElementType>
150+
<EndDevice>ARISTA01T1</EndDevice>
151+
<EndPort>Ethernet1/1</EndPort>
152+
<StartDevice>switch-t0</StartDevice>
153+
<StartPort>fortyGigE0/112</StartPort>
154+
</DeviceLinkBase>
155+
<DeviceLinkBase>
156+
<ElementType>DeviceInterfaceLink</ElementType>
157+
<EndDevice>ARISTA02T1</EndDevice>
158+
<EndPort>Ethernet1/1</EndPort>
159+
<StartDevice>switch-t0</StartDevice>
160+
<StartPort>fortyGigE0/116</StartPort>
161+
</DeviceLinkBase>
162+
<DeviceLinkBase>
163+
<ElementType>DeviceInterfaceLink</ElementType>
164+
<EndDevice>ARISTA03T1</EndDevice>
165+
<EndPort>Ethernet1/1</EndPort>
166+
<StartDevice>switch-t0</StartDevice>
167+
<StartPort>fortyGigE0/120</StartPort>
168+
</DeviceLinkBase>
169+
<DeviceLinkBase>
170+
<ElementType>DeviceInterfaceLink</ElementType>
171+
<EndDevice>ARISTA04T1</EndDevice>
172+
<EndPort>Ethernet1/1</EndPort>
173+
<StartDevice>switch-t0</StartDevice>
174+
<StartPort>fortyGigE0/124</StartPort>
175+
</DeviceLinkBase>
176+
</DeviceInterfaceLinks>
177+
<Devices>
178+
<Device i:type="ToRRouter">
179+
<Hostname>switch-t0</Hostname>
180+
<HwSku>Force10-S6000</HwSku>
181+
</Device>
182+
<Device i:type="LeafRouter">
183+
<Hostname>ARISTA01T1</Hostname>
184+
<HwSku>Arista</HwSku>
185+
</Device>
186+
<Device i:type="LeafRouter">
187+
<Hostname>ARISTA02T1</Hostname>
188+
<HwSku>Arista</HwSku>
189+
</Device>
190+
<Device i:type="LeafRouter">
191+
<Hostname>ARISTA03T1</Hostname>
192+
<HwSku>Arista</HwSku>
193+
</Device>
194+
<Device i:type="LeafRouter">
195+
<Hostname>ARISTA04T1</Hostname>
196+
<HwSku>Arista</HwSku>
197+
</Device>
198+
</Devices>
199+
</PngDec>
200+
<Hostname>switch-t0</Hostname>
201+
<HwSku>Force10-S6000</HwSku>
202+
</DeviceMiniGraph>

src/sonic-config-engine/tests/test_cfggen.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def setUp(self):
1010
self.sample_graph = os.path.join(self.test_dir, 'sample_graph.xml')
1111
self.sample_graph_t0 = os.path.join(self.test_dir, 't0-sample-graph.xml')
1212
self.sample_graph_simple = os.path.join(self.test_dir, 'simple-sample-graph.xml')
13+
self.sample_graph_pc_test = os.path.join(self.test_dir, 'pc-test-graph.xml')
1314
self.port_config = os.path.join(self.test_dir, 't0-sample-port-config.ini')
1415

1516
def run_script(self, argument):
@@ -82,7 +83,12 @@ def test_minigraph_portchannels(self):
8283
output = self.run_script(argument)
8384
self.assertEqual(output.strip(), "{'PortChannel01': {'name': 'PortChannel01', 'members': ['Ethernet4']}}")
8485

85-
def test_minigraph_portchannels(self):
86+
def test_minigraph_portchannels_more_member(self):
87+
argument = '-m "' + self.sample_graph_pc_test + '" -p "' + self.port_config + '" -v minigraph_portchannels'
88+
output = self.run_script(argument)
89+
self.assertEqual(output.strip(), "{'PortChannel01': {'name': 'PortChannel01', 'members': ['Ethernet112', 'Ethernet116', 'Ethernet120', 'Ethernet124']}}")
90+
91+
def test_minigraph_portchannel_interfaces(self):
8692
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v minigraph_portchannel_interfaces'
8793
output = self.run_script(argument)
8894
self.assertEqual(output.strip(), "[{'subnet': IPv4Network('10.0.0.56/31'), 'peer_addr': IPv4Address('10.0.0.57'), 'addr': IPv4Address('10.0.0.56'), 'mask': IPv4Address('255.255.255.254'), 'attachto': 'PortChannel01', 'prefixlen': 31}, {'subnet': IPv6Network('fc00::70/126'), 'peer_addr': IPv6Address('fc00::72'), 'addr': IPv6Address('fc00::71'), 'mask': '126', 'attachto': 'PortChannel01', 'prefixlen': 126}]")

0 commit comments

Comments
 (0)