7e9d9fd5413cdaad970f7d005c16fde8515f08db
[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_BANNER([ovsdb-server miscellaneous features])
42
43 AT_SETUP([truncating corrupted database log])
44 AT_KEYWORDS([ovsdb server positive unix])
45 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
46 ordinal_schema > schema
47 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
48 dnl Do one transaction and save the output.
49 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
50 '["ordinals",
51   {"op": "insert",
52    "table": "ordinals",
53    "row": {"number": 0, "name": "zero"}}]'
54 ]])
55 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
56 cat stdout >> output
57 dnl Add some crap to the database log and run another transaction, which should
58 dnl ignore the crap and truncate it out of the log.
59 echo 'xxx' >> db
60 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
61 '["ordinals",
62   {"op": "insert",
63    "table": "ordinals",
64    "row": {"number": 1, "name": "one"}}]'
65 ]])
66 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [stderr])
67 AT_CHECK([grep 'syntax error: db: parse error.* in header line "xxx"' stderr],
68   [0], [ignore])
69 cat stdout >> output
70 dnl Run a final transaction to verify that both transactions succeeeded.
71 dnl The crap that we added should have been truncated by the previous run,
72 dnl so ovsdb-server shouldn't log a warning this time.
73 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
74 '["ordinals",
75   {"op": "select",
76    "table": "ordinals",
77    "where": [],
78    "sort": ["number"]}]'
79 ]])
80 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
81 cat stdout >> output
82 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0],
83   [[[{"uuid":["uuid","<0>"]}]
84 [{"uuid":["uuid","<1>"]}]
85 [{"rows":[{"_uuid":["uuid","<0>"],"_version":["uuid","<2>"],"name":"zero","number":0},{"_uuid":["uuid","<1>"],"_version":["uuid","<3>"],"name":"one","number":1}]}]
86 ]], [],
87          [test ! -e pid || kill `cat pid`])
88 AT_CLEANUP
89
90 AT_SETUP([truncating database log with bad transaction])
91 AT_KEYWORDS([ovsdb server positive unix])
92 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
93 ordinal_schema > schema
94 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
95 dnl Do one transaction and save the output.
96 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
97 '["ordinals",
98   {"op": "insert",
99    "table": "ordinals",
100    "row": {"number": 0, "name": "zero"}}]'
101 ]])
102 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
103 cat stdout >> output
104 dnl Add some crap to the database log and run another transaction, which should
105 dnl ignore the crap and truncate it out of the log.
106 echo 'OVSDB JSON 15 ffbcdae4b0386265f9ea3280dd7c8f0b72a20e56
107 {"invalid":{}}' >> db
108 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
109 '["ordinals",
110   {"op": "insert",
111    "table": "ordinals",
112    "row": {"number": 1, "name": "one"}}]'
113 ]])
114 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [stderr])
115 AT_CHECK([grep 'syntax "{"invalid":{}}": unknown table: No table named invalid.' stderr],
116   [0], [ignore])
117 cat stdout >> output
118 dnl Run a final transaction to verify that both transactions succeeeded.
119 dnl The crap that we added should have been truncated by the previous run,
120 dnl so ovsdb-server shouldn't log a warning this time.
121 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
122 '["ordinals",
123   {"op": "select",
124    "table": "ordinals",
125    "where": [],
126    "sort": ["number"]}]'
127 ]])
128 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
129 cat stdout >> output
130 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0],
131   [[[{"uuid":["uuid","<0>"]}]
132 [{"uuid":["uuid","<1>"]}]
133 [{"rows":[{"_uuid":["uuid","<0>"],"_version":["uuid","<2>"],"name":"zero","number":0},{"_uuid":["uuid","<1>"],"_version":["uuid","<3>"],"name":"one","number":1}]}]
134 ]], [],
135          [test ! -e pid || kill `cat pid`])
136 AT_CLEANUP
137
138 AT_SETUP([ovsdb-client get-schema-version])
139 AT_KEYWORDS([ovsdb server positive])
140 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
141 ordinal_schema > schema
142 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
143 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=punix:socket db], [0], [ignore], [ignore])
144 AT_CHECK([ovsdb-client get-schema-version unix:socket ordinals], [0], [5.1.3
145 ])
146 OVSDB_SERVER_SHUTDOWN
147 AT_CLEANUP
148
149 AT_SETUP([database multiplexing implementation])
150 AT_KEYWORDS([ovsdb server positive])
151 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
152 ordinal_schema > schema1
153 constraint_schema > schema2
154 AT_CHECK([ovsdb-tool create db1 schema1], [0], [ignore], [ignore])
155 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
156 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=punix:socket db1 db2], [0], [ignore], [ignore])
157 AT_CHECK(
158   [[ovsdb-client list-dbs unix:socket]], 
159   [0], [constraints
160 ordinals
161 ], [ignore], [test ! -e pid || kill `cat pid`])
162 AT_CHECK(
163   [[ovstest test-jsonrpc request unix:socket get_schema [\"nonexistent\"]]], [0],
164   [[{"error":null,"id":0,"result":{"details":"get_schema request specifies unknown database nonexistent","error":"unknown database","syntax":"[\"nonexistent\"]"}}
165 ]], [], [test ! -e pid || kill `cat pid`])
166 OVSDB_SERVER_SHUTDOWN
167 AT_CLEANUP
168
169 AT_SETUP([ovsdb-server/add-db and remove-db])
170 AT_KEYWORDS([ovsdb server positive])
171 ON_EXIT([kill `cat ovsdb-server.pid`])
172 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
173 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
174 ordinal_schema > schema1
175 constraint_schema > schema2
176 AT_CHECK([ovsdb-tool create db1 schema1], [0], [ignore], [ignore])
177 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
178
179 # Start ovsdb-server with just a single database - db1.
180 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db1], [0])
181 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
182   [0], [ordinals
183 ])
184
185 # Add the second database.
186 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
187 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
188   [0], [constraints
189 ordinals
190 ])
191
192 # The databases are responsive.
193 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [0], [ignore], [ignore])
194 AT_CHECK([ovsdb-client list-tables unix:socket ordinals], [0], [ignore], [ignore])
195
196 # Add an already added database.
197 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], 2, [],
198   [db2: already open
199 ovs-appctl: ovsdb-server: server returned an error
200 ])
201
202 # Add a non-existing database.
203 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db3], 2, [], [stderr])
204 AT_CHECK([sed 's/(.*)/(...)/' stderr], [0],
205   [I/O error: open: db3 failed (...)
206 ovs-appctl: ovsdb-server: server returned an error
207 ])
208
209 # Add a remote through a db path in db1.
210 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote db:ordinals,ordinals,name], [0])
211 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
212   [0], [db:ordinals,ordinals,name
213 punix:socket
214 ])
215
216 # Removing db1 has no effect on its remote.
217 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db ordinals], [0])
218 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
219   [0], [constraints
220 ])
221 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
222   [0], [db:ordinals,ordinals,name
223 punix:socket
224 ])
225 AT_CHECK([ovsdb-client list-tables unix:socket ordinals], [1], [ignore], [ignore])
226
227 # Remove db2.
228 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db constraints], [0])
229 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
230   [0], [])
231 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [1], [ignore], [ignore])
232
233 # Remove a non-existent database.
234 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db ordinals], [2],
235   [], [Failed to find the database.
236 ovs-appctl: ovsdb-server: server returned an error
237 ])
238
239 # Add a removed database.
240 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
241 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
242   [0], [constraints
243 ])
244 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [0], [ignore], [ignore])
245 AT_CLEANUP
246
247 AT_SETUP([ovsdb-server/add-db with --monitor])
248 AT_KEYWORDS([ovsdb server positive])
249 # Start ovsdb-server, initially with one db.
250 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
251 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
252 ordinal_schema > schema
253 AT_CHECK([ovsdb-tool create db1 schema], [0], [ignore], [ignore])
254 ON_EXIT([kill `cat *.pid`])
255 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db1])
256
257 # Add the second database.
258 constraint_schema > schema2
259 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
260 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
261 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
262   [0], [constraints
263 ordinals
264 ])
265
266 # Kill the daemon process, making it look like a segfault,
267 # and wait for a new daemon process to get spawned.
268 cp ovsdb-server.pid old.pid
269 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
270 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
271 OVS_WAIT_UNTIL(
272   [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
273 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
274   [0], [constraints
275 ordinals
276 ])
277 AT_CLEANUP
278
279 AT_SETUP([ovsdb-server/add-db and remove-db with --monitor])
280 AT_KEYWORDS([ovsdb server positive])
281 # Start ovsdb-server, initially with one db.
282 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
283 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
284 ordinal_schema > schema
285 AT_CHECK([ovsdb-tool create db1 schema], [0], [ignore], [ignore])
286 constraint_schema > schema2
287 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
288 ON_EXIT([kill `cat *.pid`])
289 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db1 db2])
290
291 # Remove the second database.
292 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db constraints])
293 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
294   [0], [ordinals
295 ])
296
297 # Kill the daemon process, making it look like a segfault,
298 # and wait for a new daemon process to get spawned.
299 cp ovsdb-server.pid old.pid
300 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
301 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
302 OVS_WAIT_UNTIL(
303   [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
304 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
305   [0], [ordinals
306 ])
307 AT_CLEANUP
308
309 AT_SETUP([--remote=db: implementation])
310 AT_KEYWORDS([ovsdb server positive])
311 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
312 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
313 AT_DATA([schema],
314   [[{"name": "mydb",
315      "tables": {
316        "Root": {
317          "columns": {
318            "managers": {
319              "type": {
320                "key": "string",
321                "min": 0,
322                "max": "unlimited"}},
323            "manager_options": {
324              "type": {
325                "key": {"type": "uuid", "refTable": "Manager"},
326                "min": 0,
327                "max": "unlimited"}}}},
328        "Manager": {
329          "columns": {
330            "target": {
331              "type": "string"},
332            "is_connected": {
333              "type": {
334                "key": "boolean",
335                "min": 0,
336                "max": 1}}}}}}
337 ]])
338 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
339 AT_CHECK(
340   [[ovsdb-tool transact db \
341      '["mydb",
342        {"op": "insert",
343         "table": "Root",
344         "row": {
345           "managers": "punix:socket1",
346           "manager_options": ["set", [["named-uuid", "x"]]]}},
347        {"op": "insert",
348         "table": "Manager",
349         "uuid-name": "x",
350         "row": {"target": "punix:socket2"}}]']], [0], [ignore], [ignore])
351 ON_EXIT([kill `cat ovsdb-server.pid`])
352 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])
353 for i in 1 2 3 4 5 6; do ovs-appctl -t ovsdb-server time/warp 1000; done
354 AT_CHECK(
355   [[ovsdb-client transact unix:socket1 \
356      '["mydb",
357        {"op": "select",
358         "table": "Root",
359         "where": [],
360         "columns": ["managers"]},
361        {"op": "select",
362         "table": "Manager",
363         "where": [],
364         "columns": ["target", "is_connected"]}]']],
365   [0], [stdout], [ignore])
366 AT_CHECK(
367   [${PERL} $srcdir/uuidfilt.pl stdout], 
368   [0], 
369   [[[{"rows":[{"managers":"punix:socket1"}]},{"rows":[{"is_connected":false,"target":"punix:socket2"}]}]
370 ]], 
371   [ignore])
372 AT_CLEANUP
373
374 AT_SETUP([ovsdb-server/add-remote and remove-remote])
375 AT_KEYWORDS([ovsdb server positive])
376 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
377 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
378 ordinal_schema > schema
379 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
380 ON_EXIT([kill `cat *.pid`])
381 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile db])
382
383 AT_CHECK([test ! -e socket1])
384 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
385 OVS_WAIT_UNTIL([test -S socket1])
386 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
387   [0], [punix:socket1
388 ])
389
390 AT_CHECK([test ! -e socket2])
391 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket2])
392 OVS_WAIT_UNTIL([test -S socket2])
393 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
394   [0], [punix:socket1
395 punix:socket2
396 ])
397
398 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote db:x,y,z], [2],
399   [], ["db:x,y,z": no database named x
400 ovs-appctl: ovsdb-server: server returned an error
401 ])
402
403 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
404 OVS_WAIT_UNTIL([test ! -e socket1])
405 AT_CHECK([test -S socket2])
406 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
407   [0], [punix:socket2
408 ])
409
410 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket2])
411 OVS_WAIT_UNTIL([test ! -e socket2])
412 AT_CHECK([test ! -e socket1])
413 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
414 AT_CLEANUP
415
416 AT_SETUP([ovsdb-server/add-remote with --monitor])
417 AT_KEYWORDS([ovsdb server positive])
418 # Start ovsdb-server, initially with no remotes.
419 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
420 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
421 ordinal_schema > schema
422 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
423 ON_EXIT([kill `cat *.pid`])
424 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db])
425
426 # Add a remote.
427 AT_CHECK([test ! -e socket1])
428 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
429 OVS_WAIT_UNTIL([test -S socket1])
430 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
431   [0], [punix:socket1
432 ])
433
434 # Kill the daemon process, making it look like a segfault,
435 # and wait for a new daemon process to get spawned and for it to
436 # start listening on 'socket1'.
437 cp ovsdb-server.pid old.pid
438 rm socket1
439 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
440 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
441 OVS_WAIT_UNTIL(
442   [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
443 OVS_WAIT_UNTIL([test -S socket1])
444 AT_CLEANUP
445
446 AT_SETUP([ovsdb-server/add-remote and remove-remote with --monitor])
447 AT_KEYWORDS([ovsdb server positive])
448 # Start ovsdb-server, initially with no remotes.
449 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
450 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
451 ordinal_schema > schema
452 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
453 ON_EXIT([kill `cat *.pid`])
454 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db])
455
456 # Add a remote.
457 AT_CHECK([test ! -e socket1])
458 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
459 OVS_WAIT_UNTIL([test -S socket1])
460 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
461   [0], [punix:socket1
462 ])
463
464 # Remove the remote.
465 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
466 OVS_WAIT_UNTIL([test ! -e socket1])
467 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
468
469 # Kill the daemon process, making it look like a segfault,
470 # and wait for a new daemon process to get spawned and make sure that it
471 # does not listen on 'socket1'.
472 cp ovsdb-server.pid old.pid
473 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
474 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
475 OVS_WAIT_UNTIL(
476   [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
477 AT_CHECK([test ! -e socket1])
478 AT_CLEANUP
479
480 AT_SETUP([SSL db: implementation])
481 AT_KEYWORDS([ovsdb server positive ssl $5])
482 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
483 PKIDIR=$abs_top_builddir/tests
484 AT_SKIP_IF([expr "$PKIDIR" : ".*[       '\"
485 \\]"])
486 AT_DATA([schema],
487   [[{"name": "mydb",
488      "tables": {
489        "SSL": {
490          "columns": {
491            "private_key": {"type": "string"},
492            "certificate": {"type": "string"},
493            "ca_cert": {"type": "string"}}}}}
494 ]])
495 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
496 AT_CHECK(
497   [[ovsdb-tool transact db \
498      '["mydb",
499        {"op": "insert",
500         "table": "SSL",
501         "row": {"private_key": "'"$PKIDIR/testpki-privkey2.pem"'",
502                 "certificate": "'"$PKIDIR/testpki-cert2.pem"'",
503                 "ca_cert": "'"$PKIDIR/testpki-cacert.pem"'"}}]']],
504   [0], [ignore], [ignore])
505 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
506 AT_CHECK(
507   [ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid \
508         --private-key=db:mydb,SSL,private_key \
509         --certificate=db:mydb,SSL,certificate \
510         --ca-cert=db:mydb,SSL,ca_cert \
511         --remote=pssl:0:127.0.0.1 --unixctl="`pwd`"/unixctl db],
512   [0], [ignore], [ignore])
513 SSL_PORT=`parse_listening_port < ovsdb-server.log`
514 AT_CHECK(
515   [[ovsdb-client \
516         --private-key=$PKIDIR/testpki-privkey.pem \
517         --certificate=$PKIDIR/testpki-cert.pem \
518         --ca-cert=$PKIDIR/testpki-cacert.pem \
519         transact ssl:127.0.0.1:$SSL_PORT \
520         '["mydb",
521           {"op": "select",
522            "table": "SSL",
523            "where": [],
524            "columns": ["private_key"]}]']], 
525   [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
526 cat stdout >> output
527 AT_CHECK_UNQUOTED(
528   [cat output], [0],
529   [[[{"rows":[{"private_key":"$PKIDIR/testpki-privkey2.pem"}]}]
530 ]], [ignore], [test ! -e pid || kill `cat pid`])
531 OVSDB_SERVER_SHUTDOWN
532 AT_CLEANUP
533
534 AT_SETUP([compacting online])
535 AT_KEYWORDS([ovsdb server compact])
536 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
537 ordinal_schema > schema
538 dnl Make sure that "ovsdb-tool create" works with a dangling symlink for
539 dnl the database and the lockfile, creating the target of each symlink rather
540 dnl than replacing the symlinks with regular files.
541 mkdir dir
542 ln -s dir/db db
543 ln -s dir/.db.~lock~ .db.~lock~
544 AT_SKIP_IF([test ! -h db || test ! -h .db.~lock~])
545 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
546 dnl Start ovsdb-server.
547 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])
548 AT_CAPTURE_FILE([ovsdb-server.log])
549 dnl Do a bunch of random transactions that put crap in the database log.
550 AT_CHECK(
551   [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
552       set -- $pair
553       ovsdb-client transact unix:socket '
554         ["ordinals",
555          {"op": "insert",
556           "table": "ordinals",
557           "row": {"name": "'$1'", "number": '$2'}},
558          {"op": "comment",
559           "comment": "add row for '"$pair"'"}]'
560       ovsdb-client transact unix:socket '
561         ["ordinals",
562          {"op": "delete",
563           "table": "ordinals",
564           "where": [["number", "==", '$2']]},
565          {"op": "comment",
566           "comment": "delete row for '"$2"'"}]'
567       ovsdb-client transact unix:socket '
568         ["ordinals",
569          {"op": "insert",
570           "table": "ordinals",
571           "row": {"name": "'$1'", "number": '$2'}},
572          {"op": "comment",
573           "comment": "add back row for '"$pair"'"}]'
574     done]],
575   [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
576 dnl Check that all the crap is in fact in the database log.
577 AT_CHECK([[${PERL} $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | ovstest test-json --multiple -]], [0],
578   [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"}
579 {"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
580 {"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
581 {"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
582 {"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
583 {"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
584 {"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
585 {"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
586 {"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
587 {"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
588 {"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
589 {"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
590 {"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
591 {"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
592 {"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
593 {"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
594 {"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
595 {"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
596 {"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
597 ]], [], [test ! -e pid || kill `cat pid`])
598 dnl Dump out and check the actual database contents.
599 AT_CHECK([[ovsdb-client dump unix:socket ordinals]],
600   [0], [stdout], [ignore])
601 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
602 ordinals table
603 _uuid                                name  number
604 ------------------------------------ ----- ------
605 <0> five  5     @&t@
606 <1> four  4     @&t@
607 <2> one   1     @&t@
608 <3> three 3     @&t@
609 <4> two   2     @&t@
610 <5> zero  0     @&t@
611 ], [], [test ! -e pid || kill `cat pid`])
612 dnl Now compact the database in-place.
613 AT_CHECK([[ovs-appctl -t "`pwd`"/unixctl ovsdb-server/compact]],
614   [0], [], [ignore], [test ! -e pid || kill `cat pid`])
615 dnl Make sure that "db" is still a symlink to dir/db instead of getting
616 dnl replaced by a regular file, ditto for .db.~lock~.
617 AT_CHECK([test -h db])
618 AT_CHECK([test -h .db.~lock~])
619 AT_CHECK([test -f dir/db])
620 AT_CHECK([test -f dir/.db.~lock~])
621 dnl We can't fully re-check the contents of the database log, because the
622 dnl order of the records is not predictable, but there should only be 4 lines
623 dnl in it now.
624 AT_CAPTURE_FILE([db])
625 AT_CHECK([test `wc -l < db` -eq 4], [0], [], [],
626   [test ! -e pid || kill `cat pid`])
627 dnl And check that the dumped data is the same too:
628 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
629   [test ! -e pid || kill `cat pid`])
630 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
631 ordinals table
632 _uuid                                name  number
633 ------------------------------------ ----- ------
634 <0> five  5     @&t@
635 <1> four  4     @&t@
636 <2> one   1     @&t@
637 <3> three 3     @&t@
638 <4> two   2     @&t@
639 <5> zero  0     @&t@
640 ], [], [test ! -e pid || kill `cat pid`])
641 dnl Now do some more transactions.
642 AT_CHECK(
643   [[ovsdb-client transact unix:socket '
644      ["ordinals",
645       {"op": "delete",
646        "table": "ordinals",
647        "where": [["number", "<", 3]]}]']],
648   [0], [[[{"count":3}]
649 ]], [ignore], [test ! -e pid || kill `cat pid`])
650 dnl There should be 6 lines in the log now.
651 AT_CHECK([test `wc -l < db` -eq 6], [0], [], [],
652   [test ! -e pid || kill `cat pid`])
653 dnl Then check that the dumped data is correct.
654 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
655   [test ! -e pid || kill `cat pid`])
656 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
657 ordinals table
658 _uuid                                name  number
659 ------------------------------------ ----- ------
660 <0> five  5     @&t@
661 <1> four  4     @&t@
662 <2> three 3     @&t@
663 ], [], [test ! -e pid || kill `cat pid`])
664 OVSDB_SERVER_SHUTDOWN
665 AT_CLEANUP
666
667 AT_SETUP([ovsdb-server combines updates on backlogged connections])
668 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
669 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
670 ON_EXIT([kill `cat *.pid`])
671
672 # The maximum socket receive buffer size is important for this test, which
673 # tests behavior when the receive buffer overflows.
674 if test -e /proc/sys/net/core/rmem_max; then
675     # Linux
676     rmem_max=`cat /proc/sys/net/core/rmem_max`
677 elif rmem_max=`sysctl -n net.inet.tcp.recvbuf_max 2>/dev/null`; then
678     : # FreeBSD, NetBSD
679 else
680     # Don't know how to get maximum socket receive buffer on this OS
681     AT_SKIP_IF([:])
682 fi
683
684 # Calculate the number of iterations we need to queue.  Each of the
685 # iterations we execute, by itself, yields a monitor update of about
686 # 25 kB, so fill up that much space plus a few for luck.
687 n_iterations=`expr $rmem_max / 25000 + 5`
688 echo rmem_max=$rmem_max n_iterations=$n_iterations
689
690 # Calculate the exact number of monitor updates expected for $n_iterations,
691 # assuming no updates are combined.  The "extra" update is for the initial
692 # contents of the database.
693 n_updates=`expr $n_iterations \* 3 + 1`
694
695 # Start an ovsdb-server with the vswitchd schema.
696 OVSDB_INIT([db])
697 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --log-file --remote=punix:db.sock db],
698   [0], [ignore], [ignore])
699
700 # Executes a set of transactions that add a bridge with 100 ports, and
701 # then deletes that bridge.  This yields three monitor updates that
702 # add up to about 25 kB in size.
703 #
704 # The update also increments a counter held in the database so that we can
705 # verify that the overall effect of the transactions took effect (e.g.
706 # monitor updates at the end weren't just dropped).  We add an arbitrary
707 # string to the counter to make grepping for it more reliable.
708 counter=0
709 trigger_big_update () {
710     counter=`expr $counter + 1`
711     ovs-vsctl --no-wait -- set open_vswitch . system_version=xyzzy$counter
712     ovs-vsctl --no-wait -- add-br br0 $add
713     ovs-vsctl --no-wait -- del-br br0
714 }
715 add_ports () {
716     for j in `seq 1 100`; do
717         printf " -- add-port br0 p%d" $j
718     done
719 }
720 add=`add_ports`
721
722 AT_CAPTURE_FILE([ovsdb-client.err])
723
724 # Start an ovsdb-client monitoring all changes to the database,
725 # make it block to force the buffers to fill up, and then execute
726 # enough iterations that ovsdb-server starts combining updates.
727 AT_CHECK([ovsdb-client --detach --no-chdir --pidfile monitor ALL >ovsdb-client.out 2>ovsdb-client.err])
728 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/block])
729 for i in `seq 1 $n_iterations`; do
730     echo "blocked update ($i of $n_iterations)"
731     trigger_big_update $i
732 done
733 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/unblock])
734 OVS_WAIT_UNTIL([grep "\"xyzzy$counter\"" ovsdb-client.out])
735 AT_CHECK([ovs-appctl -t ovsdb-client exit])
736 OVS_WAIT_WHILE([test -e ovsdb-client.pid])
737
738 # Count the number of updates in the ovsdb-client output, by counting
739 # the number of changes to the Open_vSwitch table.  (All of our
740 # transactions modify the Open_vSwitch table.)  It should be less than
741 # $n_updates updates.
742 #
743 # Check that the counter is what we expect.
744 logged_updates=`grep -c '^Open_vSwitch' ovsdb-client.out`
745 echo "logged_updates=$logged_updates (expected less than $n_updates)"
746 AT_CHECK([test $logged_updates -lt $n_updates])
747 AT_CHECK_UNQUOTED([ovs-vsctl get open_vswitch . system_version], [0],
748   ["xyzzy$counter"
749 ])
750 AT_CLEANUP
751 \f
752 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv4 sockets)])
753
754 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
755 #
756 # Creates a database with the given SCHEMA, starts an ovsdb-server on
757 # that database, and runs each of the TRANSACTIONS (which should be a
758 # quoted list of quoted strings) against it with ovsdb-client one at a
759 # time.
760 #
761 # Checks that the overall output is OUTPUT, but UUIDs in the output
762 # are replaced by markers of the form <N> where N is a number.  The
763 # first unique UUID is replaced by <0>, the next by <1>, and so on.
764 # If a given UUID appears more than once it is always replaced by the
765 # same marker.
766 #
767 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
768 m4_define([OVSDB_CHECK_EXECUTION], 
769   [AT_SETUP([$1])
770    AT_KEYWORDS([ovsdb server positive ssl $5])
771    AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
772    OVS_RUNDIR=`pwd`; export OVS_RUNDIR
773    OVS_LOGDIR=`pwd`; export OVS_LOGDIR
774    $2 > schema
775    PKIDIR=$abs_top_builddir/tests
776    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
777    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])
778    SSL_PORT=`parse_listening_port < ovsdb-server.log`
779    m4_foreach([txn], [$3], 
780      [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],
781      [test ! -e pid || kill `cat pid`])
782 cat stdout >> output
783 ])
784    AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
785             [test ! -e pid || kill `cat pid`])
786    OVSDB_SERVER_SHUTDOWN
787    AT_CLEANUP])
788
789 EXECUTION_EXAMPLES
790
791 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv6 sockets)])
792
793 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
794 #
795 # Creates a database with the given SCHEMA, starts an ovsdb-server on
796 # that database, and runs each of the TRANSACTIONS (which should be a
797 # quoted list of quoted strings) against it with ovsdb-client one at a
798 # time.
799 #
800 # Checks that the overall output is OUTPUT, but UUIDs in the output
801 # are replaced by markers of the form <N> where N is a number.  The
802 # first unique UUID is replaced by <0>, the next by <1>, and so on.
803 # If a given UUID appears more than once it is always replaced by the
804 # same marker.
805 #
806 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
807 m4_define([OVSDB_CHECK_EXECUTION],
808   [AT_SETUP([$1])
809    AT_KEYWORDS([ovsdb server positive ssl6 $5])
810    AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
811    OVS_RUNDIR=`pwd`; export OVS_RUNDIR
812    OVS_LOGDIR=`pwd`; export OVS_LOGDIR
813    $2 > schema
814    PKIDIR=$abs_top_builddir/tests
815    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
816    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:[[::1]] --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
817    SSL_PORT=`parse_listening_port < ovsdb-server.log`
818    m4_foreach([txn], [$3],
819      [AT_CHECK([ovsdb-client --private-key=$PKIDIR/testpki-privkey.pem --certificate=$PKIDIR/testpki-cert.pem --ca-cert=$PKIDIR/testpki-cacert.pem transact ssl:[[::1]]:$SSL_PORT 'txn'], [0], [stdout], [ignore],
820      [test ! -e pid || kill `cat pid`])
821 cat stdout >> output
822 ])
823    AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
824             [test ! -e pid || kill `cat pid`])
825    OVSDB_SERVER_SHUTDOWN
826    AT_CLEANUP])
827
828 ONE_EXECUTION_EXAMPLE
829
830 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv4 sockets)])
831
832 AT_SETUP([ovsdb-client get-schema-version - tcp socket])
833 AT_KEYWORDS([ovsdb server positive tcp])
834 ordinal_schema > schema
835 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
836 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
837 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])
838 TCP_PORT=`parse_listening_port < ovsdb-server.log`
839 AT_CHECK([ovsdb-client get-schema-version tcp:127.0.0.1:$TCP_PORT ordinals], [0], [5.1.3
840 ])
841 OVSDB_SERVER_SHUTDOWN
842 AT_CLEANUP])
843
844 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
845 #
846 # Creates a database with the given SCHEMA, starts an ovsdb-server on
847 # that database, and runs each of the TRANSACTIONS (which should be a
848 # quoted list of quoted strings) against it with ovsdb-client one at a
849 # time.
850 #
851 # Checks that the overall output is OUTPUT, but UUIDs in the output
852 # are replaced by markers of the form <N> where N is a number.  The
853 # first unique UUID is replaced by <0>, the next by <1>, and so on.
854 # If a given UUID appears more than once it is always replaced by the
855 # same marker.
856 #
857 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
858 m4_define([OVSDB_CHECK_EXECUTION],
859   [AT_SETUP([$1])
860    AT_KEYWORDS([ovsdb server positive tcp $5])
861    OVS_RUNDIR=`pwd`; export OVS_RUNDIR
862    OVS_LOGDIR=`pwd`; export OVS_LOGDIR
863    $2 > schema
864    PKIDIR=$abs_top_builddir/tests
865    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
866    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])
867    TCP_PORT=`parse_listening_port < ovsdb-server.log`
868    m4_foreach([txn], [$3],
869      [AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT 'txn'], [0], [stdout], [ignore],
870      [test ! -e pid || kill `cat pid`])
871 cat stdout >> output
872 ])
873    AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
874             [test ! -e pid || kill `cat pid`])
875    OVSDB_SERVER_SHUTDOWN
876    AT_CLEANUP])
877
878 EXECUTION_EXAMPLES
879
880 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv6 sockets)])
881
882 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
883 #
884 # Creates a database with the given SCHEMA, starts an ovsdb-server on
885 # that database, and runs each of the TRANSACTIONS (which should be a
886 # quoted list of quoted strings) against it with ovsdb-client one at a
887 # time.
888 #
889 # Checks that the overall output is OUTPUT, but UUIDs in the output
890 # are replaced by markers of the form <N> where N is a number.  The
891 # first unique UUID is replaced by <0>, the next by <1>, and so on.
892 # If a given UUID appears more than once it is always replaced by the
893 # same marker.
894 #
895 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
896 m4_define([OVSDB_CHECK_EXECUTION],
897   [AT_SETUP([$1])
898    AT_KEYWORDS([ovsdb server positive tcp6 $5])
899    OVS_RUNDIR=`pwd`; export OVS_RUNDIR
900    OVS_LOGDIR=`pwd`; export OVS_LOGDIR
901    $2 > schema
902    PKIDIR=$abs_top_builddir/tests
903    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
904    AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid --remote=ptcp:0:[[::1]] --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
905    TCP_PORT=`parse_listening_port < ovsdb-server.log`
906    m4_foreach([txn], [$3],
907      [AT_CHECK([ovsdb-client transact tcp:[[::1]]:$TCP_PORT 'txn'], [0], [stdout], [ignore],
908      [test ! -e pid || kill `cat pid`])
909 cat stdout >> output
910 ])
911    AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
912             [test ! -e pid || kill `cat pid`])
913    OVSDB_SERVER_SHUTDOWN
914    AT_CLEANUP])
915
916 ONE_EXECUTION_EXAMPLE
917 \f
918 AT_BANNER([OVSDB -- transactions on transient ovsdb-server])
919
920 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
921 #
922 # Creates a database with the given SCHEMA and runs each of the
923 # TRANSACTIONS (which should be a quoted list of quoted strings)
924 # against it with ovsdb-client one at a time.  Each ovsdb-client
925 # is run against a separately started ovsdb-server that executes
926 # only that single transaction.  (The idea is that this should
927 # help to ferret out any differences between what ovsdb-server has
928 # in memory and what actually gets committed to disk.)
929 #
930 # Checks that the overall output is OUTPUT, but UUIDs in the output
931 # are replaced by markers of the form <N> where N is a number.  The
932 # first unique UUID is replaced by <0>, the next by <1>, and so on.
933 # If a given UUID appears more than once it is always replaced by the
934 # same marker.
935 #
936 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
937 m4_define([OVSDB_CHECK_EXECUTION], 
938   [AT_SETUP([$1])
939    AT_KEYWORDS([ovsdb server positive transient $5])
940    OVS_RUNDIR=`pwd`; export OVS_RUNDIR
941    $2 > schema
942    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
943    m4_foreach([txn], [$3], 
944      [AT_DATA([txnfile], [ovsdb-client transact unix:socket 'txn'
945 ])
946       AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [ignore])
947       cat stdout >> output
948 ])
949    AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore])
950    AT_CLEANUP])
951
952 EXECUTION_EXAMPLES