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