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 --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 --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 --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 --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 --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
252 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
253 AT_CHECK([ovsdb-server --detach --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=punix:socket --log-file="`pwd`"/ovsdb-server.log db], [0], [ignore], [ignore])
254 AT_CAPTURE_FILE([ovsdb-server.log])
255 dnl Do a bunch of random transactions that put crap in the database log.
257 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
259 ovsdb-client transact unix:socket '
263 "row": {"name": "'$1'", "number": '$2'}},
265 "comment": "add row for '"$pair"'"}]'
266 ovsdb-client transact unix:socket '
270 "where": [["number", "==", '$2']]},
272 "comment": "delete row for '"$2"'"}]'
273 ovsdb-client transact unix:socket '
277 "row": {"name": "'$1'", "number": '$2'}},
279 "comment": "add back row for '"$pair"'"}]'
281 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
282 dnl Check that all the crap is in fact in the database log.
283 AT_CHECK([[perl $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | test-json --multiple -]], [0],
284 [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"}
285 {"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
286 {"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
287 {"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
288 {"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
289 {"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
290 {"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
291 {"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
292 {"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
293 {"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
294 {"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
295 {"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
296 {"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
297 {"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
298 {"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
299 {"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
300 {"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
301 {"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
302 {"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
303 ]], [], [test ! -e pid || kill `cat pid`])
304 dnl Dump out and check the actual database contents.
305 AT_CHECK([[ovsdb-client dump unix:socket ordinals]],
306 [0], [stdout], [ignore])
307 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
310 ------------------------------------ ----- ------
317 ], [], [test ! -e pid || kill `cat pid`])
318 dnl Now compact the database in-place.
319 AT_CHECK([[ovs-appctl -t "`pwd`"/unixctl ovsdb-server/compact]],
320 [0], [], [ignore], [test ! -e pid || kill `cat pid`])
321 dnl We can't fully re-check the contents of the database log, because the
322 dnl order of the records is not predictable, but there should only be 4 lines
324 AT_CAPTURE_FILE([db])
325 AT_CHECK([wc -l < db], [0], [4
326 ], [], [test ! -e pid || kill `cat pid`])
327 dnl And check that the dumped data is the same too:
328 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
329 [test ! -e pid || kill `cat pid`])
330 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
333 ------------------------------------ ----- ------
340 ], [], [test ! -e pid || kill `cat pid`])
341 dnl Now do some more transactions.
343 [[ovsdb-client transact unix:socket '
347 "where": [["number", "<", 3]]}]']],
349 ]], [ignore], [test ! -e pid || kill `cat pid`])
350 dnl There should be 6 lines in the log now.
351 AT_CHECK([wc -l < db], [0], [6
352 ], [], [test ! -e pid || kill `cat pid`])
353 dnl Then check that the dumped data is correct.
354 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
355 [test ! -e pid || kill `cat pid`])
356 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
359 ------------------------------------ ----- ------
363 ], [], [test ! -e pid || kill `cat pid`])
364 OVSDB_SERVER_SHUTDOWN
367 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL sockets)])
369 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
371 # Creates a database with the given SCHEMA, starts an ovsdb-server on
372 # that database, and runs each of the TRANSACTIONS (which should be a
373 # quoted list of quoted strings) against it with ovsdb-client one at a
376 # Checks that the overall output is OUTPUT, but UUIDs in the output
377 # are replaced by markers of the form <N> where N is a number. The
378 # first unique UUID is replaced by <0>, the next by <1>, and so on.
379 # If a given UUID appears more than once it is always replaced by the
382 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
383 m4_define([OVSDB_CHECK_EXECUTION],
385 AT_KEYWORDS([ovsdb server positive ssl $5])
386 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
388 AT_CHECK([perl $srcdir/choose-port.pl], [0], [stdout])
389 SSL_PORT=`cat stdout`
390 PKIDIR=$abs_top_builddir/tests
391 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
392 AT_CHECK([ovsdb-server --detach --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])
393 m4_foreach([txn], [$3],
394 [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],
395 [test ! -e pid || kill `cat pid`])
398 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
399 [test ! -e pid || kill `cat pid`])
400 OVSDB_SERVER_SHUTDOWN
405 AT_BANNER([OVSDB -- transactions on transient ovsdb-server])
407 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
409 # Creates a database with the given SCHEMA and runs each of the
410 # TRANSACTIONS (which should be a quoted list of quoted strings)
411 # against it with ovsdb-client one at a time. Each ovsdb-client
412 # is run against a separately started ovsdb-server that executes
413 # only that single transaction. (The idea is that this should
414 # help to ferret out any differences between what ovsdb-server has
415 # in memory and what actually gets committed to disk.)
417 # Checks that the overall output is OUTPUT, but UUIDs in the output
418 # are replaced by markers of the form <N> where N is a number. The
419 # first unique UUID is replaced by <0>, the next by <1>, and so on.
420 # If a given UUID appears more than once it is always replaced by the
423 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
424 m4_define([OVSDB_CHECK_EXECUTION],
426 AT_KEYWORDS([ovsdb server positive transient $5])
428 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
429 m4_foreach([txn], [$3],
430 [AT_DATA([txnfile], [ovsdb-client transact unix:socket 'txn'
432 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [ignore])
435 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore])