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])
27 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
28 AT_CHECK([ovsdb-server --detach --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_SETUP([truncating corrupted database log])
42 AT_KEYWORDS([ovsdb server positive unix])
43 AT_DATA([schema], [ORDINAL_SCHEMA
45 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
46 dnl Do one transaction and save the output.
47 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
51 "row": {"number": 0, "name": "zero"}}]'
53 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl=$PWD/unixctl db --run="sh txnfile"], [0], [stdout], [])
55 dnl Add some crap to the database log and run another transaction, which should
56 dnl ignore the crap and truncate it out of the log.
58 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
62 "row": {"number": 1, "name": "one"}}]'
64 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl=$PWD/unixctl db --run="sh txnfile"], [0], [stdout], [stderr])
65 AT_CHECK([grep 'syntax error: db: parse error.* in header line "xxx"' stderr],
68 dnl Run a final transaction to verify that both transactions succeeeded.
69 dnl The crap that we added should have been truncated by the previous run,
70 dnl so ovsdb-server shouldn't log a warning this time.
71 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
78 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl=$PWD/unixctl db --run="sh txnfile"], [0], [stdout], [])
80 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0],
81 [[[{"uuid":["uuid","<0>"]}]
82 [{"uuid":["uuid","<1>"]}]
83 [{"rows":[{"_uuid":["uuid","<0>"],"_version":["uuid","<2>"],"name":"zero","number":0},{"_uuid":["uuid","<1>"],"_version":["uuid","<3>"],"name":"one","number":1}]}]
85 [test ! -e pid || kill `cat pid`])
88 AT_SETUP([ovsdb-client get-schema-version])
89 AT_KEYWORDS([ovsdb server positive])
90 AT_DATA([schema], [ORDINAL_SCHEMA
92 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
93 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --unixctl=$PWD/unixctl --remote=punix:socket db], [0], [ignore], [ignore])
94 AT_CHECK([ovsdb-client get-schema-version unix:socket ordinals], [0], [5.1.3
99 AT_SETUP([database multiplexing implementation])
100 AT_KEYWORDS([ovsdb server positive])
101 AT_DATA([schema], [ORDINAL_SCHEMA
103 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
104 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --unixctl=$PWD/unixctl --remote=punix:socket db], [0], [ignore], [ignore])
106 [[ovsdb-client list-dbs unix:socket]],
108 ], [ignore], [test ! -e pid || kill `cat pid`])
110 [[ovsdb-client get-schema unix:socket nonexistent]],
111 [1], [], [[ovsdb-client: syntax "{"details":"get_schema request specifies unknown database nonexistent","error":"unknown database","syntax":"[\"nonexistent\"]"}": syntax error: Parsing database schema failed: Required 'name' member is missing.
112 ]], [test ! -e pid || kill `cat pid`])
113 OVSDB_SERVER_SHUTDOWN
116 AT_SETUP([--remote=db: implementation])
117 AT_KEYWORDS([ovsdb server positive])
123 "manager": {"type": "string"}}}}}
125 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
127 [[ovsdb-tool transact db \
131 "row": {"manager": "punix:socket"}}]']], [0], [ignore], [ignore])
132 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --remote=db:Manager,manager --unixctl=$PWD/unixctl db], [0], [ignore], [ignore])
134 [[ovsdb-client transact unix:socket \
139 "columns": ["manager"]}]']],
140 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
142 [perl $srcdir/uuidfilt.pl stdout],
144 [[[{"rows":[{"manager":"punix:socket"}]}]
147 [test ! -e pid || kill `cat pid`])
148 OVSDB_SERVER_SHUTDOWN
151 AT_SETUP([SSL db: implementation])
152 AT_KEYWORDS([ovsdb server positive ssl $5])
153 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
154 AT_SKIP_IF([test "x$RANDOM" = x])
155 SSL_PORT=`expr 32767 + \( $RANDOM % 32767 \)`
156 PKIDIR=$abs_top_builddir/tests
157 AT_SKIP_IF([expr "$PKIDIR" : ".*[ '\"
164 "private_key": {"type": "string"},
165 "certificate": {"type": "string"},
166 "ca_cert": {"type": "string"}}}}}
168 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
170 [[ovsdb-tool transact db \
174 "row": {"private_key": "'"$PKIDIR/testpki-privkey2.pem"'",
175 "certificate": "'"$PKIDIR/testpki-cert2.pem"'",
176 "ca_cert": "'"$PKIDIR/testpki-cacert.pem"'"}}]']],
177 [0], [ignore], [ignore])
179 [ovsdb-server --detach --pidfile=$PWD/pid \
180 --private-key=db:SSL,private_key \
181 --certificate=db:SSL,certificate \
182 --ca-cert=db:SSL,ca_cert \
183 --remote=pssl:$SSL_PORT:127.0.0.1 --unixctl=$PWD/unixctl db],
184 [0], [ignore], [ignore])
187 --private-key=$PKIDIR/testpki-privkey.pem \
188 --certificate=$PKIDIR/testpki-cert.pem \
189 --ca-cert=$PKIDIR/testpki-cacert.pem \
190 transact ssl:127.0.0.1:$SSL_PORT \
195 "columns": ["private_key"]}]']],
196 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
199 [perl $srcdir/uuidfilt.pl output], [0],
200 [[[{"rows":[{"private_key":"$PKIDIR/testpki-privkey2.pem"}]}]
201 ]], [ignore], [test ! -e pid || kill `cat pid`])
202 OVSDB_SERVER_SHUTDOWN
205 AT_SETUP([compacting online])
206 AT_KEYWORDS([ovsdb server compact])
207 AT_DATA([schema], [ORDINAL_SCHEMA
210 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
211 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --unixctl=$PWD/unixctl --remote=punix:socket --log-file=$PWD/ovsdb-server.log db], [0], [ignore], [ignore])
212 AT_CAPTURE_FILE([ovsdb-server.log])
213 dnl Do a bunch of random transactions that put crap in the database log.
215 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
217 ovsdb-client transact unix:socket '
221 "row": {"name": "'$1'", "number": '$2'}},
223 "comment": "add row for '"$pair"'"}]'
224 ovsdb-client transact unix:socket '
228 "where": [["number", "==", '$2']]},
230 "comment": "delete row for '"$2"'"}]'
231 ovsdb-client transact unix:socket '
235 "row": {"name": "'$1'", "number": '$2'}},
237 "comment": "add back row for '"$pair"'"}]'
239 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
240 dnl Check that all the crap is in fact in the database log.
241 AT_CHECK([[perl $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | test-json --multiple -]], [0],
242 [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}}}},"version":"5.1.3"}
243 {"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
244 {"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
245 {"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
246 {"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
247 {"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
248 {"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
249 {"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
250 {"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
251 {"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
252 {"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
253 {"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
254 {"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
255 {"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
256 {"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
257 {"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
258 {"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
259 {"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
260 {"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
261 ]], [], [test ! -e pid || kill `cat pid`])
262 dnl Dump out and check the actual database contents.
263 AT_CHECK([[ovsdb-client dump unix:socket ordinals]],
264 [0], [stdout], [ignore])
265 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
268 ------------------------------------ ----- ------
275 ], [], [test ! -e pid || kill `cat pid`])
276 dnl Now compact the database in-place.
277 AT_CHECK([[ovs-appctl -t $PWD/unixctl ovsdb-server/compact]],
278 [0], [], [ignore], [test ! -e pid || kill `cat pid`])
279 dnl We can't fully re-check the contents of the database log, because the
280 dnl order of the records is not predictable, but there should only be 4 lines
282 AT_CAPTURE_FILE([db])
283 AT_CHECK([wc -l < db], [0], [4
284 ], [], [test ! -e pid || kill `cat pid`])
285 dnl And check that the dumped data is the same too:
286 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
287 [test ! -e pid || kill `cat pid`])
288 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
291 ------------------------------------ ----- ------
298 ], [], [test ! -e pid || kill `cat pid`])
299 dnl Now do some more transactions.
301 [[ovsdb-client transact unix:socket '
305 "where": [["number", "<", 3]]}]']],
307 ]], [ignore], [test ! -e pid || kill `cat pid`])
308 dnl There should be 6 lines in the log now.
309 AT_CHECK([wc -l < db], [0], [6
310 ], [], [test ! -e pid || kill `cat pid`])
311 dnl Then check that the dumped data is correct.
312 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
313 [test ! -e pid || kill `cat pid`])
314 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
317 ------------------------------------ ----- ------
321 ], [], [test ! -e pid || kill `cat pid`])
322 OVSDB_SERVER_SHUTDOWN
325 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL sockets)])
327 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
329 # Creates a database with the given SCHEMA, starts an ovsdb-server on
330 # that database, and runs each of the TRANSACTIONS (which should be a
331 # quoted list of quoted strings) against it with ovsdb-client one at a
334 # Checks that the overall output is OUTPUT, but UUIDs in the output
335 # are replaced by markers of the form <N> where N is a number. The
336 # first unique UUID is replaced by <0>, the next by <1>, and so on.
337 # If a given UUID appears more than once it is always replaced by the
340 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
341 m4_define([OVSDB_CHECK_EXECUTION],
343 AT_KEYWORDS([ovsdb server positive ssl $5])
344 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
345 AT_SKIP_IF([test "x$RANDOM" = x])
346 AT_DATA([schema], [$2
348 SSL_PORT=`expr 32767 + \( $RANDOM % 32767 \)`
349 PKIDIR=$abs_top_builddir/tests
350 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
351 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])
352 m4_foreach([txn], [$3],
353 [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],
354 [test ! -e pid || kill `cat pid`])
357 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
358 [test ! -e pid || kill `cat pid`])
359 OVSDB_SERVER_SHUTDOWN
364 AT_BANNER([OVSDB -- transactions on transient ovsdb-server])
366 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
368 # Creates a database with the given SCHEMA and runs each of the
369 # TRANSACTIONS (which should be a quoted list of quoted strings)
370 # against it with ovsdb-client one at a time. Each ovsdb-client
371 # is run against a separately started ovsdb-server that executes
372 # only that single transaction. (The idea is that this should
373 # help to ferret out any differences between what ovsdb-server has
374 # in memory and what actually gets committed to disk.)
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 transient $5])
386 AT_DATA([schema], [$2
388 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
389 m4_foreach([txn], [$3],
390 [AT_DATA([txnfile], [ovsdb-client transact unix:socket 'txn'
392 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl=$PWD/unixctl db --run="sh txnfile"], [0], [stdout], [ignore])
395 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore])