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 [[ovstest 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/' | ovstest 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 combines updates on backlogged connections])
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
685 # Calculate the number of iterations we need to queue. Each of the
686 # iterations we execute, by itself, yields a monitor update of about
687 # 25 kB, so fill up that much space plus a few for luck.
688 n_iterations=`expr $rmem_max / 2500 + 5`
689 echo rmem_max=$rmem_max n_iterations=$n_iterations
691 # Calculate the exact number of monitor updates expected for $n_iterations,
692 # assuming no updates are combined. The "extra" update is for the initial
693 # contents of the database.
694 n_updates=`expr $n_iterations \* 3 + 1`
696 # Start an ovsdb-server with the vswitchd schema.
698 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --log-file --remote=punix:db.sock db],
699 [0], [ignore], [ignore])
701 # Executes a set of transactions that add a bridge with 100 ports, and
702 # then deletes that bridge. This yields three monitor updates that
703 # add up to about 25 kB in size.
705 # The update also increments a counter held in the database so that we can
706 # verify that the overall effect of the transactions took effect (e.g.
707 # monitor updates at the end weren't just dropped). We add an arbitrary
708 # string to the counter to make grepping for it more reliable.
710 trigger_big_update () {
711 counter=`expr $counter + 1`
712 ovs-vsctl --no-wait -- set open_vswitch . system_version=xyzzy$counter
713 ovs-vsctl --no-wait -- add-br br0 $add
714 ovs-vsctl --no-wait -- del-br br0
717 for j in `seq 1 100`; do
718 printf " -- add-port br0 p%d" $j
723 AT_CAPTURE_FILE([ovsdb-client.err])
725 # Start an ovsdb-client monitoring all changes to the database,
726 # make it block to force the buffers to fill up, and then execute
727 # enough iterations that ovsdb-server starts combining updates.
728 AT_CHECK([ovsdb-client --detach --no-chdir --pidfile monitor ALL >ovsdb-client.out 2>ovsdb-client.err])
729 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/block])
730 for i in `seq 1 $n_iterations`; do
731 echo "blocked update ($i of $n_iterations)"
732 trigger_big_update $i
734 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/unblock])
735 OVS_WAIT_UNTIL([grep "\"xyzzy$counter\"" ovsdb-client.out])
736 AT_CHECK([ovs-appctl -t ovsdb-client exit])
737 OVS_WAIT_WHILE([test -e ovsdb-client.pid])
739 # Count the number of updates in the ovsdb-client output, by counting
740 # the number of changes to the Open_vSwitch table. (All of our
741 # transactions modify the Open_vSwitch table.) It should be less than
742 # $n_updates updates.
744 # Check that the counter is what we expect.
745 logged_updates=`grep -c '^Open_vSwitch' ovsdb-client.out`
746 echo "logged_updates=$logged_updates (expected less than $n_updates)"
747 AT_CHECK([test $logged_updates -lt $n_updates])
748 AT_CHECK_UNQUOTED([ovs-vsctl get open_vswitch . system_version], [0],
753 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv4 sockets)])
755 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
757 # Creates a database with the given SCHEMA, starts an ovsdb-server on
758 # that database, and runs each of the TRANSACTIONS (which should be a
759 # quoted list of quoted strings) against it with ovsdb-client one at a
762 # Checks that the overall output is OUTPUT, but UUIDs in the output
763 # are replaced by markers of the form <N> where N is a number. The
764 # first unique UUID is replaced by <0>, the next by <1>, and so on.
765 # If a given UUID appears more than once it is always replaced by the
768 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
769 m4_define([OVSDB_CHECK_EXECUTION],
771 AT_KEYWORDS([ovsdb server positive ssl $5])
772 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
773 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
774 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
776 PKIDIR=$abs_top_builddir/tests
777 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
778 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])
779 SSL_PORT=`parse_listening_port < ovsdb-server.log`
780 m4_foreach([txn], [$3],
781 [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],
782 [test ! -e pid || kill `cat pid`])
785 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
786 [test ! -e pid || kill `cat pid`])
787 OVSDB_SERVER_SHUTDOWN
792 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv6 sockets)])
794 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
796 # Creates a database with the given SCHEMA, starts an ovsdb-server on
797 # that database, and runs each of the TRANSACTIONS (which should be a
798 # quoted list of quoted strings) against it with ovsdb-client one at a
801 # Checks that the overall output is OUTPUT, but UUIDs in the output
802 # are replaced by markers of the form <N> where N is a number. The
803 # first unique UUID is replaced by <0>, the next by <1>, and so on.
804 # If a given UUID appears more than once it is always replaced by the
807 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
808 m4_define([OVSDB_CHECK_EXECUTION],
810 AT_KEYWORDS([ovsdb server positive ssl6 $5])
811 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
812 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
813 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
815 PKIDIR=$abs_top_builddir/tests
816 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
817 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])
818 SSL_PORT=`parse_listening_port < ovsdb-server.log`
819 m4_foreach([txn], [$3],
820 [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],
821 [test ! -e pid || kill `cat pid`])
824 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
825 [test ! -e pid || kill `cat pid`])
826 OVSDB_SERVER_SHUTDOWN
829 ONE_EXECUTION_EXAMPLE
831 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv4 sockets)])
833 AT_SETUP([ovsdb-client get-schema-version - tcp socket])
834 AT_KEYWORDS([ovsdb server positive tcp])
835 ordinal_schema > schema
836 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
837 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
838 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])
839 TCP_PORT=`parse_listening_port < ovsdb-server.log`
840 AT_CHECK([ovsdb-client get-schema-version tcp:127.0.0.1:$TCP_PORT ordinals], [0], [5.1.3
842 OVSDB_SERVER_SHUTDOWN
845 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
847 # Creates a database with the given SCHEMA, starts an ovsdb-server on
848 # that database, and runs each of the TRANSACTIONS (which should be a
849 # quoted list of quoted strings) against it with ovsdb-client one at a
852 # Checks that the overall output is OUTPUT, but UUIDs in the output
853 # are replaced by markers of the form <N> where N is a number. The
854 # first unique UUID is replaced by <0>, the next by <1>, and so on.
855 # If a given UUID appears more than once it is always replaced by the
858 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
859 m4_define([OVSDB_CHECK_EXECUTION],
861 AT_KEYWORDS([ovsdb server positive tcp $5])
862 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
863 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
865 PKIDIR=$abs_top_builddir/tests
866 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
867 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])
868 TCP_PORT=`parse_listening_port < ovsdb-server.log`
869 m4_foreach([txn], [$3],
870 [AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT 'txn'], [0], [stdout], [ignore],
871 [test ! -e pid || kill `cat pid`])
874 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
875 [test ! -e pid || kill `cat pid`])
876 OVSDB_SERVER_SHUTDOWN
881 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv6 sockets)])
883 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
885 # Creates a database with the given SCHEMA, starts an ovsdb-server on
886 # that database, and runs each of the TRANSACTIONS (which should be a
887 # quoted list of quoted strings) against it with ovsdb-client one at a
890 # Checks that the overall output is OUTPUT, but UUIDs in the output
891 # are replaced by markers of the form <N> where N is a number. The
892 # first unique UUID is replaced by <0>, the next by <1>, and so on.
893 # If a given UUID appears more than once it is always replaced by the
896 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
897 m4_define([OVSDB_CHECK_EXECUTION],
899 AT_KEYWORDS([ovsdb server positive tcp6 $5])
900 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
901 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
903 PKIDIR=$abs_top_builddir/tests
904 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
905 AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid --remote=ptcp:0:[[::1]] --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
906 TCP_PORT=`parse_listening_port < ovsdb-server.log`
907 m4_foreach([txn], [$3],
908 [AT_CHECK([ovsdb-client transact tcp:[[::1]]:$TCP_PORT 'txn'], [0], [stdout], [ignore],
909 [test ! -e pid || kill `cat pid`])
912 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
913 [test ! -e pid || kill `cat pid`])
914 OVSDB_SERVER_SHUTDOWN
917 ONE_EXECUTION_EXAMPLE
919 AT_BANNER([OVSDB -- transactions on transient ovsdb-server])
921 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
923 # Creates a database with the given SCHEMA and runs each of the
924 # TRANSACTIONS (which should be a quoted list of quoted strings)
925 # against it with ovsdb-client one at a time. Each ovsdb-client
926 # is run against a separately started ovsdb-server that executes
927 # only that single transaction. (The idea is that this should
928 # help to ferret out any differences between what ovsdb-server has
929 # in memory and what actually gets committed to disk.)
931 # Checks that the overall output is OUTPUT, but UUIDs in the output
932 # are replaced by markers of the form <N> where N is a number. The
933 # first unique UUID is replaced by <0>, the next by <1>, and so on.
934 # If a given UUID appears more than once it is always replaced by the
937 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
938 m4_define([OVSDB_CHECK_EXECUTION],
940 AT_KEYWORDS([ovsdb server positive transient $5])
941 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
943 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
944 m4_foreach([txn], [$3],
945 [AT_DATA([txnfile], [ovsdb-client transact unix:socket 'txn'
947 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [ignore])
950 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore])