1 AT_BANNER([OVSDB -- ovsdb-server transactions (Unix sockets)])
3 m4_define([OVSDB_SERVER_SHUTDOWN],
4 [OVS_APP_EXIT_AND_WAIT(["`pwd`"/unixctl])])
6 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
8 # Creates a database with the given SCHEMA, starts an ovsdb-server on
9 # that database, and runs each of the TRANSACTIONS (which should be a
10 # quoted list of quoted strings) against it with ovsdb-client one at a
13 # Checks that the overall output is OUTPUT, but UUIDs in the output
14 # are replaced by markers of the form <N> where N is a number. The
15 # first unique UUID is replaced by <0>, the next by <1>, and so on.
16 # If a given UUID appears more than once it is always replaced by the
19 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
20 m4_define([OVSDB_CHECK_EXECUTION],
22 AT_KEYWORDS([ovsdb server positive unix $5])
24 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
25 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
26 m4_foreach([txn], [$3],
27 [AT_CHECK([ovsdb-client transact unix:socket 'txn'], [0], [stdout], [ignore],
28 [test ! -e pid || kill `cat pid`])
31 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
32 [test ! -e pid || kill `cat pid`])
38 AT_BANNER([ovsdb-server miscellaneous features])
40 AT_SETUP([truncating corrupted database log])
41 AT_KEYWORDS([ovsdb server positive unix])
42 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
43 ordinal_schema > schema
44 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
45 dnl Do one transaction and save the output.
46 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
50 "row": {"number": 0, "name": "zero"}}]'
52 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
54 dnl Add some crap to the database log and run another transaction, which should
55 dnl ignore the crap and truncate it out of the log.
57 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
61 "row": {"number": 1, "name": "one"}}]'
63 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [stderr])
64 AT_CHECK([grep 'syntax error: db: parse error.* in header line "xxx"' stderr],
67 dnl Run a final transaction to verify that both transactions succeeeded.
68 dnl The crap that we added should have been truncated by the previous run,
69 dnl so ovsdb-server shouldn't log a warning this time.
70 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
77 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
79 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0],
80 [[[{"uuid":["uuid","<0>"]}]
81 [{"uuid":["uuid","<1>"]}]
82 [{"rows":[{"_uuid":["uuid","<0>"],"_version":["uuid","<2>"],"name":"zero","number":0},{"_uuid":["uuid","<1>"],"_version":["uuid","<3>"],"name":"one","number":1}]}]
84 [test ! -e pid || kill `cat pid`])
87 AT_SETUP([truncating database log with bad transaction])
88 AT_KEYWORDS([ovsdb server positive unix])
89 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
90 ordinal_schema > schema
91 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
92 dnl Do one transaction and save the output.
93 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
97 "row": {"number": 0, "name": "zero"}}]'
99 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
101 dnl Add some crap to the database log and run another transaction, which should
102 dnl ignore the crap and truncate it out of the log.
103 echo 'OVSDB JSON 15 ffbcdae4b0386265f9ea3280dd7c8f0b72a20e56
104 {"invalid":{}}' >> db
105 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
109 "row": {"number": 1, "name": "one"}}]'
111 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [stderr])
112 AT_CHECK([grep 'syntax "{"invalid":{}}": unknown table: No table named invalid.' stderr],
115 dnl Run a final transaction to verify that both transactions succeeeded.
116 dnl The crap that we added should have been truncated by the previous run,
117 dnl so ovsdb-server shouldn't log a warning this time.
118 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
123 "sort": ["number"]}]'
125 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
127 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0],
128 [[[{"uuid":["uuid","<0>"]}]
129 [{"uuid":["uuid","<1>"]}]
130 [{"rows":[{"_uuid":["uuid","<0>"],"_version":["uuid","<2>"],"name":"zero","number":0},{"_uuid":["uuid","<1>"],"_version":["uuid","<3>"],"name":"one","number":1}]}]
132 [test ! -e pid || kill `cat pid`])
135 AT_SETUP([ovsdb-client get-schema-version])
136 AT_KEYWORDS([ovsdb server positive])
137 ordinal_schema > schema
138 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
139 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=punix:socket db], [0], [ignore], [ignore])
140 AT_CHECK([ovsdb-client get-schema-version unix:socket ordinals], [0], [5.1.3
142 OVSDB_SERVER_SHUTDOWN
145 AT_SETUP([database multiplexing implementation])
146 AT_KEYWORDS([ovsdb server positive])
147 ordinal_schema > schema1
148 constraint_schema > schema2
149 AT_CHECK([ovsdb-tool create db1 schema1], [0], [ignore], [ignore])
150 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
151 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=punix:socket db1 db2], [0], [ignore], [ignore])
153 [[ovsdb-client list-dbs unix:socket]],
156 ], [ignore], [test ! -e pid || kill `cat pid`])
158 [[ovstest test-jsonrpc request unix:socket get_schema [\"nonexistent\"]]], [0],
159 [[{"error":{"details":"get_schema request specifies unknown database nonexistent","error":"unknown database","syntax":"[\"nonexistent\"]"},"id":0,"result":null}
160 ]], [], [test ! -e pid || kill `cat pid`])
161 OVSDB_SERVER_SHUTDOWN
164 AT_SETUP([ovsdb-server/add-db and remove-db])
165 AT_KEYWORDS([ovsdb server positive])
166 on_exit 'kill `cat ovsdb-server.pid`'
167 ordinal_schema > schema1
168 constraint_schema > schema2
169 AT_CHECK([ovsdb-tool create db1 schema1], [0], [ignore], [ignore])
170 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
172 # Start ovsdb-server with just a single database - db1.
173 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db1], [0])
174 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
178 # Add the second database.
179 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
180 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
185 # The databases are responsive.
186 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [0], [ignore], [ignore])
187 AT_CHECK([ovsdb-client list-tables unix:socket ordinals], [0], [ignore], [ignore])
189 # Add an already added database.
190 if test $IS_WIN32 = "yes"; then
191 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], 2, [],
192 [I/O error: db2: failed to lock lockfile (Resource deadlock avoided)
193 ovs-appctl: ovsdb-server: server returned an error
196 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], 2, [],
198 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: db3: open 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])
245 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
248 AT_SETUP([ovsdb-server/add-db with --monitor])
249 AT_KEYWORDS([ovsdb server positive])
250 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
251 # Start ovsdb-server, initially with one db.
252 ordinal_schema > schema
253 AT_CHECK([ovsdb-tool create db1 schema], [0], [ignore], [ignore])
254 on_exit 'kill `cat *.pid`'
255 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db1])
257 # Add the second database.
258 constraint_schema > schema2
259 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
260 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
261 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
266 # Kill the daemon process, making it look like a segfault,
267 # and wait for a new daemon process to get spawned.
268 cp ovsdb-server.pid old.pid
269 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
270 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
272 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
273 OVS_WAIT_UNTIL([ovs-appctl -t ovsdb-server version])
274 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
278 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
281 AT_SETUP([ovsdb-server/add-db and remove-db with --monitor])
282 AT_KEYWORDS([ovsdb server positive])
283 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
284 # Start ovsdb-server, initially with one db.
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 OVS_WAIT_UNTIL([ovs-appctl -t ovsdb-server version])
306 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
309 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
312 AT_SETUP([--remote=db: implementation])
313 AT_KEYWORDS([ovsdb server positive])
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 --detach --no-chdir --pidfile --remote=db:mydb,Root,managers --remote=db:mydb,Root,manager_options --log-file db], [0], [ignore], [ignore])
354 ovs-appctl -t ovsdb-server time/warp 6000 1000
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"}]}]
373 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
376 AT_SETUP([ovsdb-server/add-remote and remove-remote])
377 AT_KEYWORDS([ovsdb server positive])
378 ordinal_schema > schema
379 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
380 on_exit 'kill `cat *.pid`'
381 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile db])
383 AT_CHECK([test ! -e socket1])
384 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
385 if test "$IS_WIN32" = "yes"; then
386 OVS_WAIT_UNTIL([test -s socket1])
388 OVS_WAIT_UNTIL([test -S socket1])
390 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
394 AT_CHECK([test ! -e socket2])
395 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket2])
396 if test "$IS_WIN32" = "yes"; then
397 OVS_WAIT_UNTIL([test -s socket2])
399 OVS_WAIT_UNTIL([test -S socket2])
401 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
406 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote db:x,y,z], [2],
407 [], ["db:x,y,z": no database named x
408 ovs-appctl: ovsdb-server: server returned an error
411 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
412 OVS_WAIT_UNTIL([test ! -e socket1])
413 if test "$IS_WIN32" = "yes"; then
414 AT_CHECK([test -s socket2])
416 AT_CHECK([test -S socket2])
418 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
422 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket2])
423 OVS_WAIT_UNTIL([test ! -e socket2])
424 AT_CHECK([test ! -e socket1])
425 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
426 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
429 AT_SETUP([ovsdb-server/add-remote with --monitor])
430 AT_KEYWORDS([ovsdb server positive])
431 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
432 # Start ovsdb-server, initially with no remotes.
433 ordinal_schema > schema
434 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
435 on_exit 'kill `cat *.pid`'
436 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db])
439 AT_CHECK([test ! -e socket1])
440 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
441 OVS_WAIT_UNTIL([test -S socket1])
442 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
446 # Kill the daemon process, making it look like a segfault,
447 # and wait for a new daemon process to get spawned and for it to
448 # start listening on 'socket1'.
449 cp ovsdb-server.pid old.pid
451 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
452 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
454 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
455 OVS_WAIT_UNTIL([ovs-appctl -t ovsdb-server version])
456 OVS_WAIT_UNTIL([test -S socket1])
457 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
460 AT_SETUP([ovsdb-server/add-remote and remove-remote with --monitor])
461 AT_KEYWORDS([ovsdb server positive])
462 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
463 # Start ovsdb-server, initially with no remotes.
464 ordinal_schema > schema
465 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
466 on_exit 'kill `cat *.pid`'
467 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db])
470 AT_CHECK([test ! -e socket1])
471 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
472 OVS_WAIT_UNTIL([test -S socket1])
473 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
478 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
479 OVS_WAIT_UNTIL([test ! -e socket1])
480 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
482 # Kill the daemon process, making it look like a segfault,
483 # and wait for a new daemon process to get spawned and make sure that it
484 # does not listen on 'socket1'.
485 cp ovsdb-server.pid old.pid
486 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
487 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
489 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
490 OVS_WAIT_UNTIL([ovs-appctl -t ovsdb-server version])
491 AT_CHECK([test ! -e socket1])
492 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
495 AT_SETUP([SSL db: implementation])
496 AT_KEYWORDS([ovsdb server positive ssl $5])
497 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
498 # For this test, we pass PKIDIR through a ovsdb-tool transact and
499 # msys on Windows does not convert the path style automatically.
500 # So, do that forcefully with a 'pwd -W' (called through pwd() function).
501 PKIDIR="$(cd $abs_top_builddir/tests && pwd)"
502 AT_SKIP_IF([expr "$PKIDIR" : ".*[ '\"
509 "private_key": {"type": "string"},
510 "certificate": {"type": "string"},
511 "ca_cert": {"type": "string"}}}}}
513 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
515 [[ovsdb-tool transact db \
519 "row": {"private_key": "'"$PKIDIR/testpki-privkey2.pem"'",
520 "certificate": "'"$PKIDIR/testpki-cert2.pem"'",
521 "ca_cert": "'"$PKIDIR/testpki-cacert.pem"'"}}]']],
522 [0], [ignore], [ignore])
524 [ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid \
525 --private-key=db:mydb,SSL,private_key \
526 --certificate=db:mydb,SSL,certificate \
527 --ca-cert=db:mydb,SSL,ca_cert \
528 --remote=pssl:0:127.0.0.1 --unixctl="`pwd`"/unixctl db],
529 [0], [ignore], [ignore])
530 PARSE_LISTENING_PORT([ovsdb-server.log], [SSL_PORT])
533 --private-key=$PKIDIR/testpki-privkey.pem \
534 --certificate=$PKIDIR/testpki-cert.pem \
535 --ca-cert=$PKIDIR/testpki-cacert.pem \
536 transact ssl:127.0.0.1:$SSL_PORT \
541 "columns": ["private_key"]}]']],
542 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
546 [[@<:@{"rows":@<:@{"private_key":"$PKIDIR/testpki-privkey2.pem"}@:>@}@:>@
547 ]], [ignore], [test ! -e pid || kill `cat pid`])
548 OVSDB_SERVER_SHUTDOWN
551 AT_SETUP([compacting online])
552 AT_KEYWORDS([ovsdb server compact])
553 ordinal_schema > schema
554 dnl Make sure that "ovsdb-tool create" works with a dangling symlink for
555 dnl the database and the lockfile, creating the target of each symlink rather
556 dnl than replacing the symlinks with regular files.
559 ln -s dir/.db.~lock~ .db.~lock~
560 AT_SKIP_IF([test ! -h db || test ! -h .db.~lock~])
561 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
562 dnl Start ovsdb-server.
563 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])
564 AT_CAPTURE_FILE([ovsdb-server.log])
565 dnl Do a bunch of random transactions that put crap in the database log.
567 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
569 ovsdb-client transact unix:socket '
573 "row": {"name": "'$1'", "number": '$2'}},
575 "comment": "add row for '"$pair"'"}]'
576 ovsdb-client transact unix:socket '
580 "where": [["number", "==", '$2']]},
582 "comment": "delete row for '"$2"'"}]'
583 ovsdb-client transact unix:socket '
587 "row": {"name": "'$1'", "number": '$2'}},
589 "comment": "add back row for '"$pair"'"}]'
591 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
592 dnl Check that all the crap is in fact in the database log.
593 AT_CHECK([[${PERL} $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | ovstest test-json --multiple -]], [0],
594 [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"}
595 {"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
596 {"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
597 {"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
598 {"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
599 {"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
600 {"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
601 {"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
602 {"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
603 {"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
604 {"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
605 {"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
606 {"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
607 {"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
608 {"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
609 {"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
610 {"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
611 {"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
612 {"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
613 ]], [], [test ! -e pid || kill `cat pid`])
614 dnl Dump out and check the actual database contents.
615 AT_CHECK([[ovsdb-client dump unix:socket ordinals]],
616 [0], [stdout], [ignore])
617 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
620 ------------------------------------ ----- ------
627 ], [], [test ! -e pid || kill `cat pid`])
628 dnl Now compact the database in-place.
629 AT_CHECK([[ovs-appctl -t "`pwd`"/unixctl ovsdb-server/compact]],
630 [0], [], [ignore], [test ! -e pid || kill `cat pid`])
631 dnl Make sure that "db" is still a symlink to dir/db instead of getting
632 dnl replaced by a regular file, ditto for .db.~lock~.
633 AT_CHECK([test -h db])
634 AT_CHECK([test -h .db.~lock~])
635 AT_CHECK([test -f dir/db])
636 AT_CHECK([test -f dir/.db.~lock~])
637 dnl We can't fully re-check the contents of the database log, because the
638 dnl order of the records is not predictable, but there should only be 4 lines
640 AT_CAPTURE_FILE([db])
641 AT_CHECK([test `wc -l < db` -eq 4], [0], [], [],
642 [test ! -e pid || kill `cat pid`])
643 dnl And check that the dumped data is the same too:
644 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
645 [test ! -e pid || kill `cat pid`])
646 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
649 ------------------------------------ ----- ------
656 ], [], [test ! -e pid || kill `cat pid`])
657 dnl Now do some more transactions.
659 [[ovsdb-client transact unix:socket '
663 "where": [["number", "<", 3]]}]']],
665 ]], [ignore], [test ! -e pid || kill `cat pid`])
666 dnl There should be 6 lines in the log now.
667 AT_CHECK([test `wc -l < db` -eq 6], [0], [], [],
668 [test ! -e pid || kill `cat pid`])
669 dnl Then check that the dumped data is correct.
670 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
671 [test ! -e pid || kill `cat pid`])
672 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
675 ------------------------------------ ----- ------
679 ], [], [test ! -e pid || kill `cat pid`])
680 OVSDB_SERVER_SHUTDOWN
683 AT_SETUP([ovsdb-server combines updates on backlogged connections])
684 on_exit 'kill `cat *.pid`'
686 # The maximum socket receive buffer size is important for this test, which
687 # tests behavior when the receive buffer overflows.
688 if test -e /proc/sys/net/core/rmem_max; then
690 rmem_max=`cat /proc/sys/net/core/rmem_max`
691 elif rmem_max=`sysctl -n net.inet.tcp.recvbuf_max 2>/dev/null`; then
694 # Don't know how to get maximum socket receive buffer on this OS
698 # Calculate the number of iterations we need to queue. Each of the
699 # iterations we execute, by itself, yields a monitor update of about
700 # 25 kB, so fill up that much space plus a few for luck.
701 n_iterations=`expr $rmem_max / 25000 + 5`
702 echo rmem_max=$rmem_max n_iterations=$n_iterations
704 # If there's too much queuing skip the test to avoid timing out.
705 AT_SKIP_IF([test $rmem_max -gt 1048576])
707 # Calculate the exact number of monitor updates expected for $n_iterations,
708 # assuming no updates are combined. The "extra" update is for the initial
709 # contents of the database.
710 n_updates=`expr $n_iterations \* 3 + 1`
712 # Start an ovsdb-server with the vswitchd schema.
714 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --log-file --remote=punix:db.sock db],
715 [0], [ignore], [ignore])
717 # Executes a set of transactions that add a bridge with 100 ports, and
718 # then deletes that bridge. This yields three monitor updates that
719 # add up to about 25 kB in size.
721 # The update also increments a counter held in the database so that we can
722 # verify that the overall effect of the transactions took effect (e.g.
723 # monitor updates at the end weren't just dropped). We add an arbitrary
724 # string to the counter to make grepping for it more reliable.
726 trigger_big_update () {
727 counter=`expr $counter + 1`
728 ovs-vsctl --no-wait -- set open_vswitch . system_version=xyzzy$counter
729 ovs-vsctl --no-wait -- add-br br0 $add
730 ovs-vsctl --no-wait -- del-br br0
733 for j in `seq 1 100`; do
734 printf " -- add-port br0 p%d" $j
739 AT_CAPTURE_FILE([ovsdb-client.err])
740 AT_CAPTURE_FILE([ovsdb-client-nonblock.err])
743 # Start an ovsdb-client monitoring all changes to the database,
744 # By default, it is non-blocking, and will get update message
745 # for each ovsdb-server transaactions.
746 AT_CHECK([ovsdb-client --detach --no-chdir --pidfile=nonblock.pid monitor ALL >ovsdb-client-nonblock.out 2>ovsdb-client-nonblock.err])
748 # Start an ovsdb-client monitoring all changes to the database,
749 # make it block to force the buffers to fill up, and then execute
750 # enough iterations that ovsdb-server starts combining updates.
751 AT_CHECK([ovsdb-client --detach --no-chdir --pidfile monitor ALL >ovsdb-client.out 2>ovsdb-client.err])
752 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/block])
753 for i in `seq 1 $n_iterations`; do
754 echo "blocked update ($i of $n_iterations)"
755 trigger_big_update $i
757 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/unblock])
758 OVS_WAIT_UNTIL([grep "\"xyzzy$counter\"" ovsdb-client.out])
759 OVS_WAIT_UNTIL([grep "\"xyzzy$counter\"" ovsdb-client-nonblock.out])
760 OVS_APP_EXIT_AND_WAIT([ovsdb-client])
761 AT_CHECK([kill `cat nonblock.pid`])
763 # Count the number of updates in the ovsdb-client output, by counting
764 # the number of changes to the Open_vSwitch table. (All of our
765 # transactions modify the Open_vSwitch table.) It should be less than
766 # $n_updates updates.
768 # Check that the counter is what we expect.
769 logged_updates=`grep -c '^Open_vSwitch' ovsdb-client.out`
770 logged_nonblock_updates=`grep -c '^Open_vSwitch' ovsdb-client-nonblock.out`
771 echo "logged_nonblock_updates=$logged_nonblock_updates (expected less or equal to $n_updates)"
772 echo "logged_updates=$logged_updates (expected less than $logged_nonblock_updates)"
773 AT_CHECK([test $logged_nonblock_updates -le $n_updates])
774 AT_CHECK([test $logged_updates -lt $logged_nonblock_updates])
775 AT_CHECK_UNQUOTED([ovs-vsctl get open_vswitch . system_version], [0],
778 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
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])
802 PKIDIR=$abs_top_builddir/tests
803 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
804 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])
805 PARSE_LISTENING_PORT([ovsdb-server.log], [SSL_PORT])
806 m4_foreach([txn], [$3],
807 [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],
808 [test ! -e pid || kill `cat pid`])
811 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
812 [test ! -e pid || kill `cat pid`])
813 OVSDB_SERVER_SHUTDOWN
818 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv6 sockets)])
820 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
822 # Creates a database with the given SCHEMA, starts an ovsdb-server on
823 # that database, and runs each of the TRANSACTIONS (which should be a
824 # quoted list of quoted strings) against it with ovsdb-client one at a
827 # Checks that the overall output is OUTPUT, but UUIDs in the output
828 # are replaced by markers of the form <N> where N is a number. The
829 # first unique UUID is replaced by <0>, the next by <1>, and so on.
830 # If a given UUID appears more than once it is always replaced by the
833 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
834 m4_define([OVSDB_CHECK_EXECUTION],
836 AT_KEYWORDS([ovsdb server positive ssl6 $5])
837 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
838 AT_SKIP_IF([test $HAVE_IPV6 = no])
840 PKIDIR=$abs_top_builddir/tests
841 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
842 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])
843 PARSE_LISTENING_PORT([ovsdb-server.log], [SSL_PORT])
844 m4_foreach([txn], [$3],
845 [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],
846 [test ! -e pid || kill `cat pid`])
849 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
850 [test ! -e pid || kill `cat pid`])
851 OVSDB_SERVER_SHUTDOWN
854 ONE_EXECUTION_EXAMPLE
856 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv4 sockets)])
858 AT_SETUP([ovsdb-client get-schema-version - tcp socket])
859 AT_KEYWORDS([ovsdb server positive tcp])
860 ordinal_schema > schema
861 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
862 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])
863 PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
864 AT_CHECK([ovsdb-client get-schema-version tcp:127.0.0.1:$TCP_PORT ordinals], [0], [5.1.3
866 OVSDB_SERVER_SHUTDOWN
869 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
871 # Creates a database with the given SCHEMA, starts an ovsdb-server on
872 # that database, and runs each of the TRANSACTIONS (which should be a
873 # quoted list of quoted strings) against it with ovsdb-client one at a
876 # Checks that the overall output is OUTPUT, but UUIDs in the output
877 # are replaced by markers of the form <N> where N is a number. The
878 # first unique UUID is replaced by <0>, the next by <1>, and so on.
879 # If a given UUID appears more than once it is always replaced by the
882 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
883 m4_define([OVSDB_CHECK_EXECUTION],
885 AT_KEYWORDS([ovsdb server positive tcp $5])
887 PKIDIR=$abs_top_builddir/tests
888 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
889 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])
890 PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
891 m4_foreach([txn], [$3],
892 [AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT 'txn'], [0], [stdout], [ignore],
893 [test ! -e pid || kill `cat pid`])
896 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
897 [test ! -e pid || kill `cat pid`])
898 OVSDB_SERVER_SHUTDOWN
903 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv6 sockets)])
905 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
907 # Creates a database with the given SCHEMA, starts an ovsdb-server on
908 # that database, and runs each of the TRANSACTIONS (which should be a
909 # quoted list of quoted strings) against it with ovsdb-client one at a
912 # Checks that the overall output is OUTPUT, but UUIDs in the output
913 # are replaced by markers of the form <N> where N is a number. The
914 # first unique UUID is replaced by <0>, the next by <1>, and so on.
915 # If a given UUID appears more than once it is always replaced by the
918 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
919 m4_define([OVSDB_CHECK_EXECUTION],
921 AT_KEYWORDS([ovsdb server positive tcp6 $5])
922 AT_SKIP_IF([test $HAVE_IPV6 = no])
924 PKIDIR=$abs_top_builddir/tests
925 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
926 AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid --remote=ptcp:0:[[::1]] --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
927 PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
928 m4_foreach([txn], [$3],
929 [AT_CHECK([ovsdb-client transact tcp:[[::1]]:$TCP_PORT 'txn'], [0], [stdout], [ignore],
930 [test ! -e pid || kill `cat pid`])
933 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
934 [test ! -e pid || kill `cat pid`])
935 OVSDB_SERVER_SHUTDOWN
938 ONE_EXECUTION_EXAMPLE
940 AT_BANNER([OVSDB -- transactions on transient ovsdb-server])
942 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
944 # Creates a database with the given SCHEMA and runs each of the
945 # TRANSACTIONS (which should be a quoted list of quoted strings)
946 # against it with ovsdb-client one at a time. Each ovsdb-client
947 # is run against a separately started ovsdb-server that executes
948 # only that single transaction. (The idea is that this should
949 # help to ferret out any differences between what ovsdb-server has
950 # in memory and what actually gets committed to disk.)
952 # Checks that the overall output is OUTPUT, but UUIDs in the output
953 # are replaced by markers of the form <N> where N is a number. The
954 # first unique UUID is replaced by <0>, the next by <1>, and so on.
955 # If a given UUID appears more than once it is always replaced by the
958 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
959 m4_define([OVSDB_CHECK_EXECUTION],
961 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
962 AT_KEYWORDS([ovsdb server positive transient $5])
964 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
965 m4_foreach([txn], [$3],
966 [AT_DATA([txnfile], [ovsdb-client transact unix:socket 'txn'
968 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [ignore])
971 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore])