forked from ovn-org/ovn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathovn-sbctl.at
267 lines (222 loc) · 8.02 KB
/
ovn-sbctl.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
AT_BANNER([ovn-sbctl])
OVS_START_SHELL_HELPERS
# OVN_SBCTL_TEST_START
m4_define([OVN_SBCTL_TEST_START],
[AT_KEYWORDS([ovn])
AT_CAPTURE_FILE([ovsdb-server.log])
AT_CAPTURE_FILE([ovn-northd.log])
ovn_sbctl_test_start $1])
ovn_sbctl_test_start() {
dnl Create databases (ovn-nb, ovn-sb).
for daemon in ovn-nb ovn-sb; do
AT_CHECK([ovsdb-tool create $daemon.db $abs_top_srcdir/${daemon}.ovsschema])
done
dnl Start ovsdb-servers.
AT_CHECK([ovsdb-server --detach --no-chdir --pidfile=ovnnb_db.pid --unixctl=$OVS_RUNDIR/ovnnb_db.ctl --log-file=ovsdb_nb.log --remote=punix:$OVS_RUNDIR/ovnnb_db.sock ovn-nb.db ], [0], [], [stderr])
AT_CHECK([ovsdb-server --detach --no-chdir --pidfile=ovnsb_db.pid --unixctl=$OVS_RUNDIR/ovnsb_db.ctl --log-file=ovsdb_sb.log --remote=punix:$OVS_RUNDIR/ovnsb_db.sock ovn-sb.db], [0], [], [stderr])
on_exit "kill `cat ovnnb_db.pid` `cat ovnsb_db.pid`"
AT_CHECK([[sed < stderr '
/vlog|INFO|opened log file/d
/ovsdb_server|INFO|ovsdb-server (Open vSwitch)/d']])
dnl Start ovn-northd.
AT_CHECK([ovn-northd --detach --no-chdir --pidfile --log-file --ovnnb-db=unix:$OVS_RUNDIR/ovnnb_db.sock --ovnsb-db=unix:$OVS_RUNDIR/ovnsb_db.sock], [0], [], [stderr])
on_exit "kill `cat ovn-northd.pid`"
AT_CHECK([[sed < stderr '
/vlog|INFO|opened log file/d']])
AS_CASE([$1],
[daemon],
[export OVN_SB_DAEMON=$(ovn-sbctl --pidfile --detach --no-chdir --log-file -vsocket_util:off)
on_exit "kill `cat ovn-sbctl.pid`"],
[direct], [],
[*], [AT_FAIL_IF(:)])
}
# OVN_SBCTL_TEST_STOP
m4_define([OVN_SBCTL_TEST_STOP], [ovn_sbctl_test_stop])
ovn_sbctl_test_stop() {
AT_CHECK([check_logs "$1"])
OVS_APP_EXIT_AND_WAIT([ovn-northd])
OVS_APP_EXIT_AND_WAIT_BY_TARGET([$OVS_RUNDIR/ovnnb_db.ctl], [$OVS_RUNDIR/ovnnb_db.pid])
OVS_APP_EXIT_AND_WAIT_BY_TARGET([$OVS_RUNDIR/ovnsb_db.ctl], [$OVS_RUNDIR/ovnsb_db.pid])
}
OVS_END_SHELL_HELPERS
# OVN_SBCTL_TEST(NAME, TITLE, COMMANDS)
m4_define([OVN_SBCTL_TEST],
[OVS_START_SHELL_HELPERS
$1() {
$3
}
OVS_END_SHELL_HELPERS
AT_SETUP([ovn-sbctl - $2 - direct])
OVN_SBCTL_TEST_START direct
$1
OVN_SBCTL_TEST_STOP
AT_CLEANUP
AT_SETUP([ovn-sbctl - $2 - daemon])
OVN_SBCTL_TEST_START daemon
$1
OVN_SBCTL_TEST_STOP
AT_CLEANUP])
dnl ---------------------------------------------------------------------
OVN_SBCTL_TEST([ovn_sbctl_chassis_commands], [ovn-sbctl - chassis commands], [
ovn_init_db ovn-sb
AT_CHECK([ovn-sbctl chassis-add ch0 geneve 1.2.3.4])
AT_CHECK([ovn-sbctl -f csv -d bare --no-headings --columns ip,type list encap | sort],
[0], [dnl
1.2.3.4,geneve
])
AT_CHECK([ovn-sbctl chassis-add ch1 stt,geneve,vxlan 1.2.3.5])
AT_CHECK([ovn-sbctl -f csv -d bare --no-headings --columns ip,type list encap | sort],
[0], [dnl
1.2.3.4,geneve
1.2.3.5,geneve
1.2.3.5,stt
1.2.3.5,vxlan
])
AT_CHECK([ovn-sbctl chassis-del ch0])
AT_CHECK([ovn-sbctl -f csv -d bare --no-headings --columns ip,type list encap | sort],
[0], [dnl
1.2.3.5,geneve
1.2.3.5,stt
1.2.3.5,vxlan
])
AT_CHECK([ovn-sbctl chassis-add ch2 geneve 2.3.4.5])
ch2_uuid=$(ovn-sbctl -d bare --no-headings --columns _uuid find chassis name=ch2)
ovn-sbctl create Chassis_Private name=ch2 chassis=$ch2_uuid
check_row_count Chassis_Private 1
AT_CHECK([ovn-sbctl -f csv -d bare --no-headings --columns ip,type list encap | sort],
[0], [dnl
1.2.3.5,geneve
1.2.3.5,stt
1.2.3.5,vxlan
2.3.4.5,geneve
])
AT_CHECK([ovn-sbctl chassis-del ch2])
AT_CHECK([ovn-sbctl -f csv -d bare --no-headings --columns ip,type list encap | sort],
[0], [dnl
1.2.3.5,geneve
1.2.3.5,stt
1.2.3.5,vxlan
])
check_row_count Chassis_Private 0
as ovn-sb
OVS_APP_EXIT_AND_WAIT([ovsdb-server])
as
])
dnl ---------------------------------------------------------------------
OVN_SBCTL_TEST([ovn_sbctl_commands], [ovn-sbctl], [
AT_CHECK([ovn-nbctl ls-add br-test])
AT_CHECK([ovn-nbctl lsp-add br-test vif0])
AT_CHECK([ovn-nbctl lsp-set-addresses vif0 f0:ab:cd:ef:01:02])
AT_CHECK([ovn-sbctl chassis-add ch0 stt 1.2.3.5])
AT_CHECK([ovn-nbctl --wait=sb sync])
AT_CHECK([ovn-sbctl lsp-bind vif0 ch0])
AT_CHECK([ovn-sbctl show], [0], [dnl
Chassis ch0
Encap stt
ip: "1.2.3.5"
options: {csum="true"}
Port_Binding vif0
])
# adds another 'vif1'
AT_CHECK([ovn-nbctl --wait=sb lsp-add br-test vif1])
AT_CHECK([ovn-nbctl lsp-set-addresses vif1 f0:ab:cd:ef:01:03])
AT_CHECK([ovn-sbctl lsp-bind vif1 ch0])
AT_CHECK([ovn-sbctl show | sed 's/vif[[0-9]]/vif/'], [0], [dnl
Chassis ch0
Encap stt
ip: "1.2.3.5"
options: {csum="true"}
Port_Binding vif
Port_Binding vif
])
# deletes 'vif1'
AT_CHECK([ovn-nbctl lsp-del vif1])
AT_CHECK([ovn-nbctl --wait=sb sync])
AT_CHECK([ovn-sbctl show], [0], [dnl
Chassis ch0
Encap stt
ip: "1.2.3.5"
options: {csum="true"}
Port_Binding vif0
])
uuid=$(ovn-sbctl --columns=_uuid list Chassis ch0 | cut -d ':' -f2 | tr -d ' ')
AT_CHECK_UNQUOTED([ovn-sbctl --columns=logical_port,mac,chassis list Port_Binding], [0], [dnl
logical_port : vif0
mac : [["f0:ab:cd:ef:01:02"]]
chassis : ${uuid}
])
# test the passing down of logical port type and options.
AT_CHECK([ovn-nbctl --wait=sb lsp-add br-test vtep0])
AT_CHECK([ovn-nbctl lsp-set-type vtep0 vtep])
AT_CHECK([ovn-nbctl lsp-set-options vtep0 vtep_physical_switch=p0 vtep_logical_switch=l0])
AT_CHECK([ovn-sbctl wait-until Port_Binding vtep0 options!={}])
AT_CHECK([ovn-sbctl --columns=logical_port,mac,type,options list Port_Binding vtep0], [0], [dnl
logical_port : vtep0
mac : [[]]
type : vtep
options : {vtep_logical_switch=l0, vtep_physical_switch=p0}
])
])
dnl ---------------------------------------------------------------------
OVN_SBCTL_TEST([ovn_sbctl_connection], [ovn-sbctl - connection], [
AT_CHECK([ovn-sbctl --inactivity-probe=30000 set-connection ptcp:6641:127.0.0.1 punix:$OVS_RUNDIR/ovnsb_db.sock])
AT_CHECK([ovn-sbctl list connection | grep inactivity_probe], [0], [dnl
inactivity_probe : 30000
inactivity_probe : 30000
])
])
OVN_SBCTL_TEST([ovn_sbctl_invalid_0x_flow], [invalid 0x flow], [
check ovn-sbctl lflow-list 0x12345678
])
dnl ---------------------------------------------------------------------
OVN_SBCTL_TEST([ovn_sbctl_count_flows], [ovn-sbctl - count-flows], [
count_entries() {
ovn-sbctl --column=_uuid list Logical_Flow | sed -r '/^\s*$/d' | wc -l
}
count_pipeline() {
ovn-sbctl --column=pipeline list Logical_Flow | grep $1 | sed -r '/^\s*$/d' | wc -l
}
# we start with empty Logical_Flow table
# validate that the table is indeed empty
AT_CHECK([count_entries], [0], [dnl
0
])
AT_CHECK([ovn-sbctl count-flows], [0], [dnl
Total number of logical flows = 0
])
# create some logical flows
check ovn-nbctl ls-add count-test
OVS_WAIT_UNTIL([total_lflows=`count_entries`; test $total_lflows -ne 0])
total_lflows=`count_entries`
egress_lflows=`count_pipeline egress`
ingress_lflows=`count_pipeline ingress`
AT_CHECK_UNQUOTED([ovn-sbctl count-flows | grep "flows =" | awk 'NF>1{print $NF}'], [0], [dnl
$total_lflows
])
AT_CHECK_UNQUOTED([ovn-sbctl count-flows | grep Total | grep egress | awk 'NF>1{print $NF}'], [0], [dnl
$egress_lflows
])
AT_CHECK_UNQUOTED([ovn-sbctl count-flows | grep Total | grep ingress | awk 'NF>1{print $NF}'], [0], [dnl
$ingress_lflows
])
# add another datapath
check ovn-nbctl --wait=sb ls-add count-test2
# check total logical flows in 2 datapathes
AT_CHECK_UNQUOTED([ovn-sbctl count-flows | grep "flows =" | awk 'NF>1{print $NF}'], [0], [dnl
$(($total_lflows * 2))
])
# check total logical flows in a specific datapath
AT_CHECK_UNQUOTED([ovn-sbctl count-flows count-test | grep "flows =" | awk 'NF>1{print $NF}'], [0], [dnl
$total_lflows
])
AT_CHECK_UNQUOTED([ovn-sbctl count-flows count-test | grep Total | grep egress | awk 'NF>1{print $NF}'], [0], [dnl
$egress_lflows
])
AT_CHECK_UNQUOTED([ovn-sbctl count-flows count-test | grep Total | grep ingress | awk 'NF>1{print $NF}'], [0], [dnl
$ingress_lflows
])
# check nonexistent datapath
AT_CHECK([ovn-sbctl count-flows wrongDatapath], [0], [dnl
Total number of logical flows = 0
])
])