@@ -200,13 +200,15 @@ var _ = Describe("Pod Controller", func() {
200200 Execute ("ovs-vsctl --no-heading --columns=name find Port external_ids:contIface=net1 external_ids:contPodUid=" + string (pod .UID )).
201201 Return ("pod-vf-1" , nil ).Times (1 )
202202 execMock .EXPECT ().Execute ("ovs-vsctl iface-to-br pod-vf-1" ).Return ("br-rail1" , nil ).Times (1 )
203+ flowsMock .EXPECT ().IsBridgeManagedByRailCNI (gomock .Any (), gomock .Any ()).Return (true , nil ).Times (1 )
203204 flowsMock .EXPECT ().AddPodRailFlows (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil )
204205
205206 // rail2
206207 execMock .EXPECT ().
207208 Execute ("ovs-vsctl --no-heading --columns=name find Port external_ids:contIface=net2 external_ids:contPodUid=" + string (pod .UID )).
208209 Return ("pod-vf-2" , nil )
209210 execMock .EXPECT ().Execute ("ovs-vsctl iface-to-br pod-vf-2" ).Return ("br-rail2" , nil )
211+ flowsMock .EXPECT ().IsBridgeManagedByRailCNI (gomock .Any (), gomock .Any ()).Return (true , nil ).Times (1 )
210212 flowsMock .EXPECT ().AddPodRailFlows (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil )
211213
212214 result , err := flowController .Reconcile (ctx , pod )
@@ -225,6 +227,7 @@ var _ = Describe("Pod Controller", func() {
225227 Execute ("ovs-vsctl --no-heading --columns=name find Port external_ids:contIface=net2 external_ids:contPodUid=" + string (pod .UID )).
226228 Return ("pod-vf-2" , nil )
227229 execMock .EXPECT ().Execute ("ovs-vsctl iface-to-br pod-vf-2" ).Return ("br-rail2" , nil )
230+ flowsMock .EXPECT ().IsBridgeManagedByRailCNI (gomock .Any (), gomock .Any ()).Return (true , nil ).Times (1 )
228231 flowsMock .EXPECT ().AddPodRailFlows (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil )
229232
230233 result , err := flowController .Reconcile (ctx , pod )
@@ -245,6 +248,7 @@ var _ = Describe("Pod Controller", func() {
245248 Return ("pod-vf-2" , nil )
246249 execMock .EXPECT ().Execute ("ovs-vsctl iface-to-br pod-vf-2" ).Return ("br-rail2" , nil )
247250
251+ flowsMock .EXPECT ().IsBridgeManagedByRailCNI (gomock .Any (), gomock .Any ()).Return (true , nil ).Times (1 )
248252 flowsMock .EXPECT ().AddPodRailFlows (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil )
249253 result , err := flowController .Reconcile (ctx , pod )
250254 Expect (err ).Should (HaveOccurred ())
@@ -257,6 +261,7 @@ var _ = Describe("Pod Controller", func() {
257261 Execute ("ovs-vsctl --no-heading --columns=name find Port external_ids:contIface=net1 external_ids:contPodUid=" + string (pod .UID )).
258262 Return ("pod-vf-1" , nil ).Times (1 )
259263 execMock .EXPECT ().Execute ("ovs-vsctl iface-to-br pod-vf-1" ).Return ("br-rail1" , nil ).Times (1 )
264+ flowsMock .EXPECT ().IsBridgeManagedByRailCNI (gomock .Any (), gomock .Any ()).Return (true , nil ).Times (1 )
260265 flowsMock .EXPECT ().AddPodRailFlows (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).
261266 Return (fmt .Errorf ("failed to add flows to rail" ))
262267
@@ -265,12 +270,55 @@ var _ = Describe("Pod Controller", func() {
265270 Execute ("ovs-vsctl --no-heading --columns=name find Port external_ids:contIface=net2 external_ids:contPodUid=" + string (pod .UID )).
266271 Return ("pod-vf-2" , nil )
267272 execMock .EXPECT ().Execute ("ovs-vsctl iface-to-br pod-vf-2" ).Return ("br-rail2" , nil )
273+ flowsMock .EXPECT ().IsBridgeManagedByRailCNI (gomock .Any (), gomock .Any ()).Return (true , nil ).Times (1 )
268274 flowsMock .EXPECT ().AddPodRailFlows (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil )
269275
270276 result , err := flowController .Reconcile (ctx , pod )
271277 Expect (err ).Should (HaveOccurred ())
272278 Expect (result ).To (Equal (reconcile.Result {}))
273279 })
274280
281+ It ("skip when bridge is not managed by rail cni" , func () {
282+ // rail1
283+ execMock .EXPECT ().
284+ Execute ("ovs-vsctl --no-heading --columns=name find Port external_ids:contIface=net1 external_ids:contPodUid=" + string (pod .UID )).
285+ Return ("pod-vf-1" , nil ).Times (1 )
286+ execMock .EXPECT ().Execute ("ovs-vsctl iface-to-br pod-vf-1" ).Return ("br-rail1" , nil ).Times (1 )
287+ flowsMock .EXPECT ().IsBridgeManagedByRailCNI (gomock .Any (), gomock .Any ()).Return (false , nil ).Times (1 )
288+
289+ // rail2
290+ execMock .EXPECT ().
291+ Execute ("ovs-vsctl --no-heading --columns=name find Port external_ids:contIface=net2 external_ids:contPodUid=" + string (pod .UID )).
292+ Return ("pod-vf-2" , nil )
293+ execMock .EXPECT ().Execute ("ovs-vsctl iface-to-br pod-vf-2" ).Return ("br-rail2" , nil )
294+ flowsMock .EXPECT ().IsBridgeManagedByRailCNI (gomock .Any (), gomock .Any ()).Return (true , nil ).Times (1 )
295+ flowsMock .EXPECT ().AddPodRailFlows (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil )
296+
297+ result , err := flowController .Reconcile (ctx , pod )
298+ Expect (err ).Should (Succeed ())
299+ Expect (result ).To (Equal (reconcile.Result {}))
300+ })
301+
302+ It ("failed to check if bridge is managed by rail cni" , func () {
303+ // rail1
304+ execMock .EXPECT ().
305+ Execute ("ovs-vsctl --no-heading --columns=name find Port external_ids:contIface=net1 external_ids:contPodUid=" + string (pod .UID )).
306+ Return ("pod-vf-1" , nil ).Times (1 )
307+ execMock .EXPECT ().Execute ("ovs-vsctl iface-to-br pod-vf-1" ).Return ("br-rail1" , nil ).Times (1 )
308+ flowsMock .EXPECT ().
309+ IsBridgeManagedByRailCNI (gomock .Any (), gomock .Any ()).
310+ Return (false , fmt .Errorf ("failed to check if bridge is managed by rail cni" ))
311+
312+ // rail2
313+ execMock .EXPECT ().
314+ Execute ("ovs-vsctl --no-heading --columns=name find Port external_ids:contIface=net2 external_ids:contPodUid=" + string (pod .UID )).
315+ Return ("pod-vf-2" , nil )
316+ execMock .EXPECT ().Execute ("ovs-vsctl iface-to-br pod-vf-2" ).Return ("br-rail2" , nil )
317+ flowsMock .EXPECT ().IsBridgeManagedByRailCNI (gomock .Any (), gomock .Any ()).Return (true , nil ).Times (1 )
318+ flowsMock .EXPECT ().AddPodRailFlows (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil )
319+ result , err := flowController .Reconcile (ctx , pod )
320+ Expect (err ).Should (HaveOccurred ())
321+ Expect (result ).To (Equal (reconcile.Result {}))
322+ })
275323 })
276324})
0 commit comments