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 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
46 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
47 ordinal_schema > schema
48 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
49 dnl Do one transaction and save the output.
50 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
54 "row": {"number": 0, "name": "zero"}}]'
56 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
58 dnl Add some crap to the database log and run another transaction, which should
59 dnl ignore the crap and truncate it out of the log.
61 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
65 "row": {"number": 1, "name": "one"}}]'
67 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [stderr])
68 AT_CHECK([grep 'syntax error: db: parse error.* in header line "xxx"' stderr],
71 dnl Run a final transaction to verify that both transactions succeeeded.
72 dnl The crap that we added should have been truncated by the previous run,
73 dnl so ovsdb-server shouldn't log a warning this time.
74 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
81 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
83 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0],
84 [[[{"uuid":["uuid","<0>"]}]
85 [{"uuid":["uuid","<1>"]}]
86 [{"rows":[{"_uuid":["uuid","<0>"],"_version":["uuid","<2>"],"name":"zero","number":0},{"_uuid":["uuid","<1>"],"_version":["uuid","<3>"],"name":"one","number":1}]}]
88 [test ! -e pid || kill `cat pid`])
91 AT_SETUP([truncating database log with bad transaction])
92 AT_KEYWORDS([ovsdb server positive unix])
93 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
94 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
95 ordinal_schema > schema
96 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
97 dnl Do one transaction and save the output.
98 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
102 "row": {"number": 0, "name": "zero"}}]'
104 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
106 dnl Add some crap to the database log and run another transaction, which should
107 dnl ignore the crap and truncate it out of the log.
108 echo 'OVSDB JSON 15 ffbcdae4b0386265f9ea3280dd7c8f0b72a20e56
109 {"invalid":{}}' >> db
110 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
114 "row": {"number": 1, "name": "one"}}]'
116 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [stderr])
117 AT_CHECK([grep 'syntax "{"invalid":{}}": unknown table: No table named invalid.' stderr],
120 dnl Run a final transaction to verify that both transactions succeeeded.
121 dnl The crap that we added should have been truncated by the previous run,
122 dnl so ovsdb-server shouldn't log a warning this time.
123 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
128 "sort": ["number"]}]'
130 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
132 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0],
133 [[[{"uuid":["uuid","<0>"]}]
134 [{"uuid":["uuid","<1>"]}]
135 [{"rows":[{"_uuid":["uuid","<0>"],"_version":["uuid","<2>"],"name":"zero","number":0},{"_uuid":["uuid","<1>"],"_version":["uuid","<3>"],"name":"one","number":1}]}]
137 [test ! -e pid || kill `cat pid`])
140 AT_SETUP([ovsdb-client get-schema-version])
141 AT_KEYWORDS([ovsdb server positive])
142 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
143 ordinal_schema > schema
144 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
145 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=punix:socket db], [0], [ignore], [ignore])
146 AT_CHECK([ovsdb-client get-schema-version unix:socket ordinals], [0], [5.1.3
148 OVSDB_SERVER_SHUTDOWN
151 AT_SETUP([database multiplexing implementation])
152 AT_KEYWORDS([ovsdb server positive])
153 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
154 ordinal_schema > schema1
155 constraint_schema > schema2
156 AT_CHECK([ovsdb-tool create db1 schema1], [0], [ignore], [ignore])
157 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
158 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=punix:socket db1 db2], [0], [ignore], [ignore])
160 [[ovsdb-client list-dbs unix:socket]],
163 ], [ignore], [test ! -e pid || kill `cat pid`])
165 [[ovstest test-jsonrpc request unix:socket get_schema [\"nonexistent\"]]], [0],
166 [[{"error":{"details":"get_schema request specifies unknown database nonexistent","error":"unknown database","syntax":"[\"nonexistent\"]"},"id":0,"result":null}
167 ]], [], [test ! -e pid || kill `cat pid`])
168 OVSDB_SERVER_SHUTDOWN
171 AT_SETUP([ovsdb-server/add-db and remove-db])
172 AT_KEYWORDS([ovsdb server positive])
173 ON_EXIT([kill `cat ovsdb-server.pid`])
174 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
175 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
176 ordinal_schema > schema1
177 constraint_schema > schema2
178 AT_CHECK([ovsdb-tool create db1 schema1], [0], [ignore], [ignore])
179 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
181 # Start ovsdb-server with just a single database - db1.
182 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db1], [0])
183 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
187 # Add the second database.
188 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
189 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
194 # The databases are responsive.
195 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [0], [ignore], [ignore])
196 AT_CHECK([ovsdb-client list-tables unix:socket ordinals], [0], [ignore], [ignore])
198 # Add an already added database.
199 if test $IS_WIN32 = "yes"; then
200 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], 2, [],
201 [I/O error: db2: failed to lock lockfile (Resource deadlock avoided)
202 ovs-appctl: ovsdb-server: server returned an error
205 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], 2, [],
207 ovs-appctl: ovsdb-server: server returned an error
211 # Add a non-existing database.
212 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db3], 2, [], [stderr])
213 AT_CHECK([sed 's/(.*)/(...)/' stderr], [0],
214 [I/O error: open: db3 failed (...)
215 ovs-appctl: ovsdb-server: server returned an error
218 # Add a remote through a db path in db1.
219 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote db:ordinals,ordinals,name], [0])
220 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
221 [0], [db:ordinals,ordinals,name
225 # Removing db1 has no effect on its remote.
226 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db ordinals], [0])
227 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
230 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
231 [0], [db:ordinals,ordinals,name
234 AT_CHECK([ovsdb-client list-tables unix:socket ordinals], [1], [ignore], [ignore])
237 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db constraints], [0])
238 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
240 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [1], [ignore], [ignore])
242 # Remove a non-existent database.
243 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db ordinals], [2],
244 [], [Failed to find the database.
245 ovs-appctl: ovsdb-server: server returned an error
248 # Add a removed database.
249 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
250 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
253 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [0], [ignore], [ignore])
256 AT_SETUP([ovsdb-server/add-db with --monitor])
257 AT_KEYWORDS([ovsdb server positive])
258 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
259 # Start ovsdb-server, initially with one db.
260 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
261 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
262 ordinal_schema > schema
263 AT_CHECK([ovsdb-tool create db1 schema], [0], [ignore], [ignore])
264 ON_EXIT([kill `cat *.pid`])
265 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db1])
267 # Add the second database.
268 constraint_schema > schema2
269 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
270 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
271 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
276 # Kill the daemon process, making it look like a segfault,
277 # and wait for a new daemon process to get spawned.
278 cp ovsdb-server.pid old.pid
279 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
280 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
282 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
283 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
289 AT_SETUP([ovsdb-server/add-db and remove-db with --monitor])
290 AT_KEYWORDS([ovsdb server positive])
291 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
292 # Start ovsdb-server, initially with one db.
293 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
294 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
295 ordinal_schema > schema
296 AT_CHECK([ovsdb-tool create db1 schema], [0], [ignore], [ignore])
297 constraint_schema > schema2
298 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
299 ON_EXIT([kill `cat *.pid`])
300 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db1 db2])
302 # Remove the second database.
303 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db constraints])
304 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
308 # Kill the daemon process, making it look like a segfault,
309 # and wait for a new daemon process to get spawned.
310 cp ovsdb-server.pid old.pid
311 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
312 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
314 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
315 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
320 AT_SETUP([--remote=db: implementation])
321 AT_KEYWORDS([ovsdb server positive])
322 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
323 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
333 "max": "unlimited"}},
336 "key": {"type": "uuid", "refTable": "Manager"},
338 "max": "unlimited"}}}},
349 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
351 [[ovsdb-tool transact db \
356 "managers": "punix:socket1",
357 "manager_options": ["set", [["named-uuid", "x"]]]}},
361 "row": {"target": "punix:socket2"}}]']], [0], [ignore], [ignore])
362 ON_EXIT([kill `cat ovsdb-server.pid`])
363 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])
364 ovs-appctl -t ovsdb-server time/warp 6000 1000
366 [[ovsdb-client transact unix:socket1 \
371 "columns": ["managers"]},
375 "columns": ["target", "is_connected"]}]']],
376 [0], [stdout], [ignore])
378 [${PERL} $srcdir/uuidfilt.pl stdout],
380 [[[{"rows":[{"managers":"punix:socket1"}]},{"rows":[{"is_connected":false,"target":"punix:socket2"}]}]
385 AT_SETUP([ovsdb-server/add-remote and remove-remote])
386 AT_KEYWORDS([ovsdb server positive])
387 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
388 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
389 ordinal_schema > schema
390 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
391 ON_EXIT([kill `cat *.pid`])
392 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile db])
394 AT_CHECK([test ! -e socket1])
395 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
396 if test "$IS_WIN32" = "yes"; then
397 OVS_WAIT_UNTIL([test -s socket1])
399 OVS_WAIT_UNTIL([test -S socket1])
401 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
405 AT_CHECK([test ! -e socket2])
406 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket2])
407 if test "$IS_WIN32" = "yes"; then
408 OVS_WAIT_UNTIL([test -s socket2])
410 OVS_WAIT_UNTIL([test -S socket2])
412 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
417 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote db:x,y,z], [2],
418 [], ["db:x,y,z": no database named x
419 ovs-appctl: ovsdb-server: server returned an error
422 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
423 OVS_WAIT_UNTIL([test ! -e socket1])
424 if test "$IS_WIN32" = "yes"; then
425 AT_CHECK([test -s socket2])
427 AT_CHECK([test -S socket2])
429 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
433 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket2])
434 OVS_WAIT_UNTIL([test ! -e socket2])
435 AT_CHECK([test ! -e socket1])
436 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
439 AT_SETUP([ovsdb-server/add-remote with --monitor])
440 AT_KEYWORDS([ovsdb server positive])
441 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
442 # Start ovsdb-server, initially with no remotes.
443 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
444 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
445 ordinal_schema > schema
446 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
447 ON_EXIT([kill `cat *.pid`])
448 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db])
451 AT_CHECK([test ! -e socket1])
452 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
453 OVS_WAIT_UNTIL([test -S socket1])
454 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
458 # Kill the daemon process, making it look like a segfault,
459 # and wait for a new daemon process to get spawned and for it to
460 # start listening on 'socket1'.
461 cp ovsdb-server.pid old.pid
463 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
464 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
466 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
467 OVS_WAIT_UNTIL([test -S socket1])
470 AT_SETUP([ovsdb-server/add-remote and remove-remote with --monitor])
471 AT_KEYWORDS([ovsdb server positive])
472 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
473 # Start ovsdb-server, initially with no remotes.
474 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
475 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
476 ordinal_schema > schema
477 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
478 ON_EXIT([kill `cat *.pid`])
479 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db])
482 AT_CHECK([test ! -e socket1])
483 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
484 OVS_WAIT_UNTIL([test -S socket1])
485 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
490 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
491 OVS_WAIT_UNTIL([test ! -e socket1])
492 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
494 # Kill the daemon process, making it look like a segfault,
495 # and wait for a new daemon process to get spawned and make sure that it
496 # does not listen on 'socket1'.
497 cp ovsdb-server.pid old.pid
498 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
499 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
501 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
502 AT_CHECK([test ! -e socket1])
505 AT_SETUP([SSL db: implementation])
506 AT_KEYWORDS([ovsdb server positive ssl $5])
507 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
508 # For this test, we pass PKIDIR through a ovsdb-tool transact and
509 # msys on Windows does not convert the path style automatically.
510 # So, do that forcefully with a 'pwd -W' (called through pwd() function).
511 PKIDIR="$(cd $abs_top_builddir/tests && pwd)"
512 AT_SKIP_IF([expr "$PKIDIR" : ".*[ '\"
519 "private_key": {"type": "string"},
520 "certificate": {"type": "string"},
521 "ca_cert": {"type": "string"}}}}}
523 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
525 [[ovsdb-tool transact db \
529 "row": {"private_key": "'"$PKIDIR/testpki-privkey2.pem"'",
530 "certificate": "'"$PKIDIR/testpki-cert2.pem"'",
531 "ca_cert": "'"$PKIDIR/testpki-cacert.pem"'"}}]']],
532 [0], [ignore], [ignore])
533 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
535 [ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid \
536 --private-key=db:mydb,SSL,private_key \
537 --certificate=db:mydb,SSL,certificate \
538 --ca-cert=db:mydb,SSL,ca_cert \
539 --remote=pssl:0:127.0.0.1 --unixctl="`pwd`"/unixctl db],
540 [0], [ignore], [ignore])
541 SSL_PORT=`parse_listening_port < ovsdb-server.log`
544 --private-key=$PKIDIR/testpki-privkey.pem \
545 --certificate=$PKIDIR/testpki-cert.pem \
546 --ca-cert=$PKIDIR/testpki-cacert.pem \
547 transact ssl:127.0.0.1:$SSL_PORT \
552 "columns": ["private_key"]}]']],
553 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
557 [[@<:@{"rows":@<:@{"private_key":"$PKIDIR/testpki-privkey2.pem"}@:>@}@:>@
558 ]], [ignore], [test ! -e pid || kill `cat pid`])
559 OVSDB_SERVER_SHUTDOWN
562 AT_SETUP([compacting online])
563 AT_KEYWORDS([ovsdb server compact])
564 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
565 ordinal_schema > schema
566 dnl Make sure that "ovsdb-tool create" works with a dangling symlink for
567 dnl the database and the lockfile, creating the target of each symlink rather
568 dnl than replacing the symlinks with regular files.
571 ln -s dir/.db.~lock~ .db.~lock~
572 AT_SKIP_IF([test ! -h db || test ! -h .db.~lock~])
573 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
574 dnl Start ovsdb-server.
575 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])
576 AT_CAPTURE_FILE([ovsdb-server.log])
577 dnl Do a bunch of random transactions that put crap in the database log.
579 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
581 ovsdb-client transact unix:socket '
585 "row": {"name": "'$1'", "number": '$2'}},
587 "comment": "add row for '"$pair"'"}]'
588 ovsdb-client transact unix:socket '
592 "where": [["number", "==", '$2']]},
594 "comment": "delete row for '"$2"'"}]'
595 ovsdb-client transact unix:socket '
599 "row": {"name": "'$1'", "number": '$2'}},
601 "comment": "add back row for '"$pair"'"}]'
603 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
604 dnl Check that all the crap is in fact in the database log.
605 AT_CHECK([[${PERL} $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | ovstest test-json --multiple -]], [0],
606 [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"}
607 {"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
608 {"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
609 {"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
610 {"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
611 {"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
612 {"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
613 {"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
614 {"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
615 {"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
616 {"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
617 {"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
618 {"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
619 {"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
620 {"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
621 {"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
622 {"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
623 {"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
624 {"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
625 ]], [], [test ! -e pid || kill `cat pid`])
626 dnl Dump out and check the actual database contents.
627 AT_CHECK([[ovsdb-client dump unix:socket ordinals]],
628 [0], [stdout], [ignore])
629 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
632 ------------------------------------ ----- ------
639 ], [], [test ! -e pid || kill `cat pid`])
640 dnl Now compact the database in-place.
641 AT_CHECK([[ovs-appctl -t "`pwd`"/unixctl ovsdb-server/compact]],
642 [0], [], [ignore], [test ! -e pid || kill `cat pid`])
643 dnl Make sure that "db" is still a symlink to dir/db instead of getting
644 dnl replaced by a regular file, ditto for .db.~lock~.
645 AT_CHECK([test -h db])
646 AT_CHECK([test -h .db.~lock~])
647 AT_CHECK([test -f dir/db])
648 AT_CHECK([test -f dir/.db.~lock~])
649 dnl We can't fully re-check the contents of the database log, because the
650 dnl order of the records is not predictable, but there should only be 4 lines
652 AT_CAPTURE_FILE([db])
653 AT_CHECK([test `wc -l < db` -eq 4], [0], [], [],
654 [test ! -e pid || kill `cat pid`])
655 dnl And check that the dumped data is the same too:
656 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
657 [test ! -e pid || kill `cat pid`])
658 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
661 ------------------------------------ ----- ------
668 ], [], [test ! -e pid || kill `cat pid`])
669 dnl Now do some more transactions.
671 [[ovsdb-client transact unix:socket '
675 "where": [["number", "<", 3]]}]']],
677 ]], [ignore], [test ! -e pid || kill `cat pid`])
678 dnl There should be 6 lines in the log now.
679 AT_CHECK([test `wc -l < db` -eq 6], [0], [], [],
680 [test ! -e pid || kill `cat pid`])
681 dnl Then check that the dumped data is correct.
682 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
683 [test ! -e pid || kill `cat pid`])
684 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
687 ------------------------------------ ----- ------
691 ], [], [test ! -e pid || kill `cat pid`])
692 OVSDB_SERVER_SHUTDOWN
695 AT_SETUP([ovsdb-server combines updates on backlogged connections])
696 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
697 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
698 ON_EXIT([kill `cat *.pid`])
700 # The maximum socket receive buffer size is important for this test, which
701 # tests behavior when the receive buffer overflows.
702 if test -e /proc/sys/net/core/rmem_max; then
704 rmem_max=`cat /proc/sys/net/core/rmem_max`
705 elif rmem_max=`sysctl -n net.inet.tcp.recvbuf_max 2>/dev/null`; then
708 # Don't know how to get maximum socket receive buffer on this OS
712 # Calculate the number of iterations we need to queue. Each of the
713 # iterations we execute, by itself, yields a monitor update of about
714 # 25 kB, so fill up that much space plus a few for luck.
715 n_iterations=`expr $rmem_max / 25000 + 5`
716 echo rmem_max=$rmem_max n_iterations=$n_iterations
718 # If there's too much queuing skip the test to avoid timing out.
719 AT_SKIP_IF([test $rmem_max -gt 1048576])
721 # Calculate the exact number of monitor updates expected for $n_iterations,
722 # assuming no updates are combined. The "extra" update is for the initial
723 # contents of the database.
724 n_updates=`expr $n_iterations \* 3 + 1`
726 # Start an ovsdb-server with the vswitchd schema.
728 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --log-file --remote=punix:db.sock db],
729 [0], [ignore], [ignore])
731 # Executes a set of transactions that add a bridge with 100 ports, and
732 # then deletes that bridge. This yields three monitor updates that
733 # add up to about 25 kB in size.
735 # The update also increments a counter held in the database so that we can
736 # verify that the overall effect of the transactions took effect (e.g.
737 # monitor updates at the end weren't just dropped). We add an arbitrary
738 # string to the counter to make grepping for it more reliable.
740 trigger_big_update () {
741 counter=`expr $counter + 1`
742 ovs-vsctl --no-wait -- set open_vswitch . system_version=xyzzy$counter
743 ovs-vsctl --no-wait -- add-br br0 $add
744 ovs-vsctl --no-wait -- del-br br0
747 for j in `seq 1 100`; do
748 printf " -- add-port br0 p%d" $j
753 AT_CAPTURE_FILE([ovsdb-client.err])
754 AT_CAPTURE_FILE([ovsdb-client-nonblock.err])
757 # Start an ovsdb-client monitoring all changes to the database,
758 # By default, it is non-blocking, and will get update message
759 # for each ovsdb-server transaactions.
760 AT_CHECK([ovsdb-client --detach --no-chdir --pidfile=nonblock.pid monitor ALL >ovsdb-client-nonblock.out 2>ovsdb-client-nonblock.err])
762 # Start an ovsdb-client monitoring all changes to the database,
763 # make it block to force the buffers to fill up, and then execute
764 # enough iterations that ovsdb-server starts combining updates.
765 AT_CHECK([ovsdb-client --detach --no-chdir --pidfile monitor ALL >ovsdb-client.out 2>ovsdb-client.err])
766 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/block])
767 for i in `seq 1 $n_iterations`; do
768 echo "blocked update ($i of $n_iterations)"
769 trigger_big_update $i
771 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/unblock])
772 OVS_WAIT_UNTIL([grep "\"xyzzy$counter\"" ovsdb-client.out])
773 OVS_WAIT_UNTIL([grep "\"xyzzy$counter\"" ovsdb-client-nonblock.out])
774 AT_CHECK([ovs-appctl -t ovsdb-client exit])
775 OVS_WAIT_WHILE([test -e ovsdb-client.pid])
776 AT_CHECK([kill `cat nonblock.pid`])
778 # Count the number of updates in the ovsdb-client output, by counting
779 # the number of changes to the Open_vSwitch table. (All of our
780 # transactions modify the Open_vSwitch table.) It should be less than
781 # $n_updates updates.
783 # Check that the counter is what we expect.
784 logged_updates=`grep -c '^Open_vSwitch' ovsdb-client.out`
785 logged_nonblock_updates=`grep -c '^Open_vSwitch' ovsdb-client-nonblock.out`
786 echo "logged_nonblock_updates=$logged_nonblock_updates (expected less or equal to $n_updates)"
787 echo "logged_updates=$logged_updates (expected less than $logged_nonblock_updates)"
788 AT_CHECK([test $logged_nonblock_updates -le $n_updates])
789 AT_CHECK([test $logged_updates -lt $logged_nonblock_updates])
790 AT_CHECK_UNQUOTED([ovs-vsctl get open_vswitch . system_version], [0],
795 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv4 sockets)])
797 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
799 # Creates a database with the given SCHEMA, starts an ovsdb-server on
800 # that database, and runs each of the TRANSACTIONS (which should be a
801 # quoted list of quoted strings) against it with ovsdb-client one at a
804 # Checks that the overall output is OUTPUT, but UUIDs in the output
805 # are replaced by markers of the form <N> where N is a number. The
806 # first unique UUID is replaced by <0>, the next by <1>, and so on.
807 # If a given UUID appears more than once it is always replaced by the
810 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
811 m4_define([OVSDB_CHECK_EXECUTION],
813 AT_KEYWORDS([ovsdb server positive ssl $5])
814 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
815 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
816 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
818 PKIDIR=$abs_top_builddir/tests
819 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
820 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])
821 SSL_PORT=`parse_listening_port < ovsdb-server.log`
822 m4_foreach([txn], [$3],
823 [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],
824 [test ! -e pid || kill `cat pid`])
827 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
828 [test ! -e pid || kill `cat pid`])
829 OVSDB_SERVER_SHUTDOWN
834 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv6 sockets)])
836 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
838 # Creates a database with the given SCHEMA, starts an ovsdb-server on
839 # that database, and runs each of the TRANSACTIONS (which should be a
840 # quoted list of quoted strings) against it with ovsdb-client one at a
843 # Checks that the overall output is OUTPUT, but UUIDs in the output
844 # are replaced by markers of the form <N> where N is a number. The
845 # first unique UUID is replaced by <0>, the next by <1>, and so on.
846 # If a given UUID appears more than once it is always replaced by the
849 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
850 m4_define([OVSDB_CHECK_EXECUTION],
852 AT_KEYWORDS([ovsdb server positive ssl6 $5])
853 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
854 AT_SKIP_IF([test $HAVE_IPV6 = no])
855 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
856 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
858 PKIDIR=$abs_top_builddir/tests
859 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
860 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])
861 SSL_PORT=`parse_listening_port < ovsdb-server.log`
862 m4_foreach([txn], [$3],
863 [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],
864 [test ! -e pid || kill `cat pid`])
867 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
868 [test ! -e pid || kill `cat pid`])
869 OVSDB_SERVER_SHUTDOWN
872 ONE_EXECUTION_EXAMPLE
874 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv4 sockets)])
876 AT_SETUP([ovsdb-client get-schema-version - tcp socket])
877 AT_KEYWORDS([ovsdb server positive tcp])
878 ordinal_schema > schema
879 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
880 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
881 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])
882 TCP_PORT=`parse_listening_port < ovsdb-server.log`
883 AT_CHECK([ovsdb-client get-schema-version tcp:127.0.0.1:$TCP_PORT ordinals], [0], [5.1.3
885 OVSDB_SERVER_SHUTDOWN
888 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
890 # Creates a database with the given SCHEMA, starts an ovsdb-server on
891 # that database, and runs each of the TRANSACTIONS (which should be a
892 # quoted list of quoted strings) against it with ovsdb-client one at a
895 # Checks that the overall output is OUTPUT, but UUIDs in the output
896 # are replaced by markers of the form <N> where N is a number. The
897 # first unique UUID is replaced by <0>, the next by <1>, and so on.
898 # If a given UUID appears more than once it is always replaced by the
901 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
902 m4_define([OVSDB_CHECK_EXECUTION],
904 AT_KEYWORDS([ovsdb server positive tcp $5])
905 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
906 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
908 PKIDIR=$abs_top_builddir/tests
909 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
910 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])
911 TCP_PORT=`parse_listening_port < ovsdb-server.log`
912 m4_foreach([txn], [$3],
913 [AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT 'txn'], [0], [stdout], [ignore],
914 [test ! -e pid || kill `cat pid`])
917 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
918 [test ! -e pid || kill `cat pid`])
919 OVSDB_SERVER_SHUTDOWN
924 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv6 sockets)])
926 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
928 # Creates a database with the given SCHEMA, starts an ovsdb-server on
929 # that database, and runs each of the TRANSACTIONS (which should be a
930 # quoted list of quoted strings) against it with ovsdb-client one at a
933 # Checks that the overall output is OUTPUT, but UUIDs in the output
934 # are replaced by markers of the form <N> where N is a number. The
935 # first unique UUID is replaced by <0>, the next by <1>, and so on.
936 # If a given UUID appears more than once it is always replaced by the
939 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
940 m4_define([OVSDB_CHECK_EXECUTION],
942 AT_KEYWORDS([ovsdb server positive tcp6 $5])
943 AT_SKIP_IF([test $HAVE_IPV6 = no])
944 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
945 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
947 PKIDIR=$abs_top_builddir/tests
948 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
949 AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid --remote=ptcp:0:[[::1]] --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
950 TCP_PORT=`parse_listening_port < ovsdb-server.log`
951 m4_foreach([txn], [$3],
952 [AT_CHECK([ovsdb-client transact tcp:[[::1]]:$TCP_PORT 'txn'], [0], [stdout], [ignore],
953 [test ! -e pid || kill `cat pid`])
956 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
957 [test ! -e pid || kill `cat pid`])
958 OVSDB_SERVER_SHUTDOWN
961 ONE_EXECUTION_EXAMPLE
963 AT_BANNER([OVSDB -- transactions on transient ovsdb-server])
965 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
967 # Creates a database with the given SCHEMA and runs each of the
968 # TRANSACTIONS (which should be a quoted list of quoted strings)
969 # against it with ovsdb-client one at a time. Each ovsdb-client
970 # is run against a separately started ovsdb-server that executes
971 # only that single transaction. (The idea is that this should
972 # help to ferret out any differences between what ovsdb-server has
973 # in memory and what actually gets committed to disk.)
975 # Checks that the overall output is OUTPUT, but UUIDs in the output
976 # are replaced by markers of the form <N> where N is a number. The
977 # first unique UUID is replaced by <0>, the next by <1>, and so on.
978 # If a given UUID appears more than once it is always replaced by the
981 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
982 m4_define([OVSDB_CHECK_EXECUTION],
984 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
985 AT_KEYWORDS([ovsdb server positive transient $5])
986 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
988 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
989 m4_foreach([txn], [$3],
990 [AT_DATA([txnfile], [ovsdb-client transact unix:socket 'txn'
992 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [ignore])
995 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore])