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, [],
199 ovs-appctl: ovsdb-server: server returned an error
202 # Add a non-existing database.
203 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db3], 2, [], [stderr])
204 AT_CHECK([sed 's/(.*)/(...)/' stderr], [0],
205 [I/O error: open: db3 failed (...)
206 ovs-appctl: ovsdb-server: server returned an error
209 # Add a remote through a db path in db1.
210 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote db:ordinals,ordinals,name], [0])
211 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
212 [0], [db:ordinals,ordinals,name
216 # Removing db1 has no effect on its remote.
217 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db ordinals], [0])
218 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
221 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
222 [0], [db:ordinals,ordinals,name
225 AT_CHECK([ovsdb-client list-tables unix:socket ordinals], [1], [ignore], [ignore])
228 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db constraints], [0])
229 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
231 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [1], [ignore], [ignore])
233 # Remove a non-existent database.
234 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db ordinals], [2],
235 [], [Failed to find the database.
236 ovs-appctl: ovsdb-server: server returned an error
239 # Add a removed database.
240 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
241 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
244 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [0], [ignore], [ignore])
247 AT_SETUP([ovsdb-server/add-db with --monitor])
248 AT_KEYWORDS([ovsdb server positive])
249 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
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 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
283 # Start ovsdb-server, initially with one db.
284 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
285 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
286 ordinal_schema > schema
287 AT_CHECK([ovsdb-tool create db1 schema], [0], [ignore], [ignore])
288 constraint_schema > schema2
289 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
290 ON_EXIT([kill `cat *.pid`])
291 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db1 db2])
293 # Remove the second database.
294 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db constraints])
295 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
299 # Kill the daemon process, making it look like a segfault,
300 # and wait for a new daemon process to get spawned.
301 cp ovsdb-server.pid old.pid
302 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
303 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
305 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
306 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
311 AT_SETUP([--remote=db: implementation])
312 AT_KEYWORDS([ovsdb server positive])
313 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
314 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
324 "max": "unlimited"}},
327 "key": {"type": "uuid", "refTable": "Manager"},
329 "max": "unlimited"}}}},
340 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
342 [[ovsdb-tool transact db \
347 "managers": "punix:socket1",
348 "manager_options": ["set", [["named-uuid", "x"]]]}},
352 "row": {"target": "punix:socket2"}}]']], [0], [ignore], [ignore])
353 ON_EXIT([kill `cat ovsdb-server.pid`])
354 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])
355 for i in 1 2 3 4 5 6; do ovs-appctl -t ovsdb-server time/warp 1000; done
357 [[ovsdb-client transact unix:socket1 \
362 "columns": ["managers"]},
366 "columns": ["target", "is_connected"]}]']],
367 [0], [stdout], [ignore])
369 [${PERL} $srcdir/uuidfilt.pl stdout],
371 [[[{"rows":[{"managers":"punix:socket1"}]},{"rows":[{"is_connected":false,"target":"punix:socket2"}]}]
376 AT_SETUP([ovsdb-server/add-remote and remove-remote])
377 AT_KEYWORDS([ovsdb server positive])
378 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
379 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
380 ordinal_schema > schema
381 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
382 ON_EXIT([kill `cat *.pid`])
383 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile db])
385 AT_CHECK([test ! -e socket1])
386 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
387 OVS_WAIT_UNTIL([test -S socket1])
388 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
392 AT_CHECK([test ! -e socket2])
393 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket2])
394 OVS_WAIT_UNTIL([test -S socket2])
395 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
400 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote db:x,y,z], [2],
401 [], ["db:x,y,z": no database named x
402 ovs-appctl: ovsdb-server: server returned an error
405 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
406 OVS_WAIT_UNTIL([test ! -e socket1])
407 AT_CHECK([test -S socket2])
408 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
412 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket2])
413 OVS_WAIT_UNTIL([test ! -e socket2])
414 AT_CHECK([test ! -e socket1])
415 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
418 AT_SETUP([ovsdb-server/add-remote with --monitor])
419 AT_KEYWORDS([ovsdb server positive])
420 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
421 # Start ovsdb-server, initially with no remotes.
422 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
423 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
424 ordinal_schema > schema
425 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
426 ON_EXIT([kill `cat *.pid`])
427 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db])
430 AT_CHECK([test ! -e socket1])
431 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
432 OVS_WAIT_UNTIL([test -S socket1])
433 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
437 # Kill the daemon process, making it look like a segfault,
438 # and wait for a new daemon process to get spawned and for it to
439 # start listening on 'socket1'.
440 cp ovsdb-server.pid old.pid
442 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
443 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
445 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
446 OVS_WAIT_UNTIL([test -S socket1])
449 AT_SETUP([ovsdb-server/add-remote and remove-remote with --monitor])
450 AT_KEYWORDS([ovsdb server positive])
451 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
452 # Start ovsdb-server, initially with no remotes.
453 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
454 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
455 ordinal_schema > schema
456 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
457 ON_EXIT([kill `cat *.pid`])
458 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db])
461 AT_CHECK([test ! -e socket1])
462 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
463 OVS_WAIT_UNTIL([test -S socket1])
464 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
469 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
470 OVS_WAIT_UNTIL([test ! -e socket1])
471 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
473 # Kill the daemon process, making it look like a segfault,
474 # and wait for a new daemon process to get spawned and make sure that it
475 # does not listen on 'socket1'.
476 cp ovsdb-server.pid old.pid
477 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
478 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
480 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
481 AT_CHECK([test ! -e socket1])
484 AT_SETUP([SSL db: implementation])
485 AT_KEYWORDS([ovsdb server positive ssl $5])
486 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
487 PKIDIR=$abs_top_builddir/tests
488 AT_SKIP_IF([expr "$PKIDIR" : ".*[ '\"
495 "private_key": {"type": "string"},
496 "certificate": {"type": "string"},
497 "ca_cert": {"type": "string"}}}}}
499 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
501 [[ovsdb-tool transact db \
505 "row": {"private_key": "'"$PKIDIR/testpki-privkey2.pem"'",
506 "certificate": "'"$PKIDIR/testpki-cert2.pem"'",
507 "ca_cert": "'"$PKIDIR/testpki-cacert.pem"'"}}]']],
508 [0], [ignore], [ignore])
509 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
511 [ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid \
512 --private-key=db:mydb,SSL,private_key \
513 --certificate=db:mydb,SSL,certificate \
514 --ca-cert=db:mydb,SSL,ca_cert \
515 --remote=pssl:0:127.0.0.1 --unixctl="`pwd`"/unixctl db],
516 [0], [ignore], [ignore])
517 SSL_PORT=`parse_listening_port < ovsdb-server.log`
520 --private-key=$PKIDIR/testpki-privkey.pem \
521 --certificate=$PKIDIR/testpki-cert.pem \
522 --ca-cert=$PKIDIR/testpki-cacert.pem \
523 transact ssl:127.0.0.1:$SSL_PORT \
528 "columns": ["private_key"]}]']],
529 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
533 [[[{"rows":[{"private_key":"$PKIDIR/testpki-privkey2.pem"}]}]
534 ]], [ignore], [test ! -e pid || kill `cat pid`])
535 OVSDB_SERVER_SHUTDOWN
538 AT_SETUP([compacting online])
539 AT_KEYWORDS([ovsdb server compact])
540 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
541 ordinal_schema > schema
542 dnl Make sure that "ovsdb-tool create" works with a dangling symlink for
543 dnl the database and the lockfile, creating the target of each symlink rather
544 dnl than replacing the symlinks with regular files.
547 ln -s dir/.db.~lock~ .db.~lock~
548 AT_SKIP_IF([test ! -h db || test ! -h .db.~lock~])
549 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
550 dnl Start ovsdb-server.
551 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])
552 AT_CAPTURE_FILE([ovsdb-server.log])
553 dnl Do a bunch of random transactions that put crap in the database log.
555 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
557 ovsdb-client transact unix:socket '
561 "row": {"name": "'$1'", "number": '$2'}},
563 "comment": "add row for '"$pair"'"}]'
564 ovsdb-client transact unix:socket '
568 "where": [["number", "==", '$2']]},
570 "comment": "delete row for '"$2"'"}]'
571 ovsdb-client transact unix:socket '
575 "row": {"name": "'$1'", "number": '$2'}},
577 "comment": "add back row for '"$pair"'"}]'
579 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
580 dnl Check that all the crap is in fact in the database log.
581 AT_CHECK([[${PERL} $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | ovstest test-json --multiple -]], [0],
582 [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"}
583 {"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
584 {"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
585 {"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
586 {"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
587 {"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
588 {"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
589 {"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
590 {"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
591 {"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
592 {"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
593 {"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
594 {"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
595 {"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
596 {"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
597 {"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
598 {"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
599 {"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
600 {"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
601 ]], [], [test ! -e pid || kill `cat pid`])
602 dnl Dump out and check the actual database contents.
603 AT_CHECK([[ovsdb-client dump unix:socket ordinals]],
604 [0], [stdout], [ignore])
605 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
608 ------------------------------------ ----- ------
615 ], [], [test ! -e pid || kill `cat pid`])
616 dnl Now compact the database in-place.
617 AT_CHECK([[ovs-appctl -t "`pwd`"/unixctl ovsdb-server/compact]],
618 [0], [], [ignore], [test ! -e pid || kill `cat pid`])
619 dnl Make sure that "db" is still a symlink to dir/db instead of getting
620 dnl replaced by a regular file, ditto for .db.~lock~.
621 AT_CHECK([test -h db])
622 AT_CHECK([test -h .db.~lock~])
623 AT_CHECK([test -f dir/db])
624 AT_CHECK([test -f dir/.db.~lock~])
625 dnl We can't fully re-check the contents of the database log, because the
626 dnl order of the records is not predictable, but there should only be 4 lines
628 AT_CAPTURE_FILE([db])
629 AT_CHECK([test `wc -l < db` -eq 4], [0], [], [],
630 [test ! -e pid || kill `cat pid`])
631 dnl And check that the dumped data is the same too:
632 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
633 [test ! -e pid || kill `cat pid`])
634 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
637 ------------------------------------ ----- ------
644 ], [], [test ! -e pid || kill `cat pid`])
645 dnl Now do some more transactions.
647 [[ovsdb-client transact unix:socket '
651 "where": [["number", "<", 3]]}]']],
653 ]], [ignore], [test ! -e pid || kill `cat pid`])
654 dnl There should be 6 lines in the log now.
655 AT_CHECK([test `wc -l < db` -eq 6], [0], [], [],
656 [test ! -e pid || kill `cat pid`])
657 dnl Then check that the dumped data is correct.
658 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
659 [test ! -e pid || kill `cat pid`])
660 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
663 ------------------------------------ ----- ------
667 ], [], [test ! -e pid || kill `cat pid`])
668 OVSDB_SERVER_SHUTDOWN
671 AT_SETUP([ovsdb-server combines updates on backlogged connections])
672 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
673 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
674 ON_EXIT([kill `cat *.pid`])
676 # The maximum socket receive buffer size is important for this test, which
677 # tests behavior when the receive buffer overflows.
678 if test -e /proc/sys/net/core/rmem_max; then
680 rmem_max=`cat /proc/sys/net/core/rmem_max`
681 elif rmem_max=`sysctl -n net.inet.tcp.recvbuf_max 2>/dev/null`; then
684 # Don't know how to get maximum socket receive buffer on this OS
688 # Calculate the number of iterations we need to queue. Each of the
689 # iterations we execute, by itself, yields a monitor update of about
690 # 25 kB, so fill up that much space plus a few for luck.
691 n_iterations=`expr $rmem_max / 25000 + 5`
692 echo rmem_max=$rmem_max n_iterations=$n_iterations
694 # If there's too much queuing skip the test to avoid timing out.
695 AT_SKIP_IF([test $rmem_max -gt 1048576])
697 # Calculate the exact number of monitor updates expected for $n_iterations,
698 # assuming no updates are combined. The "extra" update is for the initial
699 # contents of the database.
700 n_updates=`expr $n_iterations \* 3 + 1`
702 # Start an ovsdb-server with the vswitchd schema.
704 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --log-file --remote=punix:db.sock db],
705 [0], [ignore], [ignore])
707 # Executes a set of transactions that add a bridge with 100 ports, and
708 # then deletes that bridge. This yields three monitor updates that
709 # add up to about 25 kB in size.
711 # The update also increments a counter held in the database so that we can
712 # verify that the overall effect of the transactions took effect (e.g.
713 # monitor updates at the end weren't just dropped). We add an arbitrary
714 # string to the counter to make grepping for it more reliable.
716 trigger_big_update () {
717 counter=`expr $counter + 1`
718 ovs-vsctl --no-wait -- set open_vswitch . system_version=xyzzy$counter
719 ovs-vsctl --no-wait -- add-br br0 $add
720 ovs-vsctl --no-wait -- del-br br0
723 for j in `seq 1 100`; do
724 printf " -- add-port br0 p%d" $j
729 AT_CAPTURE_FILE([ovsdb-client.err])
731 # Start an ovsdb-client monitoring all changes to the database,
732 # make it block to force the buffers to fill up, and then execute
733 # enough iterations that ovsdb-server starts combining updates.
734 AT_CHECK([ovsdb-client --detach --no-chdir --pidfile monitor ALL >ovsdb-client.out 2>ovsdb-client.err])
735 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/block])
736 for i in `seq 1 $n_iterations`; do
737 echo "blocked update ($i of $n_iterations)"
738 trigger_big_update $i
740 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/unblock])
741 OVS_WAIT_UNTIL([grep "\"xyzzy$counter\"" ovsdb-client.out])
742 AT_CHECK([ovs-appctl -t ovsdb-client exit])
743 OVS_WAIT_WHILE([test -e ovsdb-client.pid])
745 # Count the number of updates in the ovsdb-client output, by counting
746 # the number of changes to the Open_vSwitch table. (All of our
747 # transactions modify the Open_vSwitch table.) It should be less than
748 # $n_updates updates.
750 # Check that the counter is what we expect.
751 logged_updates=`grep -c '^Open_vSwitch' ovsdb-client.out`
752 echo "logged_updates=$logged_updates (expected less than $n_updates)"
753 AT_CHECK([test $logged_updates -lt $n_updates])
754 AT_CHECK_UNQUOTED([ovs-vsctl get open_vswitch . system_version], [0],
759 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv4 sockets)])
761 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
763 # Creates a database with the given SCHEMA, starts an ovsdb-server on
764 # that database, and runs each of the TRANSACTIONS (which should be a
765 # quoted list of quoted strings) against it with ovsdb-client one at a
768 # Checks that the overall output is OUTPUT, but UUIDs in the output
769 # are replaced by markers of the form <N> where N is a number. The
770 # first unique UUID is replaced by <0>, the next by <1>, and so on.
771 # If a given UUID appears more than once it is always replaced by the
774 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
775 m4_define([OVSDB_CHECK_EXECUTION],
777 AT_KEYWORDS([ovsdb server positive ssl $5])
778 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
779 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
780 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
782 PKIDIR=$abs_top_builddir/tests
783 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
784 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])
785 SSL_PORT=`parse_listening_port < ovsdb-server.log`
786 m4_foreach([txn], [$3],
787 [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],
788 [test ! -e pid || kill `cat pid`])
791 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
792 [test ! -e pid || kill `cat pid`])
793 OVSDB_SERVER_SHUTDOWN
798 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv6 sockets)])
800 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
802 # Creates a database with the given SCHEMA, starts an ovsdb-server on
803 # that database, and runs each of the TRANSACTIONS (which should be a
804 # quoted list of quoted strings) against it with ovsdb-client one at a
807 # Checks that the overall output is OUTPUT, but UUIDs in the output
808 # are replaced by markers of the form <N> where N is a number. The
809 # first unique UUID is replaced by <0>, the next by <1>, and so on.
810 # If a given UUID appears more than once it is always replaced by the
813 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
814 m4_define([OVSDB_CHECK_EXECUTION],
816 AT_KEYWORDS([ovsdb server positive ssl6 $5])
817 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
818 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
819 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
821 PKIDIR=$abs_top_builddir/tests
822 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
823 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])
824 SSL_PORT=`parse_listening_port < ovsdb-server.log`
825 m4_foreach([txn], [$3],
826 [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],
827 [test ! -e pid || kill `cat pid`])
830 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
831 [test ! -e pid || kill `cat pid`])
832 OVSDB_SERVER_SHUTDOWN
835 ONE_EXECUTION_EXAMPLE
837 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv4 sockets)])
839 AT_SETUP([ovsdb-client get-schema-version - tcp socket])
840 AT_KEYWORDS([ovsdb server positive tcp])
841 ordinal_schema > schema
842 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
843 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
844 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])
845 TCP_PORT=`parse_listening_port < ovsdb-server.log`
846 AT_CHECK([ovsdb-client get-schema-version tcp:127.0.0.1:$TCP_PORT ordinals], [0], [5.1.3
848 OVSDB_SERVER_SHUTDOWN
851 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
853 # Creates a database with the given SCHEMA, starts an ovsdb-server on
854 # that database, and runs each of the TRANSACTIONS (which should be a
855 # quoted list of quoted strings) against it with ovsdb-client one at a
858 # Checks that the overall output is OUTPUT, but UUIDs in the output
859 # are replaced by markers of the form <N> where N is a number. The
860 # first unique UUID is replaced by <0>, the next by <1>, and so on.
861 # If a given UUID appears more than once it is always replaced by the
864 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
865 m4_define([OVSDB_CHECK_EXECUTION],
867 AT_KEYWORDS([ovsdb server positive tcp $5])
868 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
869 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
871 PKIDIR=$abs_top_builddir/tests
872 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
873 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])
874 TCP_PORT=`parse_listening_port < ovsdb-server.log`
875 m4_foreach([txn], [$3],
876 [AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT 'txn'], [0], [stdout], [ignore],
877 [test ! -e pid || kill `cat pid`])
880 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
881 [test ! -e pid || kill `cat pid`])
882 OVSDB_SERVER_SHUTDOWN
887 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv6 sockets)])
889 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
891 # Creates a database with the given SCHEMA, starts an ovsdb-server on
892 # that database, and runs each of the TRANSACTIONS (which should be a
893 # quoted list of quoted strings) against it with ovsdb-client one at a
896 # Checks that the overall output is OUTPUT, but UUIDs in the output
897 # are replaced by markers of the form <N> where N is a number. The
898 # first unique UUID is replaced by <0>, the next by <1>, and so on.
899 # If a given UUID appears more than once it is always replaced by the
902 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
903 m4_define([OVSDB_CHECK_EXECUTION],
905 AT_KEYWORDS([ovsdb server positive tcp6 $5])
906 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
907 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
909 PKIDIR=$abs_top_builddir/tests
910 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
911 AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid --remote=ptcp:0:[[::1]] --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
912 TCP_PORT=`parse_listening_port < ovsdb-server.log`
913 m4_foreach([txn], [$3],
914 [AT_CHECK([ovsdb-client transact tcp:[[::1]]:$TCP_PORT 'txn'], [0], [stdout], [ignore],
915 [test ! -e pid || kill `cat pid`])
918 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
919 [test ! -e pid || kill `cat pid`])
920 OVSDB_SERVER_SHUTDOWN
923 ONE_EXECUTION_EXAMPLE
925 AT_BANNER([OVSDB -- transactions on transient ovsdb-server])
927 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
929 # Creates a database with the given SCHEMA and runs each of the
930 # TRANSACTIONS (which should be a quoted list of quoted strings)
931 # against it with ovsdb-client one at a time. Each ovsdb-client
932 # is run against a separately started ovsdb-server that executes
933 # only that single transaction. (The idea is that this should
934 # help to ferret out any differences between what ovsdb-server has
935 # in memory and what actually gets committed to disk.)
937 # Checks that the overall output is OUTPUT, but UUIDs in the output
938 # are replaced by markers of the form <N> where N is a number. The
939 # first unique UUID is replaced by <0>, the next by <1>, and so on.
940 # If a given UUID appears more than once it is always replaced by the
943 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
944 m4_define([OVSDB_CHECK_EXECUTION],
946 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
947 AT_KEYWORDS([ovsdb server positive transient $5])
948 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
950 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
951 m4_foreach([txn], [$3],
952 [AT_DATA([txnfile], [ovsdb-client transact unix:socket 'txn'
954 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [ignore])
957 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore])