-
Notifications
You must be signed in to change notification settings - Fork 59
/
acl_test.go
666 lines (591 loc) · 17.8 KB
/
acl_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
/**
* Copyright (c) 2017 eBay Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package goovn
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestLogicalSwitchACLs(t *testing.T) {
ovndbapi := getOVNClient(DBNB)
var cmds []*OvnCommand
var cmd *OvnCommand
var err error
cmds = make([]*OvnCommand, 0)
cmd, err = ovndbapi.LSAdd(LSW)
if err != nil {
t.Fatal(err)
}
cmds = append(cmds, cmd)
cmd, err = ovndbapi.LSPAdd(LSW, LSP)
if err != nil {
t.Fatal(err)
}
cmds = append(cmds, cmd)
cmd, err = ovndbapi.LSPSetAddress(LSP, ADDR)
if err != nil {
t.Fatal(err)
}
cmds = append(cmds, cmd)
cmd, err = ovndbapi.LSPSetPortSecurity(LSP, ADDR)
if err != nil {
t.Fatal(err)
}
cmds = append(cmds, cmd)
cmd, err = ovndbapi.MeterAdd("meter1", "drop", 101, "kbps", nil, 300)
if err != nil {
t.Fatal(err)
}
cmds = append(cmds, cmd)
// execute to create lsw and lsp
err = ovndbapi.Execute(cmds...)
if err != nil {
t.Fatal(err)
}
// nil cmds for next batch
cmds = make([]*OvnCommand, 0)
cmd, err = ovndbapi.ACLAdd(LSW, "to-lport", MATCH, "drop", 1001, nil, true, "meter1", "alert")
if err != nil {
t.Fatal(err)
}
cmds = append(cmds, cmd)
err = ovndbapi.Execute(cmds...)
if err != nil {
t.Fatal(err)
}
lsws, err := ovndbapi.LSGet(LSW)
if err != nil {
t.Fatal(err)
}
if len(lsws) == 0 {
t.Fatalf("ls not created %d", len(lsws))
}
lsps, err := ovndbapi.LSPList(LSW)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, true, len(lsps) == 1 && lsps[0].Name == LSP, "test[%s]: %v", "added port", lsps)
assert.Equal(t, true, len(lsps) == 1 && lsps[0].Addresses[0] == ADDR, "test[%s]", "setted port address")
assert.Equal(t, true, len(lsps) == 1 && lsps[0].PortSecurity[0] == ADDR, "test[%s]", "setted port port security")
cmd, err = ovndbapi.LSPAdd(LSW, LSP_SECOND)
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(cmd)
if err != nil {
t.Fatal(err)
}
lsps, err = ovndbapi.LSPList(LSW)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, true, len(lsps) == 2, "test[%s]: %+v", "added 2 ports", lsps)
acls, err := ovndbapi.ACLList(LSW)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, true, len(acls) == 1 && acls[0].Match == MATCH &&
acls[0].Action == "drop" && acls[0].Priority == 1001 && acls[0].Log == true && acls[0].Meter[0] == "meter1" && acls[0].Severity == "alert", "test[%s] %s", "add acl", acls[0])
cmd, err = ovndbapi.ACLAdd(LSW, "to-lport", MATCH, "drop", 1001, nil, true, "", "")
// ACLAdd must return error
assert.Equal(t, true, nil != err, "test[%s]", "add same acl twice, should only one added.")
// cmd is nil, so this is noop
err = ovndbapi.Execute(cmd)
assert.Equal(t, true, nil == err, "test[%s]", "add same acl twice, should only one added.")
cmd, err = ovndbapi.ACLAdd(LSW, "to-lport", MATCH_SECOND, "drop", 1001, map[string]string{"A": "a", "B": "b"}, false, "", "")
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(cmd)
if err != nil {
t.Fatal(err)
}
acls, err = ovndbapi.ACLList(LSW)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, true, len(acls) == 2, "test[%s]", "add second acl")
// The following should fail because it is considered a duplicate of an existing ACL
cmd, err = ovndbapi.ACLAdd(LSW, "to-lport", MATCH_SECOND, "drop", 1001, map[string]string{"A": "b", "B": "b"}, false, "", "")
if err == nil {
t.Fatal(err)
}
if cmd != nil {
t.Fatal(err)
}
// cmd is nil, so this is noop
err = ovndbapi.Execute(cmd)
if err != nil {
t.Fatal(err)
}
acls, err = ovndbapi.ACLList(LSW)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, true, len(acls) == 2, "test[%s]", "add second acl")
// The following should fail because it is considered a duplicate of an existing ACL
cmd, err = ovndbapi.ACLAdd(LSW, "to-lport", MATCH_SECOND, "drop", 1001, nil, false, "", "")
if err == nil {
t.Fatal(err)
}
// Different priority is a different ACL, so this should succeed
cmd, err = ovndbapi.ACLAdd(LSW, "to-lport", MATCH_SECOND, "drop", 1002, map[string]string{"A": "a", "B": "b"}, false, "", "")
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(cmd)
if err != nil {
t.Fatal(err)
}
acls, err = ovndbapi.ACLList(LSW)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, true, len(acls) == 3, "test[%s]", "add second acl")
// Different direction is a different ACL, so this should succeed
cmd, err = ovndbapi.ACLAdd(LSW, "from-lport", MATCH_SECOND, "drop", 1001, map[string]string{"A": "a", "B": "b"}, false, "", "")
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(cmd)
if err != nil {
t.Fatal(err)
}
acls, err = ovndbapi.ACLList(LSW)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, true, len(acls) == 4, "test[%s]", "add second acl")
cmd, err = ovndbapi.ACLDel(LSW, "to-lport", MATCH_SECOND, 1002, nil)
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(cmd)
if err != nil {
t.Fatal(err)
}
acls, err = ovndbapi.ACLList(LSW)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, true, len(acls) == 3, "test[%s]", "add second acl")
cmd, err = ovndbapi.ACLDel(LSW, "from-lport", MATCH_SECOND, 1001, nil)
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(cmd)
if err != nil {
t.Fatal(err)
}
acls, err = ovndbapi.ACLList(LSW)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, true, len(acls) == 2, "test[%s]", "acl remove")
cmd, err = ovndbapi.ACLDel(LSW, "to-lport", MATCH, 1001, map[string]string{})
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(cmd)
if err != nil {
t.Fatal(err)
}
acls, err = ovndbapi.ACLList(LSW)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, true, len(acls) == 1, "test[%s]", "acl remove")
//The following delete should fail because external ids are provided, but they don't exist in any ACL
cmd, err = ovndbapi.ACLDel(LSW, "to-lport", MATCH_SECOND, 1001, map[string]string{"A": "b"})
if err == nil {
t.Fatal(err)
}
//The following delete should succeed because the provided external_ids provided are a subset of thoe in an existing ACL
cmd, err = ovndbapi.ACLDel(LSW, "to-lport", MATCH_SECOND, 1001, map[string]string{"A": "a"})
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(cmd)
if err != nil {
t.Fatal(err)
}
acls, err = ovndbapi.ACLList(LSW)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, true, len(acls) == 0, "test[%s]", "acl remove")
// The following ACLDel should fail because all the ACLs have been deleted.
cmd, err = ovndbapi.ACLDel(LSW, "to-lport", MATCH_SECOND, 1001, map[string]string{"A": "b"})
if err == nil {
t.Fatal(err)
}
cmd, err = ovndbapi.LSPDel(LSP)
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(cmd)
if err != nil {
t.Fatal(err)
}
lsps, err = ovndbapi.LSPList(LSW)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, true, len(lsps) == 1, "test[%s]", "one port remove")
cmd, err = ovndbapi.LSPDel(LSP_SECOND)
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(cmd)
if err != nil {
t.Fatal(err)
}
lsps, err = ovndbapi.LSPList(LSW)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, true, len(lsps) == 0, "test[%s]", "one port remove")
cmd, err = ovndbapi.LSDel(LSW)
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(cmd)
if err != nil {
t.Fatal(err)
}
cmd, err = ovndbapi.MeterDel("meter1")
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(cmd)
if err != nil {
t.Fatal(err)
}
// verify ACL list for non-existing switch
_, err = ovndbapi.ACLList(FAKENOSWITCH)
if err != nil {
assert.EqualError(t, ErrorNotFound, err.Error())
}
}
func compareMeterSlices(s1, s2 []string) bool {
if (s1 == nil || s1[0] == "") && (s2 == nil || s2[0] == "") {
return true
}
if len(s1) != len(s2) {
return false
}
for i, v := range s1 {
if v != s2[i] {
return false
}
}
return true
}
// Returns true if an acl is in aclList
func containsACL(aclList []*ACL, acl *ACL) bool {
for _, a := range aclList {
if a.UUID == acl.UUID &&
a.Name == acl.Name &&
a.Action == acl.Action &&
a.Direction == acl.Direction &&
a.Match == acl.Match &&
a.Priority == acl.Priority &&
a.Log == acl.Log &&
compareMeterSlices(a.Meter, acl.Meter) &&
a.Severity == acl.Severity &&
compareExternalIds(iMapToSMap(a.ExternalID), acl.ExternalID) {
return true
}
}
return false
}
// converts and interface{} map to a string map
func iMapToSMap(iMap map[interface{}]interface{}) map[string]string {
if iMap == nil {
return nil
}
sMap := make(map[string]string, len(iMap))
for k, v := range iMap {
sMap[fmt.Sprintf("%v", k)] = fmt.Sprintf("%v", v)
}
return sMap
}
func TestACLs(t *testing.T) {
ovndbapi := getOVNClient(DBNB)
var cmd *OvnCommand
var cmds []*OvnCommand
var err error
var lsp1UUID string
var lsp2UUID string
t.Run("create switch, ports, port group, and meter for ACL testing", func(t *testing.T) {
cmds = make([]*OvnCommand, 0)
// Create switch and ports
cmd, err := ovndbapi.LSAdd(PG_TEST_LS1)
assert.Nil(t, err)
cmds = append(cmds, cmd)
// Add ports
cmd, err = ovndbapi.LSPAdd(PG_TEST_LS1, PG_TEST_LSP1)
assert.Nil(t, err)
cmds = append(cmds, cmd)
cmd, err = ovndbapi.LSPSetAddress(PG_TEST_LSP1, ADDR)
assert.Nil(t, err)
cmds = append(cmds, cmd)
cmd, err = ovndbapi.LSPSetPortSecurity(PG_TEST_LSP1, ADDR)
assert.Nil(t, err)
cmds = append(cmds, cmd)
cmd, err = ovndbapi.LSPAdd(PG_TEST_LS1, PG_TEST_LSP2)
assert.Nil(t, err)
cmds = append(cmds, cmd)
cmd, err = ovndbapi.LSPSetAddress(PG_TEST_LSP2, ADDR2)
assert.Nil(t, err)
cmds = append(cmds, cmd)
cmd, err = ovndbapi.LSPSetPortSecurity(PG_TEST_LSP2, ADDR2)
cmds = append(cmds, cmd)
assert.Nil(t, err)
result, err := ovndbapi.ExecuteR(cmds...)
assert.Nil(t, err)
assert.Equal(t, 3, len(result))
if len(result) >= 3 {
lsp1UUID = result[1]
lsp2UUID = result[2]
}
// Create port group
cmd, err = ovndbapi.PortGroupAdd(PG_TEST_PG1, []string{lsp1UUID, lsp2UUID}, nil)
assert.Nil(t, err)
err = ovndbapi.Execute(cmd)
assert.Nil(t, err)
// Create some meters
cmds = make([]*OvnCommand, 0)
cmd, err = ovndbapi.MeterAdd(METER1, "drop", 101, "kbps", nil, 300)
assert.Nil(t, err)
cmds = append(cmds, cmd)
cmd, err = ovndbapi.MeterAdd(METER2, "drop", 101, "kbps", nil, 300)
assert.Nil(t, err)
cmds = append(cmds, cmd)
// execute to create meters
err = ovndbapi.Execute(cmds...)
assert.Nil(t, err)
})
type aclTest struct {
acl ACL
newName string
newMatch string
newMeter string
newSeverity string
}
type aclEntityTest struct {
entityType EntityType
entity string
aclTests []aclTest
}
aclEntityTests := []aclEntityTest{
{
PORT_GROUP, PG_TEST_PG1,
[]aclTest{
{
ACL{"", "", "drop", "from-lport", MATCH3, 1001, false, []string{""}, "", nil},
ACL_NAME_2, MATCH_SECOND, METER1, SEVERITY_INFO,
},
{
ACL{"", ACL_NAME_1, "drop", "to-lport", MATCH, 1001, true, []string{METER1}, SEVERITY_ALERT, nil},
ACL_NAME_3, MATCH_SECOND, METER2, SEVERITY_INFO,
},
{
ACL{"", ACL_NAME_2, "drop", "from-lport", MATCH, 1002, true, []string{METER2}, SEVERITY_INFO, map[interface{}]interface{}{"A": "a", "B": "b"}},
ACL_NAME_4, MATCH3, METER1, SEVERITY_WARNING,
},
{
ACL{"", ACL_NAME_3, "drop", "to-lport", MATCH, 1002, true, []string{METER1}, SEVERITY_ALERT, map[interface{}]interface{}{"A": "b", "B": "a"}},
ACL_NAME_5, MATCH_SECOND, METER2, SEVERITY_INFO,
},
},
},
{
LOGICAL_SWITCH, PG_TEST_LS1,
[]aclTest{
{
ACL{"", "", "drop", "from-lport", MATCH3, 1001, false, []string{""}, "", nil},
ACL_NAME_2, MATCH_SECOND, METER1, SEVERITY_INFO,
},
{
ACL{"", ACL_NAME_1, "drop", "to-lport", MATCH, 1001, true, []string{METER1}, SEVERITY_ALERT, nil},
ACL_NAME_3, MATCH_SECOND, METER2, SEVERITY_INFO,
},
{
ACL{"", ACL_NAME_2, "drop", "from-lport", MATCH, 1002, true, []string{METER2}, SEVERITY_INFO, map[interface{}]interface{}{"A": "a", "B": "b"}},
ACL_NAME_4, MATCH3, METER1, SEVERITY_WARNING,
},
{
ACL{"", ACL_NAME_3, "drop", "to-lport", MATCH, 1002, true, []string{METER1}, SEVERITY_ALERT, map[interface{}]interface{}{"A": "b", "B": "a"}},
ACL_NAME_5, MATCH_SECOND, METER2, SEVERITY_INFO,
},
},
},
}
// Test ACLAddEntity()
for i, e := range aclEntityTests {
for j, _ := range e.aclTests {
tcName := fmt.Sprintf("add ACL to %s %s #%d", e.entityType, e.entity, j)
t.Run(tcName, func(t *testing.T) {
acl := &aclEntityTests[i].aclTests[j].acl
cmd, err = ovndbapi.ACLAddEntity(e.entityType, e.entity, acl.Name, acl.Direction, acl.Match, acl.Action, acl.Priority, iMapToSMap(acl.ExternalID), acl.Log, acl.Meter[0], acl.Severity)
assert.Nil(t, err)
result, err := ovndbapi.ExecuteR(cmd)
assert.Nil(t, err)
assert.Len(t, result, 1)
if len(result) > 0 {
acl.UUID = result[0]
}
acls, err := ovndbapi.ACLListEntity(e.entityType, e.entity)
assert.Nil(t, err)
assert.Equal(t, j+1, len(acls))
assert.True(t, containsACL(acls, acl))
})
}
}
// Test adding duplicate ACLs
for i, e := range aclEntityTests {
for j, _ := range e.aclTests {
tcName := fmt.Sprintf("add duplicate ACL to %s %s #%d", e.entityType, e.entity, j)
t.Run(tcName, func(t *testing.T) {
acl := &aclEntityTests[i].aclTests[j].acl
cmd, err = ovndbapi.ACLAddEntity(e.entityType, e.entity, acl.Name, acl.Direction, acl.Match, acl.Action, acl.Priority, iMapToSMap(acl.ExternalID), acl.Log, acl.Meter[0], acl.Severity)
assert.NotNil(t, err)
result, err := ovndbapi.ExecuteR(cmd)
assert.Nil(t, err)
assert.Len(t, result, 0)
})
}
}
// Test ACLSetName()
for i, e := range aclEntityTests {
for j, tc := range e.aclTests {
tcName := fmt.Sprintf("set ACL match for %s %s #%d", e.entityType, e.entity, j)
t.Run(tcName, func(t *testing.T) {
acl := &aclEntityTests[i].aclTests[j].acl
cmd, err = ovndbapi.ACLSetName(acl.UUID, tc.newName)
assert.Nil(t, err)
err = ovndbapi.Execute(cmd)
assert.Nil(t, err)
acls, err := ovndbapi.ACLListEntity(e.entityType, e.entity)
assert.Nil(t, err)
acl.Name = tc.newName
assert.True(t, containsACL(acls, acl))
})
}
}
// Test ACLSetMatch()
for i, e := range aclEntityTests {
for j, tc := range e.aclTests {
tcName := fmt.Sprintf("set ACL match for %s %s #%d", e.entityType, e.entity, j)
t.Run(tcName, func(t *testing.T) {
acl := &aclEntityTests[i].aclTests[j].acl
cmd, err = ovndbapi.ACLSetMatch(acl.UUID, tc.newMatch)
assert.Nil(t, err)
err = ovndbapi.Execute(cmd)
assert.Nil(t, err)
acls, err := ovndbapi.ACLListEntity(e.entityType, e.entity)
assert.Nil(t, err)
acl.Match = tc.newMatch
assert.True(t, containsACL(acls, acl))
})
}
}
// Test ACLSetLogging()
for i, e := range aclEntityTests {
for j, tc := range e.aclTests {
tcName := fmt.Sprintf("set ACL match for %s %s #%d", e.entityType, e.entity, j)
t.Run(tcName, func(t *testing.T) {
acl := &aclEntityTests[i].aclTests[j].acl
var newLogflag = false
if tc.newMeter != "" {
newLogflag = true
}
cmd, err = ovndbapi.ACLSetLogging(acl.UUID, newLogflag, tc.newMeter, tc.newSeverity)
assert.Nil(t, err)
err = ovndbapi.Execute(cmd)
assert.Nil(t, err)
acl.Log = newLogflag
if newLogflag {
acl.Meter[0] = tc.newMeter
switch tc.newSeverity {
case "alert", "debug", "info", "notice", "warning":
acl.Severity = tc.newSeverity
case "":
acl.Severity = "info"
default:
assert.Error(t, ErrorOption)
}
}
acls, err := ovndbapi.ACLListEntity(e.entityType, e.entity)
assert.Nil(t, err)
assert.True(t, containsACL(acls, acl))
})
}
}
t.Run("set/delete non-existent ACL", func(t *testing.T) {
cmd, err = ovndbapi.ACLSetLogging(NONEXISTENT_UUID, true, METER1, SEVERITY_INFO)
assert.NotNil(t, err)
cmd, err = ovndbapi.ACLSetMatch(NONEXISTENT_UUID, MATCH)
assert.NotNil(t, err)
cmd, err = ovndbapi.ACLSetName(NONEXISTENT_UUID, ACL_NAME_1)
assert.NotNil(t, err)
cmd, err = ovndbapi.ACLDelEntity(PORT_GROUP, PG_TEST_PG1, NONEXISTENT_UUID)
assert.NotNil(t, err)
})
t.Run("delete ACL from non-existent entities", func(t *testing.T) {
cmd, err = ovndbapi.ACLDelEntity(PORT_GROUP, PG_TEST_PG2, aclEntityTests[0].aclTests[0].acl.UUID)
assert.NotNil(t, err)
cmd, err = ovndbapi.ACLDelEntity(PORT_GROUP, LSW2, aclEntityTests[0].aclTests[0].acl.UUID)
assert.NotNil(t, err)
})
// Test ACLDelEntity()
for i, e := range aclEntityTests {
for j, tc := range e.aclTests {
tcName := fmt.Sprintf("delete ACL from %s %s #%d", e.entityType, e.entity, j)
t.Run(tcName, func(t *testing.T) {
cmd, err = ovndbapi.ACLDelEntity(e.entityType, e.entity, tc.acl.UUID)
assert.Nil(t, err)
result, err := ovndbapi.ExecuteR(cmd)
assert.Nil(t, err)
assert.Len(t, result, 0)
acls, err := ovndbapi.ACLListEntity(e.entityType, e.entity)
assert.Nil(t, err)
assert.Equal(t, len(aclEntityTests[i].aclTests)-1-j, len(acls))
assert.False(t, containsACL(acls, &tc.acl))
})
}
}
// Delete everything else
t.Run("delete meter, switch, ports and port group used for ACL testing", func(t *testing.T) {
cmd, err = ovndbapi.MeterDel(METER1)
assert.Nil(t, err)
err = ovndbapi.Execute(cmd)
assert.Nil(t, err)
cmd, err = ovndbapi.MeterDel(METER2)
assert.Nil(t, err)
err = ovndbapi.Execute(cmd)
assert.Nil(t, err)
cmd, err = ovndbapi.LSDel(PG_TEST_LS1)
assert.Nil(t, err)
err = ovndbapi.Execute(cmd)
assert.Nil(t, err)
cmd, err = ovndbapi.PortGroupDel(PG_TEST_PG1)
assert.Nil(t, err)
err = ovndbapi.Execute(cmd)
assert.Nil(t, err)
})
}