ovsdb-server: Add and remove databases during run time.
[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([ovsdb-server/add-db and remove-db])
168 AT_KEYWORDS([ovsdb server positive])
169 ON_EXIT([kill `cat ovsdb-server.pid`])
170 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
171 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
172 ordinal_schema > schema1
173 constraint_schema > schema2
174 AT_CHECK([ovsdb-tool create db1 schema1], [0], [ignore], [ignore])
175 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
176
177 # Start ovsdb-server with just a single database - db1.
178 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db1], [0])
179 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
180   [0], [ordinals
181 ])
182
183 # Add the second database.
184 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
185 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
186   [0], [constraints
187 ordinals
188 ])
189
190 # The databases are responsive.
191 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [0], [ignore], [ignore])
192 AT_CHECK([ovsdb-client list-tables unix:socket ordinals], [0], [ignore], [ignore])
193
194 # Add an already added database.
195 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], 2, [], [stderr])
196 AT_CHECK([sed 's/(.*)/(...)/' stderr], [0],
197   [I/O error: db2: failed to lock lockfile (...)
198 ovs-appctl: ovsdb-server: server returned an error
199 ])
200
201 # Add a non-existing database.
202 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db3], 2, [], [stderr])
203 AT_CHECK([sed 's/(.*)/(...)/' stderr], [0],
204   [I/O error: open: db3 failed (...)
205 ovs-appctl: ovsdb-server: server returned an error
206 ])
207
208 # Add a remote through a db path in db1.
209 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote db:ordinals,ordinals,name], [0])
210 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
211   [0], [db:ordinals,ordinals,name
212 punix:socket
213 ])
214
215 # Removing db1 has no effect on its remote.
216 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db ordinals], [0])
217 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
218   [0], [constraints
219 ])
220 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
221   [0], [db:ordinals,ordinals,name
222 punix:socket
223 ])
224 AT_CHECK([ovsdb-client list-tables unix:socket ordinals], [1], [ignore], [ignore])
225
226 # Remove db2.
227 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db constraints], [0])
228 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
229   [0], [])
230 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [1], [ignore], [ignore])
231
232 # Remove a non-existent database.
233 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db ordinals], [2],
234   [], [Failed to find the database.
235 ovs-appctl: ovsdb-server: server returned an error
236 ])
237 AT_CLEANUP
238
239 AT_SETUP([ovsdb-server/add-db and remove-db with --monitor])
240 AT_KEYWORDS([ovsdb server positive])
241 # Start ovsdb-server, initially with one db.
242 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
243 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
244 ordinal_schema > schema
245 AT_CHECK([ovsdb-tool create db1 schema], [0], [ignore], [ignore])
246 ON_EXIT([kill `cat *.pid`])
247 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db1])
248
249 # Add the second database.
250 constraint_schema > schema2
251 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
252 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
253 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
254   [0], [constraints
255 ordinals
256 ])
257
258 # Kill the daemon process, making it look like a segfault,
259 # and wait for a new daemon process to get spawned.
260 cp ovsdb-server.pid old.pid
261 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
262 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
263 OVS_WAIT_UNTIL(
264   [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
265 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
266   [0], [constraints
267 ordinals
268 ])
269
270 # Remove the recently added database.
271 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db constraints])
272 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
273   [0], [ordinals
274 ])
275
276 # Kill the daemon process, making it look like a segfault,
277 # and wait for a new daemon process to get spawned.
278 cp ovsdb-server.pid old.pid
279 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
280 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
281 OVS_WAIT_UNTIL(
282   [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
283 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
284   [0], [ordinals
285 ])
286 AT_CLEANUP
287
288 AT_SETUP([--remote=db: implementation])
289 AT_KEYWORDS([ovsdb server positive])
290 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
291 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
292 AT_DATA([schema],
293   [[{"name": "mydb",
294      "tables": {
295        "Root": {
296          "columns": {
297            "managers": {
298              "type": {
299                "key": "string",
300                "min": 0,
301                "max": "unlimited"}},
302            "manager_options": {
303              "type": {
304                "key": {"type": "uuid", "refTable": "Manager"},
305                "min": 0,
306                "max": "unlimited"}}}},
307        "Manager": {
308          "columns": {
309            "target": {
310              "type": "string"},
311            "is_connected": {
312              "type": {
313                "key": "boolean",
314                "min": 0,
315                "max": 1}}}}}}
316 ]])
317 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
318 AT_CHECK(
319   [[ovsdb-tool transact db \
320      '["mydb",
321        {"op": "insert",
322         "table": "Root",
323         "row": {
324           "managers": "punix:socket1",
325           "manager_options": ["set", [["named-uuid", "x"]]]}},
326        {"op": "insert",
327         "table": "Manager",
328         "uuid-name": "x",
329         "row": {"target": "punix:socket2"}}]']], [0], [ignore], [ignore])
330 ON_EXIT([kill `cat ovsdb-server.pid`])
331 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])
332 for i in 1 2 3 4 5 6; do ovs-appctl -t ovsdb-server time/warp 1000; done
333 AT_CHECK(
334   [[ovsdb-client transact unix:socket1 \
335      '["mydb",
336        {"op": "select",
337         "table": "Root",
338         "where": [],
339         "columns": ["managers"]},
340        {"op": "select",
341         "table": "Manager",
342         "where": [],
343         "columns": ["target", "is_connected"]}]']],
344   [0], [stdout], [ignore])
345 AT_CHECK(
346   [${PERL} $srcdir/uuidfilt.pl stdout], 
347   [0], 
348   [[[{"rows":[{"managers":"punix:socket1"}]},{"rows":[{"is_connected":false,"target":"punix:socket2"}]}]
349 ]], 
350   [ignore])
351 AT_CLEANUP
352
353 AT_SETUP([ovsdb-server/add-remote and remove-remote])
354 AT_KEYWORDS([ovsdb server positive])
355 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
356 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
357 ordinal_schema > schema
358 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
359 ON_EXIT([kill `cat *.pid`])
360 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile db])
361
362 AT_CHECK([test ! -e socket1])
363 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
364 OVS_WAIT_UNTIL([test -S socket1])
365 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
366   [0], [punix:socket1
367 ])
368
369 AT_CHECK([test ! -e socket2])
370 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket2])
371 OVS_WAIT_UNTIL([test -S socket2])
372 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
373   [0], [punix:socket1
374 punix:socket2
375 ])
376
377 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote db:x,y,z], [2],
378   [], ["db:x,y,z": no database named x
379 ovs-appctl: ovsdb-server: server returned an error
380 ])
381
382 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
383 OVS_WAIT_UNTIL([test ! -e socket1])
384 AT_CHECK([test -S socket2])
385 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
386   [0], [punix:socket2
387 ])
388
389 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket2])
390 OVS_WAIT_UNTIL([test ! -e socket2])
391 AT_CHECK([test ! -e socket1])
392 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
393 AT_CLEANUP
394
395 AT_SETUP([ovsdb-server/add-remote and remove-remote with --monitor])
396 AT_KEYWORDS([ovsdb server positive])
397 # Start ovsdb-server, initially with no remotes.
398 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
399 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
400 ordinal_schema > schema
401 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
402 ON_EXIT([kill `cat *.pid`])
403 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db])
404
405 # Add a remote.
406 AT_CHECK([test ! -e socket1])
407 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
408 OVS_WAIT_UNTIL([test -S socket1])
409 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
410   [0], [punix:socket1
411 ])
412
413 # Kill the daemon process, making it look like a segfault,
414 # and wait for a new daemon process to get spawned and for it to
415 # start listening on 'socket1'.
416 cp ovsdb-server.pid old.pid
417 rm socket1
418 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
419 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
420 OVS_WAIT_UNTIL(
421   [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
422 OVS_WAIT_UNTIL([test -S socket1])
423
424 # Remove the remote.
425 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
426 OVS_WAIT_UNTIL([test ! -e socket1])
427 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
428
429 # Kill the daemon process, making it look like a segfault,
430 # and wait for a new daemon process to get spawned and make sure that it
431 # does not listen on 'socket1'.
432 cp ovsdb-server.pid old.pid
433 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
434 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
435 OVS_WAIT_UNTIL(
436   [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
437 AT_CHECK([test ! -e socket1])
438 AT_CLEANUP
439
440 AT_SETUP([SSL db: implementation])
441 AT_KEYWORDS([ovsdb server positive ssl $5])
442 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
443 PKIDIR=$abs_top_builddir/tests
444 AT_SKIP_IF([expr "$PKIDIR" : ".*[       '\"
445 \r\\]"])
446 AT_DATA([schema],
447   [[{"name": "mydb",
448      "tables": {
449        "SSL": {
450          "columns": {
451            "private_key": {"type": "string"},
452            "certificate": {"type": "string"},
453            "ca_cert": {"type": "string"}}}}}
454 ]])
455 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
456 AT_CHECK(
457   [[ovsdb-tool transact db \
458      '["mydb",
459        {"op": "insert",
460         "table": "SSL",
461         "row": {"private_key": "'"$PKIDIR/testpki-privkey2.pem"'",
462                 "certificate": "'"$PKIDIR/testpki-cert2.pem"'",
463                 "ca_cert": "'"$PKIDIR/testpki-cacert.pem"'"}}]']],
464   [0], [ignore], [ignore])
465 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
466 AT_CHECK(
467   [ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid \
468         --private-key=db:mydb,SSL,private_key \
469         --certificate=db:mydb,SSL,certificate \
470         --ca-cert=db:mydb,SSL,ca_cert \
471         --remote=pssl:0:127.0.0.1 --unixctl="`pwd`"/unixctl db],
472   [0], [ignore], [ignore])
473 SSL_PORT=`parse_listening_port < ovsdb-server.log`
474 AT_CHECK(
475   [[ovsdb-client \
476         --private-key=$PKIDIR/testpki-privkey.pem \
477         --certificate=$PKIDIR/testpki-cert.pem \
478         --ca-cert=$PKIDIR/testpki-cacert.pem \
479         transact ssl:127.0.0.1:$SSL_PORT \
480         '["mydb",
481           {"op": "select",
482            "table": "SSL",
483            "where": [],
484            "columns": ["private_key"]}]']], 
485   [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
486 cat stdout >> output
487 AT_CHECK_UNQUOTED(
488   [${PERL} $srcdir/uuidfilt.pl output], [0], 
489   [[[{"rows":[{"private_key":"$PKIDIR/testpki-privkey2.pem"}]}]
490 ]], [ignore], [test ! -e pid || kill `cat pid`])
491 OVSDB_SERVER_SHUTDOWN
492 AT_CLEANUP
493
494 AT_SETUP([compacting online])
495 AT_KEYWORDS([ovsdb server compact])
496 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
497 ordinal_schema > schema
498 dnl Make sure that "ovsdb-tool create" works with a dangling symlink for
499 dnl the database and the lockfile, creating the target of each symlink rather
500 dnl than replacing the symlinks with regular files.
501 mkdir dir
502 ln -s dir/db db
503 ln -s dir/.db.~lock~ .db.~lock~
504 AT_SKIP_IF([test ! -h db || test ! -h .db.~lock~])
505 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
506 dnl Start ovsdb-server.
507 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])
508 AT_CAPTURE_FILE([ovsdb-server.log])
509 dnl Do a bunch of random transactions that put crap in the database log.
510 AT_CHECK(
511   [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
512       set -- $pair
513       ovsdb-client transact unix:socket '
514         ["ordinals",
515          {"op": "insert",
516           "table": "ordinals",
517           "row": {"name": "'$1'", "number": '$2'}},
518          {"op": "comment",
519           "comment": "add row for '"$pair"'"}]'
520       ovsdb-client transact unix:socket '
521         ["ordinals",
522          {"op": "delete",
523           "table": "ordinals",
524           "where": [["number", "==", '$2']]},
525          {"op": "comment",
526           "comment": "delete row for '"$2"'"}]'
527       ovsdb-client transact unix:socket '
528         ["ordinals",
529          {"op": "insert",
530           "table": "ordinals",
531           "row": {"name": "'$1'", "number": '$2'}},
532          {"op": "comment",
533           "comment": "add back row for '"$pair"'"}]'
534     done]],
535   [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
536 dnl Check that all the crap is in fact in the database log.
537 AT_CHECK([[${PERL} $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | test-json --multiple -]], [0],
538   [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"}
539 {"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
540 {"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
541 {"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
542 {"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
543 {"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
544 {"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
545 {"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
546 {"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
547 {"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
548 {"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
549 {"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
550 {"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
551 {"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
552 {"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
553 {"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
554 {"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
555 {"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
556 {"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
557 ]], [], [test ! -e pid || kill `cat pid`])
558 dnl Dump out and check the actual database contents.
559 AT_CHECK([[ovsdb-client dump unix:socket ordinals]],
560   [0], [stdout], [ignore])
561 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
562 ordinals table
563 _uuid                                name  number
564 ------------------------------------ ----- ------
565 <0> five  5     @&t@
566 <1> four  4     @&t@
567 <2> one   1     @&t@
568 <3> three 3     @&t@
569 <4> two   2     @&t@
570 <5> zero  0     @&t@
571 ], [], [test ! -e pid || kill `cat pid`])
572 dnl Now compact the database in-place.
573 AT_CHECK([[ovs-appctl -t "`pwd`"/unixctl ovsdb-server/compact]],
574   [0], [], [ignore], [test ! -e pid || kill `cat pid`])
575 dnl Make sure that "db" is still a symlink to dir/db instead of getting
576 dnl replaced by a regular file, ditto for .db.~lock~.
577 AT_CHECK([test -h db])
578 AT_CHECK([test -h .db.~lock~])
579 AT_CHECK([test -f dir/db])
580 AT_CHECK([test -f dir/.db.~lock~])
581 dnl We can't fully re-check the contents of the database log, because the
582 dnl order of the records is not predictable, but there should only be 4 lines
583 dnl in it now.
584 AT_CAPTURE_FILE([db])
585 AT_CHECK([test `wc -l < db` -eq 4], [0], [], [],
586   [test ! -e pid || kill `cat pid`])
587 dnl And check that the dumped data is the same too:
588 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
589   [test ! -e pid || kill `cat pid`])
590 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
591 ordinals table
592 _uuid                                name  number
593 ------------------------------------ ----- ------
594 <0> five  5     @&t@
595 <1> four  4     @&t@
596 <2> one   1     @&t@
597 <3> three 3     @&t@
598 <4> two   2     @&t@
599 <5> zero  0     @&t@
600 ], [], [test ! -e pid || kill `cat pid`])
601 dnl Now do some more transactions.
602 AT_CHECK(
603   [[ovsdb-client transact unix:socket '
604      ["ordinals",
605       {"op": "delete",
606        "table": "ordinals",
607        "where": [["number", "<", 3]]}]']],
608   [0], [[[{"count":3}]
609 ]], [ignore], [test ! -e pid || kill `cat pid`])
610 dnl There should be 6 lines in the log now.
611 AT_CHECK([test `wc -l < db` -eq 6], [0], [], [],
612   [test ! -e pid || kill `cat pid`])
613 dnl Then check that the dumped data is correct.
614 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
615   [test ! -e pid || kill `cat pid`])
616 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
617 ordinals table
618 _uuid                                name  number
619 ------------------------------------ ----- ------
620 <0> five  5     @&t@
621 <1> four  4     @&t@
622 <2> three 3     @&t@
623 ], [], [test ! -e pid || kill `cat pid`])
624 OVSDB_SERVER_SHUTDOWN
625 AT_CLEANUP
626 \f
627 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL sockets)])
628
629 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
630 #
631 # Creates a database with the given SCHEMA, starts an ovsdb-server on
632 # that database, and runs each of the TRANSACTIONS (which should be a
633 # quoted list of quoted strings) against it with ovsdb-client one at a
634 # time.
635 #
636 # Checks that the overall output is OUTPUT, but UUIDs in the output
637 # are replaced by markers of the form <N> where N is a number.  The
638 # first unique UUID is replaced by <0>, the next by <1>, and so on.
639 # If a given UUID appears more than once it is always replaced by the
640 # same marker.
641 #
642 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
643 m4_define([OVSDB_CHECK_EXECUTION], 
644   [AT_SETUP([$1])
645    AT_KEYWORDS([ovsdb server positive ssl $5])
646    AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
647    OVS_RUNDIR=`pwd`; export OVS_RUNDIR
648    OVS_LOGDIR=`pwd`; export OVS_LOGDIR
649    $2 > schema
650    PKIDIR=$abs_top_builddir/tests
651    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
652    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])
653    SSL_PORT=`parse_listening_port < ovsdb-server.log`
654    m4_foreach([txn], [$3], 
655      [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],
656      [test ! -e pid || kill `cat pid`])
657 cat stdout >> output
658 ])
659    AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
660             [test ! -e pid || kill `cat pid`])
661    OVSDB_SERVER_SHUTDOWN
662    AT_CLEANUP])
663
664 EXECUTION_EXAMPLES
665
666 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP sockets)])
667
668 AT_SETUP([ovsdb-client get-schema-version - tcp socket])
669 AT_KEYWORDS([ovsdb server positive tcp])
670 ordinal_schema > schema
671 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
672 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
673 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])
674 TCP_PORT=`parse_listening_port < ovsdb-server.log`
675 AT_CHECK([ovsdb-client get-schema-version tcp:127.0.0.1:$TCP_PORT ordinals], [0], [5.1.3
676 ])
677 OVSDB_SERVER_SHUTDOWN
678 AT_CLEANUP])
679
680 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
681 #
682 # Creates a database with the given SCHEMA, starts an ovsdb-server on
683 # that database, and runs each of the TRANSACTIONS (which should be a
684 # quoted list of quoted strings) against it with ovsdb-client one at a
685 # time.
686 #
687 # Checks that the overall output is OUTPUT, but UUIDs in the output
688 # are replaced by markers of the form <N> where N is a number.  The
689 # first unique UUID is replaced by <0>, the next by <1>, and so on.
690 # If a given UUID appears more than once it is always replaced by the
691 # same marker.
692 #
693 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
694 m4_define([OVSDB_CHECK_EXECUTION],
695   [AT_SETUP([$1])
696    AT_KEYWORDS([ovsdb server positive tcp $5])
697    OVS_RUNDIR=`pwd`; export OVS_RUNDIR
698    OVS_LOGDIR=`pwd`; export OVS_LOGDIR
699    $2 > schema
700    PKIDIR=$abs_top_builddir/tests
701    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
702    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])
703    TCP_PORT=`parse_listening_port < ovsdb-server.log`
704    m4_foreach([txn], [$3],
705      [AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT 'txn'], [0], [stdout], [ignore],
706      [test ! -e pid || kill `cat pid`])
707 cat stdout >> output
708 ])
709    AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
710             [test ! -e pid || kill `cat pid`])
711    OVSDB_SERVER_SHUTDOWN
712    AT_CLEANUP])
713
714 EXECUTION_EXAMPLES
715 \f
716 AT_BANNER([OVSDB -- transactions on transient ovsdb-server])
717
718 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
719 #
720 # Creates a database with the given SCHEMA and runs each of the
721 # TRANSACTIONS (which should be a quoted list of quoted strings)
722 # against it with ovsdb-client one at a time.  Each ovsdb-client
723 # is run against a separately started ovsdb-server that executes
724 # only that single transaction.  (The idea is that this should
725 # help to ferret out any differences between what ovsdb-server has
726 # in memory and what actually gets committed to disk.)
727 #
728 # Checks that the overall output is OUTPUT, but UUIDs in the output
729 # are replaced by markers of the form <N> where N is a number.  The
730 # first unique UUID is replaced by <0>, the next by <1>, and so on.
731 # If a given UUID appears more than once it is always replaced by the
732 # same marker.
733 #
734 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
735 m4_define([OVSDB_CHECK_EXECUTION], 
736   [AT_SETUP([$1])
737    AT_KEYWORDS([ovsdb server positive transient $5])
738    OVS_RUNDIR=`pwd`; export OVS_RUNDIR
739    $2 > schema
740    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
741    m4_foreach([txn], [$3], 
742      [AT_DATA([txnfile], [ovsdb-client transact unix:socket 'txn'
743 ])
744       AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [ignore])
745       cat stdout >> output
746 ])
747    AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore])
748    AT_CLEANUP])
749
750 EXECUTION_EXAMPLES