ovsdb-server: Make database name mandatory when specifying db paths.
[sliver-openvswitch.git] / tests / ovsdb-server.at
1 AT_BANNER([OVSDB -- ovsdb-server transactions (Unix sockets)])
2
3 m4_define([OVSDB_SERVER_SHUTDOWN], 
4   [cp pid savepid
5    AT_CHECK([ovs-appctl -t "`pwd`"/unixctl -e exit], [0], [ignore], [ignore])
6    OVS_WAIT_WHILE([kill -0 `cat savepid`], [kill `cat savepid`])])
7
8 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
9 #
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
13 # time.
14 #
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
19 # same marker.
20 #
21 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
22 m4_define([OVSDB_CHECK_EXECUTION], 
23   [AT_SETUP([$1])
24   OVS_RUNDIR=`pwd`; export OVS_RUNDIR
25    AT_KEYWORDS([ovsdb server positive unix $5])
26    $2 > schema
27    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
28    AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
29    m4_foreach([txn], [$3], 
30      [AT_CHECK([ovsdb-client transact unix:socket 'txn'], [0], [stdout], [ignore],
31      [test ! -e pid || kill `cat pid`])
32 cat stdout >> output
33 ])
34    AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
35             [test ! -e pid || kill `cat pid`])
36    OVSDB_SERVER_SHUTDOWN
37    AT_CLEANUP])
38
39 EXECUTION_EXAMPLES
40 \f
41 AT_SETUP([truncating corrupted database log])
42 AT_KEYWORDS([ovsdb server positive unix])
43 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
44 ordinal_schema > 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 \
48 '["ordinals",
49   {"op": "insert",
50    "table": "ordinals",
51    "row": {"number": 0, "name": "zero"}}]'
52 ]])
53 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
54 cat stdout >> output
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.
57 echo 'xxx' >> db
58 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
59 '["ordinals",
60   {"op": "insert",
61    "table": "ordinals",
62    "row": {"number": 1, "name": "one"}}]'
63 ]])
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],
66   [0], [ignore])
67 cat stdout >> output
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 \
72 '["ordinals",
73   {"op": "select",
74    "table": "ordinals",
75    "where": [],
76    "sort": ["number"]}]'
77 ]])
78 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
79 cat stdout >> output
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}]}]
84 ]], [],
85          [test ! -e pid || kill `cat pid`])
86 AT_CLEANUP
87
88 AT_SETUP([truncating database log with bad transaction])
89 AT_KEYWORDS([ovsdb server positive unix])
90 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
91 ordinal_schema > schema
92 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
93 dnl Do one transaction and save the output.
94 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
95 '["ordinals",
96   {"op": "insert",
97    "table": "ordinals",
98    "row": {"number": 0, "name": "zero"}}]'
99 ]])
100 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
101 cat stdout >> output
102 dnl Add some crap to the database log and run another transaction, which should
103 dnl ignore the crap and truncate it out of the log.
104 echo 'OVSDB JSON 15 ffbcdae4b0386265f9ea3280dd7c8f0b72a20e56
105 {"invalid":{}}' >> db
106 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
107 '["ordinals",
108   {"op": "insert",
109    "table": "ordinals",
110    "row": {"number": 1, "name": "one"}}]'
111 ]])
112 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [stderr])
113 AT_CHECK([grep 'syntax "{"invalid":{}}": unknown table: No table named invalid.' stderr],
114   [0], [ignore])
115 cat stdout >> output
116 dnl Run a final transaction to verify that both transactions succeeeded.
117 dnl The crap that we added should have been truncated by the previous run,
118 dnl so ovsdb-server shouldn't log a warning this time.
119 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
120 '["ordinals",
121   {"op": "select",
122    "table": "ordinals",
123    "where": [],
124    "sort": ["number"]}]'
125 ]])
126 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
127 cat stdout >> output
128 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0],
129   [[[{"uuid":["uuid","<0>"]}]
130 [{"uuid":["uuid","<1>"]}]
131 [{"rows":[{"_uuid":["uuid","<0>"],"_version":["uuid","<2>"],"name":"zero","number":0},{"_uuid":["uuid","<1>"],"_version":["uuid","<3>"],"name":"one","number":1}]}]
132 ]], [],
133          [test ! -e pid || kill `cat pid`])
134 AT_CLEANUP
135
136 AT_SETUP([ovsdb-client get-schema-version])
137 AT_KEYWORDS([ovsdb server positive])
138 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
139 ordinal_schema > schema
140 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
141 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=punix:socket db], [0], [ignore], [ignore])
142 AT_CHECK([ovsdb-client get-schema-version unix:socket ordinals], [0], [5.1.3
143 ])
144 OVSDB_SERVER_SHUTDOWN
145 AT_CLEANUP
146
147 AT_SETUP([database multiplexing implementation])
148 AT_KEYWORDS([ovsdb server positive])
149 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
150 ordinal_schema > schema1
151 constraint_schema > schema2
152 AT_CHECK([ovsdb-tool create db1 schema1], [0], [ignore], [ignore])
153 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
154 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=punix:socket db1 db2], [0], [ignore], [ignore])
155 AT_CHECK(
156   [[ovsdb-client list-dbs unix:socket]], 
157   [0], [constraints
158 ordinals
159 ], [ignore], [test ! -e pid || kill `cat pid`])
160 AT_CHECK(
161   [[test-jsonrpc request unix:socket get_schema [\"nonexistent\"]]], [0],
162   [[{"error":null,"id":0,"result":{"details":"get_schema request specifies unknown database nonexistent","error":"unknown database","syntax":"[\"nonexistent\"]"}}
163 ]], [], [test ! -e pid || kill `cat pid`])
164 OVSDB_SERVER_SHUTDOWN
165 AT_CLEANUP
166
167 AT_SETUP([--remote=db: implementation])
168 AT_KEYWORDS([ovsdb server positive])
169 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
170 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
171 AT_DATA([schema],
172   [[{"name": "mydb",
173      "tables": {
174        "Root": {
175          "columns": {
176            "managers": {
177              "type": {
178                "key": "string",
179                "min": 0,
180                "max": "unlimited"}},
181            "manager_options": {
182              "type": {
183                "key": {"type": "uuid", "refTable": "Manager"},
184                "min": 0,
185                "max": "unlimited"}}}},
186        "Manager": {
187          "columns": {
188            "target": {
189              "type": "string"},
190            "is_connected": {
191              "type": {
192                "key": "boolean",
193                "min": 0,
194                "max": 1}}}}}}
195 ]])
196 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
197 AT_CHECK(
198   [[ovsdb-tool transact db \
199      '["mydb",
200        {"op": "insert",
201         "table": "Root",
202         "row": {
203           "managers": "punix:socket1",
204           "manager_options": ["set", [["named-uuid", "x"]]]}},
205        {"op": "insert",
206         "table": "Manager",
207         "uuid-name": "x",
208         "row": {"target": "punix:socket2"}}]']], [0], [ignore], [ignore])
209 ON_EXIT([kill `cat ovsdb-server.pid`])
210 AT_CHECK([ovsdb-server --enable-dummy --detach --no-chdir --pidfile --remote=db:mydb,Root,managers --remote=db:mydb,Root,manager_options --log-file db], [0], [ignore], [ignore])
211 for i in 1 2 3 4 5 6; do ovs-appctl -t ovsdb-server time/warp 1000; done
212 AT_CHECK(
213   [[ovsdb-client transact unix:socket1 \
214      '["mydb",
215        {"op": "select",
216         "table": "Root",
217         "where": [],
218         "columns": ["managers"]},
219        {"op": "select",
220         "table": "Manager",
221         "where": [],
222         "columns": ["target", "is_connected"]}]']],
223   [0], [stdout], [ignore])
224 AT_CHECK(
225   [${PERL} $srcdir/uuidfilt.pl stdout], 
226   [0], 
227   [[[{"rows":[{"managers":"punix:socket1"}]},{"rows":[{"is_connected":false,"target":"punix:socket2"}]}]
228 ]], 
229   [ignore])
230 AT_CLEANUP
231
232 AT_SETUP([ovsdb-server/add-remote and remove-remote])
233 AT_KEYWORDS([ovsdb server positive])
234 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
235 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
236 ordinal_schema > schema
237 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
238 ON_EXIT([kill `cat *.pid`])
239 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile db])
240
241 AT_CHECK([test ! -e socket1])
242 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
243 OVS_WAIT_UNTIL([test -S socket1])
244 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
245   [0], [punix:socket1
246 ])
247
248 AT_CHECK([test ! -e socket2])
249 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket2])
250 OVS_WAIT_UNTIL([test -S socket2])
251 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
252   [0], [punix:socket1
253 punix:socket2
254 ])
255
256 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote db:x,y,z], [2],
257   [], ["db:x,y,z": no database named x
258 ovs-appctl: ovsdb-server: server returned an error
259 ])
260
261 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
262 OVS_WAIT_UNTIL([test ! -e socket1])
263 AT_CHECK([test -S socket2])
264 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
265   [0], [punix:socket2
266 ])
267
268 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket2])
269 OVS_WAIT_UNTIL([test ! -e socket2])
270 AT_CHECK([test ! -e socket1])
271 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
272 AT_CLEANUP
273
274 AT_SETUP([ovsdb-server/add-remote and remove-remote with --monitor])
275 AT_KEYWORDS([ovsdb server positive])
276 # Start ovsdb-server, initially with no remotes.
277 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
278 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
279 ordinal_schema > schema
280 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
281 ON_EXIT([kill `cat *.pid`])
282 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db])
283
284 # Add a remote.
285 AT_CHECK([test ! -e socket1])
286 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
287 OVS_WAIT_UNTIL([test -S socket1])
288 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
289   [0], [punix:socket1
290 ])
291
292 # Kill the daemon process, making it look like a segfault,
293 # and wait for a new daemon process to get spawned and for it to
294 # start listening on 'socket1'.
295 cp ovsdb-server.pid old.pid
296 rm socket1
297 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
298 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
299 OVS_WAIT_UNTIL(
300   [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
301 OVS_WAIT_UNTIL([test -S socket1])
302
303 # Remove the remote.
304 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
305 OVS_WAIT_UNTIL([test ! -e socket1])
306 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
307
308 # Kill the daemon process, making it look like a segfault,
309 # and wait for a new daemon process to get spawned and make sure that it
310 # does not listen on 'socket1'.
311 cp ovsdb-server.pid old.pid
312 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
313 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
314 OVS_WAIT_UNTIL(
315   [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
316 AT_CHECK([test ! -e socket1])
317 AT_CLEANUP
318
319 AT_SETUP([SSL db: implementation])
320 AT_KEYWORDS([ovsdb server positive ssl $5])
321 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
322 PKIDIR=$abs_top_builddir/tests
323 AT_SKIP_IF([expr "$PKIDIR" : ".*[       '\"
324 \r\\]"])
325 AT_DATA([schema],
326   [[{"name": "mydb",
327      "tables": {
328        "SSL": {
329          "columns": {
330            "private_key": {"type": "string"},
331            "certificate": {"type": "string"},
332            "ca_cert": {"type": "string"}}}}}
333 ]])
334 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
335 AT_CHECK(
336   [[ovsdb-tool transact db \
337      '["mydb",
338        {"op": "insert",
339         "table": "SSL",
340         "row": {"private_key": "'"$PKIDIR/testpki-privkey2.pem"'",
341                 "certificate": "'"$PKIDIR/testpki-cert2.pem"'",
342                 "ca_cert": "'"$PKIDIR/testpki-cacert.pem"'"}}]']],
343   [0], [ignore], [ignore])
344 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
345 AT_CHECK(
346   [ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid \
347         --private-key=db:mydb,SSL,private_key \
348         --certificate=db:mydb,SSL,certificate \
349         --ca-cert=db:mydb,SSL,ca_cert \
350         --remote=pssl:0:127.0.0.1 --unixctl="`pwd`"/unixctl db],
351   [0], [ignore], [ignore])
352 SSL_PORT=`parse_listening_port < ovsdb-server.log`
353 AT_CHECK(
354   [[ovsdb-client \
355         --private-key=$PKIDIR/testpki-privkey.pem \
356         --certificate=$PKIDIR/testpki-cert.pem \
357         --ca-cert=$PKIDIR/testpki-cacert.pem \
358         transact ssl:127.0.0.1:$SSL_PORT \
359         '["mydb",
360           {"op": "select",
361            "table": "SSL",
362            "where": [],
363            "columns": ["private_key"]}]']], 
364   [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
365 cat stdout >> output
366 AT_CHECK_UNQUOTED(
367   [${PERL} $srcdir/uuidfilt.pl output], [0], 
368   [[[{"rows":[{"private_key":"$PKIDIR/testpki-privkey2.pem"}]}]
369 ]], [ignore], [test ! -e pid || kill `cat pid`])
370 OVSDB_SERVER_SHUTDOWN
371 AT_CLEANUP
372
373 AT_SETUP([compacting online])
374 AT_KEYWORDS([ovsdb server compact])
375 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
376 ordinal_schema > schema
377 dnl Make sure that "ovsdb-tool create" works with a dangling symlink for
378 dnl the database and the lockfile, creating the target of each symlink rather
379 dnl than replacing the symlinks with regular files.
380 mkdir dir
381 ln -s dir/db db
382 ln -s dir/.db.~lock~ .db.~lock~
383 AT_SKIP_IF([test ! -h db || test ! -h .db.~lock~])
384 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
385 dnl Start ovsdb-server.
386 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])
387 AT_CAPTURE_FILE([ovsdb-server.log])
388 dnl Do a bunch of random transactions that put crap in the database log.
389 AT_CHECK(
390   [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
391       set -- $pair
392       ovsdb-client transact unix:socket '
393         ["ordinals",
394          {"op": "insert",
395           "table": "ordinals",
396           "row": {"name": "'$1'", "number": '$2'}},
397          {"op": "comment",
398           "comment": "add row for '"$pair"'"}]'
399       ovsdb-client transact unix:socket '
400         ["ordinals",
401          {"op": "delete",
402           "table": "ordinals",
403           "where": [["number", "==", '$2']]},
404          {"op": "comment",
405           "comment": "delete row for '"$2"'"}]'
406       ovsdb-client transact unix:socket '
407         ["ordinals",
408          {"op": "insert",
409           "table": "ordinals",
410           "row": {"name": "'$1'", "number": '$2'}},
411          {"op": "comment",
412           "comment": "add back row for '"$pair"'"}]'
413     done]],
414   [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
415 dnl Check that all the crap is in fact in the database log.
416 AT_CHECK([[${PERL} $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | test-json --multiple -]], [0],
417   [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"}
418 {"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
419 {"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
420 {"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
421 {"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
422 {"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
423 {"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
424 {"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
425 {"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
426 {"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
427 {"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
428 {"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
429 {"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
430 {"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
431 {"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
432 {"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
433 {"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
434 {"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
435 {"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
436 ]], [], [test ! -e pid || kill `cat pid`])
437 dnl Dump out and check the actual database contents.
438 AT_CHECK([[ovsdb-client dump unix:socket ordinals]],
439   [0], [stdout], [ignore])
440 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
441 ordinals table
442 _uuid                                name  number
443 ------------------------------------ ----- ------
444 <0> five  5     @&t@
445 <1> four  4     @&t@
446 <2> one   1     @&t@
447 <3> three 3     @&t@
448 <4> two   2     @&t@
449 <5> zero  0     @&t@
450 ], [], [test ! -e pid || kill `cat pid`])
451 dnl Now compact the database in-place.
452 AT_CHECK([[ovs-appctl -t "`pwd`"/unixctl ovsdb-server/compact]],
453   [0], [], [ignore], [test ! -e pid || kill `cat pid`])
454 dnl Make sure that "db" is still a symlink to dir/db instead of getting
455 dnl replaced by a regular file, ditto for .db.~lock~.
456 AT_CHECK([test -h db])
457 AT_CHECK([test -h .db.~lock~])
458 AT_CHECK([test -f dir/db])
459 AT_CHECK([test -f dir/.db.~lock~])
460 dnl We can't fully re-check the contents of the database log, because the
461 dnl order of the records is not predictable, but there should only be 4 lines
462 dnl in it now.
463 AT_CAPTURE_FILE([db])
464 AT_CHECK([test `wc -l < db` -eq 4], [0], [], [],
465   [test ! -e pid || kill `cat pid`])
466 dnl And check that the dumped data is the same too:
467 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
468   [test ! -e pid || kill `cat pid`])
469 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
470 ordinals table
471 _uuid                                name  number
472 ------------------------------------ ----- ------
473 <0> five  5     @&t@
474 <1> four  4     @&t@
475 <2> one   1     @&t@
476 <3> three 3     @&t@
477 <4> two   2     @&t@
478 <5> zero  0     @&t@
479 ], [], [test ! -e pid || kill `cat pid`])
480 dnl Now do some more transactions.
481 AT_CHECK(
482   [[ovsdb-client transact unix:socket '
483      ["ordinals",
484       {"op": "delete",
485        "table": "ordinals",
486        "where": [["number", "<", 3]]}]']],
487   [0], [[[{"count":3}]
488 ]], [ignore], [test ! -e pid || kill `cat pid`])
489 dnl There should be 6 lines in the log now.
490 AT_CHECK([test `wc -l < db` -eq 6], [0], [], [],
491   [test ! -e pid || kill `cat pid`])
492 dnl Then check that the dumped data is correct.
493 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
494   [test ! -e pid || kill `cat pid`])
495 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
496 ordinals table
497 _uuid                                name  number
498 ------------------------------------ ----- ------
499 <0> five  5     @&t@
500 <1> four  4     @&t@
501 <2> three 3     @&t@
502 ], [], [test ! -e pid || kill `cat pid`])
503 OVSDB_SERVER_SHUTDOWN
504 AT_CLEANUP
505 \f
506 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL sockets)])
507
508 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
509 #
510 # Creates a database with the given SCHEMA, starts an ovsdb-server on
511 # that database, and runs each of the TRANSACTIONS (which should be a
512 # quoted list of quoted strings) against it with ovsdb-client one at a
513 # time.
514 #
515 # Checks that the overall output is OUTPUT, but UUIDs in the output
516 # are replaced by markers of the form <N> where N is a number.  The
517 # first unique UUID is replaced by <0>, the next by <1>, and so on.
518 # If a given UUID appears more than once it is always replaced by the
519 # same marker.
520 #
521 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
522 m4_define([OVSDB_CHECK_EXECUTION], 
523   [AT_SETUP([$1])
524    AT_KEYWORDS([ovsdb server positive ssl $5])
525    AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
526    OVS_RUNDIR=`pwd`; export OVS_RUNDIR
527    OVS_LOGDIR=`pwd`; export OVS_LOGDIR
528    $2 > schema
529    PKIDIR=$abs_top_builddir/tests
530    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
531    AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid --private-key=$PKIDIR/testpki-privkey2.pem --certificate=$PKIDIR/testpki-cert2.pem --ca-cert=$PKIDIR/testpki-cacert.pem --remote=pssl:0:127.0.0.1 --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
532    SSL_PORT=`parse_listening_port < ovsdb-server.log`
533    m4_foreach([txn], [$3], 
534      [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],
535      [test ! -e pid || kill `cat pid`])
536 cat stdout >> output
537 ])
538    AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
539             [test ! -e pid || kill `cat pid`])
540    OVSDB_SERVER_SHUTDOWN
541    AT_CLEANUP])
542
543 EXECUTION_EXAMPLES
544
545 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP sockets)])
546
547 AT_SETUP([ovsdb-client get-schema-version - tcp socket])
548 AT_KEYWORDS([ovsdb server positive tcp])
549 ordinal_schema > schema
550 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
551 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
552 AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=ptcp:0:127.0.0.1 db], [0], [ignore], [ignore])
553 TCP_PORT=`parse_listening_port < ovsdb-server.log`
554 AT_CHECK([ovsdb-client get-schema-version tcp:127.0.0.1:$TCP_PORT ordinals], [0], [5.1.3
555 ])
556 OVSDB_SERVER_SHUTDOWN
557 AT_CLEANUP])
558
559 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
560 #
561 # Creates a database with the given SCHEMA, starts an ovsdb-server on
562 # that database, and runs each of the TRANSACTIONS (which should be a
563 # quoted list of quoted strings) against it with ovsdb-client one at a
564 # time.
565 #
566 # Checks that the overall output is OUTPUT, but UUIDs in the output
567 # are replaced by markers of the form <N> where N is a number.  The
568 # first unique UUID is replaced by <0>, the next by <1>, and so on.
569 # If a given UUID appears more than once it is always replaced by the
570 # same marker.
571 #
572 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
573 m4_define([OVSDB_CHECK_EXECUTION],
574   [AT_SETUP([$1])
575    AT_KEYWORDS([ovsdb server positive tcp $5])
576    OVS_RUNDIR=`pwd`; export OVS_RUNDIR
577    OVS_LOGDIR=`pwd`; export OVS_LOGDIR
578    $2 > schema
579    PKIDIR=$abs_top_builddir/tests
580    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
581    AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid --remote=ptcp:0:127.0.0.1 --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
582    TCP_PORT=`parse_listening_port < ovsdb-server.log`
583    m4_foreach([txn], [$3],
584      [AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT 'txn'], [0], [stdout], [ignore],
585      [test ! -e pid || kill `cat pid`])
586 cat stdout >> output
587 ])
588    AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
589             [test ! -e pid || kill `cat pid`])
590    OVSDB_SERVER_SHUTDOWN
591    AT_CLEANUP])
592
593 EXECUTION_EXAMPLES
594 \f
595 AT_BANNER([OVSDB -- transactions on transient ovsdb-server])
596
597 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
598 #
599 # Creates a database with the given SCHEMA and runs each of the
600 # TRANSACTIONS (which should be a quoted list of quoted strings)
601 # against it with ovsdb-client one at a time.  Each ovsdb-client
602 # is run against a separately started ovsdb-server that executes
603 # only that single transaction.  (The idea is that this should
604 # help to ferret out any differences between what ovsdb-server has
605 # in memory and what actually gets committed to disk.)
606 #
607 # Checks that the overall output is OUTPUT, but UUIDs in the output
608 # are replaced by markers of the form <N> where N is a number.  The
609 # first unique UUID is replaced by <0>, the next by <1>, and so on.
610 # If a given UUID appears more than once it is always replaced by the
611 # same marker.
612 #
613 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
614 m4_define([OVSDB_CHECK_EXECUTION], 
615   [AT_SETUP([$1])
616    AT_KEYWORDS([ovsdb server positive transient $5])
617    OVS_RUNDIR=`pwd`; export OVS_RUNDIR
618    $2 > schema
619    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
620    m4_foreach([txn], [$3], 
621      [AT_DATA([txnfile], [ovsdb-client transact unix:socket 'txn'
622 ])
623       AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [ignore])
624       cat stdout >> output
625 ])
626    AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore])
627    AT_CLEANUP])
628
629 EXECUTION_EXAMPLES