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 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
25 AT_KEYWORDS([ovsdb server positive unix $5])
27 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
28 AT_CHECK([ovsdb-server --detach --no-chdir --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_BANNER([ovsdb-server miscellaneous features])
43 AT_SETUP([truncating corrupted database log])
44 AT_KEYWORDS([ovsdb server positive unix])
45 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
46 ordinal_schema > schema
47 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
48 dnl Do one transaction and save the output.
49 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
53 "row": {"number": 0, "name": "zero"}}]'
55 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
57 dnl Add some crap to the database log and run another transaction, which should
58 dnl ignore the crap and truncate it out of the log.
60 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
64 "row": {"number": 1, "name": "one"}}]'
66 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [stderr])
67 AT_CHECK([grep 'syntax error: db: parse error.* in header line "xxx"' stderr],
70 dnl Run a final transaction to verify that both transactions succeeeded.
71 dnl The crap that we added should have been truncated by the previous run,
72 dnl so ovsdb-server shouldn't log a warning this time.
73 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
80 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
82 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0],
83 [[[{"uuid":["uuid","<0>"]}]
84 [{"uuid":["uuid","<1>"]}]
85 [{"rows":[{"_uuid":["uuid","<0>"],"_version":["uuid","<2>"],"name":"zero","number":0},{"_uuid":["uuid","<1>"],"_version":["uuid","<3>"],"name":"one","number":1}]}]
87 [test ! -e pid || kill `cat pid`])
90 AT_SETUP([truncating database log with bad transaction])
91 AT_KEYWORDS([ovsdb server positive unix])
92 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
93 ordinal_schema > schema
94 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
95 dnl Do one transaction and save the output.
96 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
100 "row": {"number": 0, "name": "zero"}}]'
102 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
104 dnl Add some crap to the database log and run another transaction, which should
105 dnl ignore the crap and truncate it out of the log.
106 echo 'OVSDB JSON 15 ffbcdae4b0386265f9ea3280dd7c8f0b72a20e56
107 {"invalid":{}}' >> db
108 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
112 "row": {"number": 1, "name": "one"}}]'
114 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [stderr])
115 AT_CHECK([grep 'syntax "{"invalid":{}}": unknown table: No table named invalid.' stderr],
118 dnl Run a final transaction to verify that both transactions succeeeded.
119 dnl The crap that we added should have been truncated by the previous run,
120 dnl so ovsdb-server shouldn't log a warning this time.
121 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
126 "sort": ["number"]}]'
128 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
130 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0],
131 [[[{"uuid":["uuid","<0>"]}]
132 [{"uuid":["uuid","<1>"]}]
133 [{"rows":[{"_uuid":["uuid","<0>"],"_version":["uuid","<2>"],"name":"zero","number":0},{"_uuid":["uuid","<1>"],"_version":["uuid","<3>"],"name":"one","number":1}]}]
135 [test ! -e pid || kill `cat pid`])
138 AT_SETUP([ovsdb-client get-schema-version])
139 AT_KEYWORDS([ovsdb server positive])
140 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
141 ordinal_schema > schema
142 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
143 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=punix:socket db], [0], [ignore], [ignore])
144 AT_CHECK([ovsdb-client get-schema-version unix:socket ordinals], [0], [5.1.3
146 OVSDB_SERVER_SHUTDOWN
149 AT_SETUP([database multiplexing implementation])
150 AT_KEYWORDS([ovsdb server positive])
151 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
152 ordinal_schema > schema1
153 constraint_schema > schema2
154 AT_CHECK([ovsdb-tool create db1 schema1], [0], [ignore], [ignore])
155 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
156 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=punix:socket db1 db2], [0], [ignore], [ignore])
158 [[ovsdb-client list-dbs unix:socket]],
161 ], [ignore], [test ! -e pid || kill `cat pid`])
163 [[test-jsonrpc request unix:socket get_schema [\"nonexistent\"]]], [0],
164 [[{"error":null,"id":0,"result":{"details":"get_schema request specifies unknown database nonexistent","error":"unknown database","syntax":"[\"nonexistent\"]"}}
165 ]], [], [test ! -e pid || kill `cat pid`])
166 OVSDB_SERVER_SHUTDOWN
169 AT_SETUP([ovsdb-server/add-db and remove-db])
170 AT_KEYWORDS([ovsdb server positive])
171 ON_EXIT([kill `cat ovsdb-server.pid`])
172 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
173 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
174 ordinal_schema > schema1
175 constraint_schema > schema2
176 AT_CHECK([ovsdb-tool create db1 schema1], [0], [ignore], [ignore])
177 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
179 # Start ovsdb-server with just a single database - db1.
180 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db1], [0])
181 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
185 # Add the second database.
186 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
187 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
192 # The databases are responsive.
193 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [0], [ignore], [ignore])
194 AT_CHECK([ovsdb-client list-tables unix:socket ordinals], [0], [ignore], [ignore])
196 # Add an already added database.
197 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], 2, [], [stderr])
198 AT_CHECK([sed 's/(.*)/(...)/' stderr], [0],
199 [I/O error: db2: failed to lock lockfile (...)
200 ovs-appctl: ovsdb-server: server returned an error
203 # Add a non-existing database.
204 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db3], 2, [], [stderr])
205 AT_CHECK([sed 's/(.*)/(...)/' stderr], [0],
206 [I/O error: open: db3 failed (...)
207 ovs-appctl: ovsdb-server: server returned an error
210 # Add a remote through a db path in db1.
211 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote db:ordinals,ordinals,name], [0])
212 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
213 [0], [db:ordinals,ordinals,name
217 # Removing db1 has no effect on its remote.
218 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db ordinals], [0])
219 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
222 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
223 [0], [db:ordinals,ordinals,name
226 AT_CHECK([ovsdb-client list-tables unix:socket ordinals], [1], [ignore], [ignore])
229 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db constraints], [0])
230 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
232 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [1], [ignore], [ignore])
234 # Remove a non-existent database.
235 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db ordinals], [2],
236 [], [Failed to find the database.
237 ovs-appctl: ovsdb-server: server returned an error
240 # Add a removed database.
241 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
242 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
245 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [0], [ignore], [ignore])
248 AT_SETUP([ovsdb-server/add-db with --monitor])
249 AT_KEYWORDS([ovsdb server positive])
250 # Start ovsdb-server, initially with one db.
251 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
252 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
253 ordinal_schema > schema
254 AT_CHECK([ovsdb-tool create db1 schema], [0], [ignore], [ignore])
255 ON_EXIT([kill `cat *.pid`])
256 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db1])
258 # Add the second database.
259 constraint_schema > schema2
260 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
261 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
262 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
267 # Kill the daemon process, making it look like a segfault,
268 # and wait for a new daemon process to get spawned.
269 cp ovsdb-server.pid old.pid
270 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
271 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
273 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
274 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
280 AT_SETUP([ovsdb-server/add-db and remove-db with --monitor])
281 AT_KEYWORDS([ovsdb server positive])
282 # Start ovsdb-server, initially with one db.
283 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
284 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
285 ordinal_schema > schema
286 AT_CHECK([ovsdb-tool create db1 schema], [0], [ignore], [ignore])
287 constraint_schema > schema2
288 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
289 ON_EXIT([kill `cat *.pid`])
290 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db1 db2])
292 # Remove the second database.
293 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db constraints])
294 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
298 # Kill the daemon process, making it look like a segfault,
299 # and wait for a new daemon process to get spawned.
300 cp ovsdb-server.pid old.pid
301 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
302 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
304 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
305 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
310 AT_SETUP([--remote=db: implementation])
311 AT_KEYWORDS([ovsdb server positive])
312 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
313 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
323 "max": "unlimited"}},
326 "key": {"type": "uuid", "refTable": "Manager"},
328 "max": "unlimited"}}}},
339 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
341 [[ovsdb-tool transact db \
346 "managers": "punix:socket1",
347 "manager_options": ["set", [["named-uuid", "x"]]]}},
351 "row": {"target": "punix:socket2"}}]']], [0], [ignore], [ignore])
352 ON_EXIT([kill `cat ovsdb-server.pid`])
353 AT_CHECK([ovsdb-server --enable-dummy --detach --no-chdir --pidfile --remote=db:mydb,Root,managers --remote=db:mydb,Root,manager_options --log-file db], [0], [ignore], [ignore])
354 for i in 1 2 3 4 5 6; do ovs-appctl -t ovsdb-server time/warp 1000; done
356 [[ovsdb-client transact unix:socket1 \
361 "columns": ["managers"]},
365 "columns": ["target", "is_connected"]}]']],
366 [0], [stdout], [ignore])
368 [${PERL} $srcdir/uuidfilt.pl stdout],
370 [[[{"rows":[{"managers":"punix:socket1"}]},{"rows":[{"is_connected":false,"target":"punix:socket2"}]}]
375 AT_SETUP([ovsdb-server/add-remote and remove-remote])
376 AT_KEYWORDS([ovsdb server positive])
377 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
378 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
379 ordinal_schema > schema
380 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
381 ON_EXIT([kill `cat *.pid`])
382 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile db])
384 AT_CHECK([test ! -e socket1])
385 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
386 OVS_WAIT_UNTIL([test -S socket1])
387 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
391 AT_CHECK([test ! -e socket2])
392 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket2])
393 OVS_WAIT_UNTIL([test -S socket2])
394 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
399 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote db:x,y,z], [2],
400 [], ["db:x,y,z": no database named x
401 ovs-appctl: ovsdb-server: server returned an error
404 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
405 OVS_WAIT_UNTIL([test ! -e socket1])
406 AT_CHECK([test -S socket2])
407 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
411 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket2])
412 OVS_WAIT_UNTIL([test ! -e socket2])
413 AT_CHECK([test ! -e socket1])
414 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
417 AT_SETUP([ovsdb-server/add-remote with --monitor])
418 AT_KEYWORDS([ovsdb server positive])
419 # Start ovsdb-server, initially with no remotes.
420 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
421 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
422 ordinal_schema > schema
423 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
424 ON_EXIT([kill `cat *.pid`])
425 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db])
428 AT_CHECK([test ! -e socket1])
429 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
430 OVS_WAIT_UNTIL([test -S socket1])
431 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
435 # Kill the daemon process, making it look like a segfault,
436 # and wait for a new daemon process to get spawned and for it to
437 # start listening on 'socket1'.
438 cp ovsdb-server.pid old.pid
440 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
441 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
443 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
444 OVS_WAIT_UNTIL([test -S socket1])
447 AT_SETUP([ovsdb-server/add-remote and remove-remote with --monitor])
448 AT_KEYWORDS([ovsdb server positive])
449 # Start ovsdb-server, initially with no remotes.
450 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
451 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
452 ordinal_schema > schema
453 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
454 ON_EXIT([kill `cat *.pid`])
455 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db])
458 AT_CHECK([test ! -e socket1])
459 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
460 OVS_WAIT_UNTIL([test -S socket1])
461 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
466 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
467 OVS_WAIT_UNTIL([test ! -e socket1])
468 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
470 # Kill the daemon process, making it look like a segfault,
471 # and wait for a new daemon process to get spawned and make sure that it
472 # does not listen on 'socket1'.
473 cp ovsdb-server.pid old.pid
474 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
475 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
477 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
478 AT_CHECK([test ! -e socket1])
481 AT_SETUP([SSL db: implementation])
482 AT_KEYWORDS([ovsdb server positive ssl $5])
483 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
484 PKIDIR=$abs_top_builddir/tests
485 AT_SKIP_IF([expr "$PKIDIR" : ".*[ '\"
492 "private_key": {"type": "string"},
493 "certificate": {"type": "string"},
494 "ca_cert": {"type": "string"}}}}}
496 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
498 [[ovsdb-tool transact db \
502 "row": {"private_key": "'"$PKIDIR/testpki-privkey2.pem"'",
503 "certificate": "'"$PKIDIR/testpki-cert2.pem"'",
504 "ca_cert": "'"$PKIDIR/testpki-cacert.pem"'"}}]']],
505 [0], [ignore], [ignore])
506 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
508 [ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid \
509 --private-key=db:mydb,SSL,private_key \
510 --certificate=db:mydb,SSL,certificate \
511 --ca-cert=db:mydb,SSL,ca_cert \
512 --remote=pssl:0:127.0.0.1 --unixctl="`pwd`"/unixctl db],
513 [0], [ignore], [ignore])
514 SSL_PORT=`parse_listening_port < ovsdb-server.log`
517 --private-key=$PKIDIR/testpki-privkey.pem \
518 --certificate=$PKIDIR/testpki-cert.pem \
519 --ca-cert=$PKIDIR/testpki-cacert.pem \
520 transact ssl:127.0.0.1:$SSL_PORT \
525 "columns": ["private_key"]}]']],
526 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
530 [[[{"rows":[{"private_key":"$PKIDIR/testpki-privkey2.pem"}]}]
531 ]], [ignore], [test ! -e pid || kill `cat pid`])
532 OVSDB_SERVER_SHUTDOWN
535 AT_SETUP([compacting online])
536 AT_KEYWORDS([ovsdb server compact])
537 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
538 ordinal_schema > schema
539 dnl Make sure that "ovsdb-tool create" works with a dangling symlink for
540 dnl the database and the lockfile, creating the target of each symlink rather
541 dnl than replacing the symlinks with regular files.
544 ln -s dir/.db.~lock~ .db.~lock~
545 AT_SKIP_IF([test ! -h db || test ! -h .db.~lock~])
546 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
547 dnl Start ovsdb-server.
548 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])
549 AT_CAPTURE_FILE([ovsdb-server.log])
550 dnl Do a bunch of random transactions that put crap in the database log.
552 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
554 ovsdb-client transact unix:socket '
558 "row": {"name": "'$1'", "number": '$2'}},
560 "comment": "add row for '"$pair"'"}]'
561 ovsdb-client transact unix:socket '
565 "where": [["number", "==", '$2']]},
567 "comment": "delete row for '"$2"'"}]'
568 ovsdb-client transact unix:socket '
572 "row": {"name": "'$1'", "number": '$2'}},
574 "comment": "add back row for '"$pair"'"}]'
576 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
577 dnl Check that all the crap is in fact in the database log.
578 AT_CHECK([[${PERL} $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | test-json --multiple -]], [0],
579 [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"}
580 {"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
581 {"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
582 {"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
583 {"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
584 {"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
585 {"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
586 {"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
587 {"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
588 {"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
589 {"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
590 {"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
591 {"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
592 {"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
593 {"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
594 {"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
595 {"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
596 {"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
597 {"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
598 ]], [], [test ! -e pid || kill `cat pid`])
599 dnl Dump out and check the actual database contents.
600 AT_CHECK([[ovsdb-client dump unix:socket ordinals]],
601 [0], [stdout], [ignore])
602 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
605 ------------------------------------ ----- ------
612 ], [], [test ! -e pid || kill `cat pid`])
613 dnl Now compact the database in-place.
614 AT_CHECK([[ovs-appctl -t "`pwd`"/unixctl ovsdb-server/compact]],
615 [0], [], [ignore], [test ! -e pid || kill `cat pid`])
616 dnl Make sure that "db" is still a symlink to dir/db instead of getting
617 dnl replaced by a regular file, ditto for .db.~lock~.
618 AT_CHECK([test -h db])
619 AT_CHECK([test -h .db.~lock~])
620 AT_CHECK([test -f dir/db])
621 AT_CHECK([test -f dir/.db.~lock~])
622 dnl We can't fully re-check the contents of the database log, because the
623 dnl order of the records is not predictable, but there should only be 4 lines
625 AT_CAPTURE_FILE([db])
626 AT_CHECK([test `wc -l < db` -eq 4], [0], [], [],
627 [test ! -e pid || kill `cat pid`])
628 dnl And check that the dumped data is the same too:
629 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
630 [test ! -e pid || kill `cat pid`])
631 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
634 ------------------------------------ ----- ------
641 ], [], [test ! -e pid || kill `cat pid`])
642 dnl Now do some more transactions.
644 [[ovsdb-client transact unix:socket '
648 "where": [["number", "<", 3]]}]']],
650 ]], [ignore], [test ! -e pid || kill `cat pid`])
651 dnl There should be 6 lines in the log now.
652 AT_CHECK([test `wc -l < db` -eq 6], [0], [], [],
653 [test ! -e pid || kill `cat pid`])
654 dnl Then check that the dumped data is correct.
655 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
656 [test ! -e pid || kill `cat pid`])
657 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
660 ------------------------------------ ----- ------
664 ], [], [test ! -e pid || kill `cat pid`])
665 OVSDB_SERVER_SHUTDOWN
668 AT_SETUP([ovsdb-server connection queue limits])
669 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
670 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
671 ON_EXIT([kill `cat *.pid`])
673 # The maximum socket receive buffer size is important for this test, which
674 # tests behavior when the receive buffer overflows.
675 if test -e /proc/sys/net/core/rmem_max; then
677 rmem_max=`cat /proc/sys/net/core/rmem_max`
678 elif rmem_max=`sysctl -n net.inet.tcp.recvbuf_max 2>/dev/null`; then
681 # Don't know how to get maximum socket receive buffer on this OS
684 # Calculate the total amount of data we need to queue: rmem_max in the
685 # kernel plus 1024 kB in jsonrpc-server sending userspace (see default
686 # backlog_threshold in ovsdb_jsonrpc_session_create() in
688 queue_size=`expr $rmem_max + 1024 \* 1024`
689 echo rmem_max=$rmem_max queue_size=$queue_size
691 # Each flow update message takes up at least 48 bytes of space in queues
692 # and in practice more than that.
693 n_msgs=`expr $queue_size / 48`
696 # Start an ovsdb-server with the vswitchd schema.
698 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --log-file --remote=punix:socket db],
699 [0], [ignore], [ignore])
701 # Executes a pair of transactions that add a bridge with 100 ports,
702 # and then deletes that bridge. Each of these transactions yields
703 # a monitor update about 25 kB in size.
704 trigger_big_update () {
705 ovs-vsctl --db=unix:socket --no-wait -- add-br br0 $add
706 ovs-vsctl --db=unix:socket --no-wait -- del-br br0
709 for j in `seq 1 100`; do
710 printf " -- add-port br0 p%d" $j
715 AT_CAPTURE_FILE([ovsdb-client.out])
716 AT_CAPTURE_FILE([ovsdb-client.err])
718 # Start an ovsdb-client monitoring all changes to the database,
719 # make it block to force the buffers to fill up, and then execute
720 # enough transactions that ovsdb-server disconnects it.
721 AT_CHECK([ovsdb-client --detach --no-chdir --pidfile monitor unix:socket ALL >ovsdb-client.out 2>ovsdb-client.err])
722 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/block])
723 for i in `seq 1 100`; do
724 echo "blocked update ($i of 100)"
727 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/unblock])
729 # Make sure that ovsdb-server disconnected the client and
730 # that the client exited as a result.
731 if grep "bytes backlogged but a complete replica would only take [[0-9]]* bytes, disconnecting" ovsdb-server.log; then
736 OVS_WAIT_WHILE([test -e ovsdb-client.pid])
738 # Start an ovsdb-client monitoring all changes to the database,
739 # without making it block, and then execute the same transactions that
740 # we did before. This time the client should not get disconnected.
741 AT_CHECK([ovsdb-client --detach --no-chdir --pidfile monitor unix:socket ALL >ovsdb-client.out 2>ovsdb-client.err])
742 for i in `seq 1 100`; do
743 echo "unblocked update ($i of 100)"
746 # Make sure that ovsdb-client gets enough CPU time to process the updates.
747 ovs-appctl -t ovsdb-client version > /dev/null
751 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv4 sockets)])
753 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
755 # Creates a database with the given SCHEMA, starts an ovsdb-server on
756 # that database, and runs each of the TRANSACTIONS (which should be a
757 # quoted list of quoted strings) against it with ovsdb-client one at a
760 # Checks that the overall output is OUTPUT, but UUIDs in the output
761 # are replaced by markers of the form <N> where N is a number. The
762 # first unique UUID is replaced by <0>, the next by <1>, and so on.
763 # If a given UUID appears more than once it is always replaced by the
766 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
767 m4_define([OVSDB_CHECK_EXECUTION],
769 AT_KEYWORDS([ovsdb server positive ssl $5])
770 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
771 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
772 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
774 PKIDIR=$abs_top_builddir/tests
775 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
776 AT_CHECK([ovsdb-server --log-file --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:0:127.0.0.1 --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
777 SSL_PORT=`parse_listening_port < ovsdb-server.log`
778 m4_foreach([txn], [$3],
779 [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],
780 [test ! -e pid || kill `cat pid`])
783 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
784 [test ! -e pid || kill `cat pid`])
785 OVSDB_SERVER_SHUTDOWN
790 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv6 sockets)])
792 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
794 # Creates a database with the given SCHEMA, starts an ovsdb-server on
795 # that database, and runs each of the TRANSACTIONS (which should be a
796 # quoted list of quoted strings) against it with ovsdb-client one at a
799 # Checks that the overall output is OUTPUT, but UUIDs in the output
800 # are replaced by markers of the form <N> where N is a number. The
801 # first unique UUID is replaced by <0>, the next by <1>, and so on.
802 # If a given UUID appears more than once it is always replaced by the
805 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
806 m4_define([OVSDB_CHECK_EXECUTION],
808 AT_KEYWORDS([ovsdb server positive ssl6 $5])
809 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
810 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
811 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
813 PKIDIR=$abs_top_builddir/tests
814 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
815 AT_CHECK([ovsdb-server --log-file --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:0:[[::1]] --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
816 SSL_PORT=`parse_listening_port < ovsdb-server.log`
817 m4_foreach([txn], [$3],
818 [AT_CHECK([ovsdb-client --private-key=$PKIDIR/testpki-privkey.pem --certificate=$PKIDIR/testpki-cert.pem --ca-cert=$PKIDIR/testpki-cacert.pem transact ssl:[[::1]]:$SSL_PORT 'txn'], [0], [stdout], [ignore],
819 [test ! -e pid || kill `cat pid`])
822 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
823 [test ! -e pid || kill `cat pid`])
824 OVSDB_SERVER_SHUTDOWN
827 ONE_EXECUTION_EXAMPLE
829 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv4 sockets)])
831 AT_SETUP([ovsdb-client get-schema-version - tcp socket])
832 AT_KEYWORDS([ovsdb server positive tcp])
833 ordinal_schema > schema
834 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
835 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
836 AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=ptcp:0:127.0.0.1 db], [0], [ignore], [ignore])
837 TCP_PORT=`parse_listening_port < ovsdb-server.log`
838 AT_CHECK([ovsdb-client get-schema-version tcp:127.0.0.1:$TCP_PORT ordinals], [0], [5.1.3
840 OVSDB_SERVER_SHUTDOWN
843 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
845 # Creates a database with the given SCHEMA, starts an ovsdb-server on
846 # that database, and runs each of the TRANSACTIONS (which should be a
847 # quoted list of quoted strings) against it with ovsdb-client one at a
850 # Checks that the overall output is OUTPUT, but UUIDs in the output
851 # are replaced by markers of the form <N> where N is a number. The
852 # first unique UUID is replaced by <0>, the next by <1>, and so on.
853 # If a given UUID appears more than once it is always replaced by the
856 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
857 m4_define([OVSDB_CHECK_EXECUTION],
859 AT_KEYWORDS([ovsdb server positive tcp $5])
860 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
861 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
863 PKIDIR=$abs_top_builddir/tests
864 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
865 AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid --remote=ptcp:0:127.0.0.1 --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
866 TCP_PORT=`parse_listening_port < ovsdb-server.log`
867 m4_foreach([txn], [$3],
868 [AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT 'txn'], [0], [stdout], [ignore],
869 [test ! -e pid || kill `cat pid`])
872 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
873 [test ! -e pid || kill `cat pid`])
874 OVSDB_SERVER_SHUTDOWN
879 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv6 sockets)])
881 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
883 # Creates a database with the given SCHEMA, starts an ovsdb-server on
884 # that database, and runs each of the TRANSACTIONS (which should be a
885 # quoted list of quoted strings) against it with ovsdb-client one at a
888 # Checks that the overall output is OUTPUT, but UUIDs in the output
889 # are replaced by markers of the form <N> where N is a number. The
890 # first unique UUID is replaced by <0>, the next by <1>, and so on.
891 # If a given UUID appears more than once it is always replaced by the
894 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
895 m4_define([OVSDB_CHECK_EXECUTION],
897 AT_KEYWORDS([ovsdb server positive tcp6 $5])
898 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
899 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
901 PKIDIR=$abs_top_builddir/tests
902 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
903 AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid --remote=ptcp:0:[[::1]] --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
904 TCP_PORT=`parse_listening_port < ovsdb-server.log`
905 m4_foreach([txn], [$3],
906 [AT_CHECK([ovsdb-client transact tcp:[[::1]]:$TCP_PORT 'txn'], [0], [stdout], [ignore],
907 [test ! -e pid || kill `cat pid`])
910 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
911 [test ! -e pid || kill `cat pid`])
912 OVSDB_SERVER_SHUTDOWN
915 ONE_EXECUTION_EXAMPLE
917 AT_BANNER([OVSDB -- transactions on transient ovsdb-server])
919 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
921 # Creates a database with the given SCHEMA and runs each of the
922 # TRANSACTIONS (which should be a quoted list of quoted strings)
923 # against it with ovsdb-client one at a time. Each ovsdb-client
924 # is run against a separately started ovsdb-server that executes
925 # only that single transaction. (The idea is that this should
926 # help to ferret out any differences between what ovsdb-server has
927 # in memory and what actually gets committed to disk.)
929 # Checks that the overall output is OUTPUT, but UUIDs in the output
930 # are replaced by markers of the form <N> where N is a number. The
931 # first unique UUID is replaced by <0>, the next by <1>, and so on.
932 # If a given UUID appears more than once it is always replaced by the
935 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
936 m4_define([OVSDB_CHECK_EXECUTION],
938 AT_KEYWORDS([ovsdb server positive transient $5])
939 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
941 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
942 m4_foreach([txn], [$3],
943 [AT_DATA([txnfile], [ovsdb-client transact unix:socket 'txn'
945 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [ignore])
948 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore])