forked from openvswitch/ovs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ovs-vsctl.at
1823 lines (1575 loc) · 58.9 KB
/
ovs-vsctl.at
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
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
dnl OVS_VSCTL_SETUP
dnl
dnl Creates an empty database in the current directory and then starts
dnl an ovsdb-server on it for ovs-vsctl to connect to.
m4_define([OVS_VSCTL_SETUP],
[OVSDB_INIT([db])
AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:db.sock db >/dev/null 2>&1], [0], [ignore], [ignore])
on_exit 'kill `cat ovsdb-server.pid`'])
dnl OVS_VSCTL_CLEANUP
dnl
dnl Kills off the database server.
m4_define([OVS_VSCTL_CLEANUP], [OVS_APP_EXIT_AND_WAIT_BY_TARGET([ovsdb-server], [ovsdb-server.pid])])
dnl RUN_OVS_VSCTL(COMMAND, ...)
dnl
dnl Executes each ovs-vsctl COMMAND.
m4_define([RUN_OVS_VSCTL],
[m4_foreach([command], [$@], [ovs-vsctl --no-wait -vreconnect:emer command
])])
m4_define([RUN_OVS_VSCTL_ONELINE],
[m4_foreach([command], [$@], [ovs-vsctl --no-wait -vreconnect:emer --oneline -- command
])])
dnl RUN_OVS_VSCTL_TOGETHER(COMMAND, ...)
dnl
dnl Executes each ovs-vsctl COMMAND in a single run of ovs-vsctl.
m4_define([RUN_OVS_VSCTL_TOGETHER],
[ovs-vsctl --no-wait -vreconnect:emer --oneline dnl
m4_foreach([command], [$@], [ -- command])])
dnl CHECK_BRIDGES([BRIDGE, PARENT, VLAN], ...)
dnl
dnl Verifies that "ovs-vsctl list-br" prints the specified list of bridges,
dnl which must be in alphabetical order. Also checks that each BRIDGE has the
dnl specified PARENT and is on the given VLAN.
m4_define([_CHECK_BRIDGE],
[AT_CHECK([RUN_OVS_VSCTL([br-to-parent $1])], [0], [$2
])
# Check br-to-vlan, without --oneline.
AT_CHECK([RUN_OVS_VSCTL([br-to-vlan $1])], [0], [$3
])
# Check br-to-vlan, with --oneline.
# (This particular test is interesting with --oneline because it returns
# an integer instead of a string and that can cause type mismatches inside
# python if not done carefully.)
AT_CHECK([RUN_OVS_VSCTL_ONELINE([br-to-vlan $1])], [0], [$3
])
# Check multiple queries in a single run.
AT_CHECK([RUN_OVS_VSCTL_TOGETHER([br-to-parent $1], [br-to-vlan $1])], [0],
[$2
$3
])])
m4_define([CHECK_BRIDGES],
[dnl Check that the bridges appear on list-br, without --oneline.
AT_CHECK(
[RUN_OVS_VSCTL([list-br])],
[0],
[m4_foreach([brinfo], [$@], [m4_car(brinfo)
])])
dnl Check that the bridges appear on list-br, with --oneline.
AT_CHECK(
[RUN_OVS_VSCTL_ONELINE([list-br])],
[0],
[m4_join([\n], m4_foreach([brinfo], [$@], [m4_car(brinfo),]))
])
dnl Check that each bridge exists according to br-exists and that
dnl a bridge that should not exist does not.
m4_foreach([brinfo], [$@],
[AT_CHECK([RUN_OVS_VSCTL([br-exists m4_car(brinfo)])])])
AT_CHECK([RUN_OVS_VSCTL([br-exists nonexistent])], [2])
dnl Check that each bridge has the expected parent and VLAN.
m4_map([_CHECK_BRIDGE], [$@])])
dnl CHECK_PORTS(BRIDGE, PORT[, PORT...])
dnl
dnl Verifies that "ovs-vsctl list-ports BRIDGE" prints the specified
dnl list of ports, which must be in alphabetical order. Also checks
dnl that "ovs-vsctl port-to-br" reports that each port is
dnl in BRIDGE.
m4_define([CHECK_PORTS],
[dnl Check ports without --oneline.
AT_CHECK(
[RUN_OVS_VSCTL([list-ports $1])],
[0],
[m4_foreach([port], m4_cdr($@), [port
])])
dnl Check ports with --oneline.
AT_CHECK(
[RUN_OVS_VSCTL_ONELINE([list-ports $1])],
[0],
[m4_join([\n], m4_shift($@))
])
AT_CHECK([RUN_OVS_VSCTL([port-to-br $1])], [1], [],
[ovs-vsctl: no port named $1
])
m4_foreach(
[port], m4_cdr($@),
[AT_CHECK([RUN_OVS_VSCTL([[port-to-br] port])], [0], [$1
])])])
dnl CHECK_IFACES(BRIDGE, IFACE[, IFACE...])
dnl
dnl Verifies that "ovs-vsctl list-ifaces BRIDGE" prints the specified
dnl list of ifaces, which must be in alphabetical order. Also checks
dnl that "ovs-vsctl iface-to-br" reports that each interface is
dnl in BRIDGE.
m4_define([CHECK_IFACES],
[AT_CHECK(
[RUN_OVS_VSCTL([list-ifaces $1])],
[0],
[m4_foreach([iface], m4_cdr($@), [iface
])])
AT_CHECK([RUN_OVS_VSCTL([iface-to-br $1])], [1], [],
[ovs-vsctl: no interface named $1
])
m4_foreach(
[iface], m4_cdr($@),
[AT_CHECK([RUN_OVS_VSCTL([[iface-to-br] iface])], [0], [$1
])])])
dnl ----------------------------------------------------------------------
AT_BANNER([ovs-vsctl unit tests])
AT_SETUP([ovs-vsctl connection retry])
dnl Without --retry, there should be no retry for active connections.
AT_CHECK([ovs-vsctl --db=unix:foo --timeout=10 -vreconnect:emer -- init],
[1], [], [stderr])
AT_CHECK([[sed 's/([^()]*)/(...reason...)/' stderr]], [0],
[ovs-vsctl: unix:foo: database connection failed (...reason...)
])
dnl With --retry, we should retry for active connections.
AT_CHECK(
[ovs-vsctl --db=unix:foo --timeout=1 --retry -vreconnect:emer -vPATTERN:console:'%c|%p|%m' -- init
echo $? > status],
[0], [], [stderr])
AT_CHECK([grep -c 'terminating with signal' stderr], [0], [1
])
if test "$IS_WIN32" = "yes"; then
AT_CHECK([cat status], [0], [3
])
else
# 128 + SIGALRM
AT_CHECK([cat status], [0], [142
])
fi
dnl Without --retry, we should retry for passive connections.
AT_CHECK(
[ovs-vsctl --db=punix:foo --timeout=1 -vreconnect:emer -vPATTERN:console:'%c|%p|%m' -- init
echo $? > status],
[0], [], [stderr])
AT_CHECK([grep -c 'terminating with signal' stderr], [0], [1
])
if test "$IS_WIN32" = "yes"; then
AT_CHECK([cat status], [0], [3
])
else
# 128 + SIGALRM
AT_CHECK([cat status], [0], [142
])
fi
AT_CLEANUP
dnl ----------------------------------------------------------------------
AT_BANNER([ovs-vsctl unit tests -- real bridges])
AT_SETUP([add-br a])
AT_KEYWORDS([ovs-vsctl])
OVS_VSCTL_SETUP
AT_CHECK([RUN_OVS_VSCTL([add-br a])])
CHECK_BRIDGES([a, a, 0])
CHECK_PORTS([a])
CHECK_IFACES([a])
OVS_VSCTL_CLEANUP
AT_CLEANUP
AT_SETUP([add-br a, add-br a])
AT_KEYWORDS([ovs-vsctl])
OVS_VSCTL_SETUP
AT_CHECK([RUN_OVS_VSCTL([add-br a])], [0])
AT_CHECK([RUN_OVS_VSCTL([add-br a])], [1], [],
[ovs-vsctl: cannot create a bridge named a because a bridge named a already exists
])
AT_CHECK([RUN_OVS_VSCTL([add-br ''])], [1], [],
[ovs-vsctl: bridge name must not be empty string
])
OVS_VSCTL_CLEANUP
AT_CLEANUP
AT_SETUP([add-br a, add-br b])
AT_KEYWORDS([ovs-vsctl])
OVS_VSCTL_SETUP
AT_CHECK([RUN_OVS_VSCTL([add-br a], [add-br b])])
AT_CHECK([RUN_OVS_VSCTL([--may-exist add-br a b 9])], [1], [],
[ovs-vsctl: "--may-exist add-br a b 9" but a is not a VLAN bridge
])
CHECK_BRIDGES([a, a, 0], [b, b, 0])
CHECK_PORTS([a])
CHECK_IFACES([a])
CHECK_PORTS([b])
CHECK_IFACES([b])
OVS_VSCTL_CLEANUP
AT_CLEANUP
AT_SETUP([add-br a, add-br b, del-br a])
AT_KEYWORDS([ovs-vsctl])
OVS_VSCTL_SETUP
AT_CHECK([RUN_OVS_VSCTL([add-br a], [add-br b], [del-br a])])
CHECK_BRIDGES([b, b, 0])
CHECK_PORTS([b])
CHECK_IFACES([b])
OVS_VSCTL_CLEANUP
AT_CLEANUP
AT_SETUP([add-br a, del-br a, add-br a])
AT_KEYWORDS([ovs-vsctl])
OVS_VSCTL_SETUP
AT_CHECK([RUN_OVS_VSCTL_TOGETHER(
[add-br a],
[del-br a],
[add-br a],
[set Interface a other_config:key=value],
[get Interface a other_config:key])], [0], [
value
])
CHECK_BRIDGES([a, a, 0])
CHECK_PORTS([a])
CHECK_IFACES([a])
OVS_VSCTL_CLEANUP
AT_CLEANUP
AT_SETUP([add-br a, add-port a a1, add-port a a2])
AT_KEYWORDS([ovs-vsctl])
OVS_VSCTL_SETUP
AT_CHECK([RUN_OVS_VSCTL(
[add-br a],
[--if-exists del-br b],
[add-port a a1],
[add-port a a2])])
CHECK_BRIDGES([a, a, 0])
CHECK_PORTS([a], [a1], [a2])
CHECK_IFACES([a], [a1], [a2])
OVS_VSCTL_CLEANUP
AT_CLEANUP
AT_SETUP([add-br a, add-port a a1, add-port a a1])
AT_KEYWORDS([ovs-vsctl])
OVS_VSCTL_SETUP
AT_CHECK([RUN_OVS_VSCTL(
[add-br a],
[add-port a a1])])
AT_CHECK([RUN_OVS_VSCTL([add-port a a1])], [1], [],
[ovs-vsctl: cannot create a port named a1 because a port named a1 already exists on bridge a
])
AT_CHECK([RUN_OVS_VSCTL([add-port a ''])], [1], [],
[ovs-vsctl: port name must not be empty string
])
OVS_VSCTL_CLEANUP
AT_CLEANUP
AT_SETUP([add-br a b, add-port a a1, add-port b b1, del-br a])
AT_KEYWORDS([ovs-vsctl])
OVS_VSCTL_SETUP
AT_CHECK([RUN_OVS_VSCTL_TOGETHER(
[add-br a],
[add-br b],
[add-port a a1],
[add-port b b1],
[--if-exists del-port b b2],
[del-br a])], [0], [
])
CHECK_BRIDGES([b, b, 0])
CHECK_PORTS([b], [b1])
CHECK_IFACES([b], [b1])
OVS_VSCTL_CLEANUP
AT_CLEANUP
AT_SETUP([add-br a, add-bond a bond0 a1 a2 a3])
AT_KEYWORDS([ovs-vsctl])
OVS_VSCTL_SETUP
AT_CHECK([RUN_OVS_VSCTL(
[add-br a],
[add-bond a bond0 a1 a2 a3])])
AT_CHECK([RUN_OVS_VSCTL([--may-exist add-bond a bond0 a3 a1 a2])])
AT_CHECK([RUN_OVS_VSCTL([--may-exist add-bond a bond0 a2 a1])], [1], [],
[ovs-vsctl: "--may-exist add-bond a bond0 a2 a1" but bond0 actually has interface(s) a1, a2, a3
])
AT_CHECK([RUN_OVS_VSCTL([add-bond a '' x y z])], [1], [],
[ovs-vsctl: port name must not be empty string
])
AT_CHECK([RUN_OVS_VSCTL([add-bond a x '' y z])], [1], [],
[ovs-vsctl: interface name must not be empty string
])
CHECK_BRIDGES([a, a, 0])
CHECK_PORTS([a], [bond0])
CHECK_IFACES([a], [a1], [a2], [a3])
OVS_VSCTL_CLEANUP
AT_CLEANUP
AT_SETUP([add-bond-iface and del-bond-iface])
AT_KEYWORDS([ovs-vsctl])
OVS_VSCTL_SETUP
# Create 2-interface bond.
AT_CHECK([RUN_OVS_VSCTL(
[add-br a],
[add-bond a bond0 a1 a2])])
CHECK_BRIDGES([a, a, 0])
CHECK_PORTS([a], [bond0])
CHECK_IFACES([a], [a1], [a2])
# Add interface a3 to bond.
AT_CHECK([RUN_OVS_VSCTL([add-bond-iface bond0 a3])])
CHECK_BRIDGES([a, a, 0])
CHECK_PORTS([a], [bond0])
CHECK_IFACES([a], [a1], [a2], [a3])
# Delete interface a2 from bond.
AT_CHECK([RUN_OVS_VSCTL([del-bond-iface bond0 a2])])
CHECK_BRIDGES([a, a, 0])
CHECK_PORTS([a], [bond0])
CHECK_IFACES([a], [a1], [a3])
# Add interface a2 to bond.
AT_CHECK([RUN_OVS_VSCTL([add-bond-iface bond0 a2])])
CHECK_BRIDGES([a, a, 0])
CHECK_PORTS([a], [bond0])
CHECK_IFACES([a], [a1], [a2], [a3])
# Delete interface a2 from bond.
AT_CHECK([RUN_OVS_VSCTL([del-bond-iface a2])])
CHECK_BRIDGES([a, a, 0])
CHECK_PORTS([a], [bond0])
CHECK_IFACES([a], [a1], [a3])
AT_CHECK([RUN_OVS_VSCTL([--if-exists del-bond-iface bond0 a4])])
AT_CHECK([RUN_OVS_VSCTL([del-bond-iface bond0 a4])], [1], [],
[ovs-vsctl: no interface named a4
])
AT_CHECK([RUN_OVS_VSCTL([del-bond-iface a4])], [1], [],
[ovs-vsctl: no interface named a4
])
AT_CHECK([RUN_OVS_VSCTL_TOGETHER([add-port a a4], [del-bond-iface bond0 a4])], [1], [],
[ovs-vsctl: port bond0 does not have an interface a4
])
AT_CHECK([RUN_OVS_VSCTL([--may-exist add-bond-iface bond0 a3])])
AT_CHECK([RUN_OVS_VSCTL_TOGETHER([add-bond a bond1 b1 b2 b3], [--may-exist add-bond-iface bond1 a3])], [1], [],
[ovs-vsctl: "--may-exist add-bond-iface bond1 a3" but a3 is actually attached to port bond0
])
AT_CHECK([RUN_OVS_VSCTL([add-bond-iface bond0 a3])], [1], [],
[ovs-vsctl: cannot create an interface named a3 because an interface named a3 already exists on bridge a
])
AT_CHECK([RUN_OVS_VSCTL_TOGETHER([del-bond-iface a1], [del-bond-iface a3])], [1], [],
[ovs-vsctl: cannot delete last interface from port bond0
])
OVS_VSCTL_CLEANUP
AT_CLEANUP
AT_SETUP([add-br a b, add-port a a1, add-port b b1, del-port a a1])
AT_KEYWORDS([ovs-vsctl])
OVS_VSCTL_SETUP
AT_CHECK([RUN_OVS_VSCTL(
[add-br a],
[add-br b],
[add-port a a1 tag=9],
[get port a1 tag],
[--may-exist add-port b b1],
[del-port a a1])], [0], [9
])
AT_CHECK([RUN_OVS_VSCTL([--may-exist add-port b b1])])
AT_CHECK([RUN_OVS_VSCTL([del-port a])], [1], [],
[ovs-vsctl: cannot delete port a because it is the local port for bridge a (deleting this port requires deleting the entire bridge)
])
AT_CHECK([RUN_OVS_VSCTL([--if-exists del-port a])])
AT_CHECK([RUN_OVS_VSCTL([--may-exist add-port a b1])], [1], [],
[ovs-vsctl: "--may-exist add-port a b1" but b1 is actually attached to bridge b
])
CHECK_BRIDGES([a, a, 0], [b, b, 0])
CHECK_PORTS([a])
CHECK_IFACES([a])
CHECK_PORTS([b], [b1])
CHECK_IFACES([b], [b1])
OVS_VSCTL_CLEANUP
AT_CLEANUP
AT_SETUP([add-br a, add-bond a bond0 a1 a2 a3, del-port bond0])
AT_KEYWORDS([ovs-vsctl])
OVS_VSCTL_SETUP
AT_CHECK([RUN_OVS_VSCTL_TOGETHER(
[add-br a],
[add-bond a bond0 a1 a2 a3 tag=9],
[get Port bond0 tag],
[del-port bond0])], [0], [
9
])
CHECK_BRIDGES([a, a, 0])
CHECK_PORTS([a])
OVS_VSCTL_CLEANUP
AT_CLEANUP
AT_SETUP([external IDs])
AT_KEYWORDS([ovs-vsctl])
OVS_VSCTL_SETUP
AT_CHECK([RUN_OVS_VSCTL_ONELINE(
[add-br a],
[add-port a a1],
[add-bond a bond0 a2 a3],
[br-set-external-id a key0 value0],
[add Bridge a external_ids key0=value1],
[set port a1 external-ids:key1=value1],
[set interface a2 external-ids:key2=value2],
[set interface a2 external-ids:key3=value3],
[set interface a3 external-ids:key4=value4],
[br-get-external-id a],
[br-get-external-id a key0],
[br-get-external-id a key1],
[br-set-external-id a key0 othervalue],
[br-get-external-id a],
[br-set-external-id a key0],
[br-get-external-id a],
[get port a1 external-ids],
[get interface a2 external-ids],
[get interface a3 external-ids])], [0], [
key0=value0
value0
key0=othervalue
{key1=value1}
{key2=value2, key3=value3}
{key4=value4}
])
AT_CHECK([RUN_OVS_VSCTL_TOGETHER(
[br-get-external-id a],
[get port a1 external-ids],
[get interface a2 external-ids],
[get interface a3 external-ids])], [0],
[
{key1=value1}
{key2=value2, key3=value3}
{key4=value4}
])
CHECK_BRIDGES([a, a, 0])
CHECK_PORTS([a], [a1], [bond0])
CHECK_IFACES([a], [a1], [a2], [a3])
OVS_VSCTL_CLEANUP
AT_CLEANUP
AT_SETUP([controllers])
AT_KEYWORDS([controller ovs-vsctl])
OVS_VSCTL_SETUP
AT_CHECK([RUN_OVS_VSCTL_TOGETHER(
[add-br br0],
[get-controller br0],
[set-controller br0 tcp:4.5.6.7],
[get-controller br0],
[del-controller br0],
[get-controller br0],
[set-controller br0 tcp:8.9.10.11 tcp:5.4.3.2],
[get-controller br0],
[--inactivity-probe=30000 set-controller br0 tcp:1.2.3.4],
[get-controller br0])], [0], [
tcp:4.5.6.7
tcp:5.4.3.2\ntcp:8.9.10.11
tcp:1.2.3.4
])
OVS_VSCTL_CLEANUP
AT_CLEANUP
AT_SETUP([fail-mode])
AT_KEYWORDS([fail-mode ovs-vsctl])
OVS_VSCTL_SETUP
AT_CHECK([RUN_OVS_VSCTL_TOGETHER(
[add-br br0],
[get-fail-mode br0],
[set-fail-mode br0 secure],
[get-fail-mode br0],
[del-fail-mode br0],
[get-fail-mode br0],
[set-fail-mode br0 standalone],
[get-fail-mode br0])], [0], [
secure
standalone
])
OVS_VSCTL_CLEANUP
AT_CLEANUP
# check if emer-reset reset switch to known good state
# test is implemented by creating switch entities and checks if after applying
# emer-reset these entities are deleted
AT_SETUP([emer-reset])
AT_KEYWORDS([emer-reset ovs-vsctl])
OVS_VSCTL_SETUP
# define controllers, fail-mode, netflow, mirror
AT_CHECK([RUN_OVS_VSCTL_TOGETHER(
[add-br br0],
[add-port br0 eth0],
[add-port br0 eth1],
[set-controller br0 tcp:4.5.6.7],
[set-fail-mode br0 secure],
[set bridge br0 netflow=@nf],
[--id=@nf create netflow targets=3.4.5.6],
[set bridge br0 mirrors=@m],
[--id=@eth0 get port eth0],
[--id=@eth1 get port eth1],
[--id=@m create mirror name=mymirror select-dst-port=@eth0 select-src-port=@eth0 output-port=@eth1],
[set bridge br0 sflow=@sf],
[--id=@sf create sflow targets=1.2.3.4],
[set bridge br0 datapath-type=dummy other-config:datapath-id=1234 other-config:hwaddr="00:12:34:56:78:bb"],
[set bridge br0 ipfix=@fix],
[--id=@fix create ipfix targets=1.2.3.4],
[set bridge br0 flood_vlans=1],
[set bridge br0 datapath_id=2 datapath_version="alpha"],
[list bridge > configured_bridge.txt]
)], [0], [stdout])
AT_CHECK(
[uuidfilt configured_bridge.txt],
[0],[[
<0>
<1>
<2>
<3>
_uuid : <4>
auto_attach : []
controller : [<5>]
datapath_id : "2"
datapath_type : dummy
datapath_version : alpha
external_ids : {}
fail_mode : secure
flood_vlans : [1]
flow_tables : {}
ipfix : <6>
mcast_snooping_enable: false
mirrors : [<7>]
name : br0
netflow : <8>
other_config : {datapath-id="1234", hwaddr="00:12:34:56:78:bb"}
ports : [<9>, <10>, <11>]
protocols : []
rstp_enable : false
rstp_status : {}
sflow : <12>
status : {}
stp_enable : false
]])
# execute emer-reset
AT_CHECK([RUN_OVS_VSCTL_TOGETHER(
[emer-reset])], [0], [
])
# check if bridge was cleaned/reset
AT_CHECK([RUN_OVS_VSCTL_TOGETHER(
[list bridge > cleaned_bridge.txt]
)], [0], [stdout])
AT_CHECK(
[uuidfilt cleaned_bridge.txt],
[0],[[_uuid : <0>
auto_attach : []
controller : []
datapath_id : "2"
datapath_type : dummy
datapath_version : alpha
external_ids : {}
fail_mode : []
flood_vlans : []
flow_tables : {}
ipfix : []
mcast_snooping_enable: false
mirrors : []
name : br0
netflow : []
other_config : {hwaddr="00:12:34:56:78:bb"}
ports : [<1>, <2>, <3>]
protocols : []
rstp_enable : false
rstp_status : {}
sflow : []
status : {}
stp_enable : false
]])
OVS_VSCTL_CLEANUP
AT_CLEANUP
dnl ----------------------------------------------------------------------
dnl OVS_VSCTL_SETUP_SIMPLE_FAKE_CONF([VLAN])
m4_define([OVS_VSCTL_SETUP_SIMPLE_FAKE_CONF],
[AT_CHECK(
[RUN_OVS_VSCTL(
[add-br xenbr0],
[--may-exist add-br xenbr0],
[add-port xenbr0 eth0],
[--may-exist add-port xenbr0 eth0],
[add-br xapi1 xenbr0 $1],
[--may-exist add-br xapi1 xenbr0 $1],
[add-port xapi1 eth0.$1])])])
dnl OVS_VSCTL_FAKE_BRIDGE_TESTS([VLAN])
m4_define([OVS_VSCTL_FAKE_BRIDGE_TESTS], [
AT_BANNER([ovs-vsctl unit tests -- fake bridges (VLAN $1)])
AT_SETUP([simple fake bridge (VLAN $1)])
AT_KEYWORDS([ovs-vsctl fake-bridge])
OVS_VSCTL_SETUP
OVS_VSCTL_SETUP_SIMPLE_FAKE_CONF([$1])
AT_CHECK([RUN_OVS_VSCTL([--may-exist add-br xapi1])], [1], [],
[ovs-vsctl: "--may-exist add-br xapi1" but xapi1 is a VLAN bridge for VLAN $1
])
AT_CHECK([RUN_OVS_VSCTL([--may-exist add-br xapi1 xxx $1])], [1], [],
[ovs-vsctl: "--may-exist add-br xapi1 xxx $1" but xapi1 has the wrong parent xenbr0
])
AT_CHECK([RUN_OVS_VSCTL([--may-exist add-br xapi1 xenbr0 10])], [1], [],
[ovs-vsctl: "--may-exist add-br xapi1 xenbr0 10" but xapi1 is a VLAN bridge for the wrong VLAN $1
])
AT_CHECK([RUN_OVS_VSCTL([--may-exist add-br dup xenbr0 $1])], [1], [],
[ovs-vsctl: bridge xenbr0 already has a child VLAN bridge xapi1 on VLAN $1
])
CHECK_BRIDGES([xapi1, xenbr0, $1], [xenbr0, xenbr0, 0])
CHECK_PORTS([xenbr0], [eth0])
CHECK_IFACES([xenbr0], [eth0])
CHECK_PORTS([xapi1], [eth0.$1])
CHECK_IFACES([xapi1], [eth0.$1])
OVS_VSCTL_CLEANUP
AT_CLEANUP
AT_SETUP([list bridges -- real and fake (VLAN $1)])
AT_KEYWORDS([ovs-vsctl fake-bridge])
OVS_VSCTL_SETUP
OVS_VSCTL_SETUP_SIMPLE_FAKE_CONF([$1])
AT_CHECK([RUN_OVS_VSCTL_ONELINE([-- list-br])], [0],
[xapi1\nxenbr0
])
AT_CHECK([RUN_OVS_VSCTL_ONELINE([-- --real list-br])], [0],
[xenbr0
])
AT_CHECK([RUN_OVS_VSCTL_ONELINE([-- --fake list-br])], [0],
[xapi1
])
OVS_VSCTL_CLEANUP
AT_CLEANUP
AT_SETUP([simple fake bridge + del-br fake bridge (VLAN $1)])
AT_KEYWORDS([ovs-vsctl fake-bridge])
OVS_VSCTL_SETUP
OVS_VSCTL_SETUP_SIMPLE_FAKE_CONF([$1])
AT_CHECK([RUN_OVS_VSCTL([del-br xapi1])])
CHECK_BRIDGES([xenbr0, xenbr0, 0])
CHECK_PORTS([xenbr0], [eth0])
CHECK_IFACES([xenbr0], [eth0])
OVS_VSCTL_CLEANUP
AT_CLEANUP
AT_SETUP([simple fake bridge + del-br real bridge (VLAN $1)])
AT_KEYWORDS([ovs-vsctl fake-bridge])
OVS_VSCTL_SETUP
OVS_VSCTL_SETUP_SIMPLE_FAKE_CONF([$1])
AT_CHECK([RUN_OVS_VSCTL([del-br xenbr0])])
CHECK_BRIDGES
OVS_VSCTL_CLEANUP
AT_CLEANUP
AT_SETUP([simple fake bridge + external IDs (VLAN $1)])
AT_KEYWORDS([ovs-vsctl fake-bridge])
OVS_VSCTL_SETUP
OVS_VSCTL_SETUP_SIMPLE_FAKE_CONF([$1])
AT_CHECK([RUN_OVS_VSCTL_TOGETHER(
[br-set-external-id xenbr0 key0 value0],
[br-set-external-id xapi1 key1 value1],
[br-get-external-id xenbr0],
[br-get-external-id xenbr0 key0],
[br-get-external-id xapi1],
[br-get-external-id xapi1 key1])], [0], [
key0=value0
value0
key1=value1
value1
])
CHECK_BRIDGES([xapi1, xenbr0, $1], [xenbr0, xenbr0, 0])
CHECK_PORTS([xenbr0], [eth0])
CHECK_IFACES([xenbr0], [eth0])
CHECK_PORTS([xapi1], [eth0.$1])
CHECK_IFACES([xapi1], [eth0.$1])
OVS_VSCTL_CLEANUP
AT_CLEANUP
AT_SETUP([simple fake bridge + del-port from parent (VLAN $1)])
AT_KEYWORDS([ovs-vsctl fake-bridge del-port])
OVS_VSCTL_SETUP
OVS_VSCTL_SETUP_SIMPLE_FAKE_CONF([$1])
AT_CHECK([RUN_OVS_VSCTL([del-port xenbr0 eth0.$1])], [1], [],
[ovs-vsctl: bridge xenbr0 does not have a port eth0.$1 (although its child bridge xapi1 does)
])
CHECK_PORTS([xenbr0], [eth0])
CHECK_IFACES([xenbr0], [eth0])
CHECK_PORTS([xapi1], [eth0.$1])
CHECK_IFACES([xapi1], [eth0.$1])
AT_CHECK([RUN_OVS_VSCTL([del-port xapi1 eth0.$1])])
CHECK_PORTS([xenbr0], [eth0])
CHECK_IFACES([xenbr0], [eth0])
OVS_VSCTL_CLEANUP
AT_CLEANUP
]) # OVS_VSCTL_FAKE_BRIDGE_TESTS
OVS_VSCTL_FAKE_BRIDGE_TESTS([9])
OVS_VSCTL_FAKE_BRIDGE_TESTS([0])
dnl OVS_VSCTL_SETUP_BOND_FAKE_CONF([VLAN])
m4_define([OVS_VSCTL_SETUP_BOND_FAKE_CONF],
[AT_CHECK(
[RUN_OVS_VSCTL(
[add-br xapi1],
[add-bond xapi1 bond0 eth0 eth1],
[add-br xapi2 xapi1 $1],
[add-port xapi2 bond0.$1])])])
AT_SETUP([fake bridge on bond])
AT_KEYWORDS([ovs-vsctl fake-bridge])
OVS_VSCTL_SETUP
OVS_VSCTL_SETUP_BOND_FAKE_CONF([11])
CHECK_BRIDGES([xapi1, xapi1, 0], [xapi2, xapi1, 11])
CHECK_PORTS([xapi1], [bond0])
CHECK_IFACES([xapi1], [eth0], [eth1])
CHECK_PORTS([xapi2], [bond0.11])
CHECK_IFACES([xapi2], [bond0.11])
OVS_VSCTL_CLEANUP
AT_CLEANUP
AT_SETUP([fake bridge on bond + del-br fake bridge])
AT_KEYWORDS([ovs-vsctl fake-bridge])
OVS_VSCTL_SETUP
OVS_VSCTL_SETUP_BOND_FAKE_CONF([11])
AT_CHECK([RUN_OVS_VSCTL_ONELINE([del-br xapi2])], [0], [
])
CHECK_BRIDGES([xapi1, xapi1, 0])
CHECK_PORTS([xapi1], [bond0])
CHECK_IFACES([xapi1], [eth0], [eth1])
OVS_VSCTL_CLEANUP
AT_CLEANUP
AT_SETUP([fake bridge on bond + del-br real bridge])
AT_KEYWORDS([ovs-vsctl fake-bridge])
OVS_VSCTL_SETUP
OVS_VSCTL_SETUP_BOND_FAKE_CONF([11])
AT_CHECK([RUN_OVS_VSCTL([del-br xapi1])])
CHECK_BRIDGES
OVS_VSCTL_CLEANUP
AT_CLEANUP
dnl ----------------------------------------------------------------------
AT_BANNER([ovs-vsctl unit tests -- manager commands])
AT_SETUP([managers])
AT_KEYWORDS([manager ovs-vsctl])
OVS_VSCTL_SETUP
AT_CHECK([RUN_OVS_VSCTL_TOGETHER(
[del-manager],
[get-manager],
[set-manager tcp:4.5.6.7],
[get-manager],
[set-manager tcp:8.9.10.11 tcp:5.4.3.2],
[get-manager],
[--inactivity-probe=30000 set-manager tcp:1.2.3.4],
[get-manager],
[del-manager],
[get-manager])], [0], [
tcp:4.5.6.7
tcp:5.4.3.2\ntcp:8.9.10.11
tcp:1.2.3.4
])
OVS_VSCTL_CLEANUP
AT_CLEANUP
dnl ----------------------------------------------------------------------
AT_BANNER([ovs-vsctl unit tests -- database commands])
AT_SETUP([database commands -- positive checks])
AT_KEYWORDS([ovs-vsctl])
OVS_VSCTL_SETUP
AT_CHECK(
[RUN_OVS_VSCTL_TOGETHER([--id=@br0 create bridge name=br123],
[set b br123 name=br0],
[set o . bridges=@br0])],
[0], [stdout])
cp stdout out1
AT_CHECK([RUN_OVS_VSCTL([list bridge], [get bridge br0 _uuid])],
[0], [stdout])
cp stdout out2
AT_CHECK([uuidfilt out1 out2], [0],
[[<0>
_uuid : <0>
auto_attach : []
controller : []
datapath_id : []
datapath_type : ""
datapath_version : ""
external_ids : {}
fail_mode : []
flood_vlans : []
flow_tables : {}
ipfix : []
mcast_snooping_enable: false
mirrors : []
name : br0
netflow : []
other_config : {}
ports : []
protocols : []
rstp_enable : false
rstp_status : {}
sflow : []
status : {}
stp_enable : false
<0>
]], [ignore])
AT_CHECK(
[RUN_OVS_VSCTL([--columns=fail_mode,name,datapath_type list bridge])],
[0],
[[fail_mode : []
name : br0
datapath_type : ""
]], [ignore])
AT_CHECK(
[RUN_OVS_VSCTL([--columns=fail_mode,name,datapath_type find bridge])],
[0],
[[fail_mode : []
name : br0
datapath_type : ""
]], [ignore])
AT_CHECK([
RUN_OVS_VSCTL_TOGETHER([--id=@br1 create bridge name=br1 datapath_type="foo"],
[--id=@br2 create bridge name=br2 external-ids:bar=quux],
[add o . bridges @br1 @br2])],
[0], [stdout])
AT_CHECK(
[RUN_OVS_VSCTL([--columns=name find bridge datapath_type!=foo])], [0], [stdout],
[ignore])
AT_CHECK([sed -n '/./p' stdout | sort], [0],
[[name : br0
name : br2
]])
AT_CHECK(
[RUN_OVS_VSCTL(
[set bridge br0 \
'other_config:datapath_id="0123456789ab"' \
'other_config:hwaddr="00:11:22:33:44:55"' \
'external-ids={"uuids"="9c45f225-a7cf-439d-976d-83db6271fda1"}' -- \
add bridge br0 external_ids '"roles"="local; remote; cloud"'])])
AT_CHECK([RUN_OVS_VSCTL_ONELINE([get bridge br0 other_config external-ids])],
[0], [{datapath_id="0123456789ab", hwaddr="00:11:22:33:44:55"}\n{roles="local; remote; cloud", uuids="9c45f225-a7cf-439d-976d-83db6271fda1"}
])
AT_CHECK([RUN_OVS_VSCTL([get bridge br0 other_config:hwaddr -- --if-exists get bridge br0 other-config:nonexistent])],
[0], ["00:11:22:33:44:55"
])
AT_CHECK([RUN_OVS_VSCTL([remove bridge br0 other_config hwaddr 'datapath_id=""' -- get bridge br0 other_config])],
[0], [{datapath_id="0123456789ab"}
])
AT_CHECK([RUN_OVS_VSCTL([remove bridge br0 other_config 'datapath_id="0123456789ab"' -- get bridge br0 other_config])],
[0], [{}
])
AT_CHECK([RUN_OVS_VSCTL([clear bridge br0 external-ids -- get bridge br0 external_ids])],
[0], [{}
])
AT_CHECK([RUN_OVS_VSCTL_TOGETHER([destroy bridge br0],
[destroy bridge br1],
[destroy bridge br2],
[clear o . bridges])],
[0], [stdout])
AT_CHECK([RUN_OVS_VSCTL([list bridge])])
AT_CHECK([RUN_OVS_VSCTL([--if-exists get bridge x datapath_id])])
AT_CHECK([RUN_OVS_VSCTL([--if-exists list bridge x])])
AT_CHECK([RUN_OVS_VSCTL([--if-exists set controller x connection_mode=standalone])])
AT_CHECK(
[RUN_OVS_VSCTL([--if-exists remove netflow x targets '"1.2.3.4:567"'])])
AT_CHECK(
[RUN_OVS_VSCTL([--if-exists clear netflow x targets])])
AT_CHECK([RUN_OVS_VSCTL([-- --id=@m create Datapath datapath_version=0 -- set Open_vSwitch . datapaths:"netdev"=@m])], [0], [stdout])
AT_CHECK([RUN_OVS_VSCTL([add-zone-tp netdev zone=1 icmp_first=1 icmp_reply=2])])
AT_CHECK([RUN_OVS_VSCTL([--may-exist add-zone-tp netdev zone=1 icmp_first=1 icmp_reply=2])])
AT_CHECK([RUN_OVS_VSCTL([list-zone-tp netdev])], [0], [Zone:1, Timeout Policies: icmp_first=1 icmp_reply=2
])
AT_CHECK([RUN_OVS_VSCTL([add-zone-tp netdev zone=2 icmp_first=2 icmp_reply=3])])
AT_CHECK([RUN_OVS_VSCTL([list-zone-tp netdev])], [0], [Zone:1, Timeout Policies: icmp_first=1 icmp_reply=2
Zone:2, Timeout Policies: icmp_first=2 icmp_reply=3
])
AT_CHECK([RUN_OVS_VSCTL([del-zone-tp netdev zone=1])])
AT_CHECK([RUN_OVS_VSCTL([--if-exists del-zone-tp netdev zone=1])])
AT_CHECK([RUN_OVS_VSCTL([list-zone-tp netdev])], [0], [Zone:2, Timeout Policies: icmp_first=2 icmp_reply=3
])
AT_CHECK(
[RUN_OVS_VSCTL_TOGETHER([--id=@n create CT_Zone external_ids:"test"="123"],
[--id=@m create Datapath datapath_version=0 ct_zones:"10"=@n],
[set Open_vSwitch . datapaths:"netdev"=@m])],
[0], [stdout])
AT_CHECK([RUN_OVS_VSCTL([list-zone-tp netdev])], [0], [Zone:10, Timeout Policies: system default
])
AT_CHECK([RUN_OVS_VSCTL([--if-exists del-zone-tp netdev zone=10])])
AT_CHECK([RUN_OVS_VSCTL([list-zone-limits netdev])])
AT_CHECK([RUN_OVS_VSCTL([set-zone-limit netdev 1 1])])
AT_CHECK([RUN_OVS_VSCTL([list-zone-limits netdev])], [0], [dnl
Zone: 1, Limit: 1
])
AT_CHECK([RUN_OVS_VSCTL([set-zone-limit netdev 1 5])])
AT_CHECK([RUN_OVS_VSCTL([list-zone-limits netdev])], [0], [dnl
Zone: 1, Limit: 5
])
AT_CHECK([RUN_OVS_VSCTL([del-zone-limit netdev 1])])
AT_CHECK([RUN_OVS_VSCTL([list-zone-limits netdev])])
AT_CHECK([RUN_OVS_VSCTL([set-zone-limit netdev 10 5])])
AT_CHECK([RUN_OVS_VSCTL([list-zone-limits netdev])], [0], [dnl
Zone: 10, Limit: 5
])
AT_CHECK([RUN_OVS_VSCTL([add-zone-tp netdev zone=10 icmp_first=1 icmp_reply=2])])