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 AT_KEYWORDS([ovsdb server positive unix $5])
26 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
27 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
28 m4_foreach([txn], [$3],
29 [AT_CHECK([ovsdb-client transact unix:socket 'txn'], [0], [stdout], [ignore],
30 [test ! -e pid || kill `cat pid`])
33 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
34 [test ! -e pid || kill `cat pid`])
40 AT_SETUP([truncating corrupted database log])
41 AT_KEYWORDS([ovsdb server positive unix])
42 ordinal_schema > schema
43 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
44 dnl Do one transaction and save the output.
45 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
49 "row": {"number": 0, "name": "zero"}}]'
51 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
53 dnl Add some crap to the database log and run another transaction, which should
54 dnl ignore the crap and truncate it out of the log.
56 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
60 "row": {"number": 1, "name": "one"}}]'
62 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [stderr])
63 AT_CHECK([grep 'syntax error: db: parse error.* in header line "xxx"' stderr],
66 dnl Run a final transaction to verify that both transactions succeeeded.
67 dnl The crap that we added should have been truncated by the previous run,
68 dnl so ovsdb-server shouldn't log a warning this time.
69 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
76 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
78 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0],
79 [[[{"uuid":["uuid","<0>"]}]
80 [{"uuid":["uuid","<1>"]}]
81 [{"rows":[{"_uuid":["uuid","<0>"],"_version":["uuid","<2>"],"name":"zero","number":0},{"_uuid":["uuid","<1>"],"_version":["uuid","<3>"],"name":"one","number":1}]}]
83 [test ! -e pid || kill `cat pid`])
86 AT_SETUP([truncating database log with bad transaction])
87 AT_KEYWORDS([ovsdb server positive unix])
88 ordinal_schema > schema
89 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
90 dnl Do one transaction and save the output.
91 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
95 "row": {"number": 0, "name": "zero"}}]'
97 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
99 dnl Add some crap to the database log and run another transaction, which should
100 dnl ignore the crap and truncate it out of the log.
101 echo 'OVSDB JSON 15 ffbcdae4b0386265f9ea3280dd7c8f0b72a20e56
102 {"invalid":{}}' >> db
103 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
107 "row": {"number": 1, "name": "one"}}]'
109 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [stderr])
110 AT_CHECK([grep 'syntax "{"invalid":{}}": unknown table: No table named invalid.' stderr],
113 dnl Run a final transaction to verify that both transactions succeeeded.
114 dnl The crap that we added should have been truncated by the previous run,
115 dnl so ovsdb-server shouldn't log a warning this time.
116 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
121 "sort": ["number"]}]'
123 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
125 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0],
126 [[[{"uuid":["uuid","<0>"]}]
127 [{"uuid":["uuid","<1>"]}]
128 [{"rows":[{"_uuid":["uuid","<0>"],"_version":["uuid","<2>"],"name":"zero","number":0},{"_uuid":["uuid","<1>"],"_version":["uuid","<3>"],"name":"one","number":1}]}]
130 [test ! -e pid || kill `cat pid`])
133 AT_SETUP([ovsdb-client get-schema-version])
134 AT_KEYWORDS([ovsdb server positive])
135 ordinal_schema > schema
136 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
137 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=punix:socket db], [0], [ignore], [ignore])
138 AT_CHECK([ovsdb-client get-schema-version unix:socket ordinals], [0], [5.1.3
140 OVSDB_SERVER_SHUTDOWN
143 AT_SETUP([database multiplexing implementation])
144 AT_KEYWORDS([ovsdb server positive])
145 ordinal_schema > schema
146 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
147 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=punix:socket db], [0], [ignore], [ignore])
149 [[ovsdb-client list-dbs unix:socket]],
151 ], [ignore], [test ! -e pid || kill `cat pid`])
153 [[test-jsonrpc request unix:socket get_schema [\"nonexistent\"]]], [0],
154 [[{"error":null,"id":0,"result":{"details":"get_schema request specifies unknown database nonexistent","error":"unknown database","syntax":"[\"nonexistent\"]"}}
155 ]], [], [test ! -e pid || kill `cat pid`])
156 OVSDB_SERVER_SHUTDOWN
159 AT_SETUP([--remote=db: implementation])
160 AT_KEYWORDS([ovsdb server positive])
166 "manager": {"type": "string"}}}}}
168 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
170 [[ovsdb-tool transact db \
174 "row": {"manager": "punix:socket"}}]']], [0], [ignore], [ignore])
175 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --remote=db:Manager,manager --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
177 [[ovsdb-client transact unix:socket \
182 "columns": ["manager"]}]']],
183 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
185 [perl $srcdir/uuidfilt.pl stdout],
187 [[[{"rows":[{"manager":"punix:socket"}]}]
190 [test ! -e pid || kill `cat pid`])
191 OVSDB_SERVER_SHUTDOWN
194 AT_SETUP([SSL db: implementation])
195 AT_KEYWORDS([ovsdb server positive ssl $5])
196 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
197 PKIDIR=$abs_top_builddir/tests
198 AT_SKIP_IF([expr "$PKIDIR" : ".*[ '\"
205 "private_key": {"type": "string"},
206 "certificate": {"type": "string"},
207 "ca_cert": {"type": "string"}}}}}
209 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
211 [[ovsdb-tool transact db \
215 "row": {"private_key": "'"$PKIDIR/testpki-privkey2.pem"'",
216 "certificate": "'"$PKIDIR/testpki-cert2.pem"'",
217 "ca_cert": "'"$PKIDIR/testpki-cacert.pem"'"}}]']],
218 [0], [ignore], [ignore])
219 AT_CHECK([perl $srcdir/choose-port.pl], [0], [stdout])
220 SSL_PORT=`cat stdout`
222 [ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid \
223 --private-key=db:SSL,private_key \
224 --certificate=db:SSL,certificate \
225 --ca-cert=db:SSL,ca_cert \
226 --remote=pssl:$SSL_PORT:127.0.0.1 --unixctl="`pwd`"/unixctl db],
227 [0], [ignore], [ignore])
230 --private-key=$PKIDIR/testpki-privkey.pem \
231 --certificate=$PKIDIR/testpki-cert.pem \
232 --ca-cert=$PKIDIR/testpki-cacert.pem \
233 transact ssl:127.0.0.1:$SSL_PORT \
238 "columns": ["private_key"]}]']],
239 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
242 [perl $srcdir/uuidfilt.pl output], [0],
243 [[[{"rows":[{"private_key":"$PKIDIR/testpki-privkey2.pem"}]}]
244 ]], [ignore], [test ! -e pid || kill `cat pid`])
245 OVSDB_SERVER_SHUTDOWN
248 AT_SETUP([compacting online])
249 AT_KEYWORDS([ovsdb server compact])
250 ordinal_schema > schema
251 dnl Make sure that "ovsdb-tool create" works with a dangling symlink for
252 dnl the database and the lockfile, creating the target of each symlink rather
253 dnl than replacing the symlinks with regular files.
256 ln -s dir/.db.~lock~ .db.~lock~
257 AT_SKIP_IF([test ! -h db || test ! -h .db.~lock~])
258 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
259 dnl Start ovsdb-server.
260 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])
261 AT_CAPTURE_FILE([ovsdb-server.log])
262 dnl Do a bunch of random transactions that put crap in the database log.
264 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
266 ovsdb-client transact unix:socket '
270 "row": {"name": "'$1'", "number": '$2'}},
272 "comment": "add row for '"$pair"'"}]'
273 ovsdb-client transact unix:socket '
277 "where": [["number", "==", '$2']]},
279 "comment": "delete row for '"$2"'"}]'
280 ovsdb-client transact unix:socket '
284 "row": {"name": "'$1'", "number": '$2'}},
286 "comment": "add back row for '"$pair"'"}]'
288 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
289 dnl Check that all the crap is in fact in the database log.
290 AT_CHECK([[perl $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | test-json --multiple -]], [0],
291 [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"}
292 {"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
293 {"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
294 {"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
295 {"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
296 {"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
297 {"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
298 {"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
299 {"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
300 {"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
301 {"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
302 {"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
303 {"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
304 {"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
305 {"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
306 {"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
307 {"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
308 {"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
309 {"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
310 ]], [], [test ! -e pid || kill `cat pid`])
311 dnl Dump out and check the actual database contents.
312 AT_CHECK([[ovsdb-client dump unix:socket ordinals]],
313 [0], [stdout], [ignore])
314 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
317 ------------------------------------ ----- ------
324 ], [], [test ! -e pid || kill `cat pid`])
325 dnl Now compact the database in-place.
326 AT_CHECK([[ovs-appctl -t "`pwd`"/unixctl ovsdb-server/compact]],
327 [0], [], [ignore], [test ! -e pid || kill `cat pid`])
328 dnl Make sure that "db" is still a symlink to dir/db instead of getting
329 dnl replaced by a regular file, ditto for .db.~lock~.
330 AT_CHECK([test -h db])
331 AT_CHECK([test -h .db.~lock~])
332 AT_CHECK([test -f dir/db])
333 AT_CHECK([test -f dir/.db.~lock~])
334 dnl We can't fully re-check the contents of the database log, because the
335 dnl order of the records is not predictable, but there should only be 4 lines
337 AT_CAPTURE_FILE([db])
338 AT_CHECK([test `wc -l < db` -eq 4], [0], [], [],
339 [test ! -e pid || kill `cat pid`])
340 dnl And check that the dumped data is the same too:
341 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
342 [test ! -e pid || kill `cat pid`])
343 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
346 ------------------------------------ ----- ------
353 ], [], [test ! -e pid || kill `cat pid`])
354 dnl Now do some more transactions.
356 [[ovsdb-client transact unix:socket '
360 "where": [["number", "<", 3]]}]']],
362 ]], [ignore], [test ! -e pid || kill `cat pid`])
363 dnl There should be 6 lines in the log now.
364 AT_CHECK([test `wc -l < db` -eq 6], [0], [], [],
365 [test ! -e pid || kill `cat pid`])
366 dnl Then check that the dumped data is correct.
367 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
368 [test ! -e pid || kill `cat pid`])
369 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
372 ------------------------------------ ----- ------
376 ], [], [test ! -e pid || kill `cat pid`])
377 OVSDB_SERVER_SHUTDOWN
380 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL sockets)])
382 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
384 # Creates a database with the given SCHEMA, starts an ovsdb-server on
385 # that database, and runs each of the TRANSACTIONS (which should be a
386 # quoted list of quoted strings) against it with ovsdb-client one at a
389 # Checks that the overall output is OUTPUT, but UUIDs in the output
390 # are replaced by markers of the form <N> where N is a number. The
391 # first unique UUID is replaced by <0>, the next by <1>, and so on.
392 # If a given UUID appears more than once it is always replaced by the
395 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
396 m4_define([OVSDB_CHECK_EXECUTION],
398 AT_KEYWORDS([ovsdb server positive ssl $5])
399 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
401 AT_CHECK([perl $srcdir/choose-port.pl], [0], [stdout])
402 SSL_PORT=`cat stdout`
403 PKIDIR=$abs_top_builddir/tests
404 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
405 AT_CHECK([ovsdb-server --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:$SSL_PORT:127.0.0.1 --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
406 m4_foreach([txn], [$3],
407 [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],
408 [test ! -e pid || kill `cat pid`])
411 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
412 [test ! -e pid || kill `cat pid`])
413 OVSDB_SERVER_SHUTDOWN
418 AT_BANNER([OVSDB -- transactions on transient ovsdb-server])
420 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
422 # Creates a database with the given SCHEMA and runs each of the
423 # TRANSACTIONS (which should be a quoted list of quoted strings)
424 # against it with ovsdb-client one at a time. Each ovsdb-client
425 # is run against a separately started ovsdb-server that executes
426 # only that single transaction. (The idea is that this should
427 # help to ferret out any differences between what ovsdb-server has
428 # in memory and what actually gets committed to disk.)
430 # Checks that the overall output is OUTPUT, but UUIDs in the output
431 # are replaced by markers of the form <N> where N is a number. The
432 # first unique UUID is replaced by <0>, the next by <1>, and so on.
433 # If a given UUID appears more than once it is always replaced by the
436 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
437 m4_define([OVSDB_CHECK_EXECUTION],
439 AT_KEYWORDS([ovsdb server positive transient $5])
441 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
442 m4_foreach([txn], [$3],
443 [AT_DATA([txnfile], [ovsdb-client transact unix:socket 'txn'
445 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [ignore])
448 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore])