1 AT_BANNER([OVSDB -- ovsdb-server transactions (Unix sockets)])
3 m4_define([OVSDB_SERVER_SHUTDOWN],
4 [OVS_APP_EXIT_AND_WAIT_BY_TARGET([ovsdb-server], [ovsdb-server.pid])])
6 m4_define([OVSDB_SERVER_SHUTDOWN2],
8 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 -e exit], [0], [ignore], [ignore])
9 OVS_WAIT_WHILE([kill -0 `cat savepid2`], [kill `cat savepid2`])])
11 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
13 # Creates a database with the given SCHEMA, starts an ovsdb-server on
14 # that database, and runs each of the TRANSACTIONS (which should be a
15 # quoted list of quoted strings) against it with ovsdb-client one at a
18 # Checks that the overall output is OUTPUT, but UUIDs in the output
19 # are replaced by markers of the form <N> where N is a number. The
20 # first unique UUID is replaced by <0>, the next by <1>, and so on.
21 # If a given UUID appears more than once it is always replaced by the
24 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
25 m4_define([OVSDB_CHECK_EXECUTION],
27 AT_KEYWORDS([ovsdb server positive unix $5])
29 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
30 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db], [0], [ignore], [ignore])
31 m4_foreach([txn], [$3],
32 [AT_CHECK([ovsdb-client transact unix:socket 'txn'], [0], [stdout], [ignore],
33 [test ! -e pid || kill `cat pid`])
36 AT_CHECK([uuidfilt output], [0], [$4], [ignore],
37 [test ! -e pid || kill `cat pid`])
43 AT_BANNER([ovsdb-server miscellaneous features])
45 AT_SETUP([truncating corrupted database log])
46 AT_KEYWORDS([ovsdb server positive unix])
47 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
48 ordinal_schema > schema
49 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
50 dnl Do one transaction and save the output.
51 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
55 "row": {"number": 0, "name": "zero"}}]'
57 AT_CHECK([ovsdb-server --remote=punix:socket db --run="sh txnfile"], [0], [stdout], [])
59 dnl Add some crap to the database log and run another transaction, which should
60 dnl ignore the crap and truncate it out of the log.
62 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
66 "row": {"number": 1, "name": "one"}}]'
68 AT_CHECK([ovsdb-server --remote=punix:socket db --run="sh txnfile"], [0], [stdout], [stderr])
69 AT_CHECK([grep 'syntax error: db: parse error.* in header line "xxx"' stderr],
72 dnl Run a final transaction to verify that both transactions succeeeded.
73 dnl The crap that we added should have been truncated by the previous run,
74 dnl so ovsdb-server shouldn't log a warning this time.
75 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
82 AT_CHECK([ovsdb-server --remote=punix:socket db --run="sh txnfile"], [0], [stdout], [])
84 AT_CHECK([uuidfilt output], [0],
85 [[[{"uuid":["uuid","<0>"]}]
86 [{"uuid":["uuid","<1>"]}]
87 [{"rows":[{"_uuid":["uuid","<0>"],"_version":["uuid","<2>"],"name":"zero","number":0},{"_uuid":["uuid","<1>"],"_version":["uuid","<3>"],"name":"one","number":1}]}]
89 [test ! -e pid || kill `cat pid`])
92 AT_SETUP([truncating database log with bad transaction])
93 AT_KEYWORDS([ovsdb server positive unix])
94 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
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 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 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 db --run="sh txnfile"], [0], [stdout], [])
132 AT_CHECK([uuidfilt 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([database multiplexing implementation])
141 AT_KEYWORDS([ovsdb server positive])
142 ordinal_schema > schema1
143 constraint_schema > schema2
144 AT_CHECK([ovsdb-tool create db1 schema1], [0], [ignore], [ignore])
145 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
146 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db1 db2], [0], [ignore], [ignore])
148 [[ovsdb-client list-dbs unix:socket]],
151 ], [ignore], [test ! -e pid || kill `cat pid`])
153 [[ovstest test-jsonrpc request unix:socket get_schema [\"nonexistent\"]]], [0],
154 [[{"error":{"details":"get_schema request specifies unknown database nonexistent","error":"unknown database","syntax":"[\"nonexistent\"]"},"id":0,"result":null}
155 ]], [], [test ! -e pid || kill `cat pid`])
156 OVSDB_SERVER_SHUTDOWN
159 AT_SETUP([ovsdb-server/add-db and remove-db])
160 AT_KEYWORDS([ovsdb server positive])
161 on_exit 'kill `cat ovsdb-server.pid`'
162 ordinal_schema > schema1
163 constraint_schema > schema2
164 AT_CHECK([ovsdb-tool create db1 schema1], [0], [ignore], [ignore])
165 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
167 # Start ovsdb-server with just a single database - db1.
168 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db1], [0])
169 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
173 # Add the second database.
174 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
175 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
180 # The databases are responsive.
181 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [0], [ignore], [ignore])
182 AT_CHECK([ovsdb-client list-tables unix:socket ordinals], [0], [ignore], [ignore])
184 # Add an already added database.
185 if test $IS_WIN32 = "yes"; then
186 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], 2, [],
187 [I/O error: db2: failed to lock lockfile (Resource deadlock avoided)
188 ovs-appctl: ovsdb-server: server returned an error
191 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], 2, [],
193 ovs-appctl: ovsdb-server: server returned an error
197 # Add a non-existing database.
198 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db3], 2, [], [stderr])
199 AT_CHECK([sed 's/(.*)/(...)/' stderr], [0],
200 [I/O error: db3: open failed (...)
201 ovs-appctl: ovsdb-server: server returned an error
204 # Add a remote through a db path in db1.
205 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote db:ordinals,ordinals,name], [0])
206 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
207 [0], [db:ordinals,ordinals,name
211 # Removing db1 has no effect on its remote.
212 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db ordinals], [0])
213 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
216 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
217 [0], [db:ordinals,ordinals,name
220 AT_CHECK([ovsdb-client list-tables unix:socket ordinals], [1], [ignore], [ignore])
223 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db constraints], [0])
224 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
226 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [1], [ignore], [ignore])
228 # Remove a non-existent database.
229 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db ordinals], [2],
230 [], [Failed to find the database.
231 ovs-appctl: ovsdb-server: server returned an error
234 # Add a removed database.
235 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
236 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
239 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [0], [ignore], [ignore])
240 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
243 AT_SETUP([ovsdb-server/add-db with --monitor])
244 AT_KEYWORDS([ovsdb server positive])
245 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
246 # Start ovsdb-server, initially with one db.
247 ordinal_schema > schema
248 AT_CHECK([ovsdb-tool create db1 schema], [0], [ignore], [ignore])
249 on_exit 'kill `cat *.pid`'
250 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db1])
252 # Add the second database.
253 constraint_schema > schema2
254 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
255 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
256 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
261 # Kill the daemon process, making it look like a segfault,
262 # and wait for a new daemon process to get spawned.
263 cp ovsdb-server.pid old.pid
264 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
265 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
267 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
268 OVS_WAIT_UNTIL([ovs-appctl -t ovsdb-server version])
269 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
273 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
276 AT_SETUP([ovsdb-server/add-db and remove-db with --monitor])
277 AT_KEYWORDS([ovsdb server positive])
278 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
279 # Start ovsdb-server, initially with one db.
280 ordinal_schema > schema
281 AT_CHECK([ovsdb-tool create db1 schema], [0], [ignore], [ignore])
282 constraint_schema > schema2
283 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
284 on_exit 'kill `cat *.pid`'
285 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db1 db2])
287 # Remove the second database.
288 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db constraints])
289 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
293 # Kill the daemon process, making it look like a segfault,
294 # and wait for a new daemon process to get spawned.
295 cp ovsdb-server.pid old.pid
296 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
297 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
299 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
300 OVS_WAIT_UNTIL([ovs-appctl -t ovsdb-server version])
301 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
304 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
307 AT_SETUP([--remote=db: implementation])
308 AT_KEYWORDS([ovsdb server positive])
318 "max": "unlimited"}},
321 "key": {"type": "uuid", "refTable": "Manager"},
323 "max": "unlimited"}}}},
334 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
336 [[ovsdb-tool transact db \
341 "managers": "punix:socket1",
342 "manager_options": ["set", [["named-uuid", "x"]]]}},
346 "row": {"target": "punix:socket2"}}]']], [0], [ignore], [ignore])
347 on_exit 'kill `cat ovsdb-server.pid`'
348 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])
349 ovs-appctl -t ovsdb-server time/warp 6000 1000
351 [[ovsdb-client transact unix:socket1 \
356 "columns": ["managers"]},
360 "columns": ["target", "is_connected"]}]']],
361 [0], [stdout], [ignore])
365 [[[{"rows":[{"managers":"punix:socket1"}]},{"rows":[{"is_connected":false,"target":"punix:socket2"}]}]
368 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
371 AT_SETUP([ovsdb-server/add-remote and remove-remote])
372 AT_KEYWORDS([ovsdb server positive])
373 ordinal_schema > schema
374 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
375 on_exit 'kill `cat *.pid`'
376 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile db])
378 AT_CHECK([test ! -e socket1])
379 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
380 if test "$IS_WIN32" = "yes"; then
381 OVS_WAIT_UNTIL([test -e socket1])
383 OVS_WAIT_UNTIL([test -S socket1])
385 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
389 AT_CHECK([test ! -e socket2])
390 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket2])
391 if test "$IS_WIN32" = "yes"; then
392 OVS_WAIT_UNTIL([test -e socket2])
394 OVS_WAIT_UNTIL([test -S socket2])
396 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
401 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote db:x,y,z], [2],
402 [], ["db:x,y,z": no database named x
403 ovs-appctl: ovsdb-server: server returned an error
406 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
407 OVS_WAIT_UNTIL([test ! -e socket1])
408 if test "$IS_WIN32" = "yes"; then
409 AT_CHECK([test -e socket2])
411 AT_CHECK([test -S socket2])
413 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
417 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket2])
418 OVS_WAIT_UNTIL([test ! -e socket2])
419 AT_CHECK([test ! -e socket1])
420 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
421 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
424 AT_SETUP([ovsdb-server/add-remote with --monitor])
425 AT_KEYWORDS([ovsdb server positive])
426 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
427 # Start ovsdb-server, initially with no remotes.
428 ordinal_schema > schema
429 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
430 on_exit 'kill `cat *.pid`'
431 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db])
434 AT_CHECK([test ! -e socket1])
435 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
436 OVS_WAIT_UNTIL([test -S socket1])
437 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
441 # Kill the daemon process, making it look like a segfault,
442 # and wait for a new daemon process to get spawned and for it to
443 # start listening on 'socket1'.
444 cp ovsdb-server.pid old.pid
446 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
447 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
449 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
450 OVS_WAIT_UNTIL([ovs-appctl -t ovsdb-server version])
451 OVS_WAIT_UNTIL([test -S socket1])
452 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
455 AT_SETUP([ovsdb-server/add-remote and remove-remote with --monitor])
456 AT_KEYWORDS([ovsdb server positive])
457 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
458 # Start ovsdb-server, initially with no remotes.
459 ordinal_schema > schema
460 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
461 on_exit 'kill `cat *.pid`'
462 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db])
465 AT_CHECK([test ! -e socket1])
466 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
467 OVS_WAIT_UNTIL([test -S socket1])
468 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
473 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
474 OVS_WAIT_UNTIL([test ! -e socket1])
475 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
477 # Kill the daemon process, making it look like a segfault,
478 # and wait for a new daemon process to get spawned and make sure that it
479 # does not listen on 'socket1'.
480 cp ovsdb-server.pid old.pid
481 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
482 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
484 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
485 OVS_WAIT_UNTIL([ovs-appctl -t ovsdb-server version])
486 AT_CHECK([test ! -e socket1])
487 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
490 AT_SETUP([SSL db: implementation])
491 AT_KEYWORDS([ovsdb server positive ssl $5])
492 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
493 # For this test, we pass PKIDIR through a ovsdb-tool transact and
494 # msys on Windows does not convert the path style automatically.
495 # So, do that forcefully with a 'pwd -W' (called through pwd() function).
496 PKIDIR="$(cd $abs_top_builddir/tests && pwd)"
497 AT_SKIP_IF([expr "$PKIDIR" : ".*[ '\"
504 "private_key": {"type": "string"},
505 "certificate": {"type": "string"},
506 "ca_cert": {"type": "string"},
507 "ssl_protocols" : {"type": "string"},
508 "ssl_ciphers" : {"type" : "string"}}}}}
510 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
511 # The !ECDHE-ECDSA-AES256-GCM-SHA384 in the ssl_ciphers is so that
512 # a cipher negotiation failure can be tested for later.
514 [[ovsdb-tool transact db \
518 "row": {"private_key": "'"$PKIDIR/testpki-privkey2.pem"'",
519 "certificate": "'"$PKIDIR/testpki-cert2.pem"'",
520 "ca_cert": "'"$PKIDIR/testpki-cacert.pem"'",
521 "ssl_protocols": "'"TLSv1.2,TLSv1.1"'",
522 "ssl_ciphers": "'"HIGH:!aNULL:!MD5:!ECDHE-ECDSA-AES256-GCM-SHA384"'"}}]']],
523 [0], [ignore], [ignore])
525 [ovsdb-server --log-file --detach --no-chdir --pidfile \
526 --private-key=db:mydb,SSL,private_key \
527 --certificate=db:mydb,SSL,certificate \
528 --ca-cert=db:mydb,SSL,ca_cert \
529 --ssl-protocols=db:mydb,SSL,ssl_protocols \
530 --ssl-ciphers=db:mydb,SSL,ssl_ciphers \
531 --remote=pssl:0:127.0.0.1 db],
532 [0], [ignore], [ignore])
533 PARSE_LISTENING_PORT([ovsdb-server.log], [SSL_PORT])
536 --private-key=$PKIDIR/testpki-privkey.pem \
537 --certificate=$PKIDIR/testpki-cert.pem \
538 --ca-cert=$PKIDIR/testpki-cacert.pem \
539 --ssl-protocols=TLSv1.2,TLSv1.1 \
540 --ssl-ciphers=HIGH:!aNULL:!MD5 \
541 transact ssl:127.0.0.1:$SSL_PORT \
546 "columns": ["private_key"]}]']],
547 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
551 [[@<:@{"rows":@<:@{"private_key":"$PKIDIR/testpki-privkey2.pem"}@:>@}@:>@
552 ]], [ignore], [test ! -e pid || kill `cat pid`])
553 # Check that when the server has TLSv1.1+ and the client has
554 # TLSv1 that the connection fails.
557 --private-key=$PKIDIR/testpki-privkey.pem \
558 --certificate=$PKIDIR/testpki-cert.pem \
559 --ca-cert=$PKIDIR/testpki-cacert.pem \
560 --ssl-protocols=TLSv1 \
561 --ssl-ciphers=HIGH:!aNULL:!MD5 \
562 transact ssl:127.0.0.1:$SSL_PORT \
567 "columns": ["private_key"]}]']],
570 [test ! -e pid || kill `cat pid`])
573 [grep "failed to connect" output], [0],
574 [ovsdb-client: failed to connect to "ssl:127.0.0.1:$SSL_PORT" (Protocol error)
576 [ignore], [test ! -e pid || kill `cat pid`])
577 # Check that when ciphers are not compatible, that a negotiation
581 --private-key=$PKIDIR/testpki-privkey.pem \
582 --certificate=$PKIDIR/testpki-cert.pem \
583 --ca-cert=$PKIDIR/testpki-cacert.pem \
584 --ssl-protocols=TLSv1.2,TLSv1.1 \
585 --ssl-ciphers=ECDHE-ECDSA-AES256-GCM-SHA384 \
586 transact ssl:127.0.0.1:$SSL_PORT \
591 "columns": ["private_key"]}]']],
594 [test ! -e pid || kill `cat pid`])
597 [grep "failed to connect" output], [0],
598 [ovsdb-client: failed to connect to "ssl:127.0.0.1:$SSL_PORT" (Protocol error)
600 [ignore], [test ! -e pid || kill `cat pid`])
601 # The error message for being unable to negotiate a shared ciphersuite
602 # is 'sslv3 alert handshake failure'. This is not the clearest message.
604 [grep "sslv3 alert handshake failure" output], [0],
606 [ignore], [test ! -e pid || kill `cat pid`])
607 OVSDB_SERVER_SHUTDOWN
610 AT_SETUP([compacting online])
611 AT_KEYWORDS([ovsdb server compact])
612 ordinal_schema > schema
613 dnl Make sure that "ovsdb-tool create" works with a dangling symlink for
614 dnl the database and the lockfile, creating the target of each symlink rather
615 dnl than replacing the symlinks with regular files.
617 if test "$IS_WIN32" = "no"; then
619 ln -s dir/.db.~lock~ .db.~lock~
620 AT_SKIP_IF([test ! -h db || test ! -h .db.~lock~])
622 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
623 dnl Start ovsdb-server.
624 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket --log-file="`pwd`"/ovsdb-server.log db], [0], [ignore], [ignore])
625 AT_CAPTURE_FILE([ovsdb-server.log])
626 dnl Do a bunch of random transactions that put crap in the database log.
628 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
630 ovsdb-client transact unix:socket '
634 "row": {"name": "'$1'", "number": '$2'}},
636 "comment": "add row for '"$pair"'"}]'
637 ovsdb-client transact unix:socket '
641 "where": [["number", "==", '$2']]},
643 "comment": "delete row for '"$2"'"}]'
644 ovsdb-client transact unix:socket '
648 "row": {"name": "'$1'", "number": '$2'}},
650 "comment": "add back row for '"$pair"'"}]'
652 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
653 dnl Check that all the crap is in fact in the database log.
654 AT_CHECK([[uuidfilt db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | ovstest test-json --multiple -]], [0],
655 [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"}
656 {"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
657 {"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
658 {"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
659 {"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
660 {"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
661 {"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
662 {"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
663 {"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
664 {"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
665 {"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
666 {"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
667 {"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
668 {"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
669 {"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
670 {"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
671 {"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
672 {"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
673 {"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
674 ]], [], [test ! -e pid || kill `cat pid`])
675 dnl Dump out and check the actual database contents.
676 AT_CHECK([[ovsdb-client dump unix:socket ordinals]],
677 [0], [stdout], [ignore])
678 AT_CHECK([uuidfilt stdout], [0], [dnl
681 ------------------------------------ ----- ------
688 ], [], [test ! -e pid || kill `cat pid`])
689 dnl Now compact the database in-place.
690 AT_CHECK([[ovs-appctl -t ovsdb-server ovsdb-server/compact]],
691 [0], [], [ignore], [test ! -e pid || kill `cat pid`])
693 AT_CHECK([[ovs-appctl -t ovsdb-server ovsdb-server/compact _Server]],
694 [2], [], [cannot compact built-in databases
695 ovs-appctl: ovsdb-server: server returned an error
697 dnl Make sure that "db" is still a symlink to dir/db instead of getting
698 dnl replaced by a regular file, ditto for .db.~lock~.
699 if test "$IS_WIN32" = "no"; then
700 AT_CHECK([test -h db])
701 AT_CHECK([test -h .db.~lock~])
702 AT_CHECK([test -f dir/db])
703 AT_CHECK([test -f dir/.db.~lock~])
705 dnl We can't fully re-check the contents of the database log, because the
706 dnl order of the records is not predictable, but there should only be 4 lines
708 AT_CAPTURE_FILE([db])
709 AT_CHECK([test `wc -l < db` -eq 4], [0], [], [],
710 [test ! -e pid || kill `cat pid`])
711 dnl And check that the dumped data is the same too:
712 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
713 [test ! -e pid || kill `cat pid`])
714 AT_CHECK([uuidfilt stdout], [0], [dnl
717 ------------------------------------ ----- ------
724 ], [], [test ! -e pid || kill `cat pid`])
725 dnl Now do some more transactions.
727 [[ovsdb-client transact unix:socket '
731 "where": [["number", "<", 3]]}]']],
733 ]], [ignore], [test ! -e pid || kill `cat pid`])
734 dnl There should be 6 lines in the log now.
735 AT_CHECK([test `wc -l < db` -eq 6], [0], [], [],
736 [test ! -e pid || kill `cat pid`])
737 dnl Then check that the dumped data is correct. This time first kill
738 dnl and restart the database server to ensure that the data is correct on
739 dnl disk as well as in memory.
740 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
741 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket --log-file="`pwd`"/ovsdb-server.log db], [0], [ignore], [ignore])
742 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
743 [test ! -e pid || kill `cat pid`])
744 AT_CHECK([uuidfilt stdout], [0], [dnl
747 ------------------------------------ ----- ------
751 ], [], [test ! -e pid || kill `cat pid`])
752 OVSDB_SERVER_SHUTDOWN
755 AT_SETUP([ovsdb-server combines updates on backlogged connections])
756 on_exit 'kill `cat *.pid`'
758 # The maximum socket receive buffer size is important for this test, which
759 # tests behavior when the receive buffer overflows.
760 if test -e /proc/sys/net/core/rmem_max; then
762 rmem_max=`cat /proc/sys/net/core/rmem_max`
763 elif rmem_max=`sysctl -n net.inet.tcp.recvbuf_max 2>/dev/null`; then
766 # Don't know how to get maximum socket receive buffer on this OS
770 # Calculate the number of iterations we need to queue. Each of the
771 # iterations we execute, by itself, yields a monitor update of about
772 # 25 kB, so fill up that much space plus a few for luck.
773 n_iterations=`expr $rmem_max / 25000 + 5`
774 echo rmem_max=$rmem_max n_iterations=$n_iterations
776 # If there's too much queuing skip the test to avoid timing out.
777 AT_SKIP_IF([test $rmem_max -gt 1048576])
779 # Calculate the exact number of monitor updates expected for $n_iterations,
780 # assuming no updates are combined. The "extra" update is for the initial
781 # contents of the database.
782 n_updates=`expr $n_iterations \* 3 + 1`
784 # Start an ovsdb-server with the vswitchd schema.
786 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --log-file --remote=punix:db.sock db],
787 [0], [ignore], [ignore])
789 # Executes a set of transactions that add a bridge with 100 ports, and
790 # then deletes that bridge. This yields three monitor updates that
791 # add up to about 25 kB in size.
793 # The update also increments a counter held in the database so that we can
794 # verify that the overall effect of the transactions took effect (e.g.
795 # monitor updates at the end weren't just dropped). We add an arbitrary
796 # string to the counter to make grepping for it more reliable.
798 trigger_big_update () {
799 counter=`expr $counter + 1`
800 ovs-vsctl --no-wait -- set open_vswitch . system_version=xyzzy$counter
801 ovs-vsctl --no-wait -- add-br br0 $add
802 ovs-vsctl --no-wait -- del-br br0
805 for j in `seq 1 100`; do
806 printf " -- add-port br0 p%d" $j
811 AT_CAPTURE_FILE([ovsdb-client.err])
812 AT_CAPTURE_FILE([ovsdb-client-nonblock.err])
815 # Start an ovsdb-client monitoring all changes to the database,
816 # By default, it is non-blocking, and will get update message
817 # for each ovsdb-server transaactions.
818 AT_CHECK([ovsdb-client --detach --no-chdir --pidfile=nonblock.pid monitor ALL >ovsdb-client-nonblock.out 2>ovsdb-client-nonblock.err])
820 # Start an ovsdb-client monitoring all changes to the database,
821 # make it block to force the buffers to fill up, and then execute
822 # enough iterations that ovsdb-server starts combining updates.
823 AT_CHECK([ovsdb-client --detach --no-chdir --pidfile monitor ALL >ovsdb-client.out 2>ovsdb-client.err])
824 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/block])
825 for i in `seq 1 $n_iterations`; do
826 echo "blocked update ($i of $n_iterations)"
827 trigger_big_update $i
829 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/unblock])
830 OVS_WAIT_UNTIL([grep "\"xyzzy$counter\"" ovsdb-client.out])
831 OVS_WAIT_UNTIL([grep "\"xyzzy$counter\"" ovsdb-client-nonblock.out])
832 OVS_APP_EXIT_AND_WAIT([ovsdb-client])
833 AT_CHECK([kill `cat nonblock.pid`])
835 # Count the number of updates in the ovsdb-client output, by counting
836 # the number of changes to the Open_vSwitch table. (All of our
837 # transactions modify the Open_vSwitch table.) It should be less than
838 # $n_updates updates.
840 # Check that the counter is what we expect.
841 logged_updates=`grep -c '^Open_vSwitch' ovsdb-client.out`
842 logged_nonblock_updates=`grep -c '^Open_vSwitch' ovsdb-client-nonblock.out`
843 echo "logged_nonblock_updates=$logged_nonblock_updates (expected less or equal to $n_updates)"
844 echo "logged_updates=$logged_updates (expected less than $logged_nonblock_updates)"
845 AT_CHECK([test $logged_nonblock_updates -le $n_updates])
846 AT_CHECK([test $logged_updates -lt $logged_nonblock_updates])
847 AT_CHECK_UNQUOTED([ovs-vsctl get open_vswitch . system_version], [0],
850 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
853 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv4 sockets)])
855 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
857 # Creates a database with the given SCHEMA, starts an ovsdb-server on
858 # that database, and runs each of the TRANSACTIONS (which should be a
859 # quoted list of quoted strings) against it with ovsdb-client one at a
862 # Checks that the overall output is OUTPUT, but UUIDs in the output
863 # are replaced by markers of the form <N> where N is a number. The
864 # first unique UUID is replaced by <0>, the next by <1>, and so on.
865 # If a given UUID appears more than once it is always replaced by the
868 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
869 m4_define([OVSDB_CHECK_EXECUTION],
871 AT_KEYWORDS([ovsdb server positive ssl $5])
872 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
874 PKIDIR=$abs_top_builddir/tests
875 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
876 AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile --private-key=$PKIDIR/testpki-privkey2.pem --certificate=$PKIDIR/testpki-cert2.pem --ca-cert=$PKIDIR/testpki-cacert.pem --remote=pssl:0:127.0.0.1 db], [0], [ignore], [ignore])
877 PARSE_LISTENING_PORT([ovsdb-server.log], [SSL_PORT])
878 m4_foreach([txn], [$3],
879 [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],
880 [test ! -e pid || kill `cat pid`])
883 AT_CHECK([uuidfilt output], [0], [$4], [ignore],
884 [test ! -e pid || kill `cat pid`])
885 OVSDB_SERVER_SHUTDOWN
890 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv6 sockets)])
892 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
894 # Creates a database with the given SCHEMA, starts an ovsdb-server on
895 # that database, and runs each of the TRANSACTIONS (which should be a
896 # quoted list of quoted strings) against it with ovsdb-client one at a
899 # Checks that the overall output is OUTPUT, but UUIDs in the output
900 # are replaced by markers of the form <N> where N is a number. The
901 # first unique UUID is replaced by <0>, the next by <1>, and so on.
902 # If a given UUID appears more than once it is always replaced by the
905 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
906 m4_define([OVSDB_CHECK_EXECUTION],
908 AT_KEYWORDS([ovsdb server positive ssl6 $5])
909 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
910 AT_SKIP_IF([test $HAVE_IPV6 = no])
912 PKIDIR=$abs_top_builddir/tests
913 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
914 AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile --private-key=$PKIDIR/testpki-privkey2.pem --certificate=$PKIDIR/testpki-cert2.pem --ca-cert=$PKIDIR/testpki-cacert.pem --remote=pssl:0:[[::1]] db], [0], [ignore], [ignore])
915 PARSE_LISTENING_PORT([ovsdb-server.log], [SSL_PORT])
916 m4_foreach([txn], [$3],
917 [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],
918 [test ! -e pid || kill `cat pid`])
921 AT_CHECK([uuidfilt output], [0], [$4], [ignore],
922 [test ! -e pid || kill `cat pid`])
923 OVSDB_SERVER_SHUTDOWN
926 ONE_EXECUTION_EXAMPLE
928 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv4 sockets)])
930 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
932 # Creates a database with the given SCHEMA, starts an ovsdb-server on
933 # that database, and runs each of the TRANSACTIONS (which should be a
934 # quoted list of quoted strings) against it with ovsdb-client one at a
937 # Checks that the overall output is OUTPUT, but UUIDs in the output
938 # are replaced by markers of the form <N> where N is a number. The
939 # first unique UUID is replaced by <0>, the next by <1>, and so on.
940 # If a given UUID appears more than once it is always replaced by the
943 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
944 m4_define([OVSDB_CHECK_EXECUTION],
946 AT_KEYWORDS([ovsdb server positive tcp $5])
948 PKIDIR=$abs_top_builddir/tests
949 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
950 AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile --remote=ptcp:0:127.0.0.1 db], [0], [ignore], [ignore])
951 PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
952 m4_foreach([txn], [$3],
953 [AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT 'txn'], [0], [stdout], [ignore],
954 [test ! -e pid || kill `cat pid`])
957 AT_CHECK([uuidfilt output], [0], [$4], [ignore],
958 [test ! -e pid || kill `cat pid`])
959 OVSDB_SERVER_SHUTDOWN
964 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv6 sockets)])
966 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
968 # Creates a database with the given SCHEMA, starts an ovsdb-server on
969 # that database, and runs each of the TRANSACTIONS (which should be a
970 # quoted list of quoted strings) against it with ovsdb-client one at a
973 # Checks that the overall output is OUTPUT, but UUIDs in the output
974 # are replaced by markers of the form <N> where N is a number. The
975 # first unique UUID is replaced by <0>, the next by <1>, and so on.
976 # If a given UUID appears more than once it is always replaced by the
979 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
980 m4_define([OVSDB_CHECK_EXECUTION],
982 AT_KEYWORDS([ovsdb server positive tcp6 $5])
983 AT_SKIP_IF([test $HAVE_IPV6 = no])
985 PKIDIR=$abs_top_builddir/tests
986 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
987 AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile --remote=ptcp:0:[[::1]] db], [0], [ignore], [ignore])
988 PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
989 m4_foreach([txn], [$3],
990 [AT_CHECK([ovsdb-client transact tcp:[[::1]]:$TCP_PORT 'txn'], [0], [stdout], [ignore],
991 [test ! -e pid || kill `cat pid`])
994 AT_CHECK([uuidfilt output], [0], [$4], [ignore],
995 [test ! -e pid || kill `cat pid`])
996 OVSDB_SERVER_SHUTDOWN
999 ONE_EXECUTION_EXAMPLE
1001 AT_BANNER([OVSDB -- transactions on transient ovsdb-server])
1003 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
1005 # Creates a database with the given SCHEMA and runs each of the
1006 # TRANSACTIONS (which should be a quoted list of quoted strings)
1007 # against it with ovsdb-client one at a time. Each ovsdb-client
1008 # is run against a separately started ovsdb-server that executes
1009 # only that single transaction. (The idea is that this should
1010 # help to ferret out any differences between what ovsdb-server has
1011 # in memory and what actually gets committed to disk.)
1013 # Checks that the overall output is OUTPUT, but UUIDs in the output
1014 # are replaced by markers of the form <N> where N is a number. The
1015 # first unique UUID is replaced by <0>, the next by <1>, and so on.
1016 # If a given UUID appears more than once it is always replaced by the
1019 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
1020 m4_define([OVSDB_CHECK_EXECUTION],
1022 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
1023 AT_KEYWORDS([ovsdb server positive transient $5])
1025 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
1026 m4_foreach([txn], [$3],
1027 [AT_DATA([txnfile], [ovsdb-client transact unix:socket 'txn'
1029 AT_CHECK([ovsdb-server --remote=punix:socket db --run="sh txnfile"], [0], [stdout], [ignore])
1030 cat stdout >> output
1032 AT_CHECK([uuidfilt output], [0], [$4], [ignore])
1037 AT_BANNER([OVSDB -- ovsdb-server replication])
1039 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
1041 # Creates two databases with the given SCHEMA, and starts an ovsdb-server on
1043 # Runs each of the TRANSACTIONS (which should be a quoted list of
1044 # quoted strings) against one of the servers with ovsdb-client one at a
1045 # time. The server replicates its database to the other ovsdb-server.
1047 # Checks that the dump of both databases are the same.
1049 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
1050 m4_define([OVSDB_CHECK_EXECUTION],
1052 AT_KEYWORDS([ovsdb server tcp replication $5])
1054 AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1055 AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1057 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile --remote=punix:db.sock db1], [0], [ignore], [ignore])
1059 on_exit 'test ! -e pid || kill `cat pid`'
1061 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server2.log --pidfile=pid2 --remote=punix:db2.sock --unixctl=unixctl2 --sync-from=unix:db.sock db2], [0], [ignore], [ignore])
1062 on_exit 'test ! -e pid2 || kill `cat pid2`'
1064 m4_foreach([txn], [$3],
1065 [AT_CHECK([ovsdb-client transact 'txn'], [0], [stdout], [ignore])
1068 AT_CHECK([ovsdb-client dump], [0], [stdout], [ignore])
1069 OVS_WAIT_UNTIL([ ovsdb-client dump unix:db2.sock > dump2; diff stdout dump2])
1071 OVSDB_SERVER_SHUTDOWN
1072 OVSDB_SERVER_SHUTDOWN2
1077 AT_BANNER([OVSDB -- ovsdb-server replication table-exclusion])
1079 # OVSDB_CHECK_REPLICATION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
1081 # Creates two databases with the given SCHEMA, and starts an
1082 # ovsdb-server on each database.
1083 # Runs each of the TRANSACTIONS (which should be a quoted list of
1084 # quoted strings) against one of the servers with ovsdb-client one at a
1085 # time. The server replicates its database to the other ovsdb-server.
1087 # Checks that the difference between the dump of the databases is
1088 # OUTPUT, but UUIDs in the output are replaced by markers of the form
1089 # <N> where N is a number. The first unique UUID is replaced by <0>,
1090 # the next by <1>, and so on.
1091 # If a given UUID appears more than once it is always replaced by the
1094 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
1095 m4_define([OVSDB_CHECK_REPLICATION],
1097 AT_KEYWORDS([ovsdb server tcp replication table-exclusion])
1099 AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1100 AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1102 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile --remote=punix:db.sock db1], [0], [ignore], [ignore])
1103 on_exit 'test ! -e pid || kill `cat pid`'
1105 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server2.log --pidfile=pid2 --remote=punix:db2.sock --unixctl=unixctl2 --sync-from=unix:db.sock --sync-exclude-tables=mydb:b db2], [0], [ignore], [ignore])
1106 on_exit 'test ! -e pid2 || kill `cat pid2`'
1108 m4_foreach([txn], [$3],
1109 [AT_CHECK([ ovsdb-client transact 'txn' ], [0], [stdout], [ignore])
1112 AT_CHECK([ovsdb-client dump], [0], [stdout], [ignore])
1115 OVS_WAIT_UNTIL([ ovsdb-client dump unix:db2.sock | grep one ])
1116 AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore])
1119 AT_CHECK([diff dump1 dump2], [1], [stdout], [ignore])
1122 AT_CHECK([uuidfilt output], [0], [$4], [ignore])
1124 OVSDB_SERVER_SHUTDOWN
1125 OVSDB_SERVER_SHUTDOWN2
1128 REPLICATION_EXAMPLES
1130 AT_BANNER([OVSDB -- ovsdb-server replication runtime management commands])
1132 #ovsdb-server/get-active-ovsdb-server command
1133 AT_SETUP([ovsdb-server/get-active-ovsdb-server])
1134 AT_KEYWORDS([ovsdb server replication get-active])
1135 ordinal_schema > schema
1136 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
1137 on_exit 'kill `cat *.pid`'
1138 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --sync-from=tcp:127.0.0.1:9999 db])
1140 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/get-active-ovsdb-server],
1141 [0], [tcp:127.0.0.1:9999
1145 #*ovsdb-server/set-active-ovsdb-server command
1146 AT_SETUP([ovsdb-server/set-active-ovsdb-server])
1147 AT_KEYWORDS([ovsdb server replication set-active])
1148 ordinal_schema > schema
1149 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
1150 on_exit 'kill `cat *.pid`'
1151 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile db])
1153 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/set-active-ovsdb-server tcp:127.0.0.1:9999])
1154 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/get-active-ovsdb-server],
1155 [0], [tcp:127.0.0.1:9999
1159 #ovsdb-server/get-sync-exclude-tables command
1160 AT_SETUP([ovsdb-server/get-sync-exclude-tables])
1161 AT_KEYWORDS([ovsdb server replication get-exclude-tables])
1162 ordinal_schema > schema
1163 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
1164 on_exit 'kill `cat *.pid`'
1165 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --sync-exclude-tables=mydb:db1,mydb:db2 db])
1167 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/get-sync-exclude-tables],
1168 [0], [mydb:db1,mydb:db2
1172 #ovsdb-server/set-sync-exclude-tables command
1173 AT_SETUP([ovsdb-server/set-sync-exclude-tables])
1174 AT_KEYWORDS([ovsdb server replication set-exclude-tables])
1175 replication_schema > schema
1176 AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1177 AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1179 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile --remote=punix:db.sock db1], [0], [ignore], [ignore])
1180 on_exit 'test ! -e pid || kill `cat pid`'
1182 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server2.log --pidfile=pid2 --remote=punix:db2.sock --unixctl=unixctl2 --sync-from=unix:db.sock db2], [0], [ignore], [ignore])
1183 on_exit 'test ! -e pid2 || kill `cat pid2`'
1185 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/set-sync-exclude-tables mydb:b], [0], [ignore], [ignore], [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1187 AT_CHECK([ovsdb-client transact unix:db.sock \
1191 "row": {"number": 0, "name": "zero"}},
1194 "row": {"number": 1, "name": "one"}}]]'], [0], [stdout], [ignore],
1195 [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1197 AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout], [ignore],
1198 [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1200 OVS_WAIT_UNTIL([ ovsdb-client dump unix:db2.sock | grep zero ])
1201 AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore])
1204 AT_CHECK([diff dump1 dump2], [1], [stdout], [ignore])
1207 AT_CHECK([uuidfilt output], [0], [7,9c7,8
1209 < ------------------------------------ ---- ------
1216 OVSDB_SERVER_SHUTDOWN
1217 OVSDB_SERVER_SHUTDOWN2
1220 #ovsdb-server/connect-active-ovsdb-server
1221 AT_SETUP([ovsdb-server/connect-active-server])
1222 AT_KEYWORDS([ovsdb server replication connect-active-server])
1223 replication_schema > schema
1224 AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1225 AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1227 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile --remote=punix:db.sock db1], [0], [ignore], [ignore])
1228 on_exit 'test ! -e pid || kill `cat pid`'
1230 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server2.log --pidfile=pid2 --remote=punix:db2.sock --unixctl=unixctl2 db2], [0], [ignore], [ignore])
1231 on_exit 'test ! -e pid2 || kill `cat pid2`'
1233 dnl Try to connect without specifying the active server.
1234 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/connect-active-ovsdb-server], [0],
1235 [Unable to connect: active server is not specified.
1238 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/set-active-ovsdb-server unix:db.sock], [0], [stdout], [ignore])
1240 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/connect-active-ovsdb-server], [0], [stdout], [ignore])
1242 AT_CHECK([ovsdb-client transact unix:db.sock \
1246 "row": {"number": 0, "name": "zero"}}]]'], [0], [stdout], [ignore])
1248 AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout], [ignore])
1250 OVS_WAIT_UNTIL([ ovsdb-client dump unix:db2.sock | grep zero ])
1251 AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore])
1254 AT_CHECK([diff dump1 dump2], [0], [], [ignore])
1255 OVSDB_SERVER_SHUTDOWN
1256 OVSDB_SERVER_SHUTDOWN2
1259 #ovsdb-server/disconnect-active-server command
1260 AT_SETUP([ovsdb-server/disconnect-active-server])
1261 AT_KEYWORDS([ovsdb server replication disconnect-active-server])
1262 replication_schema > schema
1263 AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1264 AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1266 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile --remote=punix:db.sock db1], [0], [ignore], [ignore])
1267 on_exit 'test ! -e pid || kill `cat pid`'
1269 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server2.log --pidfile=pid2 --remote=punix:db2.sock --unixctl=unixctl2 --sync-from=unix:db.sock db2], [0], [ignore], [ignore])
1270 on_exit 'test ! -e pid2 || kill `cat pid2`'
1272 AT_CHECK([ovsdb-client transact unix:db.sock \
1276 "row": {"number": 0, "name": "zero"}}]]'], [0], [stdout], [ignore])
1278 dnl Make sure the transaction shows up in db2. This also tests the back up server
1280 OVS_WAIT_UNTIL([ovsdb-client dump unix:db2.sock | grep zero])
1282 dnl The backup server does not accept any write transaction
1283 AT_CHECK([ovsdb-client transact unix:db2.sock \
1287 "row": {"number": 1, "name": "one"}}]]'], [0],
1288 [[[{"details":"insert operation not allowed when database server is in read only mode","error":"not allowed"}]]
1291 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/disconnect-active-ovsdb-server], [0], [ignore], [ignore])
1293 AT_CHECK([ovsdb-client transact unix:db.sock \
1297 "row": {"number": 1, "name": "one"}}]]'], [0], [stdout], [ignore])
1299 AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout], [ignore])
1303 AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore])
1306 AT_CHECK([diff dump1 dump2], [1], [stdout], [ignore])
1309 AT_CHECK([uuidfilt output], [0], [7,9c7,8
1311 < ------------------------------------ ---- ------
1316 ], [ignore], [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1318 dnl The backup server now become active, and can accept write transactions.
1319 AT_CHECK([ovsdb-client transact unix:db2.sock \
1323 "row": {"number": 1, "name": "one"}}]]'], [0], [stdout], [ignore])
1325 AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout])
1328 AT_CHECK([uuidfilt output], [0], [a table
1330 ------------------------------------ ---- ------
1335 ------------------------------------ ---- ------
1339 OVSDB_SERVER_SHUTDOWN
1340 OVSDB_SERVER_SHUTDOWN2
1343 #ovsdb-server/active-backup-role-switching
1344 AT_SETUP([ovsdb-server/active-backup-role-switching])
1345 AT_KEYWORDS([ovsdb server replication active-backup-switching])
1346 replication_schema > schema
1347 AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1348 AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1350 dnl Add some data to both DBs
1351 AT_CHECK([ovsdb-tool transact db1 \
1355 "row": {"number": 9, "name": "nine"}}]]'], [0], [ignore], [ignore])
1357 AT_CHECK([ovsdb-tool transact db2 \
1361 "row": {"number": 9, "name": "nine"}}]]'], [0], [ignore], [ignore])
1363 dnl Start both 'db1' and 'db2' in backup mode. Let them backup from each
1364 dnl other. This is not an supported operation state, but to simulate a start
1365 dnl up condition where an HA manger can select which one to be an active
1366 dnl server soon after.
1367 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile="`pwd`"/pid --remote=punix:db.sock --unixctl="`pwd`"/unixctl db1 --sync-from=unix:db2.sock --active ], [0], [ignore], [ignore])
1368 on_exit 'test ! -e pid || kill `cat pid`'
1370 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/connect-active-ovsdb-server])
1372 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server2.log --pidfile="`pwd`"/pid2 --remote=punix:db2.sock --unixctl="`pwd`"/unixctl2 --sync-from=unix:db.sock db2], [0], [ignore], [ignore])
1373 on_exit 'test ! -e pid2 || kill `cat pid2`'
1376 dnl make sure both servers reached the replication state
1377 OVS_WAIT_UNTIL([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/sync-status |grep replicating])
1378 OVS_WAIT_UNTIL([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/sync-status |grep replicating])
1380 dnl Switch the 'db1' to active
1381 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/disconnect-active-ovsdb-server])
1382 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/sync-status], [0], [state: active
1385 dnl Issue a transaction to 'db1'
1386 AT_CHECK([ovsdb-client transact unix:db.sock \
1390 "row": {"number": 0, "name": "zero"}}]]'], [0], [ignore])
1392 dnl It should be replicated to 'db2'
1393 OVS_WAIT_UNTIL([ovsdb-client dump unix:db2.sock | grep zero])
1395 dnl Flip the role of 'db1' and 'db2'. 'db1' becomes backup, and db2 becomes active
1396 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/disconnect-active-ovsdb-server])
1397 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/connect-active-ovsdb-server])
1399 dnl Verify the change happend
1400 OVS_WAIT_UNTIL([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/sync-status |grep replicating])
1401 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/sync-status], [0], [state: active
1404 dnl Issue an transaction to 'db2' which is now active.
1405 AT_CHECK([ovsdb-client transact unix:db2.sock \
1409 "row": {"number": 1, "name": "one"}}]]'], [0], [ignore])
1411 dnl The transaction should be replicated to 'db1'
1412 OVS_WAIT_UNTIL([ovsdb-client dump unix:db.sock | grep one])
1414 dnl Both servers should have the same content.
1415 AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout])
1418 AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout])
1421 AT_CHECK([diff dump1 dump2])
1423 dnl OVSDB_SERVER_SHUTDOWN
1424 dnl OVSDB_SERVER_SHUTDOWN2
1427 #ovsdb-server prevent self replicating
1428 AT_SETUP([ovsdb-server prevent self replicating])
1429 AT_KEYWORDS([ovsdb server replication])
1430 replication_schema > schema
1431 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
1433 dnl Add some data to both DBs
1434 AT_CHECK([ovsdb-tool transact db \
1438 "row": {"number": 9, "name": "nine"}}]]'], [0], [ignore], [ignore])
1440 dnl Start 'db', then try to be a back up server of itself.
1441 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server.log --pidfile="`pwd`"/pid --remote=punix:db.sock --unixctl="`pwd`"/unixctl db --sync-from=unix:db.sock --active ], [0], [ignore], [ignore])
1442 on_exit 'test ! -e pid || kill `cat pid`'
1444 dnl Save the current content
1445 AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout])
1448 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/connect-active-ovsdb-server])
1449 dnl Check that self replicating is blocked.
1450 AT_CHECK([grep "Self replicating is not allowed" ovsdb-server.log], [0], [stdout])
1452 dnl Check current DB content is preserved.
1453 AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout])
1456 AT_CHECK([diff dump1 dump2])
1459 AT_SETUP([ovsdb-server/read-only db:ptcp connection])
1460 AT_KEYWORDS([ovsdb server read-only])
1468 "key": {"type": "uuid", "refTable": "Manager"},
1470 "max": "unlimited"}}}},
1487 "number": {"type": "integer"},
1488 "name": {"type": "string"}},
1489 "indexes": [["number"]]}
1492 "cksum": "12345678 9"
1495 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
1497 [[ovsdb-tool transact db \
1502 "managers": ["set", [["named-uuid", "x"]]]}},
1506 "row": {"target": "ptcp:0:127.0.0.1",
1507 "read_only": true}}]']], [0], [ignore], [ignore])
1509 AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile --remote=db:mydb,Root,managers db], [0], [ignore], [ignore])
1510 PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
1511 AT_CHECK([ovsdb-client get-schema-version tcp:127.0.0.1:$TCP_PORT mydb], [0], [5.1.3
1514 AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT \
1517 "table": "ordinals",
1518 "row": {"name": "two", "number": '2'}}
1519 ]']], [0], [stdout], [ignore])
1520 cat stdout >> output
1521 AT_CHECK([uuidfilt output], [0], [[[{"details":"insert operation not allowed when database server is in read only mode","error":"not allowed"}]]
1523 OVSDB_SERVER_SHUTDOWN