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