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