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 if test $IS_WIN32 = "yes"; then
198 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], 2, [],
199 [I/O error: db2: failed to lock lockfile (Resource deadlock avoided)
200 ovs-appctl: ovsdb-server: server returned an error
203 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], 2, [],
205 ovs-appctl: ovsdb-server: server returned an error
209 # Add a non-existing database.
210 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db3], 2, [], [stderr])
211 AT_CHECK([sed 's/(.*)/(...)/' stderr], [0],
212 [I/O error: open: db3 failed (...)
213 ovs-appctl: ovsdb-server: server returned an error
216 # Add a remote through a db path in db1.
217 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote db:ordinals,ordinals,name], [0])
218 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
219 [0], [db:ordinals,ordinals,name
223 # Removing db1 has no effect on its remote.
224 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db ordinals], [0])
225 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
228 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
229 [0], [db:ordinals,ordinals,name
232 AT_CHECK([ovsdb-client list-tables unix:socket ordinals], [1], [ignore], [ignore])
235 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db constraints], [0])
236 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
238 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [1], [ignore], [ignore])
240 # Remove a non-existent database.
241 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db ordinals], [2],
242 [], [Failed to find the database.
243 ovs-appctl: ovsdb-server: server returned an error
246 # Add a removed database.
247 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
248 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
251 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [0], [ignore], [ignore])
254 AT_SETUP([ovsdb-server/add-db with --monitor])
255 AT_KEYWORDS([ovsdb server positive])
256 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
257 # Start ovsdb-server, initially with one db.
258 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
259 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
260 ordinal_schema > schema
261 AT_CHECK([ovsdb-tool create db1 schema], [0], [ignore], [ignore])
262 ON_EXIT([kill `cat *.pid`])
263 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db1])
265 # Add the second database.
266 constraint_schema > schema2
267 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
268 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
269 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
274 # Kill the daemon process, making it look like a segfault,
275 # and wait for a new daemon process to get spawned.
276 cp ovsdb-server.pid old.pid
277 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
278 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
280 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
281 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
287 AT_SETUP([ovsdb-server/add-db and remove-db with --monitor])
288 AT_KEYWORDS([ovsdb server positive])
289 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
290 # Start ovsdb-server, initially with one db.
291 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
292 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
293 ordinal_schema > schema
294 AT_CHECK([ovsdb-tool create db1 schema], [0], [ignore], [ignore])
295 constraint_schema > schema2
296 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
297 ON_EXIT([kill `cat *.pid`])
298 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db1 db2])
300 # Remove the second database.
301 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db constraints])
302 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
306 # Kill the daemon process, making it look like a segfault,
307 # and wait for a new daemon process to get spawned.
308 cp ovsdb-server.pid old.pid
309 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
310 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
312 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
313 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
318 AT_SETUP([--remote=db: implementation])
319 AT_KEYWORDS([ovsdb server positive])
320 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
321 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
331 "max": "unlimited"}},
334 "key": {"type": "uuid", "refTable": "Manager"},
336 "max": "unlimited"}}}},
347 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
349 [[ovsdb-tool transact db \
354 "managers": "punix:socket1",
355 "manager_options": ["set", [["named-uuid", "x"]]]}},
359 "row": {"target": "punix:socket2"}}]']], [0], [ignore], [ignore])
360 ON_EXIT([kill `cat ovsdb-server.pid`])
361 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])
362 for i in 1 2 3 4 5 6; do ovs-appctl -t ovsdb-server time/warp 1000; done
364 [[ovsdb-client transact unix:socket1 \
369 "columns": ["managers"]},
373 "columns": ["target", "is_connected"]}]']],
374 [0], [stdout], [ignore])
376 [${PERL} $srcdir/uuidfilt.pl stdout],
378 [[[{"rows":[{"managers":"punix:socket1"}]},{"rows":[{"is_connected":false,"target":"punix:socket2"}]}]
383 AT_SETUP([ovsdb-server/add-remote and remove-remote])
384 AT_KEYWORDS([ovsdb server positive])
385 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
386 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
387 ordinal_schema > schema
388 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
389 ON_EXIT([kill `cat *.pid`])
390 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile db])
392 AT_CHECK([test ! -e socket1])
393 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
394 if test "$IS_WIN32" = "yes"; then
395 OVS_WAIT_UNTIL([test -s socket1])
397 OVS_WAIT_UNTIL([test -S socket1])
399 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
403 AT_CHECK([test ! -e socket2])
404 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket2])
405 if test "$IS_WIN32" = "yes"; then
406 OVS_WAIT_UNTIL([test -s socket2])
408 OVS_WAIT_UNTIL([test -S socket2])
410 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
415 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote db:x,y,z], [2],
416 [], ["db:x,y,z": no database named x
417 ovs-appctl: ovsdb-server: server returned an error
420 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
421 OVS_WAIT_UNTIL([test ! -e socket1])
422 if test "$IS_WIN32" = "yes"; then
423 AT_CHECK([test -s socket2])
425 AT_CHECK([test -S socket2])
427 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
431 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket2])
432 OVS_WAIT_UNTIL([test ! -e socket2])
433 AT_CHECK([test ! -e socket1])
434 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
437 AT_SETUP([ovsdb-server/add-remote with --monitor])
438 AT_KEYWORDS([ovsdb server positive])
439 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
440 # Start ovsdb-server, initially with no remotes.
441 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
442 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
443 ordinal_schema > schema
444 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
445 ON_EXIT([kill `cat *.pid`])
446 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db])
449 AT_CHECK([test ! -e socket1])
450 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
451 OVS_WAIT_UNTIL([test -S socket1])
452 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
456 # Kill the daemon process, making it look like a segfault,
457 # and wait for a new daemon process to get spawned and for it to
458 # start listening on 'socket1'.
459 cp ovsdb-server.pid old.pid
461 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
462 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
464 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
465 OVS_WAIT_UNTIL([test -S socket1])
468 AT_SETUP([ovsdb-server/add-remote and remove-remote with --monitor])
469 AT_KEYWORDS([ovsdb server positive])
470 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
471 # Start ovsdb-server, initially with no remotes.
472 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
473 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
474 ordinal_schema > schema
475 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
476 ON_EXIT([kill `cat *.pid`])
477 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db])
480 AT_CHECK([test ! -e socket1])
481 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
482 OVS_WAIT_UNTIL([test -S socket1])
483 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
488 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
489 OVS_WAIT_UNTIL([test ! -e socket1])
490 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
492 # Kill the daemon process, making it look like a segfault,
493 # and wait for a new daemon process to get spawned and make sure that it
494 # does not listen on 'socket1'.
495 cp ovsdb-server.pid old.pid
496 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
497 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
499 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
500 AT_CHECK([test ! -e socket1])
503 AT_SETUP([SSL db: implementation])
504 AT_KEYWORDS([ovsdb server positive ssl $5])
505 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
506 # For this test, we pass PKIDIR through a ovsdb-tool transact and
507 # msys on Windows does not convert the path style automatically.
508 # So, do that forcefully with a 'pwd -W' (called through pwd() function).
509 PKIDIR="$(cd $abs_top_builddir/tests && pwd)"
510 AT_SKIP_IF([expr "$PKIDIR" : ".*[ '\"
517 "private_key": {"type": "string"},
518 "certificate": {"type": "string"},
519 "ca_cert": {"type": "string"}}}}}
521 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
523 [[ovsdb-tool transact db \
527 "row": {"private_key": "'"$PKIDIR/testpki-privkey2.pem"'",
528 "certificate": "'"$PKIDIR/testpki-cert2.pem"'",
529 "ca_cert": "'"$PKIDIR/testpki-cacert.pem"'"}}]']],
530 [0], [ignore], [ignore])
531 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
533 [ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid \
534 --private-key=db:mydb,SSL,private_key \
535 --certificate=db:mydb,SSL,certificate \
536 --ca-cert=db:mydb,SSL,ca_cert \
537 --remote=pssl:0:127.0.0.1 --unixctl="`pwd`"/unixctl db],
538 [0], [ignore], [ignore])
539 SSL_PORT=`parse_listening_port < ovsdb-server.log`
542 --private-key=$PKIDIR/testpki-privkey.pem \
543 --certificate=$PKIDIR/testpki-cert.pem \
544 --ca-cert=$PKIDIR/testpki-cacert.pem \
545 transact ssl:127.0.0.1:$SSL_PORT \
550 "columns": ["private_key"]}]']],
551 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
555 [[@<:@{"rows":@<:@{"private_key":"$PKIDIR/testpki-privkey2.pem"}@:>@}@:>@
556 ]], [ignore], [test ! -e pid || kill `cat pid`])
557 OVSDB_SERVER_SHUTDOWN
560 AT_SETUP([compacting online])
561 AT_KEYWORDS([ovsdb server compact])
562 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
563 ordinal_schema > schema
564 dnl Make sure that "ovsdb-tool create" works with a dangling symlink for
565 dnl the database and the lockfile, creating the target of each symlink rather
566 dnl than replacing the symlinks with regular files.
569 ln -s dir/.db.~lock~ .db.~lock~
570 AT_SKIP_IF([test ! -h db || test ! -h .db.~lock~])
571 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
572 dnl Start ovsdb-server.
573 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])
574 AT_CAPTURE_FILE([ovsdb-server.log])
575 dnl Do a bunch of random transactions that put crap in the database log.
577 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
579 ovsdb-client transact unix:socket '
583 "row": {"name": "'$1'", "number": '$2'}},
585 "comment": "add row for '"$pair"'"}]'
586 ovsdb-client transact unix:socket '
590 "where": [["number", "==", '$2']]},
592 "comment": "delete row for '"$2"'"}]'
593 ovsdb-client transact unix:socket '
597 "row": {"name": "'$1'", "number": '$2'}},
599 "comment": "add back row for '"$pair"'"}]'
601 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
602 dnl Check that all the crap is in fact in the database log.
603 AT_CHECK([[${PERL} $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | ovstest test-json --multiple -]], [0],
604 [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"}
605 {"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
606 {"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
607 {"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
608 {"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
609 {"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
610 {"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
611 {"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
612 {"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
613 {"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
614 {"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
615 {"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
616 {"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
617 {"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
618 {"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
619 {"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
620 {"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
621 {"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
622 {"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
623 ]], [], [test ! -e pid || kill `cat pid`])
624 dnl Dump out and check the actual database contents.
625 AT_CHECK([[ovsdb-client dump unix:socket ordinals]],
626 [0], [stdout], [ignore])
627 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
630 ------------------------------------ ----- ------
637 ], [], [test ! -e pid || kill `cat pid`])
638 dnl Now compact the database in-place.
639 AT_CHECK([[ovs-appctl -t "`pwd`"/unixctl ovsdb-server/compact]],
640 [0], [], [ignore], [test ! -e pid || kill `cat pid`])
641 dnl Make sure that "db" is still a symlink to dir/db instead of getting
642 dnl replaced by a regular file, ditto for .db.~lock~.
643 AT_CHECK([test -h db])
644 AT_CHECK([test -h .db.~lock~])
645 AT_CHECK([test -f dir/db])
646 AT_CHECK([test -f dir/.db.~lock~])
647 dnl We can't fully re-check the contents of the database log, because the
648 dnl order of the records is not predictable, but there should only be 4 lines
650 AT_CAPTURE_FILE([db])
651 AT_CHECK([test `wc -l < db` -eq 4], [0], [], [],
652 [test ! -e pid || kill `cat pid`])
653 dnl And check that the dumped data is the same too:
654 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
655 [test ! -e pid || kill `cat pid`])
656 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
659 ------------------------------------ ----- ------
666 ], [], [test ! -e pid || kill `cat pid`])
667 dnl Now do some more transactions.
669 [[ovsdb-client transact unix:socket '
673 "where": [["number", "<", 3]]}]']],
675 ]], [ignore], [test ! -e pid || kill `cat pid`])
676 dnl There should be 6 lines in the log now.
677 AT_CHECK([test `wc -l < db` -eq 6], [0], [], [],
678 [test ! -e pid || kill `cat pid`])
679 dnl Then check that the dumped data is correct.
680 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
681 [test ! -e pid || kill `cat pid`])
682 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
685 ------------------------------------ ----- ------
689 ], [], [test ! -e pid || kill `cat pid`])
690 OVSDB_SERVER_SHUTDOWN
693 AT_SETUP([ovsdb-server combines updates on backlogged connections])
694 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
695 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
696 ON_EXIT([kill `cat *.pid`])
698 # The maximum socket receive buffer size is important for this test, which
699 # tests behavior when the receive buffer overflows.
700 if test -e /proc/sys/net/core/rmem_max; then
702 rmem_max=`cat /proc/sys/net/core/rmem_max`
703 elif rmem_max=`sysctl -n net.inet.tcp.recvbuf_max 2>/dev/null`; then
706 # Don't know how to get maximum socket receive buffer on this OS
710 # Calculate the number of iterations we need to queue. Each of the
711 # iterations we execute, by itself, yields a monitor update of about
712 # 25 kB, so fill up that much space plus a few for luck.
713 n_iterations=`expr $rmem_max / 25000 + 5`
714 echo rmem_max=$rmem_max n_iterations=$n_iterations
716 # If there's too much queuing skip the test to avoid timing out.
717 AT_SKIP_IF([test $rmem_max -gt 1048576])
719 # Calculate the exact number of monitor updates expected for $n_iterations,
720 # assuming no updates are combined. The "extra" update is for the initial
721 # contents of the database.
722 n_updates=`expr $n_iterations \* 3 + 1`
724 # Start an ovsdb-server with the vswitchd schema.
726 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --log-file --remote=punix:db.sock db],
727 [0], [ignore], [ignore])
729 # Executes a set of transactions that add a bridge with 100 ports, and
730 # then deletes that bridge. This yields three monitor updates that
731 # add up to about 25 kB in size.
733 # The update also increments a counter held in the database so that we can
734 # verify that the overall effect of the transactions took effect (e.g.
735 # monitor updates at the end weren't just dropped). We add an arbitrary
736 # string to the counter to make grepping for it more reliable.
738 trigger_big_update () {
739 counter=`expr $counter + 1`
740 ovs-vsctl --no-wait -- set open_vswitch . system_version=xyzzy$counter
741 ovs-vsctl --no-wait -- add-br br0 $add
742 ovs-vsctl --no-wait -- del-br br0
745 for j in `seq 1 100`; do
746 printf " -- add-port br0 p%d" $j
751 AT_CAPTURE_FILE([ovsdb-client.err])
753 # Start an ovsdb-client monitoring all changes to the database,
754 # make it block to force the buffers to fill up, and then execute
755 # enough iterations that ovsdb-server starts combining updates.
756 AT_CHECK([ovsdb-client --detach --no-chdir --pidfile monitor ALL >ovsdb-client.out 2>ovsdb-client.err])
757 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/block])
758 for i in `seq 1 $n_iterations`; do
759 echo "blocked update ($i of $n_iterations)"
760 trigger_big_update $i
762 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/unblock])
763 OVS_WAIT_UNTIL([grep "\"xyzzy$counter\"" ovsdb-client.out])
764 AT_CHECK([ovs-appctl -t ovsdb-client exit])
765 OVS_WAIT_WHILE([test -e ovsdb-client.pid])
767 # Count the number of updates in the ovsdb-client output, by counting
768 # the number of changes to the Open_vSwitch table. (All of our
769 # transactions modify the Open_vSwitch table.) It should be less than
770 # $n_updates updates.
772 # Check that the counter is what we expect.
773 logged_updates=`grep -c '^Open_vSwitch' ovsdb-client.out`
774 echo "logged_updates=$logged_updates (expected less than $n_updates)"
775 AT_CHECK([test $logged_updates -lt $n_updates])
776 AT_CHECK_UNQUOTED([ovs-vsctl get open_vswitch . system_version], [0],
781 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv4 sockets)])
783 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
785 # Creates a database with the given SCHEMA, starts an ovsdb-server on
786 # that database, and runs each of the TRANSACTIONS (which should be a
787 # quoted list of quoted strings) against it with ovsdb-client one at a
790 # Checks that the overall output is OUTPUT, but UUIDs in the output
791 # are replaced by markers of the form <N> where N is a number. The
792 # first unique UUID is replaced by <0>, the next by <1>, and so on.
793 # If a given UUID appears more than once it is always replaced by the
796 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
797 m4_define([OVSDB_CHECK_EXECUTION],
799 AT_KEYWORDS([ovsdb server positive ssl $5])
800 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
801 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
802 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
804 PKIDIR=$abs_top_builddir/tests
805 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
806 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])
807 SSL_PORT=`parse_listening_port < ovsdb-server.log`
808 m4_foreach([txn], [$3],
809 [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],
810 [test ! -e pid || kill `cat pid`])
813 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
814 [test ! -e pid || kill `cat pid`])
815 OVSDB_SERVER_SHUTDOWN
820 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv6 sockets)])
822 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
824 # Creates a database with the given SCHEMA, starts an ovsdb-server on
825 # that database, and runs each of the TRANSACTIONS (which should be a
826 # quoted list of quoted strings) against it with ovsdb-client one at a
829 # Checks that the overall output is OUTPUT, but UUIDs in the output
830 # are replaced by markers of the form <N> where N is a number. The
831 # first unique UUID is replaced by <0>, the next by <1>, and so on.
832 # If a given UUID appears more than once it is always replaced by the
835 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
836 m4_define([OVSDB_CHECK_EXECUTION],
838 AT_KEYWORDS([ovsdb server positive ssl6 $5])
839 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
840 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
841 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
843 PKIDIR=$abs_top_builddir/tests
844 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
845 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])
846 SSL_PORT=`parse_listening_port < ovsdb-server.log`
847 m4_foreach([txn], [$3],
848 [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],
849 [test ! -e pid || kill `cat pid`])
852 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
853 [test ! -e pid || kill `cat pid`])
854 OVSDB_SERVER_SHUTDOWN
857 ONE_EXECUTION_EXAMPLE
859 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv4 sockets)])
861 AT_SETUP([ovsdb-client get-schema-version - tcp socket])
862 AT_KEYWORDS([ovsdb server positive tcp])
863 ordinal_schema > schema
864 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
865 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
866 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])
867 TCP_PORT=`parse_listening_port < ovsdb-server.log`
868 AT_CHECK([ovsdb-client get-schema-version tcp:127.0.0.1:$TCP_PORT ordinals], [0], [5.1.3
870 OVSDB_SERVER_SHUTDOWN
873 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
875 # Creates a database with the given SCHEMA, starts an ovsdb-server on
876 # that database, and runs each of the TRANSACTIONS (which should be a
877 # quoted list of quoted strings) against it with ovsdb-client one at a
880 # Checks that the overall output is OUTPUT, but UUIDs in the output
881 # are replaced by markers of the form <N> where N is a number. The
882 # first unique UUID is replaced by <0>, the next by <1>, and so on.
883 # If a given UUID appears more than once it is always replaced by the
886 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
887 m4_define([OVSDB_CHECK_EXECUTION],
889 AT_KEYWORDS([ovsdb server positive tcp $5])
890 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
891 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
893 PKIDIR=$abs_top_builddir/tests
894 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
895 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])
896 TCP_PORT=`parse_listening_port < ovsdb-server.log`
897 m4_foreach([txn], [$3],
898 [AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT 'txn'], [0], [stdout], [ignore],
899 [test ! -e pid || kill `cat pid`])
902 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
903 [test ! -e pid || kill `cat pid`])
904 OVSDB_SERVER_SHUTDOWN
909 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv6 sockets)])
911 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
913 # Creates a database with the given SCHEMA, starts an ovsdb-server on
914 # that database, and runs each of the TRANSACTIONS (which should be a
915 # quoted list of quoted strings) against it with ovsdb-client one at a
918 # Checks that the overall output is OUTPUT, but UUIDs in the output
919 # are replaced by markers of the form <N> where N is a number. The
920 # first unique UUID is replaced by <0>, the next by <1>, and so on.
921 # If a given UUID appears more than once it is always replaced by the
924 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
925 m4_define([OVSDB_CHECK_EXECUTION],
927 AT_KEYWORDS([ovsdb server positive tcp6 $5])
928 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
929 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
931 PKIDIR=$abs_top_builddir/tests
932 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
933 AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid --remote=ptcp:0:[[::1]] --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
934 TCP_PORT=`parse_listening_port < ovsdb-server.log`
935 m4_foreach([txn], [$3],
936 [AT_CHECK([ovsdb-client transact tcp:[[::1]]:$TCP_PORT 'txn'], [0], [stdout], [ignore],
937 [test ! -e pid || kill `cat pid`])
940 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
941 [test ! -e pid || kill `cat pid`])
942 OVSDB_SERVER_SHUTDOWN
945 ONE_EXECUTION_EXAMPLE
947 AT_BANNER([OVSDB -- transactions on transient ovsdb-server])
949 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
951 # Creates a database with the given SCHEMA and runs each of the
952 # TRANSACTIONS (which should be a quoted list of quoted strings)
953 # against it with ovsdb-client one at a time. Each ovsdb-client
954 # is run against a separately started ovsdb-server that executes
955 # only that single transaction. (The idea is that this should
956 # help to ferret out any differences between what ovsdb-server has
957 # in memory and what actually gets committed to disk.)
959 # Checks that the overall output is OUTPUT, but UUIDs in the output
960 # are replaced by markers of the form <N> where N is a number. The
961 # first unique UUID is replaced by <0>, the next by <1>, and so on.
962 # If a given UUID appears more than once it is always replaced by the
965 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
966 m4_define([OVSDB_CHECK_EXECUTION],
968 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
969 AT_KEYWORDS([ovsdb server positive transient $5])
970 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
972 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
973 m4_foreach([txn], [$3],
974 [AT_DATA([txnfile], [ovsdb-client transact unix:socket 'txn'
976 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [ignore])
979 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore])