1 AT_BANNER([OVSDB -- ovsdb-server transactions (Unix sockets)])
3 m4_define([OVSDB_SERVER_SHUTDOWN],
5 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl -e exit], [0], [ignore], [ignore])
6 OVS_WAIT_WHILE([kill -0 `cat savepid`], [kill `cat savepid`])])
8 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
10 # Creates a database with the given SCHEMA, starts an ovsdb-server on
11 # that database, and runs each of the TRANSACTIONS (which should be a
12 # quoted list of quoted strings) against it with ovsdb-client one at a
15 # Checks that the overall output is OUTPUT, but UUIDs in the output
16 # are replaced by markers of the form <N> where N is a number. The
17 # first unique UUID is replaced by <0>, the next by <1>, and so on.
18 # If a given UUID appears more than once it is always replaced by the
21 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
22 m4_define([OVSDB_CHECK_EXECUTION],
24 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
25 AT_KEYWORDS([ovsdb server positive unix $5])
27 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
28 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
29 m4_foreach([txn], [$3],
30 [AT_CHECK([ovsdb-client transact unix:socket 'txn'], [0], [stdout], [ignore],
31 [test ! -e pid || kill `cat pid`])
34 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
35 [test ! -e pid || kill `cat pid`])
41 AT_BANNER([ovsdb-server miscellaneous features])
43 AT_SETUP([truncating corrupted database log])
44 AT_KEYWORDS([ovsdb server positive unix])
45 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
46 ordinal_schema > schema
47 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
48 dnl Do one transaction and save the output.
49 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
53 "row": {"number": 0, "name": "zero"}}]'
55 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
57 dnl Add some crap to the database log and run another transaction, which should
58 dnl ignore the crap and truncate it out of the log.
60 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
64 "row": {"number": 1, "name": "one"}}]'
66 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [stderr])
67 AT_CHECK([grep 'syntax error: db: parse error.* in header line "xxx"' stderr],
70 dnl Run a final transaction to verify that both transactions succeeeded.
71 dnl The crap that we added should have been truncated by the previous run,
72 dnl so ovsdb-server shouldn't log a warning this time.
73 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
80 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
82 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0],
83 [[[{"uuid":["uuid","<0>"]}]
84 [{"uuid":["uuid","<1>"]}]
85 [{"rows":[{"_uuid":["uuid","<0>"],"_version":["uuid","<2>"],"name":"zero","number":0},{"_uuid":["uuid","<1>"],"_version":["uuid","<3>"],"name":"one","number":1}]}]
87 [test ! -e pid || kill `cat pid`])
90 AT_SETUP([truncating database log with bad transaction])
91 AT_KEYWORDS([ovsdb server positive unix])
92 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
93 ordinal_schema > schema
94 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
95 dnl Do one transaction and save the output.
96 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
100 "row": {"number": 0, "name": "zero"}}]'
102 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
104 dnl Add some crap to the database log and run another transaction, which should
105 dnl ignore the crap and truncate it out of the log.
106 echo 'OVSDB JSON 15 ffbcdae4b0386265f9ea3280dd7c8f0b72a20e56
107 {"invalid":{}}' >> db
108 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
112 "row": {"number": 1, "name": "one"}}]'
114 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [stderr])
115 AT_CHECK([grep 'syntax "{"invalid":{}}": unknown table: No table named invalid.' stderr],
118 dnl Run a final transaction to verify that both transactions succeeeded.
119 dnl The crap that we added should have been truncated by the previous run,
120 dnl so ovsdb-server shouldn't log a warning this time.
121 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
126 "sort": ["number"]}]'
128 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
130 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0],
131 [[[{"uuid":["uuid","<0>"]}]
132 [{"uuid":["uuid","<1>"]}]
133 [{"rows":[{"_uuid":["uuid","<0>"],"_version":["uuid","<2>"],"name":"zero","number":0},{"_uuid":["uuid","<1>"],"_version":["uuid","<3>"],"name":"one","number":1}]}]
135 [test ! -e pid || kill `cat pid`])
138 AT_SETUP([ovsdb-client get-schema-version])
139 AT_KEYWORDS([ovsdb server positive])
140 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
141 ordinal_schema > schema
142 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
143 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=punix:socket db], [0], [ignore], [ignore])
144 AT_CHECK([ovsdb-client get-schema-version unix:socket ordinals], [0], [5.1.3
146 OVSDB_SERVER_SHUTDOWN
149 AT_SETUP([database multiplexing implementation])
150 AT_KEYWORDS([ovsdb server positive])
151 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
152 ordinal_schema > schema1
153 constraint_schema > schema2
154 AT_CHECK([ovsdb-tool create db1 schema1], [0], [ignore], [ignore])
155 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
156 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=punix:socket db1 db2], [0], [ignore], [ignore])
158 [[ovsdb-client list-dbs unix:socket]],
161 ], [ignore], [test ! -e pid || kill `cat pid`])
163 [[ovstest test-jsonrpc request unix:socket get_schema [\"nonexistent\"]]], [0],
164 [[{"error":null,"id":0,"result":{"details":"get_schema request specifies unknown database nonexistent","error":"unknown database","syntax":"[\"nonexistent\"]"}}
165 ]], [], [test ! -e pid || kill `cat pid`])
166 OVSDB_SERVER_SHUTDOWN
169 AT_SETUP([ovsdb-server/add-db and remove-db])
170 AT_KEYWORDS([ovsdb server positive])
171 ON_EXIT([kill `cat ovsdb-server.pid`])
172 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
173 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
174 ordinal_schema > schema1
175 constraint_schema > schema2
176 AT_CHECK([ovsdb-tool create db1 schema1], [0], [ignore], [ignore])
177 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
179 # Start ovsdb-server with just a single database - db1.
180 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db1], [0])
181 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
185 # Add the second database.
186 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
187 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
192 # The databases are responsive.
193 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [0], [ignore], [ignore])
194 AT_CHECK([ovsdb-client list-tables unix:socket ordinals], [0], [ignore], [ignore])
196 # Add an already added database.
197 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], 2, [],
199 ovs-appctl: ovsdb-server: server returned an error
202 # Add a non-existing database.
203 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db3], 2, [], [stderr])
204 AT_CHECK([sed 's/(.*)/(...)/' stderr], [0],
205 [I/O error: open: db3 failed (...)
206 ovs-appctl: ovsdb-server: server returned an error
209 # Add a remote through a db path in db1.
210 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote db:ordinals,ordinals,name], [0])
211 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
212 [0], [db:ordinals,ordinals,name
216 # Removing db1 has no effect on its remote.
217 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db ordinals], [0])
218 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
221 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
222 [0], [db:ordinals,ordinals,name
225 AT_CHECK([ovsdb-client list-tables unix:socket ordinals], [1], [ignore], [ignore])
228 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db constraints], [0])
229 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
231 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [1], [ignore], [ignore])
233 # Remove a non-existent database.
234 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db ordinals], [2],
235 [], [Failed to find the database.
236 ovs-appctl: ovsdb-server: server returned an error
239 # Add a removed database.
240 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
241 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
244 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [0], [ignore], [ignore])
247 AT_SETUP([ovsdb-server/add-db with --monitor])
248 AT_KEYWORDS([ovsdb server positive])
249 # Start ovsdb-server, initially with one db.
250 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
251 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
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],
279 AT_SETUP([ovsdb-server/add-db and remove-db with --monitor])
280 AT_KEYWORDS([ovsdb server positive])
281 # Start ovsdb-server, initially with one db.
282 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
283 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
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],
309 AT_SETUP([--remote=db: implementation])
310 AT_KEYWORDS([ovsdb server positive])
311 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
312 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
322 "max": "unlimited"}},
325 "key": {"type": "uuid", "refTable": "Manager"},
327 "max": "unlimited"}}}},
338 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
340 [[ovsdb-tool transact db \
345 "managers": "punix:socket1",
346 "manager_options": ["set", [["named-uuid", "x"]]]}},
350 "row": {"target": "punix:socket2"}}]']], [0], [ignore], [ignore])
351 ON_EXIT([kill `cat ovsdb-server.pid`])
352 AT_CHECK([ovsdb-server --enable-dummy --detach --no-chdir --pidfile --remote=db:mydb,Root,managers --remote=db:mydb,Root,manager_options --log-file db], [0], [ignore], [ignore])
353 for i in 1 2 3 4 5 6; do ovs-appctl -t ovsdb-server time/warp 1000; done
355 [[ovsdb-client transact unix:socket1 \
360 "columns": ["managers"]},
364 "columns": ["target", "is_connected"]}]']],
365 [0], [stdout], [ignore])
367 [${PERL} $srcdir/uuidfilt.pl stdout],
369 [[[{"rows":[{"managers":"punix:socket1"}]},{"rows":[{"is_connected":false,"target":"punix:socket2"}]}]
374 AT_SETUP([ovsdb-server/add-remote and remove-remote])
375 AT_KEYWORDS([ovsdb server positive])
376 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
377 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
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 OVS_WAIT_UNTIL([test -S socket1])
386 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
390 AT_CHECK([test ! -e socket2])
391 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket2])
392 OVS_WAIT_UNTIL([test -S socket2])
393 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
398 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote db:x,y,z], [2],
399 [], ["db:x,y,z": no database named x
400 ovs-appctl: ovsdb-server: server returned an error
403 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
404 OVS_WAIT_UNTIL([test ! -e socket1])
405 AT_CHECK([test -S socket2])
406 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
410 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket2])
411 OVS_WAIT_UNTIL([test ! -e socket2])
412 AT_CHECK([test ! -e socket1])
413 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
416 AT_SETUP([ovsdb-server/add-remote with --monitor])
417 AT_KEYWORDS([ovsdb server positive])
418 # Start ovsdb-server, initially with no remotes.
419 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
420 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
421 ordinal_schema > schema
422 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
423 ON_EXIT([kill `cat *.pid`])
424 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db])
427 AT_CHECK([test ! -e socket1])
428 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
429 OVS_WAIT_UNTIL([test -S socket1])
430 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
434 # Kill the daemon process, making it look like a segfault,
435 # and wait for a new daemon process to get spawned and for it to
436 # start listening on 'socket1'.
437 cp ovsdb-server.pid old.pid
439 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
440 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
442 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
443 OVS_WAIT_UNTIL([test -S socket1])
446 AT_SETUP([ovsdb-server/add-remote and remove-remote with --monitor])
447 AT_KEYWORDS([ovsdb server positive])
448 # Start ovsdb-server, initially with no remotes.
449 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
450 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
451 ordinal_schema > schema
452 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
453 ON_EXIT([kill `cat *.pid`])
454 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db])
457 AT_CHECK([test ! -e socket1])
458 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
459 OVS_WAIT_UNTIL([test -S socket1])
460 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
465 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
466 OVS_WAIT_UNTIL([test ! -e socket1])
467 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
469 # Kill the daemon process, making it look like a segfault,
470 # and wait for a new daemon process to get spawned and make sure that it
471 # does not listen on 'socket1'.
472 cp ovsdb-server.pid old.pid
473 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
474 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
476 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
477 AT_CHECK([test ! -e socket1])
480 AT_SETUP([SSL db: implementation])
481 AT_KEYWORDS([ovsdb server positive ssl $5])
482 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
483 PKIDIR=$abs_top_builddir/tests
484 AT_SKIP_IF([expr "$PKIDIR" : ".*[ '\"
491 "private_key": {"type": "string"},
492 "certificate": {"type": "string"},
493 "ca_cert": {"type": "string"}}}}}
495 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
497 [[ovsdb-tool transact db \
501 "row": {"private_key": "'"$PKIDIR/testpki-privkey2.pem"'",
502 "certificate": "'"$PKIDIR/testpki-cert2.pem"'",
503 "ca_cert": "'"$PKIDIR/testpki-cacert.pem"'"}}]']],
504 [0], [ignore], [ignore])
505 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
507 [ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid \
508 --private-key=db:mydb,SSL,private_key \
509 --certificate=db:mydb,SSL,certificate \
510 --ca-cert=db:mydb,SSL,ca_cert \
511 --remote=pssl:0:127.0.0.1 --unixctl="`pwd`"/unixctl db],
512 [0], [ignore], [ignore])
513 SSL_PORT=`parse_listening_port < ovsdb-server.log`
516 --private-key=$PKIDIR/testpki-privkey.pem \
517 --certificate=$PKIDIR/testpki-cert.pem \
518 --ca-cert=$PKIDIR/testpki-cacert.pem \
519 transact ssl:127.0.0.1:$SSL_PORT \
524 "columns": ["private_key"]}]']],
525 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
529 [[[{"rows":[{"private_key":"$PKIDIR/testpki-privkey2.pem"}]}]
530 ]], [ignore], [test ! -e pid || kill `cat pid`])
531 OVSDB_SERVER_SHUTDOWN
534 AT_SETUP([compacting online])
535 AT_KEYWORDS([ovsdb server compact])
536 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
537 ordinal_schema > schema
538 dnl Make sure that "ovsdb-tool create" works with a dangling symlink for
539 dnl the database and the lockfile, creating the target of each symlink rather
540 dnl than replacing the symlinks with regular files.
543 ln -s dir/.db.~lock~ .db.~lock~
544 AT_SKIP_IF([test ! -h db || test ! -h .db.~lock~])
545 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
546 dnl Start ovsdb-server.
547 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])
548 AT_CAPTURE_FILE([ovsdb-server.log])
549 dnl Do a bunch of random transactions that put crap in the database log.
551 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
553 ovsdb-client transact unix:socket '
557 "row": {"name": "'$1'", "number": '$2'}},
559 "comment": "add row for '"$pair"'"}]'
560 ovsdb-client transact unix:socket '
564 "where": [["number", "==", '$2']]},
566 "comment": "delete row for '"$2"'"}]'
567 ovsdb-client transact unix:socket '
571 "row": {"name": "'$1'", "number": '$2'}},
573 "comment": "add back row for '"$pair"'"}]'
575 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
576 dnl Check that all the crap is in fact in the database log.
577 AT_CHECK([[${PERL} $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | ovstest test-json --multiple -]], [0],
578 [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"}
579 {"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
580 {"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
581 {"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
582 {"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
583 {"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
584 {"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
585 {"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
586 {"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
587 {"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
588 {"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
589 {"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
590 {"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
591 {"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
592 {"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
593 {"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
594 {"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
595 {"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
596 {"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
597 ]], [], [test ! -e pid || kill `cat pid`])
598 dnl Dump out and check the actual database contents.
599 AT_CHECK([[ovsdb-client dump unix:socket ordinals]],
600 [0], [stdout], [ignore])
601 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
604 ------------------------------------ ----- ------
611 ], [], [test ! -e pid || kill `cat pid`])
612 dnl Now compact the database in-place.
613 AT_CHECK([[ovs-appctl -t "`pwd`"/unixctl ovsdb-server/compact]],
614 [0], [], [ignore], [test ! -e pid || kill `cat pid`])
615 dnl Make sure that "db" is still a symlink to dir/db instead of getting
616 dnl replaced by a regular file, ditto for .db.~lock~.
617 AT_CHECK([test -h db])
618 AT_CHECK([test -h .db.~lock~])
619 AT_CHECK([test -f dir/db])
620 AT_CHECK([test -f dir/.db.~lock~])
621 dnl We can't fully re-check the contents of the database log, because the
622 dnl order of the records is not predictable, but there should only be 4 lines
624 AT_CAPTURE_FILE([db])
625 AT_CHECK([test `wc -l < db` -eq 4], [0], [], [],
626 [test ! -e pid || kill `cat pid`])
627 dnl And check that the dumped data is the same too:
628 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
629 [test ! -e pid || kill `cat pid`])
630 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
633 ------------------------------------ ----- ------
640 ], [], [test ! -e pid || kill `cat pid`])
641 dnl Now do some more transactions.
643 [[ovsdb-client transact unix:socket '
647 "where": [["number", "<", 3]]}]']],
649 ]], [ignore], [test ! -e pid || kill `cat pid`])
650 dnl There should be 6 lines in the log now.
651 AT_CHECK([test `wc -l < db` -eq 6], [0], [], [],
652 [test ! -e pid || kill `cat pid`])
653 dnl Then check that the dumped data is correct.
654 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
655 [test ! -e pid || kill `cat pid`])
656 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
659 ------------------------------------ ----- ------
663 ], [], [test ! -e pid || kill `cat pid`])
664 OVSDB_SERVER_SHUTDOWN
667 AT_SETUP([ovsdb-server combines updates on backlogged connections])
668 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
669 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
670 ON_EXIT([kill `cat *.pid`])
672 # The maximum socket receive buffer size is important for this test, which
673 # tests behavior when the receive buffer overflows.
674 if test -e /proc/sys/net/core/rmem_max; then
676 rmem_max=`cat /proc/sys/net/core/rmem_max`
677 elif rmem_max=`sysctl -n net.inet.tcp.recvbuf_max 2>/dev/null`; then
680 # Don't know how to get maximum socket receive buffer on this OS
684 # Calculate the number of iterations we need to queue. Each of the
685 # iterations we execute, by itself, yields a monitor update of about
686 # 25 kB, so fill up that much space plus a few for luck.
687 n_iterations=`expr $rmem_max / 25000 + 5`
688 echo rmem_max=$rmem_max n_iterations=$n_iterations
690 # If there's too much queuing skip the test to avoid timing out.
691 AT_SKIP_IF([test $rmem_max -gt 1048576])
693 # Calculate the exact number of monitor updates expected for $n_iterations,
694 # assuming no updates are combined. The "extra" update is for the initial
695 # contents of the database.
696 n_updates=`expr $n_iterations \* 3 + 1`
698 # Start an ovsdb-server with the vswitchd schema.
700 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --log-file --remote=punix:db.sock db],
701 [0], [ignore], [ignore])
703 # Executes a set of transactions that add a bridge with 100 ports, and
704 # then deletes that bridge. This yields three monitor updates that
705 # add up to about 25 kB in size.
707 # The update also increments a counter held in the database so that we can
708 # verify that the overall effect of the transactions took effect (e.g.
709 # monitor updates at the end weren't just dropped). We add an arbitrary
710 # string to the counter to make grepping for it more reliable.
712 trigger_big_update () {
713 counter=`expr $counter + 1`
714 ovs-vsctl --no-wait -- set open_vswitch . system_version=xyzzy$counter
715 ovs-vsctl --no-wait -- add-br br0 $add
716 ovs-vsctl --no-wait -- del-br br0
719 for j in `seq 1 100`; do
720 printf " -- add-port br0 p%d" $j
725 AT_CAPTURE_FILE([ovsdb-client.err])
727 # Start an ovsdb-client monitoring all changes to the database,
728 # make it block to force the buffers to fill up, and then execute
729 # enough iterations that ovsdb-server starts combining updates.
730 AT_CHECK([ovsdb-client --detach --no-chdir --pidfile monitor ALL >ovsdb-client.out 2>ovsdb-client.err])
731 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/block])
732 for i in `seq 1 $n_iterations`; do
733 echo "blocked update ($i of $n_iterations)"
734 trigger_big_update $i
736 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/unblock])
737 OVS_WAIT_UNTIL([grep "\"xyzzy$counter\"" ovsdb-client.out])
738 AT_CHECK([ovs-appctl -t ovsdb-client exit])
739 OVS_WAIT_WHILE([test -e ovsdb-client.pid])
741 # Count the number of updates in the ovsdb-client output, by counting
742 # the number of changes to the Open_vSwitch table. (All of our
743 # transactions modify the Open_vSwitch table.) It should be less than
744 # $n_updates updates.
746 # Check that the counter is what we expect.
747 logged_updates=`grep -c '^Open_vSwitch' ovsdb-client.out`
748 echo "logged_updates=$logged_updates (expected less than $n_updates)"
749 AT_CHECK([test $logged_updates -lt $n_updates])
750 AT_CHECK_UNQUOTED([ovs-vsctl get open_vswitch . system_version], [0],
755 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv4 sockets)])
757 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
759 # Creates a database with the given SCHEMA, starts an ovsdb-server on
760 # that database, and runs each of the TRANSACTIONS (which should be a
761 # quoted list of quoted strings) against it with ovsdb-client one at a
764 # Checks that the overall output is OUTPUT, but UUIDs in the output
765 # are replaced by markers of the form <N> where N is a number. The
766 # first unique UUID is replaced by <0>, the next by <1>, and so on.
767 # If a given UUID appears more than once it is always replaced by the
770 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
771 m4_define([OVSDB_CHECK_EXECUTION],
773 AT_KEYWORDS([ovsdb server positive ssl $5])
774 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
775 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
776 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
778 PKIDIR=$abs_top_builddir/tests
779 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
780 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])
781 SSL_PORT=`parse_listening_port < ovsdb-server.log`
782 m4_foreach([txn], [$3],
783 [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],
784 [test ! -e pid || kill `cat pid`])
787 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
788 [test ! -e pid || kill `cat pid`])
789 OVSDB_SERVER_SHUTDOWN
794 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv6 sockets)])
796 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
798 # Creates a database with the given SCHEMA, starts an ovsdb-server on
799 # that database, and runs each of the TRANSACTIONS (which should be a
800 # quoted list of quoted strings) against it with ovsdb-client one at a
803 # Checks that the overall output is OUTPUT, but UUIDs in the output
804 # are replaced by markers of the form <N> where N is a number. The
805 # first unique UUID is replaced by <0>, the next by <1>, and so on.
806 # If a given UUID appears more than once it is always replaced by the
809 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
810 m4_define([OVSDB_CHECK_EXECUTION],
812 AT_KEYWORDS([ovsdb server positive ssl6 $5])
813 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
814 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
815 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
817 PKIDIR=$abs_top_builddir/tests
818 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
819 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])
820 SSL_PORT=`parse_listening_port < ovsdb-server.log`
821 m4_foreach([txn], [$3],
822 [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],
823 [test ! -e pid || kill `cat pid`])
826 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
827 [test ! -e pid || kill `cat pid`])
828 OVSDB_SERVER_SHUTDOWN
831 ONE_EXECUTION_EXAMPLE
833 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv4 sockets)])
835 AT_SETUP([ovsdb-client get-schema-version - tcp socket])
836 AT_KEYWORDS([ovsdb server positive tcp])
837 ordinal_schema > schema
838 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
839 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
840 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])
841 TCP_PORT=`parse_listening_port < ovsdb-server.log`
842 AT_CHECK([ovsdb-client get-schema-version tcp:127.0.0.1:$TCP_PORT ordinals], [0], [5.1.3
844 OVSDB_SERVER_SHUTDOWN
847 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
849 # Creates a database with the given SCHEMA, starts an ovsdb-server on
850 # that database, and runs each of the TRANSACTIONS (which should be a
851 # quoted list of quoted strings) against it with ovsdb-client one at a
854 # Checks that the overall output is OUTPUT, but UUIDs in the output
855 # are replaced by markers of the form <N> where N is a number. The
856 # first unique UUID is replaced by <0>, the next by <1>, and so on.
857 # If a given UUID appears more than once it is always replaced by the
860 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
861 m4_define([OVSDB_CHECK_EXECUTION],
863 AT_KEYWORDS([ovsdb server positive tcp $5])
864 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
865 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
867 PKIDIR=$abs_top_builddir/tests
868 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
869 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])
870 TCP_PORT=`parse_listening_port < ovsdb-server.log`
871 m4_foreach([txn], [$3],
872 [AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT 'txn'], [0], [stdout], [ignore],
873 [test ! -e pid || kill `cat pid`])
876 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
877 [test ! -e pid || kill `cat pid`])
878 OVSDB_SERVER_SHUTDOWN
883 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv6 sockets)])
885 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
887 # Creates a database with the given SCHEMA, starts an ovsdb-server on
888 # that database, and runs each of the TRANSACTIONS (which should be a
889 # quoted list of quoted strings) against it with ovsdb-client one at a
892 # Checks that the overall output is OUTPUT, but UUIDs in the output
893 # are replaced by markers of the form <N> where N is a number. The
894 # first unique UUID is replaced by <0>, the next by <1>, and so on.
895 # If a given UUID appears more than once it is always replaced by the
898 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
899 m4_define([OVSDB_CHECK_EXECUTION],
901 AT_KEYWORDS([ovsdb server positive tcp6 $5])
902 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
903 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
905 PKIDIR=$abs_top_builddir/tests
906 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
907 AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid --remote=ptcp:0:[[::1]] --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
908 TCP_PORT=`parse_listening_port < ovsdb-server.log`
909 m4_foreach([txn], [$3],
910 [AT_CHECK([ovsdb-client transact tcp:[[::1]]:$TCP_PORT 'txn'], [0], [stdout], [ignore],
911 [test ! -e pid || kill `cat pid`])
914 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
915 [test ! -e pid || kill `cat pid`])
916 OVSDB_SERVER_SHUTDOWN
919 ONE_EXECUTION_EXAMPLE
921 AT_BANNER([OVSDB -- transactions on transient ovsdb-server])
923 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
925 # Creates a database with the given SCHEMA and runs each of the
926 # TRANSACTIONS (which should be a quoted list of quoted strings)
927 # against it with ovsdb-client one at a time. Each ovsdb-client
928 # is run against a separately started ovsdb-server that executes
929 # only that single transaction. (The idea is that this should
930 # help to ferret out any differences between what ovsdb-server has
931 # in memory and what actually gets committed to disk.)
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_SKIP_IF([test "$IS_WIN32" = "yes"])
943 AT_KEYWORDS([ovsdb server positive transient $5])
944 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
946 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
947 m4_foreach([txn], [$3],
948 [AT_DATA([txnfile], [ovsdb-client transact unix:socket 'txn'
950 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [ignore])
953 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore])