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 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
277 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
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 ordinal_schema > schema
285 AT_CHECK([ovsdb-tool create db1 schema], [0], [ignore], [ignore])
286 constraint_schema > schema2
287 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
288 on_exit 'kill `cat *.pid`'
289 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db1 db2])
291 # Remove the second database.
292 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db constraints])
293 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
297 # Kill the daemon process, making it look like a segfault,
298 # and wait for a new daemon process to get spawned.
299 cp ovsdb-server.pid old.pid
300 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
301 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
303 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
304 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
307 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
310 AT_SETUP([--remote=db: implementation])
311 AT_KEYWORDS([ovsdb server positive])
321 "max": "unlimited"}},
324 "key": {"type": "uuid", "refTable": "Manager"},
326 "max": "unlimited"}}}},
337 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
339 [[ovsdb-tool transact db \
344 "managers": "punix:socket1",
345 "manager_options": ["set", [["named-uuid", "x"]]]}},
349 "row": {"target": "punix:socket2"}}]']], [0], [ignore], [ignore])
350 on_exit 'kill `cat ovsdb-server.pid`'
351 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])
352 ovs-appctl -t ovsdb-server time/warp 6000 1000
354 [[ovsdb-client transact unix:socket1 \
359 "columns": ["managers"]},
363 "columns": ["target", "is_connected"]}]']],
364 [0], [stdout], [ignore])
366 [${PERL} $srcdir/uuidfilt.pl stdout],
368 [[[{"rows":[{"managers":"punix:socket1"}]},{"rows":[{"is_connected":false,"target":"punix:socket2"}]}]
371 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
374 AT_SETUP([ovsdb-server/add-remote and remove-remote])
375 AT_KEYWORDS([ovsdb server positive])
376 ordinal_schema > schema
377 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
378 on_exit 'kill `cat *.pid`'
379 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile db])
381 AT_CHECK([test ! -e socket1])
382 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
383 if test "$IS_WIN32" = "yes"; then
384 OVS_WAIT_UNTIL([test -s socket1])
386 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 if test "$IS_WIN32" = "yes"; then
395 OVS_WAIT_UNTIL([test -s socket2])
397 OVS_WAIT_UNTIL([test -S socket2])
399 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
404 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote db:x,y,z], [2],
405 [], ["db:x,y,z": no database named x
406 ovs-appctl: ovsdb-server: server returned an error
409 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
410 OVS_WAIT_UNTIL([test ! -e socket1])
411 if test "$IS_WIN32" = "yes"; then
412 AT_CHECK([test -s socket2])
414 AT_CHECK([test -S socket2])
416 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
420 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket2])
421 OVS_WAIT_UNTIL([test ! -e socket2])
422 AT_CHECK([test ! -e socket1])
423 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
424 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
427 AT_SETUP([ovsdb-server/add-remote with --monitor])
428 AT_KEYWORDS([ovsdb server positive])
429 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
430 # Start ovsdb-server, initially with no remotes.
431 ordinal_schema > schema
432 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
433 on_exit 'kill `cat *.pid`'
434 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db])
437 AT_CHECK([test ! -e socket1])
438 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
439 OVS_WAIT_UNTIL([test -S socket1])
440 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
444 # Kill the daemon process, making it look like a segfault,
445 # and wait for a new daemon process to get spawned and for it to
446 # start listening on 'socket1'.
447 cp ovsdb-server.pid old.pid
449 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
450 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
452 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
453 OVS_WAIT_UNTIL([test -S socket1])
454 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
457 AT_SETUP([ovsdb-server/add-remote and remove-remote with --monitor])
458 AT_KEYWORDS([ovsdb server positive])
459 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
460 # Start ovsdb-server, initially with no remotes.
461 ordinal_schema > schema
462 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
463 on_exit 'kill `cat *.pid`'
464 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db])
467 AT_CHECK([test ! -e socket1])
468 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
469 OVS_WAIT_UNTIL([test -S socket1])
470 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
475 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
476 OVS_WAIT_UNTIL([test ! -e socket1])
477 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
479 # Kill the daemon process, making it look like a segfault,
480 # and wait for a new daemon process to get spawned and make sure that it
481 # does not listen on 'socket1'.
482 cp ovsdb-server.pid old.pid
483 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
484 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
486 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
487 AT_CHECK([test ! -e socket1])
488 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
491 AT_SETUP([SSL db: implementation])
492 AT_KEYWORDS([ovsdb server positive ssl $5])
493 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
494 # For this test, we pass PKIDIR through a ovsdb-tool transact and
495 # msys on Windows does not convert the path style automatically.
496 # So, do that forcefully with a 'pwd -W' (called through pwd() function).
497 PKIDIR="$(cd $abs_top_builddir/tests && pwd)"
498 AT_SKIP_IF([expr "$PKIDIR" : ".*[ '\"
505 "private_key": {"type": "string"},
506 "certificate": {"type": "string"},
507 "ca_cert": {"type": "string"}}}}}
509 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
511 [[ovsdb-tool transact db \
515 "row": {"private_key": "'"$PKIDIR/testpki-privkey2.pem"'",
516 "certificate": "'"$PKIDIR/testpki-cert2.pem"'",
517 "ca_cert": "'"$PKIDIR/testpki-cacert.pem"'"}}]']],
518 [0], [ignore], [ignore])
520 [ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid \
521 --private-key=db:mydb,SSL,private_key \
522 --certificate=db:mydb,SSL,certificate \
523 --ca-cert=db:mydb,SSL,ca_cert \
524 --remote=pssl:0:127.0.0.1 --unixctl="`pwd`"/unixctl db],
525 [0], [ignore], [ignore])
526 PARSE_LISTENING_PORT([ovsdb-server.log], [SSL_PORT])
529 --private-key=$PKIDIR/testpki-privkey.pem \
530 --certificate=$PKIDIR/testpki-cert.pem \
531 --ca-cert=$PKIDIR/testpki-cacert.pem \
532 transact ssl:127.0.0.1:$SSL_PORT \
537 "columns": ["private_key"]}]']],
538 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
542 [[@<:@{"rows":@<:@{"private_key":"$PKIDIR/testpki-privkey2.pem"}@:>@}@:>@
543 ]], [ignore], [test ! -e pid || kill `cat pid`])
544 OVSDB_SERVER_SHUTDOWN
547 AT_SETUP([compacting online])
548 AT_KEYWORDS([ovsdb server compact])
549 ordinal_schema > schema
550 dnl Make sure that "ovsdb-tool create" works with a dangling symlink for
551 dnl the database and the lockfile, creating the target of each symlink rather
552 dnl than replacing the symlinks with regular files.
555 ln -s dir/.db.~lock~ .db.~lock~
556 AT_SKIP_IF([test ! -h db || test ! -h .db.~lock~])
557 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
558 dnl Start ovsdb-server.
559 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])
560 AT_CAPTURE_FILE([ovsdb-server.log])
561 dnl Do a bunch of random transactions that put crap in the database log.
563 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
565 ovsdb-client transact unix:socket '
569 "row": {"name": "'$1'", "number": '$2'}},
571 "comment": "add row for '"$pair"'"}]'
572 ovsdb-client transact unix:socket '
576 "where": [["number", "==", '$2']]},
578 "comment": "delete row for '"$2"'"}]'
579 ovsdb-client transact unix:socket '
583 "row": {"name": "'$1'", "number": '$2'}},
585 "comment": "add back row for '"$pair"'"}]'
587 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
588 dnl Check that all the crap is in fact in the database log.
589 AT_CHECK([[${PERL} $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | ovstest test-json --multiple -]], [0],
590 [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"}
591 {"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
592 {"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
593 {"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
594 {"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
595 {"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
596 {"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
597 {"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
598 {"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
599 {"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
600 {"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
601 {"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
602 {"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
603 {"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
604 {"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
605 {"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
606 {"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
607 {"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
608 {"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
609 ]], [], [test ! -e pid || kill `cat pid`])
610 dnl Dump out and check the actual database contents.
611 AT_CHECK([[ovsdb-client dump unix:socket ordinals]],
612 [0], [stdout], [ignore])
613 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
616 ------------------------------------ ----- ------
623 ], [], [test ! -e pid || kill `cat pid`])
624 dnl Now compact the database in-place.
625 AT_CHECK([[ovs-appctl -t "`pwd`"/unixctl ovsdb-server/compact]],
626 [0], [], [ignore], [test ! -e pid || kill `cat pid`])
627 dnl Make sure that "db" is still a symlink to dir/db instead of getting
628 dnl replaced by a regular file, ditto for .db.~lock~.
629 AT_CHECK([test -h db])
630 AT_CHECK([test -h .db.~lock~])
631 AT_CHECK([test -f dir/db])
632 AT_CHECK([test -f dir/.db.~lock~])
633 dnl We can't fully re-check the contents of the database log, because the
634 dnl order of the records is not predictable, but there should only be 4 lines
636 AT_CAPTURE_FILE([db])
637 AT_CHECK([test `wc -l < db` -eq 4], [0], [], [],
638 [test ! -e pid || kill `cat pid`])
639 dnl And check that the dumped data is the same too:
640 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
641 [test ! -e pid || kill `cat pid`])
642 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
645 ------------------------------------ ----- ------
652 ], [], [test ! -e pid || kill `cat pid`])
653 dnl Now do some more transactions.
655 [[ovsdb-client transact unix:socket '
659 "where": [["number", "<", 3]]}]']],
661 ]], [ignore], [test ! -e pid || kill `cat pid`])
662 dnl There should be 6 lines in the log now.
663 AT_CHECK([test `wc -l < db` -eq 6], [0], [], [],
664 [test ! -e pid || kill `cat pid`])
665 dnl Then check that the dumped data is correct.
666 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
667 [test ! -e pid || kill `cat pid`])
668 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
671 ------------------------------------ ----- ------
675 ], [], [test ! -e pid || kill `cat pid`])
676 OVSDB_SERVER_SHUTDOWN
679 AT_SETUP([ovsdb-server combines updates on backlogged connections])
680 on_exit 'kill `cat *.pid`'
682 # The maximum socket receive buffer size is important for this test, which
683 # tests behavior when the receive buffer overflows.
684 if test -e /proc/sys/net/core/rmem_max; then
686 rmem_max=`cat /proc/sys/net/core/rmem_max`
687 elif rmem_max=`sysctl -n net.inet.tcp.recvbuf_max 2>/dev/null`; then
690 # Don't know how to get maximum socket receive buffer on this OS
694 # Calculate the number of iterations we need to queue. Each of the
695 # iterations we execute, by itself, yields a monitor update of about
696 # 25 kB, so fill up that much space plus a few for luck.
697 n_iterations=`expr $rmem_max / 25000 + 5`
698 echo rmem_max=$rmem_max n_iterations=$n_iterations
700 # If there's too much queuing skip the test to avoid timing out.
701 AT_SKIP_IF([test $rmem_max -gt 1048576])
703 # Calculate the exact number of monitor updates expected for $n_iterations,
704 # assuming no updates are combined. The "extra" update is for the initial
705 # contents of the database.
706 n_updates=`expr $n_iterations \* 3 + 1`
708 # Start an ovsdb-server with the vswitchd schema.
710 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --log-file --remote=punix:db.sock db],
711 [0], [ignore], [ignore])
713 # Executes a set of transactions that add a bridge with 100 ports, and
714 # then deletes that bridge. This yields three monitor updates that
715 # add up to about 25 kB in size.
717 # The update also increments a counter held in the database so that we can
718 # verify that the overall effect of the transactions took effect (e.g.
719 # monitor updates at the end weren't just dropped). We add an arbitrary
720 # string to the counter to make grepping for it more reliable.
722 trigger_big_update () {
723 counter=`expr $counter + 1`
724 ovs-vsctl --no-wait -- set open_vswitch . system_version=xyzzy$counter
725 ovs-vsctl --no-wait -- add-br br0 $add
726 ovs-vsctl --no-wait -- del-br br0
729 for j in `seq 1 100`; do
730 printf " -- add-port br0 p%d" $j
735 AT_CAPTURE_FILE([ovsdb-client.err])
736 AT_CAPTURE_FILE([ovsdb-client-nonblock.err])
739 # Start an ovsdb-client monitoring all changes to the database,
740 # By default, it is non-blocking, and will get update message
741 # for each ovsdb-server transaactions.
742 AT_CHECK([ovsdb-client --detach --no-chdir --pidfile=nonblock.pid monitor ALL >ovsdb-client-nonblock.out 2>ovsdb-client-nonblock.err])
744 # Start an ovsdb-client monitoring all changes to the database,
745 # make it block to force the buffers to fill up, and then execute
746 # enough iterations that ovsdb-server starts combining updates.
747 AT_CHECK([ovsdb-client --detach --no-chdir --pidfile monitor ALL >ovsdb-client.out 2>ovsdb-client.err])
748 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/block])
749 for i in `seq 1 $n_iterations`; do
750 echo "blocked update ($i of $n_iterations)"
751 trigger_big_update $i
753 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/unblock])
754 OVS_WAIT_UNTIL([grep "\"xyzzy$counter\"" ovsdb-client.out])
755 OVS_WAIT_UNTIL([grep "\"xyzzy$counter\"" ovsdb-client-nonblock.out])
756 OVS_APP_EXIT_AND_WAIT([ovsdb-client])
757 AT_CHECK([kill `cat nonblock.pid`])
759 # Count the number of updates in the ovsdb-client output, by counting
760 # the number of changes to the Open_vSwitch table. (All of our
761 # transactions modify the Open_vSwitch table.) It should be less than
762 # $n_updates updates.
764 # Check that the counter is what we expect.
765 logged_updates=`grep -c '^Open_vSwitch' ovsdb-client.out`
766 logged_nonblock_updates=`grep -c '^Open_vSwitch' ovsdb-client-nonblock.out`
767 echo "logged_nonblock_updates=$logged_nonblock_updates (expected less or equal to $n_updates)"
768 echo "logged_updates=$logged_updates (expected less than $logged_nonblock_updates)"
769 AT_CHECK([test $logged_nonblock_updates -le $n_updates])
770 AT_CHECK([test $logged_updates -lt $logged_nonblock_updates])
771 AT_CHECK_UNQUOTED([ovs-vsctl get open_vswitch . system_version], [0],
774 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
777 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv4 sockets)])
779 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
781 # Creates a database with the given SCHEMA, starts an ovsdb-server on
782 # that database, and runs each of the TRANSACTIONS (which should be a
783 # quoted list of quoted strings) against it with ovsdb-client one at a
786 # Checks that the overall output is OUTPUT, but UUIDs in the output
787 # are replaced by markers of the form <N> where N is a number. The
788 # first unique UUID is replaced by <0>, the next by <1>, and so on.
789 # If a given UUID appears more than once it is always replaced by the
792 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
793 m4_define([OVSDB_CHECK_EXECUTION],
795 AT_KEYWORDS([ovsdb server positive ssl $5])
796 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
798 PKIDIR=$abs_top_builddir/tests
799 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
800 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])
801 PARSE_LISTENING_PORT([ovsdb-server.log], [SSL_PORT])
802 m4_foreach([txn], [$3],
803 [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],
804 [test ! -e pid || kill `cat pid`])
807 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
808 [test ! -e pid || kill `cat pid`])
809 OVSDB_SERVER_SHUTDOWN
814 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv6 sockets)])
816 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
818 # Creates a database with the given SCHEMA, starts an ovsdb-server on
819 # that database, and runs each of the TRANSACTIONS (which should be a
820 # quoted list of quoted strings) against it with ovsdb-client one at a
823 # Checks that the overall output is OUTPUT, but UUIDs in the output
824 # are replaced by markers of the form <N> where N is a number. The
825 # first unique UUID is replaced by <0>, the next by <1>, and so on.
826 # If a given UUID appears more than once it is always replaced by the
829 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
830 m4_define([OVSDB_CHECK_EXECUTION],
832 AT_KEYWORDS([ovsdb server positive ssl6 $5])
833 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
834 AT_SKIP_IF([test $HAVE_IPV6 = no])
836 PKIDIR=$abs_top_builddir/tests
837 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
838 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])
839 PARSE_LISTENING_PORT([ovsdb-server.log], [SSL_PORT])
840 m4_foreach([txn], [$3],
841 [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],
842 [test ! -e pid || kill `cat pid`])
845 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
846 [test ! -e pid || kill `cat pid`])
847 OVSDB_SERVER_SHUTDOWN
850 ONE_EXECUTION_EXAMPLE
852 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv4 sockets)])
854 AT_SETUP([ovsdb-client get-schema-version - tcp socket])
855 AT_KEYWORDS([ovsdb server positive tcp])
856 ordinal_schema > schema
857 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
858 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])
859 PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
860 AT_CHECK([ovsdb-client get-schema-version tcp:127.0.0.1:$TCP_PORT ordinals], [0], [5.1.3
862 OVSDB_SERVER_SHUTDOWN
865 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
867 # Creates a database with the given SCHEMA, starts an ovsdb-server on
868 # that database, and runs each of the TRANSACTIONS (which should be a
869 # quoted list of quoted strings) against it with ovsdb-client one at a
872 # Checks that the overall output is OUTPUT, but UUIDs in the output
873 # are replaced by markers of the form <N> where N is a number. The
874 # first unique UUID is replaced by <0>, the next by <1>, and so on.
875 # If a given UUID appears more than once it is always replaced by the
878 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
879 m4_define([OVSDB_CHECK_EXECUTION],
881 AT_KEYWORDS([ovsdb server positive tcp $5])
883 PKIDIR=$abs_top_builddir/tests
884 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
885 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])
886 PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
887 m4_foreach([txn], [$3],
888 [AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT 'txn'], [0], [stdout], [ignore],
889 [test ! -e pid || kill `cat pid`])
892 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
893 [test ! -e pid || kill `cat pid`])
894 OVSDB_SERVER_SHUTDOWN
899 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv6 sockets)])
901 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
903 # Creates a database with the given SCHEMA, starts an ovsdb-server on
904 # that database, and runs each of the TRANSACTIONS (which should be a
905 # quoted list of quoted strings) against it with ovsdb-client one at a
908 # Checks that the overall output is OUTPUT, but UUIDs in the output
909 # are replaced by markers of the form <N> where N is a number. The
910 # first unique UUID is replaced by <0>, the next by <1>, and so on.
911 # If a given UUID appears more than once it is always replaced by the
914 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
915 m4_define([OVSDB_CHECK_EXECUTION],
917 AT_KEYWORDS([ovsdb server positive tcp6 $5])
918 AT_SKIP_IF([test $HAVE_IPV6 = no])
920 PKIDIR=$abs_top_builddir/tests
921 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
922 AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid --remote=ptcp:0:[[::1]] --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
923 PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
924 m4_foreach([txn], [$3],
925 [AT_CHECK([ovsdb-client transact tcp:[[::1]]:$TCP_PORT 'txn'], [0], [stdout], [ignore],
926 [test ! -e pid || kill `cat pid`])
929 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
930 [test ! -e pid || kill `cat pid`])
931 OVSDB_SERVER_SHUTDOWN
934 ONE_EXECUTION_EXAMPLE
936 AT_BANNER([OVSDB -- transactions on transient ovsdb-server])
938 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
940 # Creates a database with the given SCHEMA and runs each of the
941 # TRANSACTIONS (which should be a quoted list of quoted strings)
942 # against it with ovsdb-client one at a time. Each ovsdb-client
943 # is run against a separately started ovsdb-server that executes
944 # only that single transaction. (The idea is that this should
945 # help to ferret out any differences between what ovsdb-server has
946 # in memory and what actually gets committed to disk.)
948 # Checks that the overall output is OUTPUT, but UUIDs in the output
949 # are replaced by markers of the form <N> where N is a number. The
950 # first unique UUID is replaced by <0>, the next by <1>, and so on.
951 # If a given UUID appears more than once it is always replaced by the
954 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
955 m4_define([OVSDB_CHECK_EXECUTION],
957 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
958 AT_KEYWORDS([ovsdb server positive transient $5])
960 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
961 m4_foreach([txn], [$3],
962 [AT_DATA([txnfile], [ovsdb-client transact unix:socket 'txn'
964 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [ignore])
967 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore])