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])
26 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
27 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
28 m4_foreach([txn], [$3],
29 [AT_CHECK([ovsdb-client transact unix:socket 'txn'], [0], [stdout], [ignore],
30 [test ! -e pid || kill `cat pid`])
33 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
34 [test ! -e pid || kill `cat pid`])
40 AT_SETUP([truncating corrupted database log])
41 AT_KEYWORDS([ovsdb server positive unix])
42 ordinal_schema > schema
43 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
44 dnl Do one transaction and save the output.
45 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
49 "row": {"number": 0, "name": "zero"}}]'
51 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
53 dnl Add some crap to the database log and run another transaction, which should
54 dnl ignore the crap and truncate it out of the log.
56 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
60 "row": {"number": 1, "name": "one"}}]'
62 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [stderr])
63 AT_CHECK([grep 'syntax error: db: parse error.* in header line "xxx"' stderr],
66 dnl Run a final transaction to verify that both transactions succeeeded.
67 dnl The crap that we added should have been truncated by the previous run,
68 dnl so ovsdb-server shouldn't log a warning this time.
69 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
76 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
78 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0],
79 [[[{"uuid":["uuid","<0>"]}]
80 [{"uuid":["uuid","<1>"]}]
81 [{"rows":[{"_uuid":["uuid","<0>"],"_version":["uuid","<2>"],"name":"zero","number":0},{"_uuid":["uuid","<1>"],"_version":["uuid","<3>"],"name":"one","number":1}]}]
83 [test ! -e pid || kill `cat pid`])
86 AT_SETUP([truncating database log with bad transaction])
87 AT_KEYWORDS([ovsdb server positive unix])
88 ordinal_schema > schema
89 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
90 dnl Do one transaction and save the output.
91 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
95 "row": {"number": 0, "name": "zero"}}]'
97 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
99 dnl Add some crap to the database log and run another transaction, which should
100 dnl ignore the crap and truncate it out of the log.
101 echo 'OVSDB JSON 15 ffbcdae4b0386265f9ea3280dd7c8f0b72a20e56
102 {"invalid":{}}' >> db
103 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
107 "row": {"number": 1, "name": "one"}}]'
109 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [stderr])
110 AT_CHECK([grep 'syntax "{"invalid":{}}": unknown table: No table named invalid.' stderr],
113 dnl Run a final transaction to verify that both transactions succeeeded.
114 dnl The crap that we added should have been truncated by the previous run,
115 dnl so ovsdb-server shouldn't log a warning this time.
116 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
121 "sort": ["number"]}]'
123 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
125 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0],
126 [[[{"uuid":["uuid","<0>"]}]
127 [{"uuid":["uuid","<1>"]}]
128 [{"rows":[{"_uuid":["uuid","<0>"],"_version":["uuid","<2>"],"name":"zero","number":0},{"_uuid":["uuid","<1>"],"_version":["uuid","<3>"],"name":"one","number":1}]}]
130 [test ! -e pid || kill `cat pid`])
133 AT_SETUP([ovsdb-client get-schema-version])
134 AT_KEYWORDS([ovsdb server positive])
135 ordinal_schema > schema
136 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
137 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=punix:socket db], [0], [ignore], [ignore])
138 AT_CHECK([ovsdb-client get-schema-version unix:socket ordinals], [0], [5.1.3
140 OVSDB_SERVER_SHUTDOWN
143 AT_SETUP([database multiplexing implementation])
144 AT_KEYWORDS([ovsdb server positive])
145 ordinal_schema > schema1
146 constraint_schema > schema2
147 AT_CHECK([ovsdb-tool create db1 schema1], [0], [ignore], [ignore])
148 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
149 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=punix:socket db1 db2], [0], [ignore], [ignore])
151 [[ovsdb-client list-dbs unix:socket]],
154 ], [ignore], [test ! -e pid || kill `cat pid`])
156 [[test-jsonrpc request unix:socket get_schema [\"nonexistent\"]]], [0],
157 [[{"error":null,"id":0,"result":{"details":"get_schema request specifies unknown database nonexistent","error":"unknown database","syntax":"[\"nonexistent\"]"}}
158 ]], [], [test ! -e pid || kill `cat pid`])
159 OVSDB_SERVER_SHUTDOWN
162 AT_SETUP([--remote=db: implementation])
163 AT_KEYWORDS([ovsdb server positive])
164 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
165 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
175 "max": "unlimited"}},
178 "key": {"type": "uuid", "refTable": "Manager"},
180 "max": "unlimited"}}}},
191 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
193 [[ovsdb-tool transact db \
198 "managers": "punix:socket1",
199 "manager_options": ["set", [["named-uuid", "x"]]]}},
203 "row": {"target": "punix:socket2"}}]']], [0], [ignore], [ignore])
204 ON_EXIT([kill `cat ovsdb-server.pid`])
205 AT_CHECK([ovsdb-server --enable-dummy --detach --no-chdir --pidfile --remote=db:Root,managers --remote=db:Root,manager_options --log-file db], [0], [ignore], [ignore])
206 for i in 1 2 3 4 5 6; do ovs-appctl -t ovsdb-server time/warp 1000; done
208 [[ovsdb-client transact unix:socket1 \
213 "columns": ["managers"]},
217 "columns": ["target", "is_connected"]}]']],
218 [0], [stdout], [ignore])
220 [perl $srcdir/uuidfilt.pl stdout],
222 [[[{"rows":[{"managers":"punix:socket1"}]},{"rows":[{"is_connected":false,"target":"punix:socket2"}]}]
227 AT_SETUP([SSL db: implementation])
228 AT_KEYWORDS([ovsdb server positive ssl $5])
229 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
230 PKIDIR=$abs_top_builddir/tests
231 AT_SKIP_IF([expr "$PKIDIR" : ".*[ '\"
238 "private_key": {"type": "string"},
239 "certificate": {"type": "string"},
240 "ca_cert": {"type": "string"}}}}}
242 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
244 [[ovsdb-tool transact db \
248 "row": {"private_key": "'"$PKIDIR/testpki-privkey2.pem"'",
249 "certificate": "'"$PKIDIR/testpki-cert2.pem"'",
250 "ca_cert": "'"$PKIDIR/testpki-cacert.pem"'"}}]']],
251 [0], [ignore], [ignore])
252 AT_CHECK([perl $srcdir/choose-port.pl], [0], [stdout])
253 SSL_PORT=`cat stdout`
255 [ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid \
256 --private-key=db:SSL,private_key \
257 --certificate=db:SSL,certificate \
258 --ca-cert=db:SSL,ca_cert \
259 --remote=pssl:$SSL_PORT:127.0.0.1 --unixctl="`pwd`"/unixctl db],
260 [0], [ignore], [ignore])
263 --private-key=$PKIDIR/testpki-privkey.pem \
264 --certificate=$PKIDIR/testpki-cert.pem \
265 --ca-cert=$PKIDIR/testpki-cacert.pem \
266 transact ssl:127.0.0.1:$SSL_PORT \
271 "columns": ["private_key"]}]']],
272 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
275 [perl $srcdir/uuidfilt.pl output], [0],
276 [[[{"rows":[{"private_key":"$PKIDIR/testpki-privkey2.pem"}]}]
277 ]], [ignore], [test ! -e pid || kill `cat pid`])
278 OVSDB_SERVER_SHUTDOWN
281 AT_SETUP([compacting online])
282 AT_KEYWORDS([ovsdb server compact])
283 ordinal_schema > schema
284 dnl Make sure that "ovsdb-tool create" works with a dangling symlink for
285 dnl the database and the lockfile, creating the target of each symlink rather
286 dnl than replacing the symlinks with regular files.
289 ln -s dir/.db.~lock~ .db.~lock~
290 AT_SKIP_IF([test ! -h db || test ! -h .db.~lock~])
291 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
292 dnl Start ovsdb-server.
293 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=punix:socket --log-file="`pwd`"/ovsdb-server.log db], [0], [ignore], [ignore])
294 AT_CAPTURE_FILE([ovsdb-server.log])
295 dnl Do a bunch of random transactions that put crap in the database log.
297 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
299 ovsdb-client transact unix:socket '
303 "row": {"name": "'$1'", "number": '$2'}},
305 "comment": "add row for '"$pair"'"}]'
306 ovsdb-client transact unix:socket '
310 "where": [["number", "==", '$2']]},
312 "comment": "delete row for '"$2"'"}]'
313 ovsdb-client transact unix:socket '
317 "row": {"name": "'$1'", "number": '$2'}},
319 "comment": "add back row for '"$pair"'"}]'
321 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
322 dnl Check that all the crap is in fact in the database log.
323 AT_CHECK([[perl $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | test-json --multiple -]], [0],
324 [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"}
325 {"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
326 {"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
327 {"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
328 {"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
329 {"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
330 {"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
331 {"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
332 {"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
333 {"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
334 {"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
335 {"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
336 {"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
337 {"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
338 {"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
339 {"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
340 {"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
341 {"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
342 {"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
343 ]], [], [test ! -e pid || kill `cat pid`])
344 dnl Dump out and check the actual database contents.
345 AT_CHECK([[ovsdb-client dump unix:socket ordinals]],
346 [0], [stdout], [ignore])
347 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
350 ------------------------------------ ----- ------
357 ], [], [test ! -e pid || kill `cat pid`])
358 dnl Now compact the database in-place.
359 AT_CHECK([[ovs-appctl -t "`pwd`"/unixctl ovsdb-server/compact]],
360 [0], [], [ignore], [test ! -e pid || kill `cat pid`])
361 dnl Make sure that "db" is still a symlink to dir/db instead of getting
362 dnl replaced by a regular file, ditto for .db.~lock~.
363 AT_CHECK([test -h db])
364 AT_CHECK([test -h .db.~lock~])
365 AT_CHECK([test -f dir/db])
366 AT_CHECK([test -f dir/.db.~lock~])
367 dnl We can't fully re-check the contents of the database log, because the
368 dnl order of the records is not predictable, but there should only be 4 lines
370 AT_CAPTURE_FILE([db])
371 AT_CHECK([test `wc -l < db` -eq 4], [0], [], [],
372 [test ! -e pid || kill `cat pid`])
373 dnl And check that the dumped data is the same too:
374 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
375 [test ! -e pid || kill `cat pid`])
376 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
379 ------------------------------------ ----- ------
386 ], [], [test ! -e pid || kill `cat pid`])
387 dnl Now do some more transactions.
389 [[ovsdb-client transact unix:socket '
393 "where": [["number", "<", 3]]}]']],
395 ]], [ignore], [test ! -e pid || kill `cat pid`])
396 dnl There should be 6 lines in the log now.
397 AT_CHECK([test `wc -l < db` -eq 6], [0], [], [],
398 [test ! -e pid || kill `cat pid`])
399 dnl Then check that the dumped data is correct.
400 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
401 [test ! -e pid || kill `cat pid`])
402 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
405 ------------------------------------ ----- ------
409 ], [], [test ! -e pid || kill `cat pid`])
410 OVSDB_SERVER_SHUTDOWN
413 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL sockets)])
415 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
417 # Creates a database with the given SCHEMA, starts an ovsdb-server on
418 # that database, and runs each of the TRANSACTIONS (which should be a
419 # quoted list of quoted strings) against it with ovsdb-client one at a
422 # Checks that the overall output is OUTPUT, but UUIDs in the output
423 # are replaced by markers of the form <N> where N is a number. The
424 # first unique UUID is replaced by <0>, the next by <1>, and so on.
425 # If a given UUID appears more than once it is always replaced by the
428 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
429 m4_define([OVSDB_CHECK_EXECUTION],
431 AT_KEYWORDS([ovsdb server positive ssl $5])
432 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
434 AT_CHECK([perl $srcdir/choose-port.pl], [0], [stdout])
435 SSL_PORT=`cat stdout`
436 PKIDIR=$abs_top_builddir/tests
437 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
438 AT_CHECK([ovsdb-server --detach --no-chdir --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])
439 m4_foreach([txn], [$3],
440 [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],
441 [test ! -e pid || kill `cat pid`])
444 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
445 [test ! -e pid || kill `cat pid`])
446 OVSDB_SERVER_SHUTDOWN
451 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP sockets)])
453 AT_SETUP([ovsdb-client get-schema-version - tcp socket])
454 AT_KEYWORDS([ovsdb server positive tcp])
455 ordinal_schema > schema
456 AT_CHECK([perl $srcdir/choose-port.pl], [0], [stdout])
457 TCP_PORT=`cat stdout`
458 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
459 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=ptcp:$TCP_PORT:127.0.0.1 db], [0], [ignore], [ignore])
460 AT_CHECK([ovsdb-client get-schema-version tcp:127.0.0.1:$TCP_PORT ordinals], [0], [5.1.3
462 OVSDB_SERVER_SHUTDOWN
465 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
467 # Creates a database with the given SCHEMA, starts an ovsdb-server on
468 # that database, and runs each of the TRANSACTIONS (which should be a
469 # quoted list of quoted strings) against it with ovsdb-client one at a
472 # Checks that the overall output is OUTPUT, but UUIDs in the output
473 # are replaced by markers of the form <N> where N is a number. The
474 # first unique UUID is replaced by <0>, the next by <1>, and so on.
475 # If a given UUID appears more than once it is always replaced by the
478 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
479 m4_define([OVSDB_CHECK_EXECUTION],
481 AT_KEYWORDS([ovsdb server positive tcp $5])
483 AT_CHECK([perl $srcdir/choose-port.pl], [0], [stdout])
484 TCP_PORT=`cat stdout`
485 PKIDIR=$abs_top_builddir/tests
486 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
487 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --remote=ptcp:$TCP_PORT:127.0.0.1 --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
488 m4_foreach([txn], [$3],
489 [AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT 'txn'], [0], [stdout], [ignore],
490 [test ! -e pid || kill `cat pid`])
493 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
494 [test ! -e pid || kill `cat pid`])
495 OVSDB_SERVER_SHUTDOWN
500 AT_BANNER([OVSDB -- transactions on transient ovsdb-server])
502 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
504 # Creates a database with the given SCHEMA and runs each of the
505 # TRANSACTIONS (which should be a quoted list of quoted strings)
506 # against it with ovsdb-client one at a time. Each ovsdb-client
507 # is run against a separately started ovsdb-server that executes
508 # only that single transaction. (The idea is that this should
509 # help to ferret out any differences between what ovsdb-server has
510 # in memory and what actually gets committed to disk.)
512 # Checks that the overall output is OUTPUT, but UUIDs in the output
513 # are replaced by markers of the form <N> where N is a number. The
514 # first unique UUID is replaced by <0>, the next by <1>, and so on.
515 # If a given UUID appears more than once it is always replaced by the
518 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
519 m4_define([OVSDB_CHECK_EXECUTION],
521 AT_KEYWORDS([ovsdb server positive transient $5])
523 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
524 m4_foreach([txn], [$3],
525 [AT_DATA([txnfile], [ovsdb-client transact unix:socket 'txn'
527 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [ignore])
530 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore])