test: change replication test to use unix domain socket
[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_BY_TARGET([`pwd`/unixctl], [`pwd`/pid])])
5
6 m4_define([OVSDB_SERVER_SHUTDOWN2],
7   [cp pid2 savepid2
8    AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 -e exit], [0], [ignore], [ignore])
9    OVS_WAIT_WHILE([kill -0 `cat savepid2`], [kill `cat savepid2`])])
10
11 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
12 #
13 # Creates a database with the given SCHEMA, starts an ovsdb-server on
14 # that database, and runs each of the TRANSACTIONS (which should be a
15 # quoted list of quoted strings) against it with ovsdb-client one at a
16 # time.
17 #
18 # Checks that the overall output is OUTPUT, but UUIDs in the output
19 # are replaced by markers of the form <N> where N is a number.  The
20 # first unique UUID is replaced by <0>, the next by <1>, and so on.
21 # If a given UUID appears more than once it is always replaced by the
22 # same marker.
23 #
24 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
25 m4_define([OVSDB_CHECK_EXECUTION], 
26   [AT_SETUP([$1])
27    AT_KEYWORDS([ovsdb server positive unix $5])
28    $2 > schema
29    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
30    AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
31    m4_foreach([txn], [$3], 
32      [AT_CHECK([ovsdb-client transact unix:socket 'txn'], [0], [stdout], [ignore],
33      [test ! -e pid || kill `cat pid`])
34 cat stdout >> output
35 ])
36    AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
37             [test ! -e pid || kill `cat pid`])
38    OVSDB_SERVER_SHUTDOWN
39    AT_CLEANUP])
40
41 EXECUTION_EXAMPLES
42 \f
43 AT_BANNER([ovsdb-server miscellaneous features])
44
45 AT_SETUP([truncating corrupted database log])
46 AT_KEYWORDS([ovsdb server positive unix])
47 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
48 ordinal_schema > schema
49 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
50 dnl Do one transaction and save the output.
51 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
52 '["ordinals",
53   {"op": "insert",
54    "table": "ordinals",
55    "row": {"number": 0, "name": "zero"}}]'
56 ]])
57 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
58 cat stdout >> output
59 dnl Add some crap to the database log and run another transaction, which should
60 dnl ignore the crap and truncate it out of the log.
61 echo 'xxx' >> db
62 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
63 '["ordinals",
64   {"op": "insert",
65    "table": "ordinals",
66    "row": {"number": 1, "name": "one"}}]'
67 ]])
68 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [stderr])
69 AT_CHECK([grep 'syntax error: db: parse error.* in header line "xxx"' stderr],
70   [0], [ignore])
71 cat stdout >> output
72 dnl Run a final transaction to verify that both transactions succeeeded.
73 dnl The crap that we added should have been truncated by the previous run,
74 dnl so ovsdb-server shouldn't log a warning this time.
75 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
76 '["ordinals",
77   {"op": "select",
78    "table": "ordinals",
79    "where": [],
80    "sort": ["number"]}]'
81 ]])
82 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
83 cat stdout >> output
84 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0],
85   [[[{"uuid":["uuid","<0>"]}]
86 [{"uuid":["uuid","<1>"]}]
87 [{"rows":[{"_uuid":["uuid","<0>"],"_version":["uuid","<2>"],"name":"zero","number":0},{"_uuid":["uuid","<1>"],"_version":["uuid","<3>"],"name":"one","number":1}]}]
88 ]], [],
89          [test ! -e pid || kill `cat pid`])
90 AT_CLEANUP
91
92 AT_SETUP([truncating database log with bad transaction])
93 AT_KEYWORDS([ovsdb server positive unix])
94 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
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 ordinal_schema > schema
143 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
144 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=punix:socket db], [0], [ignore], [ignore])
145 AT_CHECK([ovsdb-client get-schema-version unix:socket ordinals], [0], [5.1.3
146 ])
147 OVSDB_SERVER_SHUTDOWN
148 AT_CLEANUP
149
150 AT_SETUP([database multiplexing implementation])
151 AT_KEYWORDS([ovsdb server positive])
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":{"details":"get_schema request specifies unknown database nonexistent","error":"unknown database","syntax":"[\"nonexistent\"]"},"id":0,"result":null}
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 ordinal_schema > schema1
173 constraint_schema > schema2
174 AT_CHECK([ovsdb-tool create db1 schema1], [0], [ignore], [ignore])
175 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
176
177 # Start ovsdb-server with just a single database - db1.
178 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db1], [0])
179 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
180   [0], [ordinals
181 ])
182
183 # Add the second database.
184 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
185 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
186   [0], [constraints
187 ordinals
188 ])
189
190 # The databases are responsive.
191 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [0], [ignore], [ignore])
192 AT_CHECK([ovsdb-client list-tables unix:socket ordinals], [0], [ignore], [ignore])
193
194 # Add an already added database.
195 if test $IS_WIN32 = "yes"; then
196   AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], 2, [],
197   [I/O error: db2: failed to lock lockfile (Resource deadlock avoided)
198 ovs-appctl: ovsdb-server: server returned an error
199 ])
200 else
201   AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], 2, [],
202   [db2: already open
203 ovs-appctl: ovsdb-server: server returned an error
204 ])
205 fi
206
207 # Add a non-existing database.
208 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db3], 2, [], [stderr])
209 AT_CHECK([sed 's/(.*)/(...)/' stderr], [0],
210   [I/O error: db3: open failed (...)
211 ovs-appctl: ovsdb-server: server returned an error
212 ])
213
214 # Add a remote through a db path in db1.
215 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote db:ordinals,ordinals,name], [0])
216 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
217   [0], [db:ordinals,ordinals,name
218 punix:socket
219 ])
220
221 # Removing db1 has no effect on its remote.
222 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db ordinals], [0])
223 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
224   [0], [constraints
225 ])
226 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
227   [0], [db:ordinals,ordinals,name
228 punix:socket
229 ])
230 AT_CHECK([ovsdb-client list-tables unix:socket ordinals], [1], [ignore], [ignore])
231
232 # Remove db2.
233 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db constraints], [0])
234 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
235   [0], [])
236 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [1], [ignore], [ignore])
237
238 # Remove a non-existent database.
239 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db ordinals], [2],
240   [], [Failed to find the database.
241 ovs-appctl: ovsdb-server: server returned an error
242 ])
243
244 # Add a removed database.
245 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
246 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
247   [0], [constraints
248 ])
249 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [0], [ignore], [ignore])
250 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
251 AT_CLEANUP
252
253 AT_SETUP([ovsdb-server/add-db with --monitor])
254 AT_KEYWORDS([ovsdb server positive])
255 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
256 # Start ovsdb-server, initially with one db.
257 ordinal_schema > schema
258 AT_CHECK([ovsdb-tool create db1 schema], [0], [ignore], [ignore])
259 on_exit 'kill `cat *.pid`'
260 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db1])
261
262 # Add the second database.
263 constraint_schema > schema2
264 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
265 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
266 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
267   [0], [constraints
268 ordinals
269 ])
270
271 # Kill the daemon process, making it look like a segfault,
272 # and wait for a new daemon process to get spawned.
273 cp ovsdb-server.pid old.pid
274 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
275 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
276 OVS_WAIT_UNTIL(
277   [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
278 OVS_WAIT_UNTIL([ovs-appctl -t ovsdb-server version])
279 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
280   [0], [constraints
281 ordinals
282 ])
283 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
284 AT_CLEANUP
285
286 AT_SETUP([ovsdb-server/add-db and remove-db with --monitor])
287 AT_KEYWORDS([ovsdb server positive])
288 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
289 # Start ovsdb-server, initially with one db.
290 ordinal_schema > schema
291 AT_CHECK([ovsdb-tool create db1 schema], [0], [ignore], [ignore])
292 constraint_schema > schema2
293 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
294 on_exit 'kill `cat *.pid`'
295 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db1 db2])
296
297 # Remove the second database.
298 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db constraints])
299 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
300   [0], [ordinals
301 ])
302
303 # Kill the daemon process, making it look like a segfault,
304 # and wait for a new daemon process to get spawned.
305 cp ovsdb-server.pid old.pid
306 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
307 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
308 OVS_WAIT_UNTIL(
309   [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
310 OVS_WAIT_UNTIL([ovs-appctl -t ovsdb-server version])
311 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
312   [0], [ordinals
313 ])
314 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
315 AT_CLEANUP
316
317 AT_SETUP([--remote=db: implementation])
318 AT_KEYWORDS([ovsdb server positive])
319 AT_DATA([schema],
320   [[{"name": "mydb",
321      "tables": {
322        "Root": {
323          "columns": {
324            "managers": {
325              "type": {
326                "key": "string",
327                "min": 0,
328                "max": "unlimited"}},
329            "manager_options": {
330              "type": {
331                "key": {"type": "uuid", "refTable": "Manager"},
332                "min": 0,
333                "max": "unlimited"}}}},
334        "Manager": {
335          "columns": {
336            "target": {
337              "type": "string"},
338            "is_connected": {
339              "type": {
340                "key": "boolean",
341                "min": 0,
342                "max": 1}}}}}}
343 ]])
344 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
345 AT_CHECK(
346   [[ovsdb-tool transact db \
347      '["mydb",
348        {"op": "insert",
349         "table": "Root",
350         "row": {
351           "managers": "punix:socket1",
352           "manager_options": ["set", [["named-uuid", "x"]]]}},
353        {"op": "insert",
354         "table": "Manager",
355         "uuid-name": "x",
356         "row": {"target": "punix:socket2"}}]']], [0], [ignore], [ignore])
357 on_exit 'kill `cat ovsdb-server.pid`'
358 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])
359 ovs-appctl -t ovsdb-server time/warp 6000 1000
360 AT_CHECK(
361   [[ovsdb-client transact unix:socket1 \
362      '["mydb",
363        {"op": "select",
364         "table": "Root",
365         "where": [],
366         "columns": ["managers"]},
367        {"op": "select",
368         "table": "Manager",
369         "where": [],
370         "columns": ["target", "is_connected"]}]']],
371   [0], [stdout], [ignore])
372 AT_CHECK(
373   [${PERL} $srcdir/uuidfilt.pl stdout], 
374   [0], 
375   [[[{"rows":[{"managers":"punix:socket1"}]},{"rows":[{"is_connected":false,"target":"punix:socket2"}]}]
376 ]], 
377   [ignore])
378 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
379 AT_CLEANUP
380
381 AT_SETUP([ovsdb-server/add-remote and remove-remote])
382 AT_KEYWORDS([ovsdb server positive])
383 ordinal_schema > schema
384 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
385 on_exit 'kill `cat *.pid`'
386 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile db])
387
388 AT_CHECK([test ! -e socket1])
389 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
390 if test "$IS_WIN32" = "yes"; then
391   OVS_WAIT_UNTIL([test -s socket1])
392 else
393   OVS_WAIT_UNTIL([test -S socket1])
394 fi
395 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
396   [0], [punix:socket1
397 ])
398
399 AT_CHECK([test ! -e socket2])
400 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket2])
401 if test "$IS_WIN32" = "yes"; then
402   OVS_WAIT_UNTIL([test -s socket2])
403 else
404   OVS_WAIT_UNTIL([test -S socket2])
405 fi
406 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
407   [0], [punix:socket1
408 punix:socket2
409 ])
410
411 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote db:x,y,z], [2],
412   [], ["db:x,y,z": no database named x
413 ovs-appctl: ovsdb-server: server returned an error
414 ])
415
416 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
417 OVS_WAIT_UNTIL([test ! -e socket1])
418 if test "$IS_WIN32" = "yes"; then
419   AT_CHECK([test -s socket2])
420 else
421   AT_CHECK([test -S socket2])
422 fi
423 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
424   [0], [punix:socket2
425 ])
426
427 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket2])
428 OVS_WAIT_UNTIL([test ! -e socket2])
429 AT_CHECK([test ! -e socket1])
430 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
431 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
432 AT_CLEANUP
433
434 AT_SETUP([ovsdb-server/add-remote with --monitor])
435 AT_KEYWORDS([ovsdb server positive])
436 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
437 # Start ovsdb-server, initially with no remotes.
438 ordinal_schema > schema
439 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
440 on_exit 'kill `cat *.pid`'
441 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db])
442
443 # Add a remote.
444 AT_CHECK([test ! -e socket1])
445 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
446 OVS_WAIT_UNTIL([test -S socket1])
447 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
448   [0], [punix:socket1
449 ])
450
451 # Kill the daemon process, making it look like a segfault,
452 # and wait for a new daemon process to get spawned and for it to
453 # start listening on 'socket1'.
454 cp ovsdb-server.pid old.pid
455 rm socket1
456 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
457 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
458 OVS_WAIT_UNTIL(
459   [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
460 OVS_WAIT_UNTIL([ovs-appctl -t ovsdb-server version])
461 OVS_WAIT_UNTIL([test -S socket1])
462 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
463 AT_CLEANUP
464
465 AT_SETUP([ovsdb-server/add-remote and remove-remote with --monitor])
466 AT_KEYWORDS([ovsdb server positive])
467 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
468 # Start ovsdb-server, initially with no remotes.
469 ordinal_schema > schema
470 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
471 on_exit 'kill `cat *.pid`'
472 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db])
473
474 # Add a remote.
475 AT_CHECK([test ! -e socket1])
476 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
477 OVS_WAIT_UNTIL([test -S socket1])
478 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
479   [0], [punix:socket1
480 ])
481
482 # Remove the remote.
483 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
484 OVS_WAIT_UNTIL([test ! -e socket1])
485 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
486
487 # Kill the daemon process, making it look like a segfault,
488 # and wait for a new daemon process to get spawned and make sure that it
489 # does not listen on 'socket1'.
490 cp ovsdb-server.pid old.pid
491 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
492 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
493 OVS_WAIT_UNTIL(
494   [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
495 OVS_WAIT_UNTIL([ovs-appctl -t ovsdb-server version])
496 AT_CHECK([test ! -e socket1])
497 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
498 AT_CLEANUP
499
500 AT_SETUP([SSL db: implementation])
501 AT_KEYWORDS([ovsdb server positive ssl $5])
502 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
503 # For this test, we pass PKIDIR through a ovsdb-tool transact and
504 # msys on Windows does not convert the path style automatically.
505 # So, do that forcefully with a 'pwd -W' (called through pwd() function).
506 PKIDIR="$(cd $abs_top_builddir/tests && pwd)"
507 AT_SKIP_IF([expr "$PKIDIR" : ".*[       '\"
508 \\]"])
509 AT_DATA([schema],
510   [[{"name": "mydb",
511      "tables": {
512        "SSL": {
513          "columns": {
514            "private_key": {"type": "string"},
515            "certificate": {"type": "string"},
516            "ca_cert": {"type": "string"}}}}}
517 ]])
518 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
519 AT_CHECK(
520   [[ovsdb-tool transact db \
521      '["mydb",
522        {"op": "insert",
523         "table": "SSL",
524         "row": {"private_key": "'"$PKIDIR/testpki-privkey2.pem"'",
525                 "certificate": "'"$PKIDIR/testpki-cert2.pem"'",
526                 "ca_cert": "'"$PKIDIR/testpki-cacert.pem"'"}}]']],
527   [0], [ignore], [ignore])
528 AT_CHECK(
529   [ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid \
530         --private-key=db:mydb,SSL,private_key \
531         --certificate=db:mydb,SSL,certificate \
532         --ca-cert=db:mydb,SSL,ca_cert \
533         --remote=pssl:0:127.0.0.1 --unixctl="`pwd`"/unixctl db],
534   [0], [ignore], [ignore])
535 PARSE_LISTENING_PORT([ovsdb-server.log], [SSL_PORT])
536 AT_CHECK(
537   [[ovsdb-client \
538         --private-key=$PKIDIR/testpki-privkey.pem \
539         --certificate=$PKIDIR/testpki-cert.pem \
540         --ca-cert=$PKIDIR/testpki-cacert.pem \
541         transact ssl:127.0.0.1:$SSL_PORT \
542         '["mydb",
543           {"op": "select",
544            "table": "SSL",
545            "where": [],
546            "columns": ["private_key"]}]']], 
547   [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
548 cat stdout >> output
549 AT_CHECK_UNQUOTED(
550   [cat output], [0],
551   [[@<:@{"rows":@<:@{"private_key":"$PKIDIR/testpki-privkey2.pem"}@:>@}@:>@
552 ]], [ignore], [test ! -e pid || kill `cat pid`])
553 OVSDB_SERVER_SHUTDOWN
554 AT_CLEANUP
555
556 AT_SETUP([compacting online])
557 AT_KEYWORDS([ovsdb server compact])
558 ordinal_schema > schema
559 dnl Make sure that "ovsdb-tool create" works with a dangling symlink for
560 dnl the database and the lockfile, creating the target of each symlink rather
561 dnl than replacing the symlinks with regular files.
562 mkdir dir
563 ln -s dir/db db
564 ln -s dir/.db.~lock~ .db.~lock~
565 AT_SKIP_IF([test ! -h db || test ! -h .db.~lock~])
566 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
567 dnl Start ovsdb-server.
568 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])
569 AT_CAPTURE_FILE([ovsdb-server.log])
570 dnl Do a bunch of random transactions that put crap in the database log.
571 AT_CHECK(
572   [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
573       set -- $pair
574       ovsdb-client transact unix:socket '
575         ["ordinals",
576          {"op": "insert",
577           "table": "ordinals",
578           "row": {"name": "'$1'", "number": '$2'}},
579          {"op": "comment",
580           "comment": "add row for '"$pair"'"}]'
581       ovsdb-client transact unix:socket '
582         ["ordinals",
583          {"op": "delete",
584           "table": "ordinals",
585           "where": [["number", "==", '$2']]},
586          {"op": "comment",
587           "comment": "delete row for '"$2"'"}]'
588       ovsdb-client transact unix:socket '
589         ["ordinals",
590          {"op": "insert",
591           "table": "ordinals",
592           "row": {"name": "'$1'", "number": '$2'}},
593          {"op": "comment",
594           "comment": "add back row for '"$pair"'"}]'
595     done]],
596   [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
597 dnl Check that all the crap is in fact in the database log.
598 AT_CHECK([[${PERL} $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | ovstest test-json --multiple -]], [0],
599   [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"}
600 {"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
601 {"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
602 {"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
603 {"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
604 {"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
605 {"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
606 {"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
607 {"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
608 {"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
609 {"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
610 {"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
611 {"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
612 {"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
613 {"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
614 {"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
615 {"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
616 {"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
617 {"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
618 ]], [], [test ! -e pid || kill `cat pid`])
619 dnl Dump out and check the actual database contents.
620 AT_CHECK([[ovsdb-client dump unix:socket ordinals]],
621   [0], [stdout], [ignore])
622 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
623 ordinals table
624 _uuid                                name  number
625 ------------------------------------ ----- ------
626 <0> five  5     @&t@
627 <1> four  4     @&t@
628 <2> one   1     @&t@
629 <3> three 3     @&t@
630 <4> two   2     @&t@
631 <5> zero  0     @&t@
632 ], [], [test ! -e pid || kill `cat pid`])
633 dnl Now compact the database in-place.
634 AT_CHECK([[ovs-appctl -t "`pwd`"/unixctl ovsdb-server/compact]],
635   [0], [], [ignore], [test ! -e pid || kill `cat pid`])
636 dnl Make sure that "db" is still a symlink to dir/db instead of getting
637 dnl replaced by a regular file, ditto for .db.~lock~.
638 AT_CHECK([test -h db])
639 AT_CHECK([test -h .db.~lock~])
640 AT_CHECK([test -f dir/db])
641 AT_CHECK([test -f dir/.db.~lock~])
642 dnl We can't fully re-check the contents of the database log, because the
643 dnl order of the records is not predictable, but there should only be 4 lines
644 dnl in it now.
645 AT_CAPTURE_FILE([db])
646 AT_CHECK([test `wc -l < db` -eq 4], [0], [], [],
647   [test ! -e pid || kill `cat pid`])
648 dnl And check that the dumped data is the same too:
649 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
650   [test ! -e pid || kill `cat pid`])
651 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
652 ordinals table
653 _uuid                                name  number
654 ------------------------------------ ----- ------
655 <0> five  5     @&t@
656 <1> four  4     @&t@
657 <2> one   1     @&t@
658 <3> three 3     @&t@
659 <4> two   2     @&t@
660 <5> zero  0     @&t@
661 ], [], [test ! -e pid || kill `cat pid`])
662 dnl Now do some more transactions.
663 AT_CHECK(
664   [[ovsdb-client transact unix:socket '
665      ["ordinals",
666       {"op": "delete",
667        "table": "ordinals",
668        "where": [["number", "<", 3]]}]']],
669   [0], [[[{"count":3}]
670 ]], [ignore], [test ! -e pid || kill `cat pid`])
671 dnl There should be 6 lines in the log now.
672 AT_CHECK([test `wc -l < db` -eq 6], [0], [], [],
673   [test ! -e pid || kill `cat pid`])
674 dnl Then check that the dumped data is correct.
675 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
676   [test ! -e pid || kill `cat pid`])
677 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
678 ordinals table
679 _uuid                                name  number
680 ------------------------------------ ----- ------
681 <0> five  5     @&t@
682 <1> four  4     @&t@
683 <2> three 3     @&t@
684 ], [], [test ! -e pid || kill `cat pid`])
685 OVSDB_SERVER_SHUTDOWN
686 AT_CLEANUP
687
688 AT_SETUP([ovsdb-server combines updates on backlogged connections])
689 on_exit 'kill `cat *.pid`'
690
691 # The maximum socket receive buffer size is important for this test, which
692 # tests behavior when the receive buffer overflows.
693 if test -e /proc/sys/net/core/rmem_max; then
694     # Linux
695     rmem_max=`cat /proc/sys/net/core/rmem_max`
696 elif rmem_max=`sysctl -n net.inet.tcp.recvbuf_max 2>/dev/null`; then
697     : # FreeBSD, NetBSD
698 else
699     # Don't know how to get maximum socket receive buffer on this OS
700     AT_SKIP_IF([:])
701 fi
702
703 # Calculate the number of iterations we need to queue.  Each of the
704 # iterations we execute, by itself, yields a monitor update of about
705 # 25 kB, so fill up that much space plus a few for luck.
706 n_iterations=`expr $rmem_max / 25000 + 5`
707 echo rmem_max=$rmem_max n_iterations=$n_iterations
708
709 # If there's too much queuing skip the test to avoid timing out.
710 AT_SKIP_IF([test $rmem_max -gt 1048576])
711
712 # Calculate the exact number of monitor updates expected for $n_iterations,
713 # assuming no updates are combined.  The "extra" update is for the initial
714 # contents of the database.
715 n_updates=`expr $n_iterations \* 3 + 1`
716
717 # Start an ovsdb-server with the vswitchd schema.
718 OVSDB_INIT([db])
719 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --log-file --remote=punix:db.sock db],
720   [0], [ignore], [ignore])
721
722 # Executes a set of transactions that add a bridge with 100 ports, and
723 # then deletes that bridge.  This yields three monitor updates that
724 # add up to about 25 kB in size.
725 #
726 # The update also increments a counter held in the database so that we can
727 # verify that the overall effect of the transactions took effect (e.g.
728 # monitor updates at the end weren't just dropped).  We add an arbitrary
729 # string to the counter to make grepping for it more reliable.
730 counter=0
731 trigger_big_update () {
732     counter=`expr $counter + 1`
733     ovs-vsctl --no-wait -- set open_vswitch . system_version=xyzzy$counter
734     ovs-vsctl --no-wait -- add-br br0 $add
735     ovs-vsctl --no-wait -- del-br br0
736 }
737 add_ports () {
738     for j in `seq 1 100`; do
739         printf " -- add-port br0 p%d" $j
740     done
741 }
742 add=`add_ports`
743
744 AT_CAPTURE_FILE([ovsdb-client.err])
745 AT_CAPTURE_FILE([ovsdb-client-nonblock.err])
746
747
748 # Start an ovsdb-client monitoring all changes to the database,
749 # By default, it is non-blocking, and will get update message
750 # for each ovsdb-server transaactions.
751 AT_CHECK([ovsdb-client --detach --no-chdir --pidfile=nonblock.pid monitor ALL >ovsdb-client-nonblock.out 2>ovsdb-client-nonblock.err])
752
753 # Start an ovsdb-client monitoring all changes to the database,
754 # make it block to force the buffers to fill up, and then execute
755 # enough iterations that ovsdb-server starts combining updates.
756 AT_CHECK([ovsdb-client --detach --no-chdir --pidfile monitor ALL >ovsdb-client.out 2>ovsdb-client.err])
757 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/block])
758 for i in `seq 1 $n_iterations`; do
759     echo "blocked update ($i of $n_iterations)"
760     trigger_big_update $i
761 done
762 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/unblock])
763 OVS_WAIT_UNTIL([grep "\"xyzzy$counter\"" ovsdb-client.out])
764 OVS_WAIT_UNTIL([grep "\"xyzzy$counter\"" ovsdb-client-nonblock.out])
765 OVS_APP_EXIT_AND_WAIT([ovsdb-client])
766 AT_CHECK([kill `cat nonblock.pid`])
767
768 # Count the number of updates in the ovsdb-client output, by counting
769 # the number of changes to the Open_vSwitch table.  (All of our
770 # transactions modify the Open_vSwitch table.)  It should be less than
771 # $n_updates updates.
772 #
773 # Check that the counter is what we expect.
774 logged_updates=`grep -c '^Open_vSwitch' ovsdb-client.out`
775 logged_nonblock_updates=`grep -c '^Open_vSwitch' ovsdb-client-nonblock.out`
776 echo "logged_nonblock_updates=$logged_nonblock_updates (expected less or equal to $n_updates)"
777 echo "logged_updates=$logged_updates (expected less than $logged_nonblock_updates)"
778 AT_CHECK([test $logged_nonblock_updates -le $n_updates])
779 AT_CHECK([test $logged_updates -lt $logged_nonblock_updates])
780 AT_CHECK_UNQUOTED([ovs-vsctl get open_vswitch . system_version], [0],
781   ["xyzzy$counter"
782 ])
783 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
784 AT_CLEANUP
785 \f
786 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv4 sockets)])
787
788 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
789 #
790 # Creates a database with the given SCHEMA, starts an ovsdb-server on
791 # that database, and runs each of the TRANSACTIONS (which should be a
792 # quoted list of quoted strings) against it with ovsdb-client one at a
793 # time.
794 #
795 # Checks that the overall output is OUTPUT, but UUIDs in the output
796 # are replaced by markers of the form <N> where N is a number.  The
797 # first unique UUID is replaced by <0>, the next by <1>, and so on.
798 # If a given UUID appears more than once it is always replaced by the
799 # same marker.
800 #
801 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
802 m4_define([OVSDB_CHECK_EXECUTION], 
803   [AT_SETUP([$1])
804    AT_KEYWORDS([ovsdb server positive ssl $5])
805    AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
806    $2 > schema
807    PKIDIR=$abs_top_builddir/tests
808    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
809    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])
810    PARSE_LISTENING_PORT([ovsdb-server.log], [SSL_PORT])
811    m4_foreach([txn], [$3], 
812      [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],
813      [test ! -e pid || kill `cat pid`])
814 cat stdout >> output
815 ])
816    AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
817             [test ! -e pid || kill `cat pid`])
818    OVSDB_SERVER_SHUTDOWN
819    AT_CLEANUP])
820
821 EXECUTION_EXAMPLES
822
823 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv6 sockets)])
824
825 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
826 #
827 # Creates a database with the given SCHEMA, starts an ovsdb-server on
828 # that database, and runs each of the TRANSACTIONS (which should be a
829 # quoted list of quoted strings) against it with ovsdb-client one at a
830 # time.
831 #
832 # Checks that the overall output is OUTPUT, but UUIDs in the output
833 # are replaced by markers of the form <N> where N is a number.  The
834 # first unique UUID is replaced by <0>, the next by <1>, and so on.
835 # If a given UUID appears more than once it is always replaced by the
836 # same marker.
837 #
838 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
839 m4_define([OVSDB_CHECK_EXECUTION],
840   [AT_SETUP([$1])
841    AT_KEYWORDS([ovsdb server positive ssl6 $5])
842    AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
843    AT_SKIP_IF([test $HAVE_IPV6 = no])
844    $2 > schema
845    PKIDIR=$abs_top_builddir/tests
846    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
847    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])
848    PARSE_LISTENING_PORT([ovsdb-server.log], [SSL_PORT])
849    m4_foreach([txn], [$3],
850      [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],
851      [test ! -e pid || kill `cat pid`])
852 cat stdout >> output
853 ])
854    AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
855             [test ! -e pid || kill `cat pid`])
856    OVSDB_SERVER_SHUTDOWN
857    AT_CLEANUP])
858
859 ONE_EXECUTION_EXAMPLE
860
861 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv4 sockets)])
862
863 AT_SETUP([ovsdb-client get-schema-version - tcp socket])
864 AT_KEYWORDS([ovsdb server positive tcp])
865 ordinal_schema > schema
866 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
867 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])
868 PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
869 AT_CHECK([ovsdb-client get-schema-version tcp:127.0.0.1:$TCP_PORT ordinals], [0], [5.1.3
870 ])
871 OVSDB_SERVER_SHUTDOWN
872 AT_CLEANUP])
873
874 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
875 #
876 # Creates a database with the given SCHEMA, starts an ovsdb-server on
877 # that database, and runs each of the TRANSACTIONS (which should be a
878 # quoted list of quoted strings) against it with ovsdb-client one at a
879 # time.
880 #
881 # Checks that the overall output is OUTPUT, but UUIDs in the output
882 # are replaced by markers of the form <N> where N is a number.  The
883 # first unique UUID is replaced by <0>, the next by <1>, and so on.
884 # If a given UUID appears more than once it is always replaced by the
885 # same marker.
886 #
887 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
888 m4_define([OVSDB_CHECK_EXECUTION],
889   [AT_SETUP([$1])
890    AT_KEYWORDS([ovsdb server positive tcp $5])
891    $2 > schema
892    PKIDIR=$abs_top_builddir/tests
893    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
894    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])
895    PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
896    m4_foreach([txn], [$3],
897      [AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT 'txn'], [0], [stdout], [ignore],
898      [test ! -e pid || kill `cat pid`])
899 cat stdout >> output
900 ])
901    AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
902             [test ! -e pid || kill `cat pid`])
903    OVSDB_SERVER_SHUTDOWN
904    AT_CLEANUP])
905
906 EXECUTION_EXAMPLES
907
908 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv6 sockets)])
909
910 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
911 #
912 # Creates a database with the given SCHEMA, starts an ovsdb-server on
913 # that database, and runs each of the TRANSACTIONS (which should be a
914 # quoted list of quoted strings) against it with ovsdb-client one at a
915 # time.
916 #
917 # Checks that the overall output is OUTPUT, but UUIDs in the output
918 # are replaced by markers of the form <N> where N is a number.  The
919 # first unique UUID is replaced by <0>, the next by <1>, and so on.
920 # If a given UUID appears more than once it is always replaced by the
921 # same marker.
922 #
923 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
924 m4_define([OVSDB_CHECK_EXECUTION],
925   [AT_SETUP([$1])
926    AT_KEYWORDS([ovsdb server positive tcp6 $5])
927    AT_SKIP_IF([test $HAVE_IPV6 = no])
928    $2 > schema
929    PKIDIR=$abs_top_builddir/tests
930    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
931    AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid --remote=ptcp:0:[[::1]] --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
932    PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
933    m4_foreach([txn], [$3],
934      [AT_CHECK([ovsdb-client transact tcp:[[::1]]:$TCP_PORT 'txn'], [0], [stdout], [ignore],
935      [test ! -e pid || kill `cat pid`])
936 cat stdout >> output
937 ])
938    AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
939             [test ! -e pid || kill `cat pid`])
940    OVSDB_SERVER_SHUTDOWN
941    AT_CLEANUP])
942
943 ONE_EXECUTION_EXAMPLE
944 \f
945 AT_BANNER([OVSDB -- transactions on transient ovsdb-server])
946
947 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
948 #
949 # Creates a database with the given SCHEMA and runs each of the
950 # TRANSACTIONS (which should be a quoted list of quoted strings)
951 # against it with ovsdb-client one at a time.  Each ovsdb-client
952 # is run against a separately started ovsdb-server that executes
953 # only that single transaction.  (The idea is that this should
954 # help to ferret out any differences between what ovsdb-server has
955 # in memory and what actually gets committed to disk.)
956 #
957 # Checks that the overall output is OUTPUT, but UUIDs in the output
958 # are replaced by markers of the form <N> where N is a number.  The
959 # first unique UUID is replaced by <0>, the next by <1>, and so on.
960 # If a given UUID appears more than once it is always replaced by the
961 # same marker.
962 #
963 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
964 m4_define([OVSDB_CHECK_EXECUTION], 
965   [AT_SETUP([$1])
966    AT_SKIP_IF([test "$IS_WIN32" = "yes"])
967    AT_KEYWORDS([ovsdb server positive transient $5])
968    $2 > schema
969    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
970    m4_foreach([txn], [$3], 
971      [AT_DATA([txnfile], [ovsdb-client transact unix:socket 'txn'
972 ])
973       AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [ignore])
974       cat stdout >> output
975 ])
976    AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore])
977    AT_CLEANUP])
978
979 EXECUTION_EXAMPLES
980 \f
981 AT_BANNER([OVSDB -- ovsdb-server replication])
982
983 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
984 #
985 # Creates two databases with the given SCHEMA, and starts an ovsdb-server on
986 # each database.
987 # Runs each of the TRANSACTIONS (which should be a quoted list of
988 # quoted strings) against one of the servers with ovsdb-client one at a
989 # time. The server replicates its database to the other ovsdb-server.
990 #
991 # Checks that the dump of both databases are the same.
992 #
993 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
994 m4_define([OVSDB_CHECK_EXECUTION],
995   [AT_SETUP([$1])
996    AT_KEYWORDS([ovsdb server tcp replication $5])
997    $2 > schema
998    AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
999    AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1000
1001    AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile="`pwd`"/pid --remote=punix:db.sock --unixctl="`pwd`"/unixctl db1], [0], [ignore], [ignore])
1002
1003    AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server2.log --pidfile="`pwd`"/pid2 --remote=punix:db2.sock --unixctl="`pwd`"/unixctl2 --sync-from=unix:db.sock db2], [0], [ignore], [ignore])
1004
1005    m4_foreach([txn], [$3],
1006      [AT_CHECK([ovsdb-client transact 'txn'; sleep 2], [0], [stdout], [ignore],
1007      [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1008    ])
1009
1010    AT_CHECK([ovsdb-client dump], [0], [stdout], [ignore],
1011      [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1012    cat stdout >> dump1
1013    AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore],
1014      [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1015    cat stdout >> dump2
1016
1017    AT_CHECK([diff dump1 dump2], [0], [], [ignore],
1018             [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1019    OVSDB_SERVER_SHUTDOWN
1020    OVSDB_SERVER_SHUTDOWN2
1021    AT_CLEANUP])
1022
1023 EXECUTION_EXAMPLES
1024
1025 AT_BANNER([OVSDB -- ovsdb-server replication table-exclusion])
1026
1027 # OVSDB_CHECK_REPLICATION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
1028 #
1029 # Creates two databases with the given SCHEMA, and starts an
1030 # ovsdb-server on each database.
1031 # Runs each of the TRANSACTIONS (which should be a quoted list of
1032 # quoted strings) against one of the servers with ovsdb-client one at a
1033 # time. The server replicates its database to the other ovsdb-server.
1034 #
1035 # Checks that the difference between the dump of the databases is
1036 # OUTPUT, but UUIDs in the output are replaced by markers of the form
1037 # <N> where N is a number.  The first unique UUID is replaced by <0>,
1038 # the next by <1>, and so on.
1039 # If a given UUID appears more than once it is always replaced by the
1040 # same marker.
1041 #
1042 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
1043 m4_define([OVSDB_CHECK_REPLICATION],
1044    [AT_SETUP([$1])
1045    AT_KEYWORDS([ovsdb server tcp replication table-exclusion])
1046    $2 > schema
1047    AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1048    AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1049
1050    AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile="`pwd`"/pid --remote=punix:db.sock --unixctl="`pwd`"/unixctl db1], [0], [ignore], [ignore])
1051
1052    AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server2.log --pidfile="`pwd`"/pid2 --remote=punix:db2.sock --unixctl="`pwd`"/unixctl2 --sync-from=unix:db.sock --sync-exclude-tables=mydb:b db2], [0], [ignore], [ignore])
1053
1054    m4_foreach([txn], [$3],
1055      [AT_CHECK([ovsdb-client transact 'txn'; sleep 2], [0], [stdout], [ignore],
1056      [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1057    ])
1058
1059    AT_CHECK([ovsdb-client dump], [0], [stdout], [ignore],
1060      [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1061    cat stdout >> dump1
1062    AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore],
1063      [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1064    cat stdout >> dump2
1065
1066    AT_CHECK([diff dump1 dump2], [1], [stdout], [ignore],
1067             [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1068    cat stdout >> output
1069
1070    AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
1071             [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1072
1073    OVSDB_SERVER_SHUTDOWN
1074    OVSDB_SERVER_SHUTDOWN2
1075    AT_CLEANUP])
1076
1077 REPLICATION_EXAMPLES
1078
1079 AT_BANNER([OVSDB -- ovsdb-server replication runtime management commands])
1080
1081 #ovsdb-server/get-remote-ovsdb-server command
1082 AT_SETUP([ovsdb-server/get-remote-ovsdb-server])
1083 AT_KEYWORDS([ovsdb server replication get-remote])
1084 ordinal_schema > schema
1085 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
1086 on_exit 'kill `cat *.pid`'
1087 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --sync-from=tcp:127.0.0.1:9999 db])
1088
1089 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/get-remote-ovsdb-server],
1090   [0], [tcp:127.0.0.1:9999
1091 ])
1092 AT_CLEANUP
1093
1094 #*ovsdb-server/set-remote-ovsdb-server command
1095 AT_SETUP([ovsdb-server/set-remote-ovsdb-server])
1096 AT_KEYWORDS([ovsdb server replication set-remote])
1097 ordinal_schema > schema
1098 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
1099 on_exit 'kill `cat *.pid`'
1100 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile db])
1101
1102 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/set-remote-ovsdb-server tcp:127.0.0.1:9999])
1103 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/get-remote-ovsdb-server],
1104   [0], [tcp:127.0.0.1:9999
1105 ])
1106 AT_CLEANUP
1107
1108 #ovsdb-server/get-sync-excluded-tables command
1109 AT_SETUP([ovsdb-server/get-sync-excluded-tables])
1110 AT_KEYWORDS([ovsdb server replication get-excluded-tables])
1111 ordinal_schema > schema
1112 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
1113 on_exit 'kill `cat *.pid`'
1114 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --sync-exclude-tables=mydb:db1,mydb:db2 db])
1115
1116 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/get-sync-excluded-tables],
1117   [0], [mydb:db2
1118 mydb:db1
1119 ])
1120 AT_CLEANUP
1121
1122 #ovsdb-server/set-sync-excluded-tables command
1123 AT_SETUP([ovsdb-server/set-sync-excluded-tables])
1124 AT_KEYWORDS([ovsdb server replication set-excluded-tables])
1125 replication_schema > schema
1126 AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1127 AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1128
1129 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile="`pwd`"/pid --remote=punix:db.sock --unixctl="`pwd`"/unixctl db1], [0], [ignore], [ignore])
1130
1131 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server2.log --pidfile="`pwd`"/pid2 --remote=punix:db2.sock --unixctl="`pwd`"/unixctl2 --sync-from=unix:db.sock db2], [0], [ignore], [ignore])
1132
1133 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/set-sync-excluded-tables mydb:b], [0], [ignore], [ignore], [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1134
1135 AT_CHECK([ovsdb-client transact unix:db.sock \
1136  '[["mydb",
1137     {"op": "insert",
1138       "table": "a",
1139       "row": {"number": 0, "name": "zero"}},
1140     {"op": "insert",
1141       "table": "b",
1142       "row": {"number": 1, "name": "one"}}]]'], [0], [stdout], [ignore],
1143  [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1144 sleep 2
1145
1146 AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout], [ignore],
1147  [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1148 cat stdout >> dump1
1149 AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore],
1150  [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1151 cat stdout >> dump2
1152
1153 AT_CHECK([diff dump1 dump2], [1], [stdout], [ignore],
1154         [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1155 cat stdout >> output
1156
1157 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [7,9c7,8
1158 < _uuid                                name number
1159 < ------------------------------------ ---- ------
1160 < <0> one  1     @&t@
1161 ---
1162 > _uuid name number
1163 > ----- ---- ------
1164 ], [ignore], [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1165
1166 OVSDB_SERVER_SHUTDOWN
1167 OVSDB_SERVER_SHUTDOWN2
1168 AT_CLEANUP
1169
1170 #ovsdb-server/connect-remote-ovsdb-server
1171 AT_SETUP([ovsdb-server/connect-remote-server])
1172 AT_KEYWORDS([ovsdb server replication connect-remote-server])
1173 replication_schema > schema
1174 AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1175 AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1176
1177 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile="`pwd`"/pid --remote=punix:db.sock --unixctl="`pwd`"/unixctl db1], [0], [ignore], [ignore])
1178
1179 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server2.log --pidfile="`pwd`"/pid2 --remote=punix:db2.sock --unixctl="`pwd`"/unixctl2 db2], [0], [ignore], [ignore])
1180
1181 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/set-remote-ovsdb-server unix:db.sock], [0], [ignore], [ignore], [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1182
1183 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/connect-remote-ovsdb-server], [0], [ignore], [ignore],
1184         [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1185
1186 AT_CHECK([ovsdb-client transact unix:db.sock \
1187  '[["mydb",
1188   {"op": "insert",
1189    "table": "a",
1190    "row": {},
1191    "uuid-name": "0"}]]'], [0], [stdout], [ignore],
1192  [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1193 sleep 2
1194
1195 AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout], [ignore],
1196  [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1197 cat stdout >> dump1
1198 AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore],
1199  [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1200 cat stdout >> dump2
1201
1202 AT_CHECK([diff dump1 dump2], [0], [], [ignore], [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1203 OVSDB_SERVER_SHUTDOWN
1204 OVSDB_SERVER_SHUTDOWN2
1205 AT_CLEANUP
1206
1207 #ovsdb-server/disconnect-remote-server command
1208 AT_SETUP([ovsdb-server/disconnect-remote-server])
1209 AT_KEYWORDS([ovsdb server replication disconnect-remote-server])
1210 replication_schema > schema
1211 AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1212 AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1213
1214 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile="`pwd`"/pid --remote=punix:db.sock --unixctl="`pwd`"/unixctl db1], [0], [ignore], [ignore])
1215
1216 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server2.log --pidfile="`pwd`"/pid2 --remote=punix:db2.sock --unixctl="`pwd`"/unixctl2 --sync-from=unix:db.sock db2], [0], [ignore], [ignore])
1217
1218 AT_CHECK([ovsdb-client transact unix:db.sock \
1219 '[["mydb",
1220   {"op": "insert",
1221    "table": "a",
1222    "row": {"number": 0, "name": "zero"}}]]'], [0], [stdout], [ignore],
1223 [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1224
1225 OVS_WAIT_UNTIL([ovsdb-client dump unix:db2.sock | grep zero])
1226
1227 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/disconnect-remote-ovsdb-server], [0], [ignore], [ignore],
1228         [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1229
1230 AT_CHECK([ovsdb-client transact unix:db.sock \
1231 '[["mydb",
1232   {"op": "insert",
1233    "table": "b",
1234    "row": {"number": 1, "name": "one"}}]]'], [0], [stdout], [ignore],
1235 [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1236
1237 AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout], [ignore],
1238  [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1239 cat stdout >> dump1
1240
1241 AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore],
1242  [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1243 cat stdout >> dump2
1244
1245 AT_CHECK([diff dump1 dump2], [1], [stdout], [ignore],
1246         [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1247 cat stdout >> output
1248
1249 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [7,9c7,8
1250 < _uuid                                name number
1251 < ------------------------------------ ---- ------
1252 < <0> one  1     @&t@
1253 ---
1254 > _uuid name number
1255 > ----- ---- ------
1256 ], [ignore], [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1257
1258 OVSDB_SERVER_SHUTDOWN
1259 OVSDB_SERVER_SHUTDOWN2
1260 AT_CLEANUP