@@ -65,6 +65,54 @@ func newACL(parentName, direction, priority, match, action string, tier int, opt
6565 return acl
6666}
6767
68+ func (suite * OvnClientTestSuite ) testUpdateDefaultBlockACLOps () {
69+ t := suite .T ()
70+ t .Parallel ()
71+
72+ nbClient := suite .ovnNBClient
73+
74+ expect := func (row ovsdb.Row , action , direction , match , priority string ) {
75+ intPriority , err := strconv .Atoi (priority )
76+ require .NoError (t , err )
77+ require .Equal (t , action , row ["action" ])
78+ require .Equal (t , direction , row ["direction" ])
79+ require .Equal (t , match , row ["match" ])
80+ require .Equal (t , intPriority , row ["priority" ])
81+ }
82+
83+ t .Run ("default block ingress" , func (t * testing.T ) {
84+ t .Parallel ()
85+
86+ netpol := "default block ingress"
87+ pgName := "test_create_block_ingress_acl_pg"
88+
89+ err := nbClient .CreatePortGroup (pgName , nil )
90+ require .NoError (t , err )
91+
92+ ops , err := nbClient .UpdateDefaultBlockACLOps (netpol , pgName , ovnnb .ACLDirectionToLport , true )
93+ require .NoError (t , err )
94+ require .Len (t , ops , 1 )
95+
96+ expect (ops [0 ].Row , "drop" , ovnnb .ACLDirectionToLport , fmt .Sprintf ("outport == @%s && ip" , pgName ), util .IngressDefaultDrop )
97+ })
98+
99+ t .Run ("default block egress" , func (t * testing.T ) {
100+ t .Parallel ()
101+
102+ netpol := "default block egress"
103+ pgName := "test_create_block_egress_acl_pg"
104+
105+ err := nbClient .CreatePortGroup (pgName , nil )
106+ require .NoError (t , err )
107+
108+ ops , err := nbClient .UpdateDefaultBlockACLOps (netpol , pgName , ovnnb .ACLDirectionFromLport , true )
109+ require .NoError (t , err )
110+ require .Len (t , ops , 1 )
111+
112+ expect (ops [0 ].Row , "drop" , ovnnb .ACLDirectionFromLport , fmt .Sprintf ("inport == @%s && ip" , pgName ), util .EgressDefaultDrop )
113+ })
114+ }
115+
68116func (suite * OvnClientTestSuite ) testUpdateIngressACLOps () {
69117 t := suite .T ()
70118 t .Parallel ()
@@ -83,7 +131,6 @@ func (suite *OvnClientTestSuite) testUpdateIngressACLOps() {
83131 t .Run ("ipv4 acl" , func (t * testing.T ) {
84132 t .Parallel ()
85133
86- netpol := "ipv4 ingress"
87134 pgName := "test_create_v4_ingress_acl_pg"
88135 asIngressName := "test.default.ingress.allow.ipv4.all"
89136 asExceptName := "test.default.ingress.except.ipv4.all"
@@ -95,11 +142,9 @@ func (suite *OvnClientTestSuite) testUpdateIngressACLOps() {
95142
96143 npp := mockNetworkPolicyPort ()
97144
98- ops , err := nbClient .UpdateIngressACLOps (netpol , pgName , asIngressName , asExceptName , protocol , aclName , npp , true , nil , nil )
145+ ops , err := nbClient .UpdateIngressACLOps (pgName , asIngressName , asExceptName , protocol , aclName , npp , true , nil , nil )
99146 require .NoError (t , err )
100- require .Len (t , ops , 4 )
101-
102- expect (ops [0 ].Row , "drop" , ovnnb .ACLDirectionToLport , fmt .Sprintf ("outport == @%s && ip" , pgName ), util .IngressDefaultDrop )
147+ require .Len (t , ops , 3 )
103148
104149 matches := newNetworkPolicyACLMatch (pgName , asIngressName , asExceptName , protocol , ovnnb .ACLDirectionToLport , npp , nil )
105150 i := 1
@@ -113,7 +158,6 @@ func (suite *OvnClientTestSuite) testUpdateIngressACLOps() {
113158 t .Run ("ipv6 acl" , func (t * testing.T ) {
114159 t .Parallel ()
115160
116- netpol := "ipv6 ingress"
117161 pgName := "test_create_v6_ingress_acl_pg"
118162 asIngressName := "test.default.ingress.allow.ipv6.all"
119163 asExceptName := "test.default.ingress.except.ipv6.all"
@@ -123,11 +167,9 @@ func (suite *OvnClientTestSuite) testUpdateIngressACLOps() {
123167 err := nbClient .CreatePortGroup (pgName , nil )
124168 require .NoError (t , err )
125169
126- ops , err := nbClient .UpdateIngressACLOps (netpol , pgName , asIngressName , asExceptName , protocol , aclName , nil , true , nil , nil )
170+ ops , err := nbClient .UpdateIngressACLOps (pgName , asIngressName , asExceptName , protocol , aclName , nil , true , nil , nil )
127171 require .NoError (t , err )
128- require .Len (t , ops , 3 )
129-
130- expect (ops [0 ].Row , "drop" , ovnnb .ACLDirectionToLport , fmt .Sprintf ("outport == @%s && ip" , pgName ), util .IngressDefaultDrop )
172+ require .Len (t , ops , 2 )
131173
132174 matches := newNetworkPolicyACLMatch (pgName , asIngressName , asExceptName , protocol , ovnnb .ACLDirectionToLport , nil , nil )
133175 i := 1
@@ -141,28 +183,26 @@ func (suite *OvnClientTestSuite) testUpdateIngressACLOps() {
141183 t .Run ("test empty pgName" , func (t * testing.T ) {
142184 t .Parallel ()
143185
144- netpol := "ingress with empty pg name"
145186 pgName := ""
146187 asIngressName := "test.default.ingress.allow.ipv4.all"
147188 asExceptName := "test.default.ingress.except.ipv4.all"
148189 protocol := kubeovnv1 .ProtocolIPv4
149190 aclName := "test_create_v4_ingress_acl_pg"
150191
151- _ , err := nbClient .UpdateIngressACLOps (netpol , pgName , asIngressName , asExceptName , protocol , aclName , nil , true , nil , nil )
192+ _ , err := nbClient .UpdateIngressACLOps (pgName , asIngressName , asExceptName , protocol , aclName , nil , true , nil , nil )
152193 require .ErrorContains (t , err , "the port group name or logical switch name is required" )
153194 })
154195
155196 t .Run ("test empty pgName without suffix" , func (t * testing.T ) {
156197 t .Parallel ()
157198
158- netpol := "ingress with empty pg name and no suffix"
159199 pgName := ""
160200 asIngressName := "test.default.ingress.allow.ipv4"
161201 asExceptName := "test.default.ingress.except.ipv4"
162202 protocol := kubeovnv1 .ProtocolIPv4
163203 aclName := "test_create_v4_ingress_acl_pg"
164204
165- _ , err := nbClient .UpdateIngressACLOps (netpol , pgName , asIngressName , asExceptName , protocol , aclName , nil , true , nil , nil )
205+ _ , err := nbClient .UpdateIngressACLOps (pgName , asIngressName , asExceptName , protocol , aclName , nil , true , nil , nil )
166206 require .ErrorContains (t , err , "the port group name or logical switch name is required" )
167207 })
168208}
@@ -185,7 +225,6 @@ func (suite *OvnClientTestSuite) testUpdateEgressACLOps() {
185225 t .Run ("ipv4 acl" , func (t * testing.T ) {
186226 t .Parallel ()
187227
188- netpol := "ipv4 egress"
189228 pgName := "test_create_v4_egress_acl_pg"
190229 asEgressName := "test.default.egress.allow.ipv4.all"
191230 asExceptName := "test.default.egress.except.ipv4.all"
@@ -197,11 +236,9 @@ func (suite *OvnClientTestSuite) testUpdateEgressACLOps() {
197236
198237 npp := mockNetworkPolicyPort ()
199238
200- ops , err := nbClient .UpdateEgressACLOps (netpol , pgName , asEgressName , asExceptName , protocol , aclName , npp , true , nil , nil )
239+ ops , err := nbClient .UpdateEgressACLOps (pgName , asEgressName , asExceptName , protocol , aclName , npp , true , nil , nil )
201240 require .NoError (t , err )
202- require .Len (t , ops , 4 )
203-
204- expect (ops [0 ].Row , "drop" , ovnnb .ACLDirectionFromLport , fmt .Sprintf ("inport == @%s && ip" , pgName ), util .EgressDefaultDrop )
241+ require .Len (t , ops , 3 )
205242
206243 matches := newNetworkPolicyACLMatch (pgName , asEgressName , asExceptName , protocol , ovnnb .ACLDirectionFromLport , npp , nil )
207244 i := 1
@@ -215,7 +252,6 @@ func (suite *OvnClientTestSuite) testUpdateEgressACLOps() {
215252 t .Run ("ipv6 acl" , func (t * testing.T ) {
216253 t .Parallel ()
217254
218- netpol := "ipv6 egress"
219255 pgName := "test_create_v6_egress_acl_pg"
220256 asEgressName := "test.default.egress.allow.ipv6.all"
221257 asExceptName := "test.default.egress.except.ipv6.all"
@@ -225,11 +261,9 @@ func (suite *OvnClientTestSuite) testUpdateEgressACLOps() {
225261 err := nbClient .CreatePortGroup (pgName , nil )
226262 require .NoError (t , err )
227263
228- ops , err := nbClient .UpdateEgressACLOps (netpol , pgName , asEgressName , asExceptName , protocol , aclName , nil , true , nil , nil )
264+ ops , err := nbClient .UpdateEgressACLOps (pgName , asEgressName , asExceptName , protocol , aclName , nil , true , nil , nil )
229265 require .NoError (t , err )
230- require .Len (t , ops , 3 )
231-
232- expect (ops [0 ].Row , "drop" , ovnnb .ACLDirectionFromLport , fmt .Sprintf ("inport == @%s && ip" , pgName ), util .EgressDefaultDrop )
266+ require .Len (t , ops , 2 )
233267
234268 matches := newNetworkPolicyACLMatch (pgName , asEgressName , asExceptName , protocol , ovnnb .ACLDirectionFromLport , nil , nil )
235269 i := 1
@@ -243,28 +277,26 @@ func (suite *OvnClientTestSuite) testUpdateEgressACLOps() {
243277 t .Run ("test empty pgName" , func (t * testing.T ) {
244278 t .Parallel ()
245279
246- netpol := "egress with empty pg name"
247280 pgName := ""
248281 asEgressName := "test.default.egress.allow.ipv4.all"
249282 asExceptName := "test.default.egress.except.ipv4.all"
250283 protocol := kubeovnv1 .ProtocolIPv4
251284 aclName := "test_create_v4_egress_acl_pg"
252285
253- _ , err := nbClient .UpdateEgressACLOps (netpol , pgName , asEgressName , asExceptName , protocol , aclName , nil , true , nil , nil )
286+ _ , err := nbClient .UpdateEgressACLOps (pgName , asEgressName , asExceptName , protocol , aclName , nil , true , nil , nil )
254287 require .ErrorContains (t , err , "the port group name or logical switch name is required" )
255288 })
256289
257290 t .Run ("test empty pgName without suffix" , func (t * testing.T ) {
258291 t .Parallel ()
259292
260- netpol := "egress with empty pg name and no suffix"
261293 pgName := ""
262294 asEgressName := "test.default.egress.allow.ipv4"
263295 asExceptName := "test.default.egress.except.ipv4"
264296 protocol := kubeovnv1 .ProtocolIPv4
265297 aclName := "test_create_v4_egress_acl_pg"
266298
267- _ , err := nbClient .UpdateEgressACLOps (netpol , pgName , asEgressName , asExceptName , protocol , aclName , nil , true , nil , nil )
299+ _ , err := nbClient .UpdateEgressACLOps (pgName , asEgressName , asExceptName , protocol , aclName , nil , true , nil , nil )
268300 require .ErrorContains (t , err , "the port group name or logical switch name is required" )
269301 })
270302}
0 commit comments