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