1 AT_BANNER([OVSDB -- ovsdb-server transactions (Unix sockets)])
3 m4_define([OVSDB_SERVER_SHUTDOWN],
5 AT_CHECK([ovs-appctl -t $PWD/unixctl -e exit], [0], [ignore], [ignore])
6 OVS_WAIT_WHILE([kill -0 `cat savepid`], [kill `cat savepid`])])
8 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
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
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
21 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
22 m4_define([OVSDB_CHECK_EXECUTION],
24 AT_KEYWORDS([ovsdb server positive unix $5])
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`])
34 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
35 [test ! -e pid || kill `cat pid`])
41 AT_SETUP([truncating corrupted database log])
42 AT_KEYWORDS([ovsdb server positive unix])
43 AT_DATA([schema], [ORDINAL_SCHEMA
45 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
46 dnl Do one transaction and save the output.
47 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
51 "row": {"number": 0, "name": "zero"}}]'
53 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl=$PWD/unixctl db --run="sh txnfile"], [0], [stdout], [])
55 dnl Add some crap to the database log and run another transaction, which should
56 dnl ignore the crap and truncate it out of the log.
58 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
62 "row": {"number": 1, "name": "one"}}]'
64 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl=$PWD/unixctl db --run="sh txnfile"], [0], [stdout], [stderr])
65 AT_CHECK([grep 'syntax error: db: parse error.* in header line "xxx"' stderr],
68 dnl Run a final transaction to verify that both transactions succeeeded.
69 dnl The crap that we added should have been truncated by the previous run,
70 dnl so ovsdb-server shouldn't log a warning this time.
71 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
78 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl=$PWD/unixctl db --run="sh txnfile"], [0], [stdout], [])
80 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0],
81 [[[{"uuid":["uuid","<0>"]}]
82 [{"uuid":["uuid","<1>"]}]
83 [{"rows":[{"_uuid":["uuid","<0>"],"_version":["uuid","<2>"],"name":"zero","number":0},{"_uuid":["uuid","<1>"],"_version":["uuid","<3>"],"name":"one","number":1}]}]
85 [test ! -e pid || kill `cat pid`])
88 AT_SETUP([truncating database log with bad transaction])
89 AT_KEYWORDS([ovsdb server positive unix])
90 AT_DATA([schema], [ORDINAL_SCHEMA
92 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
93 dnl Do one transaction and save the output.
94 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
98 "row": {"number": 0, "name": "zero"}}]'
100 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl=$PWD/unixctl db --run="sh txnfile"], [0], [stdout], [])
102 dnl Add some crap to the database log and run another transaction, which should
103 dnl ignore the crap and truncate it out of the log.
104 echo 'OVSDB JSON 15 ffbcdae4b0386265f9ea3280dd7c8f0b72a20e56
105 {"invalid":{}}' >> db
106 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
110 "row": {"number": 1, "name": "one"}}]'
112 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl=$PWD/unixctl db --run="sh txnfile"], [0], [stdout], [stderr])
113 AT_CHECK([grep 'syntax "{"invalid":{}}": unknown table: No table named invalid.' stderr],
116 dnl Run a final transaction to verify that both transactions succeeeded.
117 dnl The crap that we added should have been truncated by the previous run,
118 dnl so ovsdb-server shouldn't log a warning this time.
119 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
124 "sort": ["number"]}]'
126 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl=$PWD/unixctl db --run="sh txnfile"], [0], [stdout], [])
128 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0],
129 [[[{"uuid":["uuid","<0>"]}]
130 [{"uuid":["uuid","<1>"]}]
131 [{"rows":[{"_uuid":["uuid","<0>"],"_version":["uuid","<2>"],"name":"zero","number":0},{"_uuid":["uuid","<1>"],"_version":["uuid","<3>"],"name":"one","number":1}]}]
133 [test ! -e pid || kill `cat pid`])
136 AT_SETUP([ovsdb-client get-schema-version])
137 AT_KEYWORDS([ovsdb server positive])
138 AT_DATA([schema], [ORDINAL_SCHEMA
140 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
141 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --unixctl=$PWD/unixctl --remote=punix:socket db], [0], [ignore], [ignore])
142 AT_CHECK([ovsdb-client get-schema-version unix:socket ordinals], [0], [5.1.3
144 OVSDB_SERVER_SHUTDOWN
147 AT_SETUP([database multiplexing implementation])
148 AT_KEYWORDS([ovsdb server positive])
149 AT_DATA([schema], [ORDINAL_SCHEMA
151 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
152 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --unixctl=$PWD/unixctl --remote=punix:socket db], [0], [ignore], [ignore])
154 [[ovsdb-client list-dbs unix:socket]],
156 ], [ignore], [test ! -e pid || kill `cat pid`])
158 [[ovsdb-client get-schema unix:socket nonexistent]],
159 [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.
160 ]], [test ! -e pid || kill `cat pid`])
161 OVSDB_SERVER_SHUTDOWN
164 AT_SETUP([--remote=db: implementation])
165 AT_KEYWORDS([ovsdb server positive])
171 "manager": {"type": "string"}}}}}
173 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
175 [[ovsdb-tool transact db \
179 "row": {"manager": "punix:socket"}}]']], [0], [ignore], [ignore])
180 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --remote=db:Manager,manager --unixctl=$PWD/unixctl db], [0], [ignore], [ignore])
182 [[ovsdb-client transact unix:socket \
187 "columns": ["manager"]}]']],
188 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
190 [perl $srcdir/uuidfilt.pl stdout],
192 [[[{"rows":[{"manager":"punix:socket"}]}]
195 [test ! -e pid || kill `cat pid`])
196 OVSDB_SERVER_SHUTDOWN
199 AT_SETUP([SSL db: implementation])
200 AT_KEYWORDS([ovsdb server positive ssl $5])
201 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
202 AT_SKIP_IF([test "x$RANDOM" = x])
203 SSL_PORT=`expr 32767 + \( $RANDOM % 32767 \)`
204 PKIDIR=$abs_top_builddir/tests
205 AT_SKIP_IF([expr "$PKIDIR" : ".*[ '\"
212 "private_key": {"type": "string"},
213 "certificate": {"type": "string"},
214 "ca_cert": {"type": "string"}}}}}
216 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
218 [[ovsdb-tool transact db \
222 "row": {"private_key": "'"$PKIDIR/testpki-privkey2.pem"'",
223 "certificate": "'"$PKIDIR/testpki-cert2.pem"'",
224 "ca_cert": "'"$PKIDIR/testpki-cacert.pem"'"}}]']],
225 [0], [ignore], [ignore])
227 [ovsdb-server --detach --pidfile=$PWD/pid \
228 --private-key=db:SSL,private_key \
229 --certificate=db:SSL,certificate \
230 --ca-cert=db:SSL,ca_cert \
231 --remote=pssl:$SSL_PORT:127.0.0.1 --unixctl=$PWD/unixctl db],
232 [0], [ignore], [ignore])
235 --private-key=$PKIDIR/testpki-privkey.pem \
236 --certificate=$PKIDIR/testpki-cert.pem \
237 --ca-cert=$PKIDIR/testpki-cacert.pem \
238 transact ssl:127.0.0.1:$SSL_PORT \
243 "columns": ["private_key"]}]']],
244 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
247 [perl $srcdir/uuidfilt.pl output], [0],
248 [[[{"rows":[{"private_key":"$PKIDIR/testpki-privkey2.pem"}]}]
249 ]], [ignore], [test ! -e pid || kill `cat pid`])
250 OVSDB_SERVER_SHUTDOWN
253 AT_SETUP([compacting online])
254 AT_KEYWORDS([ovsdb server compact])
255 AT_DATA([schema], [ORDINAL_SCHEMA
258 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
259 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --unixctl=$PWD/unixctl --remote=punix:socket --log-file=$PWD/ovsdb-server.log db], [0], [ignore], [ignore])
260 AT_CAPTURE_FILE([ovsdb-server.log])
261 dnl Do a bunch of random transactions that put crap in the database log.
263 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
265 ovsdb-client transact unix:socket '
269 "row": {"name": "'$1'", "number": '$2'}},
271 "comment": "add row for '"$pair"'"}]'
272 ovsdb-client transact unix:socket '
276 "where": [["number", "==", '$2']]},
278 "comment": "delete row for '"$2"'"}]'
279 ovsdb-client transact unix:socket '
283 "row": {"name": "'$1'", "number": '$2'}},
285 "comment": "add back row for '"$pair"'"}]'
287 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
288 dnl Check that all the crap is in fact in the database log.
289 AT_CHECK([[perl $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | test-json --multiple -]], [0],
290 [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"}
291 {"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
292 {"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
293 {"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
294 {"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
295 {"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
296 {"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
297 {"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
298 {"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
299 {"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
300 {"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
301 {"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
302 {"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
303 {"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
304 {"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
305 {"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
306 {"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
307 {"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
308 {"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
309 ]], [], [test ! -e pid || kill `cat pid`])
310 dnl Dump out and check the actual database contents.
311 AT_CHECK([[ovsdb-client dump unix:socket ordinals]],
312 [0], [stdout], [ignore])
313 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
316 ------------------------------------ ----- ------
323 ], [], [test ! -e pid || kill `cat pid`])
324 dnl Now compact the database in-place.
325 AT_CHECK([[ovs-appctl -t $PWD/unixctl ovsdb-server/compact]],
326 [0], [], [ignore], [test ! -e pid || kill `cat pid`])
327 dnl We can't fully re-check the contents of the database log, because the
328 dnl order of the records is not predictable, but there should only be 4 lines
330 AT_CAPTURE_FILE([db])
331 AT_CHECK([wc -l < db], [0], [4
332 ], [], [test ! -e pid || kill `cat pid`])
333 dnl And check that the dumped data is the same too:
334 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
335 [test ! -e pid || kill `cat pid`])
336 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
339 ------------------------------------ ----- ------
346 ], [], [test ! -e pid || kill `cat pid`])
347 dnl Now do some more transactions.
349 [[ovsdb-client transact unix:socket '
353 "where": [["number", "<", 3]]}]']],
355 ]], [ignore], [test ! -e pid || kill `cat pid`])
356 dnl There should be 6 lines in the log now.
357 AT_CHECK([wc -l < db], [0], [6
358 ], [], [test ! -e pid || kill `cat pid`])
359 dnl Then check that the dumped data is correct.
360 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
361 [test ! -e pid || kill `cat pid`])
362 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
365 ------------------------------------ ----- ------
369 ], [], [test ! -e pid || kill `cat pid`])
370 OVSDB_SERVER_SHUTDOWN
373 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL sockets)])
375 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
377 # Creates a database with the given SCHEMA, starts an ovsdb-server on
378 # that database, and runs each of the TRANSACTIONS (which should be a
379 # quoted list of quoted strings) against it with ovsdb-client one at a
382 # Checks that the overall output is OUTPUT, but UUIDs in the output
383 # are replaced by markers of the form <N> where N is a number. The
384 # first unique UUID is replaced by <0>, the next by <1>, and so on.
385 # If a given UUID appears more than once it is always replaced by the
388 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
389 m4_define([OVSDB_CHECK_EXECUTION],
391 AT_KEYWORDS([ovsdb server positive ssl $5])
392 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
393 AT_SKIP_IF([test "x$RANDOM" = x])
394 AT_DATA([schema], [$2
396 SSL_PORT=`expr 32767 + \( $RANDOM % 32767 \)`
397 PKIDIR=$abs_top_builddir/tests
398 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
399 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])
400 m4_foreach([txn], [$3],
401 [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],
402 [test ! -e pid || kill `cat pid`])
405 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
406 [test ! -e pid || kill `cat pid`])
407 OVSDB_SERVER_SHUTDOWN
412 AT_BANNER([OVSDB -- transactions on transient ovsdb-server])
414 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
416 # Creates a database with the given SCHEMA and runs each of the
417 # TRANSACTIONS (which should be a quoted list of quoted strings)
418 # against it with ovsdb-client one at a time. Each ovsdb-client
419 # is run against a separately started ovsdb-server that executes
420 # only that single transaction. (The idea is that this should
421 # help to ferret out any differences between what ovsdb-server has
422 # in memory and what actually gets committed to disk.)
424 # Checks that the overall output is OUTPUT, but UUIDs in the output
425 # are replaced by markers of the form <N> where N is a number. The
426 # first unique UUID is replaced by <0>, the next by <1>, and so on.
427 # If a given UUID appears more than once it is always replaced by the
430 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
431 m4_define([OVSDB_CHECK_EXECUTION],
433 AT_KEYWORDS([ovsdb server positive transient $5])
434 AT_DATA([schema], [$2
436 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
437 m4_foreach([txn], [$3],
438 [AT_DATA([txnfile], [ovsdb-client transact unix:socket 'txn'
440 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl=$PWD/unixctl db --run="sh txnfile"], [0], [stdout], [ignore])
443 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore])