]> git.proxmox.com Git - ovs.git/blob - tests/ovsdb-server.at
expr: Add additional invariant check in test.
[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([ovsdb-server], [ovsdb-server.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 --remote=punix:socket 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([uuidfilt 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 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 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 db --run="sh txnfile"], [0], [stdout], [])
83 cat stdout >> output
84 AT_CHECK([uuidfilt 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 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 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 db --run="sh txnfile"], [0], [stdout], [])
131 cat stdout >> output
132 AT_CHECK([uuidfilt 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([database multiplexing implementation])
141 AT_KEYWORDS([ovsdb server positive])
142 ordinal_schema > schema1
143 constraint_schema > schema2
144 AT_CHECK([ovsdb-tool create db1 schema1], [0], [ignore], [ignore])
145 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
146 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db1 db2], [0], [ignore], [ignore])
147 AT_CHECK(
148 [[ovsdb-client list-dbs unix:socket]],
149 [0], [constraints
150 ordinals
151 ], [ignore], [test ! -e pid || kill `cat pid`])
152 AT_CHECK(
153 [[ovstest test-jsonrpc request unix:socket get_schema [\"nonexistent\"]]], [0],
154 [[{"error":{"details":"get_schema request specifies unknown database nonexistent","error":"unknown database","syntax":"[\"nonexistent\"]"},"id":0,"result":null}
155 ]], [], [test ! -e pid || kill `cat pid`])
156 OVSDB_SERVER_SHUTDOWN
157 AT_CLEANUP
158
159 AT_SETUP([ovsdb-server/add-db and remove-db])
160 AT_KEYWORDS([ovsdb server positive])
161 on_exit 'kill `cat ovsdb-server.pid`'
162 ordinal_schema > schema1
163 constraint_schema > schema2
164 AT_CHECK([ovsdb-tool create db1 schema1], [0], [ignore], [ignore])
165 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
166
167 # Start ovsdb-server with just a single database - db1.
168 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db1], [0])
169 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
170 [0], [ordinals
171 ])
172
173 # Add the second database.
174 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
175 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
176 [0], [constraints
177 ordinals
178 ])
179
180 # The databases are responsive.
181 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [0], [ignore], [ignore])
182 AT_CHECK([ovsdb-client list-tables unix:socket ordinals], [0], [ignore], [ignore])
183
184 # Add an already added database.
185 if test $IS_WIN32 = "yes"; then
186 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], 2, [],
187 [I/O error: db2: failed to lock lockfile (Resource deadlock avoided)
188 ovs-appctl: ovsdb-server: server returned an error
189 ])
190 else
191 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], 2, [],
192 [db2: already open
193 ovs-appctl: ovsdb-server: server returned an error
194 ])
195 fi
196
197 # Add a non-existing database.
198 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db3], 2, [], [stderr])
199 AT_CHECK([sed 's/(.*)/(...)/' stderr], [0],
200 [I/O error: db3: open failed (...)
201 ovs-appctl: ovsdb-server: server returned an error
202 ])
203
204 # Add a remote through a db path in db1.
205 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote db:ordinals,ordinals,name], [0])
206 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
207 [0], [db:ordinals,ordinals,name
208 punix:socket
209 ])
210
211 # Removing db1 has no effect on its remote.
212 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db ordinals], [0])
213 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
214 [0], [constraints
215 ])
216 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
217 [0], [db:ordinals,ordinals,name
218 punix:socket
219 ])
220 AT_CHECK([ovsdb-client list-tables unix:socket ordinals], [1], [ignore], [ignore])
221
222 # Remove db2.
223 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db constraints], [0])
224 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
225 [0], [])
226 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [1], [ignore], [ignore])
227
228 # Remove a non-existent database.
229 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db ordinals], [2],
230 [], [Failed to find the database.
231 ovs-appctl: ovsdb-server: server returned an error
232 ])
233
234 # Add a removed database.
235 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
236 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
237 [0], [constraints
238 ])
239 AT_CHECK([ovsdb-client list-tables unix:socket constraints], [0], [ignore], [ignore])
240 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
241 AT_CLEANUP
242
243 AT_SETUP([ovsdb-server/add-db with --monitor])
244 AT_KEYWORDS([ovsdb server positive])
245 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
246 # Start ovsdb-server, initially with one db.
247 ordinal_schema > schema
248 AT_CHECK([ovsdb-tool create db1 schema], [0], [ignore], [ignore])
249 on_exit 'kill `cat *.pid`'
250 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db1])
251
252 # Add the second database.
253 constraint_schema > schema2
254 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
255 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
256 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
257 [0], [constraints
258 ordinals
259 ])
260
261 # Kill the daemon process, making it look like a segfault,
262 # and wait for a new daemon process to get spawned.
263 cp ovsdb-server.pid old.pid
264 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
265 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
266 OVS_WAIT_UNTIL(
267 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
268 OVS_WAIT_UNTIL([ovs-appctl -t ovsdb-server version])
269 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
270 [0], [constraints
271 ordinals
272 ])
273 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
274 AT_CLEANUP
275
276 AT_SETUP([ovsdb-server/add-db and remove-db with --monitor])
277 AT_KEYWORDS([ovsdb server positive])
278 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
279 # Start ovsdb-server, initially with one db.
280 ordinal_schema > schema
281 AT_CHECK([ovsdb-tool create db1 schema], [0], [ignore], [ignore])
282 constraint_schema > schema2
283 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
284 on_exit 'kill `cat *.pid`'
285 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db1 db2])
286
287 # Remove the second database.
288 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db constraints])
289 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
290 [0], [ordinals
291 ])
292
293 # Kill the daemon process, making it look like a segfault,
294 # and wait for a new daemon process to get spawned.
295 cp ovsdb-server.pid old.pid
296 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
297 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
298 OVS_WAIT_UNTIL(
299 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
300 OVS_WAIT_UNTIL([ovs-appctl -t ovsdb-server version])
301 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
302 [0], [ordinals
303 ])
304 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
305 AT_CLEANUP
306
307 AT_SETUP([--remote=db: implementation])
308 AT_KEYWORDS([ovsdb server positive])
309 AT_DATA([schema],
310 [[{"name": "mydb",
311 "tables": {
312 "Root": {
313 "columns": {
314 "managers": {
315 "type": {
316 "key": "string",
317 "min": 0,
318 "max": "unlimited"}},
319 "manager_options": {
320 "type": {
321 "key": {"type": "uuid", "refTable": "Manager"},
322 "min": 0,
323 "max": "unlimited"}}}},
324 "Manager": {
325 "columns": {
326 "target": {
327 "type": "string"},
328 "is_connected": {
329 "type": {
330 "key": "boolean",
331 "min": 0,
332 "max": 1}}}}}}
333 ]])
334 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
335 AT_CHECK(
336 [[ovsdb-tool transact db \
337 '["mydb",
338 {"op": "insert",
339 "table": "Root",
340 "row": {
341 "managers": "punix:socket1",
342 "manager_options": ["set", [["named-uuid", "x"]]]}},
343 {"op": "insert",
344 "table": "Manager",
345 "uuid-name": "x",
346 "row": {"target": "punix:socket2"}}]']], [0], [ignore], [ignore])
347 on_exit 'kill `cat ovsdb-server.pid`'
348 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])
349 ovs-appctl -t ovsdb-server time/warp 6000 1000
350 AT_CHECK(
351 [[ovsdb-client transact unix:socket1 \
352 '["mydb",
353 {"op": "select",
354 "table": "Root",
355 "where": [],
356 "columns": ["managers"]},
357 {"op": "select",
358 "table": "Manager",
359 "where": [],
360 "columns": ["target", "is_connected"]}]']],
361 [0], [stdout], [ignore])
362 AT_CHECK(
363 [uuidfilt stdout],
364 [0],
365 [[[{"rows":[{"managers":"punix:socket1"}]},{"rows":[{"is_connected":false,"target":"punix:socket2"}]}]
366 ]],
367 [ignore])
368 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
369 AT_CLEANUP
370
371 AT_SETUP([ovsdb-server/add-remote and remove-remote])
372 AT_KEYWORDS([ovsdb server positive])
373 ordinal_schema > schema
374 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
375 on_exit 'kill `cat *.pid`'
376 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile db])
377
378 AT_CHECK([test ! -e socket1])
379 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
380 if test "$IS_WIN32" = "yes"; then
381 OVS_WAIT_UNTIL([test -e socket1])
382 else
383 OVS_WAIT_UNTIL([test -S socket1])
384 fi
385 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
386 [0], [punix:socket1
387 ])
388
389 AT_CHECK([test ! -e socket2])
390 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket2])
391 if test "$IS_WIN32" = "yes"; then
392 OVS_WAIT_UNTIL([test -e socket2])
393 else
394 OVS_WAIT_UNTIL([test -S socket2])
395 fi
396 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
397 [0], [punix:socket1
398 punix:socket2
399 ])
400
401 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote db:x,y,z], [2],
402 [], ["db:x,y,z": no database named x
403 ovs-appctl: ovsdb-server: server returned an error
404 ])
405
406 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
407 OVS_WAIT_UNTIL([test ! -e socket1])
408 if test "$IS_WIN32" = "yes"; then
409 AT_CHECK([test -e socket2])
410 else
411 AT_CHECK([test -S socket2])
412 fi
413 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
414 [0], [punix:socket2
415 ])
416
417 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket2])
418 OVS_WAIT_UNTIL([test ! -e socket2])
419 AT_CHECK([test ! -e socket1])
420 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
421 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
422 AT_CLEANUP
423
424 AT_SETUP([ovsdb-server/add-remote with --monitor])
425 AT_KEYWORDS([ovsdb server positive])
426 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
427 # Start ovsdb-server, initially with no remotes.
428 ordinal_schema > schema
429 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
430 on_exit 'kill `cat *.pid`'
431 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db])
432
433 # Add a remote.
434 AT_CHECK([test ! -e socket1])
435 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
436 OVS_WAIT_UNTIL([test -S socket1])
437 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
438 [0], [punix:socket1
439 ])
440
441 # Kill the daemon process, making it look like a segfault,
442 # and wait for a new daemon process to get spawned and for it to
443 # start listening on 'socket1'.
444 cp ovsdb-server.pid old.pid
445 rm socket1
446 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
447 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
448 OVS_WAIT_UNTIL(
449 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
450 OVS_WAIT_UNTIL([ovs-appctl -t ovsdb-server version])
451 OVS_WAIT_UNTIL([test -S socket1])
452 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
453 AT_CLEANUP
454
455 AT_SETUP([ovsdb-server/add-remote and remove-remote with --monitor])
456 AT_KEYWORDS([ovsdb server positive])
457 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
458 # Start ovsdb-server, initially with no remotes.
459 ordinal_schema > schema
460 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
461 on_exit 'kill `cat *.pid`'
462 AT_CHECK([ovsdb-server -v -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db])
463
464 # Add a remote.
465 AT_CHECK([test ! -e socket1])
466 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
467 OVS_WAIT_UNTIL([test -S socket1])
468 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
469 [0], [punix:socket1
470 ])
471
472 # Remove the remote.
473 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
474 OVS_WAIT_UNTIL([test ! -e socket1])
475 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
476
477 # Kill the daemon process, making it look like a segfault,
478 # and wait for a new daemon process to get spawned and make sure that it
479 # does not listen on 'socket1'.
480 cp ovsdb-server.pid old.pid
481 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
482 OVS_WAIT_WHILE([kill -0 `cat old.pid`])
483 OVS_WAIT_UNTIL(
484 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
485 OVS_WAIT_UNTIL([ovs-appctl -t ovsdb-server version])
486 AT_CHECK([test ! -e socket1])
487 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
488 AT_CLEANUP
489
490 AT_SETUP([SSL db: implementation])
491 AT_KEYWORDS([ovsdb server positive ssl $5])
492 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
493 # For this test, we pass PKIDIR through a ovsdb-tool transact and
494 # msys on Windows does not convert the path style automatically.
495 # So, do that forcefully with a 'pwd -W' (called through pwd() function).
496 PKIDIR="$(cd $abs_top_builddir/tests && pwd)"
497 AT_SKIP_IF([expr "$PKIDIR" : ".*[ '\"
498 \\]"])
499 AT_DATA([schema],
500 [[{"name": "mydb",
501 "tables": {
502 "SSL": {
503 "columns": {
504 "private_key": {"type": "string"},
505 "certificate": {"type": "string"},
506 "ca_cert": {"type": "string"},
507 "ssl_protocols" : {"type": "string"},
508 "ssl_ciphers" : {"type" : "string"}}}}}
509 ]])
510 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
511 # The !ECDHE-ECDSA-AES256-GCM-SHA384 in the ssl_ciphers is so that
512 # a cipher negotiation failure can be tested for later.
513 AT_CHECK(
514 [[ovsdb-tool transact db \
515 '["mydb",
516 {"op": "insert",
517 "table": "SSL",
518 "row": {"private_key": "'"$PKIDIR/testpki-privkey2.pem"'",
519 "certificate": "'"$PKIDIR/testpki-cert2.pem"'",
520 "ca_cert": "'"$PKIDIR/testpki-cacert.pem"'",
521 "ssl_protocols": "'"TLSv1.2,TLSv1.1"'",
522 "ssl_ciphers": "'"HIGH:!aNULL:!MD5:!ECDHE-ECDSA-AES256-GCM-SHA384"'"}}]']],
523 [0], [ignore], [ignore])
524 AT_CHECK(
525 [ovsdb-server --log-file --detach --no-chdir --pidfile \
526 --private-key=db:mydb,SSL,private_key \
527 --certificate=db:mydb,SSL,certificate \
528 --ca-cert=db:mydb,SSL,ca_cert \
529 --ssl-protocols=db:mydb,SSL,ssl_protocols \
530 --ssl-ciphers=db:mydb,SSL,ssl_ciphers \
531 --remote=pssl:0:127.0.0.1 db],
532 [0], [ignore], [ignore])
533 PARSE_LISTENING_PORT([ovsdb-server.log], [SSL_PORT])
534 AT_CHECK(
535 [[ovsdb-client \
536 --private-key=$PKIDIR/testpki-privkey.pem \
537 --certificate=$PKIDIR/testpki-cert.pem \
538 --ca-cert=$PKIDIR/testpki-cacert.pem \
539 --ssl-protocols=TLSv1.2,TLSv1.1 \
540 --ssl-ciphers=HIGH:!aNULL:!MD5 \
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 # Check that when the server has TLSv1.1+ and the client has
554 # TLSv1 that the connection fails.
555 AT_CHECK(
556 [[ovsdb-client \
557 --private-key=$PKIDIR/testpki-privkey.pem \
558 --certificate=$PKIDIR/testpki-cert.pem \
559 --ca-cert=$PKIDIR/testpki-cacert.pem \
560 --ssl-protocols=TLSv1 \
561 --ssl-ciphers=HIGH:!aNULL:!MD5 \
562 transact ssl:127.0.0.1:$SSL_PORT \
563 '["mydb",
564 {"op": "select",
565 "table": "SSL",
566 "where": [],
567 "columns": ["private_key"]}]']],
568 [1], [stdout],
569 [stderr],
570 [test ! -e pid || kill `cat pid`])
571 cat stderr > output
572 AT_CHECK_UNQUOTED(
573 [grep "failed to connect" output], [0],
574 [ovsdb-client: failed to connect to "ssl:127.0.0.1:$SSL_PORT" (Protocol error)
575 ],
576 [ignore], [test ! -e pid || kill `cat pid`])
577 # Check that when ciphers are not compatible, that a negotiation
578 # failure occurs.
579 AT_CHECK(
580 [[ovsdb-client \
581 --private-key=$PKIDIR/testpki-privkey.pem \
582 --certificate=$PKIDIR/testpki-cert.pem \
583 --ca-cert=$PKIDIR/testpki-cacert.pem \
584 --ssl-protocols=TLSv1.2,TLSv1.1 \
585 --ssl-ciphers=ECDHE-ECDSA-AES256-GCM-SHA384 \
586 transact ssl:127.0.0.1:$SSL_PORT \
587 '["mydb",
588 {"op": "select",
589 "table": "SSL",
590 "where": [],
591 "columns": ["private_key"]}]']],
592 [1], [stdout],
593 [stderr],
594 [test ! -e pid || kill `cat pid`])
595 cat stderr > output
596 AT_CHECK_UNQUOTED(
597 [grep "failed to connect" output], [0],
598 [ovsdb-client: failed to connect to "ssl:127.0.0.1:$SSL_PORT" (Protocol error)
599 ],
600 [ignore], [test ! -e pid || kill `cat pid`])
601 # The error message for being unable to negotiate a shared ciphersuite
602 # is 'sslv3 alert handshake failure'. This is not the clearest message.
603 AT_CHECK_UNQUOTED(
604 [grep "sslv3 alert handshake failure" output], [0],
605 [stdout],
606 [ignore], [test ! -e pid || kill `cat pid`])
607 OVSDB_SERVER_SHUTDOWN
608 AT_CLEANUP
609
610 AT_SETUP([compacting online])
611 AT_KEYWORDS([ovsdb server compact])
612 ordinal_schema > schema
613 dnl Make sure that "ovsdb-tool create" works with a dangling symlink for
614 dnl the database and the lockfile, creating the target of each symlink rather
615 dnl than replacing the symlinks with regular files.
616 mkdir dir
617 if test "$IS_WIN32" = "no"; then
618 ln -s dir/db db
619 ln -s dir/.db.~lock~ .db.~lock~
620 AT_SKIP_IF([test ! -h db || test ! -h .db.~lock~])
621 fi
622 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
623 dnl Start ovsdb-server.
624 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket --log-file="`pwd`"/ovsdb-server.log db], [0], [ignore], [ignore])
625 AT_CAPTURE_FILE([ovsdb-server.log])
626 dnl Do a bunch of random transactions that put crap in the database log.
627 AT_CHECK(
628 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
629 set -- $pair
630 ovsdb-client transact unix:socket '
631 ["ordinals",
632 {"op": "insert",
633 "table": "ordinals",
634 "row": {"name": "'$1'", "number": '$2'}},
635 {"op": "comment",
636 "comment": "add row for '"$pair"'"}]'
637 ovsdb-client transact unix:socket '
638 ["ordinals",
639 {"op": "delete",
640 "table": "ordinals",
641 "where": [["number", "==", '$2']]},
642 {"op": "comment",
643 "comment": "delete row for '"$2"'"}]'
644 ovsdb-client transact unix:socket '
645 ["ordinals",
646 {"op": "insert",
647 "table": "ordinals",
648 "row": {"name": "'$1'", "number": '$2'}},
649 {"op": "comment",
650 "comment": "add back row for '"$pair"'"}]'
651 done]],
652 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
653 dnl Check that all the crap is in fact in the database log.
654 AT_CHECK([[uuidfilt db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | ovstest test-json --multiple -]], [0],
655 [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"}
656 {"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
657 {"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
658 {"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
659 {"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
660 {"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
661 {"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
662 {"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
663 {"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
664 {"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
665 {"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
666 {"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
667 {"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
668 {"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
669 {"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
670 {"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
671 {"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
672 {"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
673 {"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
674 ]], [], [test ! -e pid || kill `cat pid`])
675 dnl Dump out and check the actual database contents.
676 AT_CHECK([[ovsdb-client dump unix:socket ordinals]],
677 [0], [stdout], [ignore])
678 AT_CHECK([uuidfilt stdout], [0], [dnl
679 ordinals table
680 _uuid name number
681 ------------------------------------ ----- ------
682 <0> five 5
683 <1> four 4
684 <2> one 1
685 <3> three 3
686 <4> two 2
687 <5> zero 0
688 ], [], [test ! -e pid || kill `cat pid`])
689 dnl Now compact the database in-place.
690 AT_CHECK([[ovs-appctl -t ovsdb-server ovsdb-server/compact]],
691 [0], [], [ignore], [test ! -e pid || kill `cat pid`])
692 dnl Negative test.
693 AT_CHECK([[ovs-appctl -t ovsdb-server ovsdb-server/compact _Server]],
694 [2], [], [cannot compact built-in databases
695 ovs-appctl: ovsdb-server: server returned an error
696 ])
697 dnl Make sure that "db" is still a symlink to dir/db instead of getting
698 dnl replaced by a regular file, ditto for .db.~lock~.
699 if test "$IS_WIN32" = "no"; then
700 AT_CHECK([test -h db])
701 AT_CHECK([test -h .db.~lock~])
702 AT_CHECK([test -f dir/db])
703 AT_CHECK([test -f dir/.db.~lock~])
704 fi
705 dnl We can't fully re-check the contents of the database log, because the
706 dnl order of the records is not predictable, but there should only be 4 lines
707 dnl in it now.
708 AT_CAPTURE_FILE([db])
709 AT_CHECK([test `wc -l < db` -eq 4], [0], [], [],
710 [test ! -e pid || kill `cat pid`])
711 dnl And check that the dumped data is the same too:
712 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
713 [test ! -e pid || kill `cat pid`])
714 AT_CHECK([uuidfilt stdout], [0], [dnl
715 ordinals table
716 _uuid name number
717 ------------------------------------ ----- ------
718 <0> five 5
719 <1> four 4
720 <2> one 1
721 <3> three 3
722 <4> two 2
723 <5> zero 0
724 ], [], [test ! -e pid || kill `cat pid`])
725 dnl Now do some more transactions.
726 AT_CHECK(
727 [[ovsdb-client transact unix:socket '
728 ["ordinals",
729 {"op": "delete",
730 "table": "ordinals",
731 "where": [["number", "<", 3]]}]']],
732 [0], [[[{"count":3}]
733 ]], [ignore], [test ! -e pid || kill `cat pid`])
734 dnl There should be 6 lines in the log now.
735 AT_CHECK([test `wc -l < db` -eq 6], [0], [], [],
736 [test ! -e pid || kill `cat pid`])
737 dnl Then check that the dumped data is correct. This time first kill
738 dnl and restart the database server to ensure that the data is correct on
739 dnl disk as well as in memory.
740 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
741 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket --log-file="`pwd`"/ovsdb-server.log db], [0], [ignore], [ignore])
742 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
743 [test ! -e pid || kill `cat pid`])
744 AT_CHECK([uuidfilt stdout], [0], [dnl
745 ordinals table
746 _uuid name number
747 ------------------------------------ ----- ------
748 <0> five 5
749 <1> four 4
750 <2> three 3
751 ], [], [test ! -e pid || kill `cat pid`])
752 OVSDB_SERVER_SHUTDOWN
753 AT_CLEANUP
754
755 AT_SETUP([ovsdb-server combines updates on backlogged connections])
756 on_exit 'kill `cat *.pid`'
757
758 # The maximum socket receive buffer size is important for this test, which
759 # tests behavior when the receive buffer overflows.
760 if test -e /proc/sys/net/core/rmem_max; then
761 # Linux
762 rmem_max=`cat /proc/sys/net/core/rmem_max`
763 elif rmem_max=`sysctl -n net.inet.tcp.recvbuf_max 2>/dev/null`; then
764 : # FreeBSD, NetBSD
765 else
766 # Don't know how to get maximum socket receive buffer on this OS
767 AT_SKIP_IF([:])
768 fi
769
770 # Calculate the number of iterations we need to queue. Each of the
771 # iterations we execute, by itself, yields a monitor update of about
772 # 25 kB, so fill up that much space plus a few for luck.
773 n_iterations=`expr $rmem_max / 25000 + 5`
774 echo rmem_max=$rmem_max n_iterations=$n_iterations
775
776 # If there's too much queuing skip the test to avoid timing out.
777 AT_SKIP_IF([test $rmem_max -gt 1048576])
778
779 # Calculate the exact number of monitor updates expected for $n_iterations,
780 # assuming no updates are combined. The "extra" update is for the initial
781 # contents of the database.
782 n_updates=`expr $n_iterations \* 3 + 1`
783
784 # Start an ovsdb-server with the vswitchd schema.
785 OVSDB_INIT([db])
786 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --log-file --remote=punix:db.sock db],
787 [0], [ignore], [ignore])
788
789 # Executes a set of transactions that add a bridge with 100 ports, and
790 # then deletes that bridge. This yields three monitor updates that
791 # add up to about 25 kB in size.
792 #
793 # The update also increments a counter held in the database so that we can
794 # verify that the overall effect of the transactions took effect (e.g.
795 # monitor updates at the end weren't just dropped). We add an arbitrary
796 # string to the counter to make grepping for it more reliable.
797 counter=0
798 trigger_big_update () {
799 counter=`expr $counter + 1`
800 ovs-vsctl --no-wait -- set open_vswitch . system_version=xyzzy$counter
801 ovs-vsctl --no-wait -- add-br br0 $add
802 ovs-vsctl --no-wait -- del-br br0
803 }
804 add_ports () {
805 for j in `seq 1 100`; do
806 printf " -- add-port br0 p%d" $j
807 done
808 }
809 add=`add_ports`
810
811 AT_CAPTURE_FILE([ovsdb-client.err])
812 AT_CAPTURE_FILE([ovsdb-client-nonblock.err])
813
814
815 # Start an ovsdb-client monitoring all changes to the database,
816 # By default, it is non-blocking, and will get update message
817 # for each ovsdb-server transaactions.
818 AT_CHECK([ovsdb-client --detach --no-chdir --pidfile=nonblock.pid monitor ALL >ovsdb-client-nonblock.out 2>ovsdb-client-nonblock.err])
819
820 # Start an ovsdb-client monitoring all changes to the database,
821 # make it block to force the buffers to fill up, and then execute
822 # enough iterations that ovsdb-server starts combining updates.
823 AT_CHECK([ovsdb-client --detach --no-chdir --pidfile monitor ALL >ovsdb-client.out 2>ovsdb-client.err])
824 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/block])
825 for i in `seq 1 $n_iterations`; do
826 echo "blocked update ($i of $n_iterations)"
827 trigger_big_update $i
828 done
829 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/unblock])
830 OVS_WAIT_UNTIL([grep "\"xyzzy$counter\"" ovsdb-client.out])
831 OVS_WAIT_UNTIL([grep "\"xyzzy$counter\"" ovsdb-client-nonblock.out])
832 OVS_APP_EXIT_AND_WAIT([ovsdb-client])
833 AT_CHECK([kill `cat nonblock.pid`])
834
835 # Count the number of updates in the ovsdb-client output, by counting
836 # the number of changes to the Open_vSwitch table. (All of our
837 # transactions modify the Open_vSwitch table.) It should be less than
838 # $n_updates updates.
839 #
840 # Check that the counter is what we expect.
841 logged_updates=`grep -c '^Open_vSwitch' ovsdb-client.out`
842 logged_nonblock_updates=`grep -c '^Open_vSwitch' ovsdb-client-nonblock.out`
843 echo "logged_nonblock_updates=$logged_nonblock_updates (expected less or equal to $n_updates)"
844 echo "logged_updates=$logged_updates (expected less than $logged_nonblock_updates)"
845 AT_CHECK([test $logged_nonblock_updates -le $n_updates])
846 AT_CHECK([test $logged_updates -lt $logged_nonblock_updates])
847 AT_CHECK_UNQUOTED([ovs-vsctl get open_vswitch . system_version], [0],
848 ["xyzzy$counter"
849 ])
850 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
851 AT_CLEANUP
852 \f
853 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv4 sockets)])
854
855 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
856 #
857 # Creates a database with the given SCHEMA, starts an ovsdb-server on
858 # that database, and runs each of the TRANSACTIONS (which should be a
859 # quoted list of quoted strings) against it with ovsdb-client one at a
860 # time.
861 #
862 # Checks that the overall output is OUTPUT, but UUIDs in the output
863 # are replaced by markers of the form <N> where N is a number. The
864 # first unique UUID is replaced by <0>, the next by <1>, and so on.
865 # If a given UUID appears more than once it is always replaced by the
866 # same marker.
867 #
868 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
869 m4_define([OVSDB_CHECK_EXECUTION],
870 [AT_SETUP([$1])
871 AT_KEYWORDS([ovsdb server positive ssl $5])
872 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
873 $2 > schema
874 PKIDIR=$abs_top_builddir/tests
875 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
876 AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile --private-key=$PKIDIR/testpki-privkey2.pem --certificate=$PKIDIR/testpki-cert2.pem --ca-cert=$PKIDIR/testpki-cacert.pem --remote=pssl:0:127.0.0.1 db], [0], [ignore], [ignore])
877 PARSE_LISTENING_PORT([ovsdb-server.log], [SSL_PORT])
878 m4_foreach([txn], [$3],
879 [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],
880 [test ! -e pid || kill `cat pid`])
881 cat stdout >> output
882 ])
883 AT_CHECK([uuidfilt output], [0], [$4], [ignore],
884 [test ! -e pid || kill `cat pid`])
885 OVSDB_SERVER_SHUTDOWN
886 AT_CLEANUP])
887
888 EXECUTION_EXAMPLES
889
890 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv6 sockets)])
891
892 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
893 #
894 # Creates a database with the given SCHEMA, starts an ovsdb-server on
895 # that database, and runs each of the TRANSACTIONS (which should be a
896 # quoted list of quoted strings) against it with ovsdb-client one at a
897 # time.
898 #
899 # Checks that the overall output is OUTPUT, but UUIDs in the output
900 # are replaced by markers of the form <N> where N is a number. The
901 # first unique UUID is replaced by <0>, the next by <1>, and so on.
902 # If a given UUID appears more than once it is always replaced by the
903 # same marker.
904 #
905 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
906 m4_define([OVSDB_CHECK_EXECUTION],
907 [AT_SETUP([$1])
908 AT_KEYWORDS([ovsdb server positive ssl6 $5])
909 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
910 AT_SKIP_IF([test $HAVE_IPV6 = no])
911 $2 > schema
912 PKIDIR=$abs_top_builddir/tests
913 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
914 AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile --private-key=$PKIDIR/testpki-privkey2.pem --certificate=$PKIDIR/testpki-cert2.pem --ca-cert=$PKIDIR/testpki-cacert.pem --remote=pssl:0:[[::1]] db], [0], [ignore], [ignore])
915 PARSE_LISTENING_PORT([ovsdb-server.log], [SSL_PORT])
916 m4_foreach([txn], [$3],
917 [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],
918 [test ! -e pid || kill `cat pid`])
919 cat stdout >> output
920 ])
921 AT_CHECK([uuidfilt output], [0], [$4], [ignore],
922 [test ! -e pid || kill `cat pid`])
923 OVSDB_SERVER_SHUTDOWN
924 AT_CLEANUP])
925
926 ONE_EXECUTION_EXAMPLE
927
928 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv4 sockets)])
929
930 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
931 #
932 # Creates a database with the given SCHEMA, starts an ovsdb-server on
933 # that database, and runs each of the TRANSACTIONS (which should be a
934 # quoted list of quoted strings) against it with ovsdb-client one at a
935 # time.
936 #
937 # Checks that the overall output is OUTPUT, but UUIDs in the output
938 # are replaced by markers of the form <N> where N is a number. The
939 # first unique UUID is replaced by <0>, the next by <1>, and so on.
940 # If a given UUID appears more than once it is always replaced by the
941 # same marker.
942 #
943 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
944 m4_define([OVSDB_CHECK_EXECUTION],
945 [AT_SETUP([$1])
946 AT_KEYWORDS([ovsdb server positive tcp $5])
947 $2 > schema
948 PKIDIR=$abs_top_builddir/tests
949 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
950 AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile --remote=ptcp:0:127.0.0.1 db], [0], [ignore], [ignore])
951 PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
952 m4_foreach([txn], [$3],
953 [AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT 'txn'], [0], [stdout], [ignore],
954 [test ! -e pid || kill `cat pid`])
955 cat stdout >> output
956 ])
957 AT_CHECK([uuidfilt output], [0], [$4], [ignore],
958 [test ! -e pid || kill `cat pid`])
959 OVSDB_SERVER_SHUTDOWN
960 AT_CLEANUP])
961
962 EXECUTION_EXAMPLES
963
964 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv6 sockets)])
965
966 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
967 #
968 # Creates a database with the given SCHEMA, starts an ovsdb-server on
969 # that database, and runs each of the TRANSACTIONS (which should be a
970 # quoted list of quoted strings) against it with ovsdb-client one at a
971 # time.
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_KEYWORDS([ovsdb server positive tcp6 $5])
983 AT_SKIP_IF([test $HAVE_IPV6 = no])
984 $2 > schema
985 PKIDIR=$abs_top_builddir/tests
986 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
987 AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile --remote=ptcp:0:[[::1]] db], [0], [ignore], [ignore])
988 PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
989 m4_foreach([txn], [$3],
990 [AT_CHECK([ovsdb-client transact tcp:[[::1]]:$TCP_PORT 'txn'], [0], [stdout], [ignore],
991 [test ! -e pid || kill `cat pid`])
992 cat stdout >> output
993 ])
994 AT_CHECK([uuidfilt output], [0], [$4], [ignore],
995 [test ! -e pid || kill `cat pid`])
996 OVSDB_SERVER_SHUTDOWN
997 AT_CLEANUP])
998
999 ONE_EXECUTION_EXAMPLE
1000 \f
1001 AT_BANNER([OVSDB -- transactions on transient ovsdb-server])
1002
1003 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
1004 #
1005 # Creates a database with the given SCHEMA and runs each of the
1006 # TRANSACTIONS (which should be a quoted list of quoted strings)
1007 # against it with ovsdb-client one at a time. Each ovsdb-client
1008 # is run against a separately started ovsdb-server that executes
1009 # only that single transaction. (The idea is that this should
1010 # help to ferret out any differences between what ovsdb-server has
1011 # in memory and what actually gets committed to disk.)
1012 #
1013 # Checks that the overall output is OUTPUT, but UUIDs in the output
1014 # are replaced by markers of the form <N> where N is a number. The
1015 # first unique UUID is replaced by <0>, the next by <1>, and so on.
1016 # If a given UUID appears more than once it is always replaced by the
1017 # same marker.
1018 #
1019 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
1020 m4_define([OVSDB_CHECK_EXECUTION],
1021 [AT_SETUP([$1])
1022 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
1023 AT_KEYWORDS([ovsdb server positive transient $5])
1024 $2 > schema
1025 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
1026 m4_foreach([txn], [$3],
1027 [AT_DATA([txnfile], [ovsdb-client transact unix:socket 'txn'
1028 ])
1029 AT_CHECK([ovsdb-server --remote=punix:socket db --run="sh txnfile"], [0], [stdout], [ignore])
1030 cat stdout >> output
1031 ])
1032 AT_CHECK([uuidfilt output], [0], [$4], [ignore])
1033 AT_CLEANUP])
1034
1035 EXECUTION_EXAMPLES
1036 \f
1037 AT_BANNER([OVSDB -- ovsdb-server replication])
1038
1039 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
1040 #
1041 # Creates two databases with the given SCHEMA, and starts an ovsdb-server on
1042 # each database.
1043 # Runs each of the TRANSACTIONS (which should be a quoted list of
1044 # quoted strings) against one of the servers with ovsdb-client one at a
1045 # time. The server replicates its database to the other ovsdb-server.
1046 #
1047 # Checks that the dump of both databases are the same.
1048 #
1049 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
1050 m4_define([OVSDB_CHECK_EXECUTION],
1051 [AT_SETUP([$1])
1052 AT_KEYWORDS([ovsdb server tcp replication $5])
1053 $2 > schema
1054 AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1055 AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1056
1057 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile --remote=punix:db.sock db1], [0], [ignore], [ignore])
1058 i
1059 on_exit 'test ! -e pid || kill `cat pid`'
1060
1061 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server2.log --pidfile=pid2 --remote=punix:db2.sock --unixctl=unixctl2 --sync-from=unix:db.sock db2], [0], [ignore], [ignore])
1062 on_exit 'test ! -e pid2 || kill `cat pid2`'
1063
1064 m4_foreach([txn], [$3],
1065 [AT_CHECK([ovsdb-client transact 'txn'], [0], [stdout], [ignore])
1066 ])
1067
1068 AT_CHECK([ovsdb-client dump], [0], [stdout], [ignore])
1069 OVS_WAIT_UNTIL([ ovsdb-client dump unix:db2.sock > dump2; diff stdout dump2])
1070
1071 OVSDB_SERVER_SHUTDOWN
1072 OVSDB_SERVER_SHUTDOWN2
1073 AT_CLEANUP])
1074
1075 EXECUTION_EXAMPLES
1076
1077 AT_BANNER([OVSDB -- ovsdb-server replication table-exclusion])
1078
1079 # OVSDB_CHECK_REPLICATION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
1080 #
1081 # Creates two databases with the given SCHEMA, and starts an
1082 # ovsdb-server on each database.
1083 # Runs each of the TRANSACTIONS (which should be a quoted list of
1084 # quoted strings) against one of the servers with ovsdb-client one at a
1085 # time. The server replicates its database to the other ovsdb-server.
1086 #
1087 # Checks that the difference between the dump of the databases is
1088 # OUTPUT, but UUIDs in the output are replaced by markers of the form
1089 # <N> where N is a number. The first unique UUID is replaced by <0>,
1090 # the next by <1>, and so on.
1091 # If a given UUID appears more than once it is always replaced by the
1092 # same marker.
1093 #
1094 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
1095 m4_define([OVSDB_CHECK_REPLICATION],
1096 [AT_SETUP([$1])
1097 AT_KEYWORDS([ovsdb server tcp replication table-exclusion])
1098 $2 > schema
1099 AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1100 AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1101
1102 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile --remote=punix:db.sock db1], [0], [ignore], [ignore])
1103 on_exit 'test ! -e pid || kill `cat pid`'
1104
1105 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server2.log --pidfile=pid2 --remote=punix:db2.sock --unixctl=unixctl2 --sync-from=unix:db.sock --sync-exclude-tables=mydb:b db2], [0], [ignore], [ignore])
1106 on_exit 'test ! -e pid2 || kill `cat pid2`'
1107
1108 m4_foreach([txn], [$3],
1109 [AT_CHECK([ ovsdb-client transact 'txn' ], [0], [stdout], [ignore])
1110 ])
1111
1112 AT_CHECK([ovsdb-client dump], [0], [stdout], [ignore])
1113 cat stdout > dump1
1114
1115 OVS_WAIT_UNTIL([ ovsdb-client dump unix:db2.sock | grep one ])
1116 AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore])
1117 cat stdout > dump2
1118
1119 AT_CHECK([diff dump1 dump2], [1], [stdout], [ignore])
1120 cat stdout > output
1121
1122 AT_CHECK([uuidfilt output], [0], [$4], [ignore])
1123
1124 OVSDB_SERVER_SHUTDOWN
1125 OVSDB_SERVER_SHUTDOWN2
1126 AT_CLEANUP])
1127
1128 REPLICATION_EXAMPLES
1129
1130 AT_BANNER([OVSDB -- ovsdb-server replication runtime management commands])
1131
1132 #ovsdb-server/get-active-ovsdb-server command
1133 AT_SETUP([ovsdb-server/get-active-ovsdb-server])
1134 AT_KEYWORDS([ovsdb server replication get-active])
1135 ordinal_schema > schema
1136 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
1137 on_exit 'kill `cat *.pid`'
1138 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --sync-from=tcp:127.0.0.1:9999 db])
1139
1140 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/get-active-ovsdb-server],
1141 [0], [tcp:127.0.0.1:9999
1142 ])
1143 AT_CLEANUP
1144
1145 #*ovsdb-server/set-active-ovsdb-server command
1146 AT_SETUP([ovsdb-server/set-active-ovsdb-server])
1147 AT_KEYWORDS([ovsdb server replication set-active])
1148 ordinal_schema > schema
1149 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
1150 on_exit 'kill `cat *.pid`'
1151 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile db])
1152
1153 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/set-active-ovsdb-server tcp:127.0.0.1:9999])
1154 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/get-active-ovsdb-server],
1155 [0], [tcp:127.0.0.1:9999
1156 ])
1157 AT_CLEANUP
1158
1159 #ovsdb-server/get-sync-exclude-tables command
1160 AT_SETUP([ovsdb-server/get-sync-exclude-tables])
1161 AT_KEYWORDS([ovsdb server replication get-exclude-tables])
1162 ordinal_schema > schema
1163 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
1164 on_exit 'kill `cat *.pid`'
1165 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --sync-exclude-tables=mydb:db1,mydb:db2 db])
1166
1167 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/get-sync-exclude-tables],
1168 [0], [mydb:db1,mydb:db2
1169 ])
1170 AT_CLEANUP
1171
1172 #ovsdb-server/set-sync-exclude-tables command
1173 AT_SETUP([ovsdb-server/set-sync-exclude-tables])
1174 AT_KEYWORDS([ovsdb server replication set-exclude-tables])
1175 replication_schema > schema
1176 AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1177 AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1178
1179 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile --remote=punix:db.sock db1], [0], [ignore], [ignore])
1180 on_exit 'test ! -e pid || kill `cat pid`'
1181
1182 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server2.log --pidfile=pid2 --remote=punix:db2.sock --unixctl=unixctl2 --sync-from=unix:db.sock db2], [0], [ignore], [ignore])
1183 on_exit 'test ! -e pid2 || kill `cat pid2`'
1184
1185 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/set-sync-exclude-tables mydb:b], [0], [ignore], [ignore], [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1186
1187 AT_CHECK([ovsdb-client transact unix:db.sock \
1188 '[["mydb",
1189 {"op": "insert",
1190 "table": "a",
1191 "row": {"number": 0, "name": "zero"}},
1192 {"op": "insert",
1193 "table": "b",
1194 "row": {"number": 1, "name": "one"}}]]'], [0], [stdout], [ignore],
1195 [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1196
1197 AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout], [ignore],
1198 [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1199 cat stdout > dump1
1200 OVS_WAIT_UNTIL([ ovsdb-client dump unix:db2.sock | grep zero ])
1201 AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore])
1202 cat stdout > dump2
1203
1204 AT_CHECK([diff dump1 dump2], [1], [stdout], [ignore])
1205 cat stdout > output
1206
1207 AT_CHECK([uuidfilt output], [0], [7,9c7,8
1208 < _uuid name number
1209 < ------------------------------------ ---- ------
1210 < <0> one 1
1211 ---
1212 > _uuid name number
1213 > ----- ---- ------
1214 ])
1215
1216 OVSDB_SERVER_SHUTDOWN
1217 OVSDB_SERVER_SHUTDOWN2
1218 AT_CLEANUP
1219
1220 #ovsdb-server/connect-active-ovsdb-server
1221 AT_SETUP([ovsdb-server/connect-active-server])
1222 AT_KEYWORDS([ovsdb server replication connect-active-server])
1223 replication_schema > schema
1224 AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1225 AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1226
1227 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile --remote=punix:db.sock db1], [0], [ignore], [ignore])
1228 on_exit 'test ! -e pid || kill `cat pid`'
1229
1230 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server2.log --pidfile=pid2 --remote=punix:db2.sock --unixctl=unixctl2 db2], [0], [ignore], [ignore])
1231 on_exit 'test ! -e pid2 || kill `cat pid2`'
1232
1233 dnl Try to connect without specifying the active server.
1234 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/connect-active-ovsdb-server], [0],
1235 [Unable to connect: active server is not specified.
1236 ], [ignore])
1237
1238 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/set-active-ovsdb-server unix:db.sock], [0], [stdout], [ignore])
1239
1240 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/connect-active-ovsdb-server], [0], [stdout], [ignore])
1241
1242 AT_CHECK([ovsdb-client transact unix:db.sock \
1243 '[["mydb",
1244 {"op": "insert",
1245 "table": "a",
1246 "row": {"number": 0, "name": "zero"}}]]'], [0], [stdout], [ignore])
1247
1248 AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout], [ignore])
1249 cat stdout > dump1
1250 OVS_WAIT_UNTIL([ ovsdb-client dump unix:db2.sock | grep zero ])
1251 AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore])
1252 cat stdout > dump2
1253
1254 AT_CHECK([diff dump1 dump2], [0], [], [ignore])
1255 OVSDB_SERVER_SHUTDOWN
1256 OVSDB_SERVER_SHUTDOWN2
1257 AT_CLEANUP
1258
1259 #ovsdb-server/disconnect-active-server command
1260 AT_SETUP([ovsdb-server/disconnect-active-server])
1261 AT_KEYWORDS([ovsdb server replication disconnect-active-server])
1262 replication_schema > schema
1263 AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1264 AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1265
1266 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile --remote=punix:db.sock db1], [0], [ignore], [ignore])
1267 on_exit 'test ! -e pid || kill `cat pid`'
1268
1269 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server2.log --pidfile=pid2 --remote=punix:db2.sock --unixctl=unixctl2 --sync-from=unix:db.sock db2], [0], [ignore], [ignore])
1270 on_exit 'test ! -e pid2 || kill `cat pid2`'
1271
1272 AT_CHECK([ovsdb-client transact unix:db.sock \
1273 '[["mydb",
1274 {"op": "insert",
1275 "table": "a",
1276 "row": {"number": 0, "name": "zero"}}]]'], [0], [stdout], [ignore])
1277
1278 dnl Make sure the transaction shows up in db2. This also tests the back up server
1279 dnl can be read.
1280 OVS_WAIT_UNTIL([ovsdb-client dump unix:db2.sock | grep zero])
1281
1282 dnl The backup server does not accept any write transaction
1283 AT_CHECK([ovsdb-client transact unix:db2.sock \
1284 '[["mydb",
1285 {"op": "insert",
1286 "table": "b",
1287 "row": {"number": 1, "name": "one"}}]]'], [0],
1288 [[[{"details":"insert operation not allowed when database server is in read only mode","error":"not allowed"}]]
1289 ])
1290
1291 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/disconnect-active-ovsdb-server], [0], [ignore], [ignore])
1292
1293 AT_CHECK([ovsdb-client transact unix:db.sock \
1294 '[["mydb",
1295 {"op": "insert",
1296 "table": "b",
1297 "row": {"number": 1, "name": "one"}}]]'], [0], [stdout], [ignore])
1298
1299 AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout], [ignore])
1300 cat stdout > dump1
1301
1302 sleep 1
1303 AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore])
1304 cat stdout > dump2
1305
1306 AT_CHECK([diff dump1 dump2], [1], [stdout], [ignore])
1307 cat stdout > output
1308
1309 AT_CHECK([uuidfilt output], [0], [7,9c7,8
1310 < _uuid name number
1311 < ------------------------------------ ---- ------
1312 < <0> one 1
1313 ---
1314 > _uuid name number
1315 > ----- ---- ------
1316 ], [ignore], [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1317
1318 dnl The backup server now become active, and can accept write transactions.
1319 AT_CHECK([ovsdb-client transact unix:db2.sock \
1320 '[["mydb",
1321 {"op": "insert",
1322 "table": "b",
1323 "row": {"number": 1, "name": "one"}}]]'], [0], [stdout], [ignore])
1324
1325 AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout])
1326 cat stdout > output
1327
1328 AT_CHECK([uuidfilt output], [0], [a table
1329 _uuid name number
1330 ------------------------------------ ---- ------
1331 <0> zero 0
1332
1333 b table
1334 _uuid name number
1335 ------------------------------------ ---- ------
1336 <1> one 1
1337 ])
1338
1339 OVSDB_SERVER_SHUTDOWN
1340 OVSDB_SERVER_SHUTDOWN2
1341 AT_CLEANUP
1342
1343 #ovsdb-server/active-backup-role-switching
1344 AT_SETUP([ovsdb-server/active-backup-role-switching])
1345 AT_KEYWORDS([ovsdb server replication active-backup-switching])
1346 replication_schema > schema
1347 AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1348 AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1349
1350 dnl Add some data to both DBs
1351 AT_CHECK([ovsdb-tool transact db1 \
1352 '[["mydb",
1353 {"op": "insert",
1354 "table": "a",
1355 "row": {"number": 9, "name": "nine"}}]]'], [0], [ignore], [ignore])
1356
1357 AT_CHECK([ovsdb-tool transact db2 \
1358 '[["mydb",
1359 {"op": "insert",
1360 "table": "a",
1361 "row": {"number": 9, "name": "nine"}}]]'], [0], [ignore], [ignore])
1362
1363 dnl Start both 'db1' and 'db2' in backup mode. Let them backup from each
1364 dnl other. This is not an supported operation state, but to simulate a start
1365 dnl up condition where an HA manger can select which one to be an active
1366 dnl server soon after.
1367 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile="`pwd`"/pid --remote=punix:db.sock --unixctl="`pwd`"/unixctl db1 --sync-from=unix:db2.sock --active ], [0], [ignore], [ignore])
1368 on_exit 'test ! -e pid || kill `cat pid`'
1369
1370 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/connect-active-ovsdb-server])
1371
1372 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])
1373 on_exit 'test ! -e pid2 || kill `cat pid2`'
1374
1375 dnl
1376 dnl make sure both servers reached the replication state
1377 OVS_WAIT_UNTIL([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/sync-status |grep replicating])
1378 OVS_WAIT_UNTIL([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/sync-status |grep replicating])
1379
1380 dnl Switch the 'db1' to active
1381 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/disconnect-active-ovsdb-server])
1382 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/sync-status], [0], [state: active
1383 ])
1384
1385 dnl Issue a transaction to 'db1'
1386 AT_CHECK([ovsdb-client transact unix:db.sock \
1387 '[["mydb",
1388 {"op": "insert",
1389 "table": "a",
1390 "row": {"number": 0, "name": "zero"}}]]'], [0], [ignore])
1391
1392 dnl It should be replicated to 'db2'
1393 OVS_WAIT_UNTIL([ovsdb-client dump unix:db2.sock | grep zero])
1394
1395 dnl Flip the role of 'db1' and 'db2'. 'db1' becomes backup, and db2 becomes active
1396 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/disconnect-active-ovsdb-server])
1397 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/connect-active-ovsdb-server])
1398
1399 dnl Verify the change happend
1400 OVS_WAIT_UNTIL([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/sync-status |grep replicating])
1401 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/sync-status], [0], [state: active
1402 ])
1403
1404 dnl Issue an transaction to 'db2' which is now active.
1405 AT_CHECK([ovsdb-client transact unix:db2.sock \
1406 '[["mydb",
1407 {"op": "insert",
1408 "table": "b",
1409 "row": {"number": 1, "name": "one"}}]]'], [0], [ignore])
1410
1411 dnl The transaction should be replicated to 'db1'
1412 OVS_WAIT_UNTIL([ovsdb-client dump unix:db.sock | grep one])
1413
1414 dnl Both servers should have the same content.
1415 AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout])
1416 cat stdout > dump1
1417
1418 AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout])
1419 cat stdout > dump2
1420
1421 AT_CHECK([diff dump1 dump2])
1422
1423 dnl OVSDB_SERVER_SHUTDOWN
1424 dnl OVSDB_SERVER_SHUTDOWN2
1425 AT_CLEANUP
1426
1427 #ovsdb-server prevent self replicating
1428 AT_SETUP([ovsdb-server prevent self replicating])
1429 AT_KEYWORDS([ovsdb server replication])
1430 replication_schema > schema
1431 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
1432
1433 dnl Add some data to both DBs
1434 AT_CHECK([ovsdb-tool transact db \
1435 '[["mydb",
1436 {"op": "insert",
1437 "table": "a",
1438 "row": {"number": 9, "name": "nine"}}]]'], [0], [ignore], [ignore])
1439
1440 dnl Start 'db', then try to be a back up server of itself.
1441 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server.log --pidfile="`pwd`"/pid --remote=punix:db.sock --unixctl="`pwd`"/unixctl db --sync-from=unix:db.sock --active ], [0], [ignore], [ignore])
1442 on_exit 'test ! -e pid || kill `cat pid`'
1443
1444 dnl Save the current content
1445 AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout])
1446 cp stdout dump1
1447
1448 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/connect-active-ovsdb-server])
1449 dnl Check that self replicating is blocked.
1450 AT_CHECK([grep "Self replicating is not allowed" ovsdb-server.log], [0], [stdout])
1451
1452 dnl Check current DB content is preserved.
1453 AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout])
1454 cat stdout > dump2
1455
1456 AT_CHECK([diff dump1 dump2])
1457 AT_CLEANUP
1458
1459 AT_SETUP([ovsdb-server/read-only db:ptcp connection])
1460 AT_KEYWORDS([ovsdb server read-only])
1461 AT_DATA([schema],
1462 [[{"name": "mydb",
1463 "tables": {
1464 "Root": {
1465 "columns": {
1466 "managers": {
1467 "type": {
1468 "key": {"type": "uuid", "refTable": "Manager"},
1469 "min": 0,
1470 "max": "unlimited"}}}},
1471 "Manager": {
1472 "columns": {
1473 "target": {
1474 "type": "string"},
1475 "read_only": {
1476 "type": {
1477 "key": "boolean",
1478 "min": 0,
1479 "max": 1}},
1480 "is_connected": {
1481 "type": {
1482 "key": "boolean",
1483 "min": 0,
1484 "max": 1}}}},
1485 "ordinals": {
1486 "columns": {
1487 "number": {"type": "integer"},
1488 "name": {"type": "string"}},
1489 "indexes": [["number"]]}
1490 },
1491 "version": "5.1.3",
1492 "cksum": "12345678 9"
1493 }
1494 ]])
1495 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
1496 AT_CHECK(
1497 [[ovsdb-tool transact db \
1498 '["mydb",
1499 {"op": "insert",
1500 "table": "Root",
1501 "row": {
1502 "managers": ["set", [["named-uuid", "x"]]]}},
1503 {"op": "insert",
1504 "table": "Manager",
1505 "uuid-name": "x",
1506 "row": {"target": "ptcp:0:127.0.0.1",
1507 "read_only": true}}]']], [0], [ignore], [ignore])
1508
1509 AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile --remote=db:mydb,Root,managers db], [0], [ignore], [ignore])
1510 PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
1511 AT_CHECK([ovsdb-client get-schema-version tcp:127.0.0.1:$TCP_PORT mydb], [0], [5.1.3
1512 ])
1513
1514 AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT \
1515 ['["mydb",
1516 {"op": "insert",
1517 "table": "ordinals",
1518 "row": {"name": "two", "number": '2'}}
1519 ]']], [0], [stdout], [ignore])
1520 cat stdout >> output
1521 AT_CHECK([uuidfilt output], [0], [[[{"details":"insert operation not allowed when database server is in read only mode","error":"not allowed"}]]
1522 ], [ignore])
1523 OVSDB_SERVER_SHUTDOWN
1524 AT_CLEANUP