]> git.proxmox.com Git - mirror_ovs.git/blob - tests/ovsdb-server.at
tests: Fix bug in ovsdb-server test suite.
[mirror_ovs.git] / tests / ovsdb-server.at
1 AT_BANNER([OVSDB -- ovsdb-server transactions (Unix sockets)])
2
3 m4_define([OVSDB_SERVER_SHUTDOWN],
4 [cp pid savepid
5 AT_CHECK([ovs-appctl -t $PWD/unixctl -e exit], [0], [ignore], [ignore])
6 OVS_WAIT_WHILE([kill -0 `cat savepid`], [kill `cat savepid`])])
7
8 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
9 #
10 # Creates a database with the given SCHEMA, starts an ovsdb-server on
11 # that database, and runs each of the TRANSACTIONS (which should be a
12 # quoted list of quoted strings) against it with ovsdb-client one at a
13 # time.
14 #
15 # Checks that the overall output is OUTPUT, but UUIDs in the output
16 # are replaced by markers of the form <N> where N is a number. The
17 # first unique UUID is replaced by <0>, the next by <1>, and so on.
18 # If a given UUID appears more than once it is always replaced by the
19 # same marker.
20 #
21 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
22 m4_define([OVSDB_CHECK_EXECUTION],
23 [AT_SETUP([$1])
24 AT_KEYWORDS([ovsdb server positive unix $5])
25 AT_DATA([schema], [$2
26 ])
27 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
28 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --remote=punix:socket --unixctl=$PWD/unixctl db], [0], [ignore], [ignore])
29 m4_foreach([txn], [$3],
30 [AT_CHECK([ovsdb-client transact unix:socket 'txn'], [0], [stdout], [ignore],
31 [test ! -e pid || kill `cat pid`])
32 cat stdout >> output
33 ])
34 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
35 [test ! -e pid || kill `cat pid`])
36 OVSDB_SERVER_SHUTDOWN
37 AT_CLEANUP])
38
39 EXECUTION_EXAMPLES
40 \f
41 AT_SETUP([database multiplexing implementation])
42 AT_KEYWORDS([ovsdb server positive])
43 AT_DATA([schema], [ORDINAL_SCHEMA
44 ])
45 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
46 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --unixctl=$PWD/unixctl --remote=punix:socket db], [0], [ignore], [ignore])
47 AT_CHECK(
48 [[ovsdb-client list-dbs unix:socket]],
49 [0], [ordinals
50 ], [ignore], [test ! -e pid || kill `cat pid`])
51 AT_CHECK(
52 [[ovsdb-client get-schema unix:socket nonexistent]],
53 [1], [], [[ovsdb-client: syntax "{"details":"get_schema request specifies unknown database nonexistent","error":"unknown database","syntax":"[\"nonexistent\"]"}": syntax error: Parsing database schema failed: Required 'name' member is missing.
54 ]], [test ! -e pid || kill `cat pid`])
55 OVSDB_SERVER_SHUTDOWN
56 AT_CLEANUP
57
58 AT_SETUP([--remote=db: implementation])
59 AT_KEYWORDS([ovsdb server positive])
60 AT_DATA([schema],
61 [[{"name": "mydb",
62 "tables": {
63 "Manager": {
64 "columns": {
65 "manager": {"type": "string"}}}}}
66 ]])
67 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
68 AT_CHECK(
69 [[ovsdb-tool transact db \
70 '["mydb",
71 {"op": "insert",
72 "table": "Manager",
73 "row": {"manager": "punix:socket"}}]']], [0], [ignore], [ignore])
74 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --remote=db:Manager,manager --unixctl=$PWD/unixctl db], [0], [ignore], [ignore])
75 AT_CHECK(
76 [[ovsdb-client transact unix:socket \
77 '["mydb",
78 {"op": "select",
79 "table": "Manager",
80 "where": [],
81 "columns": ["manager"]}]']],
82 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
83 AT_CHECK(
84 [perl $srcdir/uuidfilt.pl stdout],
85 [0],
86 [[[{"rows":[{"manager":"punix:socket"}]}]
87 ]],
88 [ignore],
89 [test ! -e pid || kill `cat pid`])
90 OVSDB_SERVER_SHUTDOWN
91 AT_CLEANUP
92
93 AT_SETUP([SSL db: implementation])
94 AT_KEYWORDS([ovsdb server positive ssl $5])
95 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
96 AT_SKIP_IF([test "x$RANDOM" = x])
97 SSL_PORT=`expr 32767 + \( $RANDOM % 32767 \)`
98 PKIDIR=$abs_top_srcdir/tests
99 AT_SKIP_IF([expr "$PKIDIR" : ".*[ '\"
100 \\]"])
101 AT_DATA([schema],
102 [[{"name": "mydb",
103 "tables": {
104 "SSL": {
105 "columns": {
106 "private_key": {"type": "string"},
107 "certificate": {"type": "string"},
108 "ca_cert": {"type": "string"}}}}}
109 ]])
110 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
111 AT_CHECK(
112 [[ovsdb-tool transact db \
113 '["mydb",
114 {"op": "insert",
115 "table": "SSL",
116 "row": {"private_key": "'"$PKIDIR/testpki-privkey2.pem"'",
117 "certificate": "'"$PKIDIR/testpki-cert2.pem"'",
118 "ca_cert": "'"$PKIDIR/testpki-cacert.pem"'"}}]']],
119 [0], [ignore], [ignore])
120 AT_CHECK(
121 [ovsdb-server --detach --pidfile=$PWD/pid \
122 --private-key=db:SSL,private_key \
123 --certificate=db:SSL,certificate \
124 --ca-cert=db:SSL,ca_cert \
125 --remote=pssl:$SSL_PORT:127.0.0.1 --unixctl=$PWD/unixctl db],
126 [0], [ignore], [ignore])
127 AT_CHECK(
128 [[ovsdb-client \
129 --private-key=$PKIDIR/testpki-privkey.pem \
130 --certificate=$PKIDIR/testpki-cert.pem \
131 --ca-cert=$PKIDIR/testpki-cacert.pem \
132 transact ssl:127.0.0.1:$SSL_PORT \
133 '["mydb",
134 {"op": "select",
135 "table": "SSL",
136 "where": [],
137 "columns": ["private_key"]}]']],
138 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
139 cat stdout >> output
140 AT_CHECK_UNQUOTED(
141 [perl $srcdir/uuidfilt.pl output], [0],
142 [[[{"rows":[{"private_key":"$PKIDIR/testpki-privkey2.pem"}]}]
143 ]], [ignore], [test ! -e pid || kill `cat pid`])
144 OVSDB_SERVER_SHUTDOWN
145 AT_CLEANUP
146
147 AT_SETUP([compacting online])
148 AT_KEYWORDS([ovsdb server compact])
149 AT_DATA([schema], [ORDINAL_SCHEMA
150 ])
151 touch .db.~lock~
152 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
153 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --unixctl=$PWD/unixctl --remote=punix:socket --log-file=$PWD/ovsdb-server.log db], [0], [ignore], [ignore])
154 AT_CAPTURE_FILE([ovsdb-server.log])
155 dnl Do a bunch of random transactions that put crap in the database log.
156 AT_CHECK(
157 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
158 set -- $pair
159 ovsdb-client transact unix:socket '
160 ["ordinals",
161 {"op": "insert",
162 "table": "ordinals",
163 "row": {"name": "'$1'", "number": '$2'}},
164 {"op": "comment",
165 "comment": "add row for '"$pair"'"}]'
166 ovsdb-client transact unix:socket '
167 ["ordinals",
168 {"op": "delete",
169 "table": "ordinals",
170 "where": [["number", "==", '$2']]},
171 {"op": "comment",
172 "comment": "delete row for '"$2"'"}]'
173 ovsdb-client transact unix:socket '
174 ["ordinals",
175 {"op": "insert",
176 "table": "ordinals",
177 "row": {"name": "'$1'", "number": '$2'}},
178 {"op": "comment",
179 "comment": "add back row for '"$pair"'"}]'
180 done]],
181 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
182 dnl Check that all the crap is in fact in the database log.
183 AT_CHECK([[perl $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | test-json --multiple -]], [0],
184 [[{"name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}}}}}
185 {"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
186 {"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
187 {"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
188 {"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
189 {"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
190 {"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
191 {"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
192 {"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
193 {"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
194 {"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
195 {"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
196 {"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
197 {"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
198 {"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
199 {"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
200 {"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
201 {"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
202 {"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
203 ]], [], [test ! -e pid || kill `cat pid`])
204 dnl Dump out and check the actual database contents.
205 AT_CHECK([[ovsdb-client dump unix:socket ordinals]],
206 [0], [stdout], [ignore])
207 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0],
208 [_uuid name number
209 ------------------------------------ ----- ------
210 <0> five 5 @&t@
211 <1> four 4 @&t@
212 <2> one 1 @&t@
213 <3> three 3 @&t@
214 <4> two 2 @&t@
215 <5> zero 0 @&t@
216 ], [], [test ! -e pid || kill `cat pid`])
217 dnl Now compact the database in-place.
218 AT_CHECK([[ovs-appctl -t $PWD/unixctl ovsdb-server/compact]],
219 [0], [], [ignore], [test ! -e pid || kill `cat pid`])
220 dnl We can't fully re-check the contents of the database log, because the
221 dnl order of the records is not predictable, but there should only be 4 lines
222 dnl in it now.
223 AT_CAPTURE_FILE([db])
224 AT_CHECK([wc -l < db], [0], [4
225 ], [], [test ! -e pid || kill `cat pid`])
226 dnl And check that the dumped data is the same too:
227 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
228 [test ! -e pid || kill `cat pid`])
229 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0],
230 [_uuid name number
231 ------------------------------------ ----- ------
232 <0> five 5 @&t@
233 <1> four 4 @&t@
234 <2> one 1 @&t@
235 <3> three 3 @&t@
236 <4> two 2 @&t@
237 <5> zero 0 @&t@
238 ], [], [test ! -e pid || kill `cat pid`])
239 dnl Now do some more transactions.
240 AT_CHECK(
241 [[ovsdb-client transact unix:socket '
242 ["ordinals",
243 {"op": "delete",
244 "table": "ordinals",
245 "where": [["number", "<", 3]]}]']],
246 [0], [[[{"count":3}]
247 ]], [ignore], [test ! -e pid || kill `cat pid`])
248 dnl There should be 6 lines in the log now.
249 AT_CHECK([wc -l < db], [0], [6
250 ], [], [test ! -e pid || kill `cat pid`])
251 dnl Then check that the dumped data is correct.
252 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
253 [test ! -e pid || kill `cat pid`])
254 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0],
255 [_uuid name number
256 ------------------------------------ ----- ------
257 <0> five 5 @&t@
258 <1> four 4 @&t@
259 <2> three 3 @&t@
260 ], [], [test ! -e pid || kill `cat pid`])
261 OVSDB_SERVER_SHUTDOWN
262 AT_CLEANUP
263 \f
264 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL sockets)])
265
266 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
267 #
268 # Creates a database with the given SCHEMA, starts an ovsdb-server on
269 # that database, and runs each of the TRANSACTIONS (which should be a
270 # quoted list of quoted strings) against it with ovsdb-client one at a
271 # time.
272 #
273 # Checks that the overall output is OUTPUT, but UUIDs in the output
274 # are replaced by markers of the form <N> where N is a number. The
275 # first unique UUID is replaced by <0>, the next by <1>, and so on.
276 # If a given UUID appears more than once it is always replaced by the
277 # same marker.
278 #
279 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
280 m4_define([OVSDB_CHECK_EXECUTION],
281 [AT_SETUP([$1])
282 AT_KEYWORDS([ovsdb server positive ssl $5])
283 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
284 AT_SKIP_IF([test "x$RANDOM" = x])
285 AT_DATA([schema], [$2
286 ])
287 SSL_PORT=`expr 32767 + \( $RANDOM % 32767 \)`
288 PKIDIR=$abs_top_srcdir/tests
289 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
290 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --private-key=$PKIDIR/testpki-privkey2.pem --certificate=$PKIDIR/testpki-cert2.pem --ca-cert=$PKIDIR/testpki-cacert.pem --remote=pssl:$SSL_PORT:127.0.0.1 --unixctl=$PWD/unixctl db], [0], [ignore], [ignore])
291 m4_foreach([txn], [$3],
292 [AT_CHECK([ovsdb-client --private-key=$PKIDIR/testpki-privkey.pem --certificate=$PKIDIR/testpki-cert.pem --ca-cert=$PKIDIR/testpki-cacert.pem transact ssl:127.0.0.1:$SSL_PORT 'txn'], [0], [stdout], [ignore],
293 [test ! -e pid || kill `cat pid`])
294 cat stdout >> output
295 ])
296 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
297 [test ! -e pid || kill `cat pid`])
298 OVSDB_SERVER_SHUTDOWN
299 AT_CLEANUP])
300
301 EXECUTION_EXAMPLES
302 \f
303 AT_BANNER([OVSDB -- transactions on transient ovsdb-server])
304
305 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
306 #
307 # Creates a database with the given SCHEMA and runs each of the
308 # TRANSACTIONS (which should be a quoted list of quoted strings)
309 # against it with ovsdb-client one at a time. Each ovsdb-client
310 # is run against a separately started ovsdb-server that executes
311 # only that single transaction. (The idea is that this should
312 # help to ferret out any differences between what ovsdb-server has
313 # in memory and what actually gets committed to disk.)
314 #
315 # Checks that the overall output is OUTPUT, but UUIDs in the output
316 # are replaced by markers of the form <N> where N is a number. The
317 # first unique UUID is replaced by <0>, the next by <1>, and so on.
318 # If a given UUID appears more than once it is always replaced by the
319 # same marker.
320 #
321 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
322 m4_define([OVSDB_CHECK_EXECUTION],
323 [AT_SETUP([$1])
324 AT_KEYWORDS([ovsdb server positive transient $5])
325 AT_DATA([schema], [$2
326 ])
327 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
328 m4_foreach([txn], [$3],
329 [AT_DATA([txnfile], [ovsdb-client transact unix:socket 'txn'
330 ])
331 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl=$PWD/unixctl db --run="sh txnfile"], [0], [stdout], [ignore])
332 cat stdout >> output
333 ])
334 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore])
335 AT_CLEANUP])
336
337 EXECUTION_EXAMPLES