@@ -23,11 +23,11 @@ import (
2323
2424 "github.com/Mellanox/spectrum-x-operator/pkg/exec"
2525 mock_netlink "github.com/Mellanox/spectrum-x-operator/pkg/lib/netlink/mocks"
26- gomock "github.com/golang/mock/gomock"
27- vishvananda_netlink "github.com/vishvananda/netlink"
2826
27+ gomock "github.com/golang/mock/gomock"
2928 . "github.com/onsi/ginkgo/v2"
3029 . "github.com/onsi/gomega"
30+ vishvananda_netlink "github.com/vishvananda/netlink"
3131)
3232
3333type containsSubstringMatcher struct {
@@ -223,15 +223,76 @@ var _ = Describe("Flows", func() {
223223
224224 Context ("DeletePodRailFlows" , func () {
225225 It ("should delete flows on pod deletion" , func () {
226+ execMock .EXPECT ().Execute ("ovs-vsctl list-br" ).Return ("br-rail1\n br-rail2" , nil )
227+ execMock .EXPECT ().Execute ("ovs-vsctl br-get-external-id br-rail1 test-pod-uid" ).
228+ Return ("rail_pod_id" , nil )
229+ execMock .EXPECT ().Execute ("ovs-vsctl br-get-external-id br-rail2 test-pod-uid" ).
230+ Return ("rail_pod_id" , nil )
226231 execMock .EXPECT ().Execute ("ovs-ofctl del-flows br-rail1 cookie=0x5/-1" ).Return ("" , nil )
227- err := flows .DeletePodRailFlows (0x5 , "br-rail1" )
232+ execMock .EXPECT ().Execute ("ovs-ofctl del-flows br-rail2 cookie=0x5/-1" ).Return ("" , nil )
233+ execMock .EXPECT ().Execute (`ovs-vsctl br-set-external-id br-rail1 test-pod-uid ""` ).Return ("" , nil )
234+ execMock .EXPECT ().Execute (`ovs-vsctl br-set-external-id br-rail2 test-pod-uid ""` ).Return ("" , nil )
235+ err := flows .DeletePodRailFlows (0x5 , "test-pod-uid" )
228236 Expect (err ).Should (Succeed ())
229237 })
230238
231- It ("should return error if ovs-ofctl fails" , func () {
232- execMock .EXPECT ().Execute ("ovs-ofctl del-flows br-rail1 cookie=0x5/-1" ).Return ("" , fmt .Errorf ("failed to delete flows" ))
233- err := flows .DeletePodRailFlows (0x5 , "br-rail1" )
239+ It ("should return error if failed to list bridges" , func () {
240+ execMock .EXPECT ().Execute ("ovs-vsctl list-br" ).Return ("" , fmt .Errorf ("failed to list bridges" ))
241+ err := flows .DeletePodRailFlows (0x5 , "test-pod-uid" )
242+ Expect (err ).Should (HaveOccurred ())
243+ })
244+
245+ It ("should return error if failed to get external id" , func () {
246+ execMock .EXPECT ().Execute ("ovs-vsctl list-br" ).Return ("br-rail1" , nil )
247+ execMock .EXPECT ().
248+ Execute ("ovs-vsctl br-get-external-id br-rail1 test-pod-uid" ).
249+ Return ("" , fmt .Errorf ("failed to get external id" ))
250+
251+ err := flows .DeletePodRailFlows (0x5 , "test-pod-uid" )
252+ Expect (err ).Should (HaveOccurred ())
253+ })
254+
255+ It ("should return error if failed to delete flows" , func () {
256+ execMock .EXPECT ().Execute ("ovs-vsctl list-br" ).Return ("br-rail1" , nil )
257+
258+ execMock .EXPECT ().
259+ Execute ("ovs-vsctl br-get-external-id br-rail1 test-pod-uid" ).
260+ Return ("rail_pod_id" , nil )
261+
262+ execMock .EXPECT ().Execute ("ovs-ofctl del-flows br-rail1 cookie=0x5/-1" ).
263+ Return ("" , fmt .Errorf ("failed to delete flows" ))
264+
265+ err := flows .DeletePodRailFlows (0x5 , "test-pod-uid" )
266+ Expect (err ).Should (HaveOccurred ())
267+ })
268+
269+ It ("should return error if failed to clear external id" , func () {
270+ execMock .EXPECT ().Execute ("ovs-vsctl list-br" ).Return ("br-rail1" , nil )
271+ execMock .EXPECT ().
272+ Execute ("ovs-vsctl br-get-external-id br-rail1 test-pod-uid" ).
273+ Return ("rail_pod_id" , nil )
274+ execMock .EXPECT ().Execute ("ovs-ofctl del-flows br-rail1 cookie=0x5/-1" ).Return ("" , nil )
275+ execMock .EXPECT ().
276+ Execute (`ovs-vsctl br-set-external-id br-rail1 test-pod-uid ""` ).
277+ Return ("" , fmt .Errorf ("failed to clear external id" ))
278+
279+ err := flows .DeletePodRailFlows (0x5 , "test-pod-uid" )
280+ Expect (err ).Should (HaveOccurred ())
281+ Expect (err .Error ()).Should (ContainSubstring ("failed to clear external id" ))
282+ })
283+
284+ It ("should try to delete all flows before returning error" , func () {
285+ execMock .EXPECT ().Execute ("ovs-vsctl list-br" ).Return ("br-rail1\n br-rail2" , nil )
286+ execMock .EXPECT ().Execute ("ovs-vsctl br-get-external-id br-rail1 test-pod-uid" ).
287+ Return ("rail_pod_id" , fmt .Errorf ("failed to get external id" ))
288+ execMock .EXPECT ().Execute ("ovs-vsctl br-get-external-id br-rail2 test-pod-uid" ).
289+ Return ("rail_pod_id" , nil )
290+ execMock .EXPECT ().Execute ("ovs-ofctl del-flows br-rail2 cookie=0x5/-1" ).Return ("" , fmt .Errorf ("failed to delete flows" ))
291+
292+ err := flows .DeletePodRailFlows (0x5 , "test-pod-uid" )
234293 Expect (err ).Should (HaveOccurred ())
294+ Expect (err .Error ()).Should (ContainSubstring ("failed to get external id" ))
295+ Expect (err .Error ()).Should (ContainSubstring ("failed to delete flows" ))
235296 })
236297 })
237298})
0 commit comments