]> git.proxmox.com Git - mirror_ovs.git/blame - tests/ovsdb-server.at
tests: Log commands being executed for async message control test.
[mirror_ovs.git] / tests / ovsdb-server.at
CommitLineData
80d326ad 1AT_BANNER([OVSDB -- ovsdb-server transactions (Unix sockets)])
21ff1aee 2
56120500
BP
3m4_define([OVSDB_SERVER_SHUTDOWN],
4 [OVS_APP_EXIT_AND_WAIT_BY_TARGET([ovsdb-server], [ovsdb-server.pid])])
028cbd99 5
ae671c5f
MC
6m4_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
21ff1aee
BP
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.
25m4_define([OVSDB_CHECK_EXECUTION],
26 [AT_SETUP([$1])
9ff373db 27 AT_KEYWORDS([ovsdb server positive unix $5])
39ab07af 28 $2 > schema
7c126fbb 29 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
56120500 30 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db], [0], [ignore], [ignore])
21ff1aee 31 m4_foreach([txn], [$3],
7c126fbb 32 [AT_CHECK([ovsdb-client transact unix:socket 'txn'], [0], [stdout], [ignore],
21ff1aee
BP
33 [test ! -e pid || kill `cat pid`])
34cat stdout >> output
35])
c724bd67 36 AT_CHECK([uuidfilt output], [0], [$4], [ignore],
21ff1aee 37 [test ! -e pid || kill `cat pid`])
028cbd99 38 OVSDB_SERVER_SHUTDOWN
21ff1aee
BP
39 AT_CLEANUP])
40
41EXECUTION_EXAMPLES
80d326ad 42\f
48f6e410
BP
43AT_BANNER([ovsdb-server miscellaneous features])
44
db90b374
BP
45AT_SETUP([truncating corrupted database log])
46AT_KEYWORDS([ovsdb server positive unix])
bdb2e73b 47AT_SKIP_IF([test "$IS_WIN32" = "yes"])
39ab07af 48ordinal_schema > schema
db90b374
BP
49AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
50dnl Do one transaction and save the output.
51AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
52'["ordinals",
53 {"op": "insert",
54 "table": "ordinals",
55 "row": {"number": 0, "name": "zero"}}]'
56]])
56120500 57AT_CHECK([ovsdb-server --remote=punix:socket db --run="sh txnfile"], [0], [stdout], [])
db90b374
BP
58cat stdout >> output
59dnl Add some crap to the database log and run another transaction, which should
60dnl ignore the crap and truncate it out of the log.
61echo 'xxx' >> db
62AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
63'["ordinals",
64 {"op": "insert",
65 "table": "ordinals",
66 "row": {"number": 1, "name": "one"}}]'
67]])
56120500 68AT_CHECK([ovsdb-server --remote=punix:socket db --run="sh txnfile"], [0], [stdout], [stderr])
db90b374
BP
69AT_CHECK([grep 'syntax error: db: parse error.* in header line "xxx"' stderr],
70 [0], [ignore])
71cat stdout >> output
72dnl Run a final transaction to verify that both transactions succeeeded.
73dnl The crap that we added should have been truncated by the previous run,
74dnl so ovsdb-server shouldn't log a warning this time.
75AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
76'["ordinals",
77 {"op": "select",
78 "table": "ordinals",
79 "where": [],
80 "sort": ["number"]}]'
81]])
56120500 82AT_CHECK([ovsdb-server --remote=punix:socket db --run="sh txnfile"], [0], [stdout], [])
43675e26 83cat stdout >> output
c724bd67 84AT_CHECK([uuidfilt output], [0],
43675e26
BP
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`])
90AT_CLEANUP
91
92AT_SETUP([truncating database log with bad transaction])
93AT_KEYWORDS([ovsdb server positive unix])
bdb2e73b 94AT_SKIP_IF([test "$IS_WIN32" = "yes"])
39ab07af 95ordinal_schema > schema
43675e26
BP
96AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
97dnl Do one transaction and save the output.
98AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
99'["ordinals",
100 {"op": "insert",
101 "table": "ordinals",
102 "row": {"number": 0, "name": "zero"}}]'
103]])
56120500 104AT_CHECK([ovsdb-server --remote=punix:socket db --run="sh txnfile"], [0], [stdout], [])
43675e26
BP
105cat stdout >> output
106dnl Add some crap to the database log and run another transaction, which should
107dnl ignore the crap and truncate it out of the log.
108echo 'OVSDB JSON 15 ffbcdae4b0386265f9ea3280dd7c8f0b72a20e56
109{"invalid":{}}' >> db
110AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
111'["ordinals",
112 {"op": "insert",
113 "table": "ordinals",
114 "row": {"number": 1, "name": "one"}}]'
115]])
56120500 116AT_CHECK([ovsdb-server --remote=punix:socket db --run="sh txnfile"], [0], [stdout], [stderr])
43675e26
BP
117AT_CHECK([grep 'syntax "{"invalid":{}}": unknown table: No table named invalid.' stderr],
118 [0], [ignore])
119cat stdout >> output
120dnl Run a final transaction to verify that both transactions succeeeded.
121dnl The crap that we added should have been truncated by the previous run,
122dnl so ovsdb-server shouldn't log a warning this time.
123AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
124'["ordinals",
125 {"op": "select",
126 "table": "ordinals",
127 "where": [],
128 "sort": ["number"]}]'
129]])
56120500 130AT_CHECK([ovsdb-server --remote=punix:socket db --run="sh txnfile"], [0], [stdout], [])
db90b374 131cat stdout >> output
c724bd67 132AT_CHECK([uuidfilt output], [0],
db90b374
BP
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`])
138AT_CLEANUP
139
6bb9b060
BP
140dnl CHECK_DBS([databases])
141dnl
142dnl Checks that ovsdb-server hosts the given 'databases', each of which
143dnl needs to be followed by a newline.
144m4_define([CHECK_DBS],
145 [AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs],
146 [0], [_Server
147$1])
148AT_CHECK([ovsdb-client --no-headings dump _Server Database name | sort], [0], [dnl
149Database table
150_Server
151$1])])
152
9cb53f26
BP
153AT_SETUP([database multiplexing implementation])
154AT_KEYWORDS([ovsdb server positive])
b4e8d170
BP
155ordinal_schema > schema1
156constraint_schema > schema2
157AT_CHECK([ovsdb-tool create db1 schema1], [0], [ignore], [ignore])
158AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
6bb9b060
BP
159AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:db.sock db1 db2], [0], [ignore], [ignore])
160CHECK_DBS([constraints
b4e8d170 161ordinals
6bb9b060 162])
9cb53f26 163AT_CHECK(
6bb9b060 164 [[ovstest test-jsonrpc request unix:db.sock get_schema [\"nonexistent\"]]], [0],
508624b6 165 [[{"error":{"details":"get_schema request specifies unknown database nonexistent","error":"unknown database","syntax":"[\"nonexistent\"]"},"id":0,"result":null}
53ffefe9 166]], [], [test ! -e pid || kill `cat pid`])
9cb53f26
BP
167OVSDB_SERVER_SHUTDOWN
168AT_CLEANUP
169
0a3b723b
BP
170AT_SETUP([ovsdb-server/add-db and remove-db])
171AT_KEYWORDS([ovsdb server positive])
10621d79 172on_exit 'kill `cat *.pid`'
0a3b723b
BP
173ordinal_schema > schema1
174constraint_schema > schema2
175AT_CHECK([ovsdb-tool create db1 schema1], [0], [ignore], [ignore])
176AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
177
178# Start ovsdb-server with just a single database - db1.
10621d79
BP
179AT_CHECK([ovsdb-server -vfile -vvlog:off --log-file --detach --no-chdir --pidfile --remote=punix:db.sock db1], [0])
180CHECK_DBS([ordinals
181])
182
183# Remove the database.
184AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db ordinals], [0])
185CHECK_DBS([])
186
187# Start monitoring processes.
9a403b07
BP
188AT_CHECK([ovsdb-client --detach --no-chdir --pidfile=ovsdb-client-1.pid --no-db-change-aware --no-headings monitor _Server Database name > db-change-unaware.stdout 2> db-change-unaware.stderr])
189AT_CHECK([ovsdb-client --detach --no-chdir --pidfile=ovsdb-client-2.pid --db-change-aware --no-headings monitor _Server Database name > db-change-aware.stdout 2> db-change-aware.stderr])
10621d79
BP
190AT_CAPTURE_FILE([db-change-unaware.stdout])
191AT_CAPTURE_FILE([db-change-unaware.stderr])
192AT_CAPTURE_FILE([db-change-aware.stdout])
193AT_CAPTURE_FILE([db-change-aware.stderr])
194
195# Add the first database back.
196AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db1], [0])
6bb9b060 197CHECK_DBS([ordinals
0a3b723b
BP
198])
199
200# Add the second database.
201AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
6bb9b060 202CHECK_DBS([constraints
0a3b723b
BP
203ordinals
204])
205
206# The databases are responsive.
6bb9b060
BP
207AT_CHECK([ovsdb-client list-tables unix:db.sock constraints], [0], [ignore], [ignore])
208AT_CHECK([ovsdb-client list-tables unix:db.sock ordinals], [0], [ignore], [ignore])
0a3b723b
BP
209
210# Add an already added database.
bd270dc3
GS
211if test $IS_WIN32 = "yes"; then
212 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], 2, [],
213 [I/O error: db2: failed to lock lockfile (Resource deadlock avoided)
214ovs-appctl: ovsdb-server: server returned an error
215])
216else
217 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], 2, [],
1b1d2e6d 218 [ovsdb error: db2: already open
0a3b723b
BP
219ovs-appctl: ovsdb-server: server returned an error
220])
bd270dc3 221fi
0a3b723b
BP
222
223# Add a non-existing database.
224AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db3], 2, [], [stderr])
225AT_CHECK([sed 's/(.*)/(...)/' stderr], [0],
a6be657b 226 [I/O error: db3: open failed (...)
0a3b723b
BP
227ovs-appctl: ovsdb-server: server returned an error
228])
229
230# Add a remote through a db path in db1.
231AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote db:ordinals,ordinals,name], [0])
232AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
233 [0], [db:ordinals,ordinals,name
6bb9b060 234punix:db.sock
0a3b723b
BP
235])
236
237# Removing db1 has no effect on its remote.
238AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db ordinals], [0])
6bb9b060 239CHECK_DBS([constraints
0a3b723b
BP
240])
241AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
242 [0], [db:ordinals,ordinals,name
6bb9b060 243punix:db.sock
0a3b723b 244])
6bb9b060 245AT_CHECK([ovsdb-client list-tables unix:db.sock ordinals], [1], [ignore], [ignore])
0a3b723b
BP
246
247# Remove db2.
248AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db constraints], [0])
6bb9b060
BP
249CHECK_DBS()
250AT_CHECK([ovsdb-client list-tables unix:db.sock constraints], [1], [ignore], [ignore])
0a3b723b
BP
251
252# Remove a non-existent database.
253AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db ordinals], [2],
254 [], [Failed to find the database.
255ovs-appctl: ovsdb-server: server returned an error
256])
3fc53787
GS
257
258# Add a removed database.
259AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
6bb9b060 260CHECK_DBS([constraints
3fc53787 261])
6bb9b060 262AT_CHECK([ovsdb-client list-tables unix:db.sock constraints], [0], [ignore], [ignore])
10621d79
BP
263
264# Check the monitoring results.
265AT_CHECK([uuidfilt db-change-aware.stdout], [0], [dnl
266<0> initial _Server
267
268<1> insert ordinals
269
270<2> insert constraints
271
272<1> delete ordinals
273
274<2> delete constraints
275
276<3> insert constraints
277])
278AT_CHECK([uuidfilt db-change-unaware.stdout], [0], [dnl
279<0> initial _Server
280])
281
d9c8c57c 282OVS_APP_EXIT_AND_WAIT([ovsdb-server])
0a3b723b
BP
283AT_CLEANUP
284
d7ae8d6b 285AT_SETUP([ovsdb-server/add-db with --monitor])
0a3b723b 286AT_KEYWORDS([ovsdb server positive])
36373c1a 287AT_SKIP_IF([test "$IS_WIN32" = "yes"])
5f223e92
BP
288
289# This test intentionally causes SIGSEGV, so make Address Sanitizer ignore it.
290ASAN_OPTIONS=$ASAN_OPTIONS:handle_segv=0; export ASAN_OPTIONS
291
0a3b723b 292# Start ovsdb-server, initially with one db.
0a3b723b
BP
293ordinal_schema > schema
294AT_CHECK([ovsdb-tool create db1 schema], [0], [ignore], [ignore])
53eb8cb8 295on_exit 'kill `cat *.pid`'
1b1d2e6d 296AT_CHECK([ovsdb-server -vfile -vvlog:off --monitor --detach --no-chdir --pidfile --log-file --remote=punix:db.sock db1])
0a3b723b
BP
297
298# Add the second database.
299constraint_schema > schema2
300AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
301AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-db db2], [0])
6bb9b060 302CHECK_DBS([constraints
0a3b723b
BP
303ordinals
304])
305
306# Kill the daemon process, making it look like a segfault,
307# and wait for a new daemon process to get spawned.
308cp ovsdb-server.pid old.pid
309AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
310OVS_WAIT_WHILE([kill -0 `cat old.pid`])
311OVS_WAIT_UNTIL(
312 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
857570c4 313OVS_WAIT_UNTIL([ovs-appctl -t ovsdb-server version])
6bb9b060 314CHECK_DBS([constraints
0a3b723b
BP
315ordinals
316])
d9c8c57c 317OVS_APP_EXIT_AND_WAIT([ovsdb-server])
d7ae8d6b
BP
318AT_CLEANUP
319
320AT_SETUP([ovsdb-server/add-db and remove-db with --monitor])
321AT_KEYWORDS([ovsdb server positive])
36373c1a 322AT_SKIP_IF([test "$IS_WIN32" = "yes"])
5f223e92
BP
323
324# This test intentionally causes SIGSEGV, so make Address Sanitizer ignore it.
325ASAN_OPTIONS=$ASAN_OPTIONS:handle_segv=0; export ASAN_OPTIONS
326
d7ae8d6b 327# Start ovsdb-server, initially with one db.
d7ae8d6b
BP
328ordinal_schema > schema
329AT_CHECK([ovsdb-tool create db1 schema], [0], [ignore], [ignore])
330constraint_schema > schema2
331AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
53eb8cb8 332on_exit 'kill `cat *.pid`'
1b1d2e6d 333AT_CHECK([ovsdb-server -vfile -vvlog:off --monitor --detach --no-chdir --pidfile --log-file --remote=punix:db.sock db1 db2])
0a3b723b 334
d7ae8d6b 335# Remove the second database.
0a3b723b 336AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-db constraints])
6bb9b060 337CHECK_DBS([ordinals
0a3b723b
BP
338])
339
340# Kill the daemon process, making it look like a segfault,
341# and wait for a new daemon process to get spawned.
342cp ovsdb-server.pid old.pid
343AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
344OVS_WAIT_WHILE([kill -0 `cat old.pid`])
345OVS_WAIT_UNTIL(
346 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
857570c4 347OVS_WAIT_UNTIL([ovs-appctl -t ovsdb-server version])
6bb9b060 348CHECK_DBS([ordinals
0a3b723b 349])
d9c8c57c 350OVS_APP_EXIT_AND_WAIT([ovsdb-server])
0a3b723b
BP
351AT_CLEANUP
352
0b1fae1b
BP
353AT_SETUP([--remote=db: implementation])
354AT_KEYWORDS([ovsdb server positive])
355AT_DATA([schema],
356 [[{"name": "mydb",
357 "tables": {
b4e8d170
BP
358 "Root": {
359 "columns": {
360 "managers": {
361 "type": {
362 "key": "string",
363 "min": 0,
364 "max": "unlimited"}},
365 "manager_options": {
366 "type": {
367 "key": {"type": "uuid", "refTable": "Manager"},
368 "min": 0,
369 "max": "unlimited"}}}},
0b1fae1b
BP
370 "Manager": {
371 "columns": {
b4e8d170
BP
372 "target": {
373 "type": "string"},
374 "is_connected": {
375 "type": {
376 "key": "boolean",
377 "min": 0,
378 "max": 1}}}}}}
0b1fae1b 379]])
7c126fbb
BP
380AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
381AT_CHECK(
0b1fae1b 382 [[ovsdb-tool transact db \
9cb53f26 383 '["mydb",
b4e8d170
BP
384 {"op": "insert",
385 "table": "Root",
386 "row": {
387 "managers": "punix:socket1",
388 "manager_options": ["set", [["named-uuid", "x"]]]}},
9cb53f26 389 {"op": "insert",
0b1fae1b 390 "table": "Manager",
b4e8d170
BP
391 "uuid-name": "x",
392 "row": {"target": "punix:socket2"}}]']], [0], [ignore], [ignore])
53eb8cb8 393on_exit 'kill `cat ovsdb-server.pid`'
8ad822c9 394AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=db:mydb,Root,managers --remote=db:mydb,Root,manager_options --log-file db], [0], [ignore], [ignore])
bdba1947 395ovs-appctl -t ovsdb-server time/warp 6000 1000
7c126fbb 396AT_CHECK(
b4e8d170 397 [[ovsdb-client transact unix:socket1 \
9cb53f26 398 '["mydb",
b4e8d170
BP
399 {"op": "select",
400 "table": "Root",
401 "where": [],
402 "columns": ["managers"]},
9cb53f26 403 {"op": "select",
0b1fae1b
BP
404 "table": "Manager",
405 "where": [],
b4e8d170
BP
406 "columns": ["target", "is_connected"]}]']],
407 [0], [stdout], [ignore])
0b1fae1b 408AT_CHECK(
c724bd67 409 [uuidfilt stdout],
0b1fae1b 410 [0],
b4e8d170 411 [[[{"rows":[{"managers":"punix:socket1"}]},{"rows":[{"is_connected":false,"target":"punix:socket2"}]}]
0b1fae1b 412]],
b4e8d170 413 [ignore])
d9c8c57c 414OVS_APP_EXIT_AND_WAIT([ovsdb-server])
0b1fae1b 415AT_CLEANUP
ada496b5 416
b421d2af
BP
417AT_SETUP([ovsdb-server/add-remote and remove-remote])
418AT_KEYWORDS([ovsdb server positive])
b421d2af
BP
419ordinal_schema > schema
420AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
53eb8cb8 421on_exit 'kill `cat *.pid`'
b421d2af
BP
422AT_CHECK([ovsdb-server --detach --no-chdir --pidfile db])
423
424AT_CHECK([test ! -e socket1])
425AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
91fc9298 426if test "$IS_WIN32" = "yes"; then
922247c6 427 OVS_WAIT_UNTIL([test -e socket1])
91fc9298
GS
428else
429 OVS_WAIT_UNTIL([test -S socket1])
430fi
b421d2af
BP
431AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
432 [0], [punix:socket1
433])
434
435AT_CHECK([test ! -e socket2])
436AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket2])
91fc9298 437if test "$IS_WIN32" = "yes"; then
922247c6 438 OVS_WAIT_UNTIL([test -e socket2])
91fc9298
GS
439else
440 OVS_WAIT_UNTIL([test -S socket2])
441fi
b421d2af
BP
442AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
443 [0], [punix:socket1
444punix:socket2
445])
446
447AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote db:x,y,z], [2],
448 [], ["db:x,y,z": no database named x
449ovs-appctl: ovsdb-server: server returned an error
450])
451
452AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
453OVS_WAIT_UNTIL([test ! -e socket1])
91fc9298 454if test "$IS_WIN32" = "yes"; then
922247c6 455 AT_CHECK([test -e socket2])
91fc9298
GS
456else
457 AT_CHECK([test -S socket2])
458fi
b421d2af
BP
459AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
460 [0], [punix:socket2
461])
462
463AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket2])
464OVS_WAIT_UNTIL([test ! -e socket2])
465AT_CHECK([test ! -e socket1])
466AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
d9c8c57c 467OVS_APP_EXIT_AND_WAIT([ovsdb-server])
b421d2af
BP
468AT_CLEANUP
469
09993217 470AT_SETUP([ovsdb-server/add-remote with --monitor])
5f36127e 471AT_KEYWORDS([ovsdb server positive])
36373c1a 472AT_SKIP_IF([test "$IS_WIN32" = "yes"])
5f223e92
BP
473
474# This test intentionally causes SIGSEGV, so make Address Sanitizer ignore it.
475ASAN_OPTIONS=$ASAN_OPTIONS:handle_segv=0; export ASAN_OPTIONS
476
5f36127e 477# Start ovsdb-server, initially with no remotes.
5f36127e
BP
478ordinal_schema > schema
479AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
53eb8cb8 480on_exit 'kill `cat *.pid`'
1b1d2e6d 481AT_CHECK([ovsdb-server -vfile -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db])
5f36127e
BP
482
483# Add a remote.
484AT_CHECK([test ! -e socket1])
485AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
486OVS_WAIT_UNTIL([test -S socket1])
487AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
488 [0], [punix:socket1
489])
490
491# Kill the daemon process, making it look like a segfault,
492# and wait for a new daemon process to get spawned and for it to
493# start listening on 'socket1'.
494cp ovsdb-server.pid old.pid
495rm socket1
496AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
497OVS_WAIT_WHILE([kill -0 `cat old.pid`])
498OVS_WAIT_UNTIL(
499 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
857570c4 500OVS_WAIT_UNTIL([ovs-appctl -t ovsdb-server version])
5f36127e 501OVS_WAIT_UNTIL([test -S socket1])
d9c8c57c 502OVS_APP_EXIT_AND_WAIT([ovsdb-server])
09993217
AW
503AT_CLEANUP
504
505AT_SETUP([ovsdb-server/add-remote and remove-remote with --monitor])
506AT_KEYWORDS([ovsdb server positive])
36373c1a 507AT_SKIP_IF([test "$IS_WIN32" = "yes"])
5f223e92
BP
508
509# This test intentionally causes SIGSEGV, so make Address Sanitizer ignore it.
510ASAN_OPTIONS=$ASAN_OPTIONS:handle_segv=0; export ASAN_OPTIONS
511
09993217 512# Start ovsdb-server, initially with no remotes.
09993217
AW
513ordinal_schema > schema
514AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
53eb8cb8 515on_exit 'kill `cat *.pid`'
1b1d2e6d 516AT_CHECK([ovsdb-server -vfile -vvlog:off --monitor --detach --no-chdir --pidfile --log-file db])
09993217
AW
517
518# Add a remote.
519AT_CHECK([test ! -e socket1])
520AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote punix:socket1])
521OVS_WAIT_UNTIL([test -S socket1])
522AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes],
523 [0], [punix:socket1
524])
5f36127e
BP
525
526# Remove the remote.
527AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1])
528OVS_WAIT_UNTIL([test ! -e socket1])
529AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes])
530
531# Kill the daemon process, making it look like a segfault,
532# and wait for a new daemon process to get spawned and make sure that it
533# does not listen on 'socket1'.
534cp ovsdb-server.pid old.pid
535AT_CHECK([kill -SEGV `cat ovsdb-server.pid`])
536OVS_WAIT_WHILE([kill -0 `cat old.pid`])
537OVS_WAIT_UNTIL(
538 [test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat old.pid`])
857570c4 539OVS_WAIT_UNTIL([ovs-appctl -t ovsdb-server version])
5f36127e 540AT_CHECK([test ! -e socket1])
d9c8c57c 541OVS_APP_EXIT_AND_WAIT([ovsdb-server])
5f36127e
BP
542AT_CLEANUP
543
78876719
BP
544AT_SETUP([SSL db: implementation])
545AT_KEYWORDS([ovsdb server positive ssl $5])
546AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
b028245a
GS
547# For this test, we pass PKIDIR through a ovsdb-tool transact and
548# msys on Windows does not convert the path style automatically.
549# So, do that forcefully with a 'pwd -W' (called through pwd() function).
550PKIDIR="$(cd $abs_top_builddir/tests && pwd)"
5a0e4aec 551AT_SKIP_IF([expr "$PKIDIR" : ".*[ '\"
0bcff889 552\\]"])
78876719
BP
553AT_DATA([schema],
554 [[{"name": "mydb",
555 "tables": {
556 "SSL": {
557 "columns": {
558 "private_key": {"type": "string"},
559 "certificate": {"type": "string"},
e18a1d08
ER
560 "ca_cert": {"type": "string"},
561 "ssl_protocols" : {"type": "string"},
562 "ssl_ciphers" : {"type" : "string"}}}}}
78876719
BP
563]])
564AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
e18a1d08
ER
565# The !ECDHE-ECDSA-AES256-GCM-SHA384 in the ssl_ciphers is so that
566# a cipher negotiation failure can be tested for later.
78876719
BP
567AT_CHECK(
568 [[ovsdb-tool transact db \
569 '["mydb",
570 {"op": "insert",
571 "table": "SSL",
572 "row": {"private_key": "'"$PKIDIR/testpki-privkey2.pem"'",
573 "certificate": "'"$PKIDIR/testpki-cert2.pem"'",
e18a1d08
ER
574 "ca_cert": "'"$PKIDIR/testpki-cacert.pem"'",
575 "ssl_protocols": "'"TLSv1.2,TLSv1.1"'",
576 "ssl_ciphers": "'"HIGH:!aNULL:!MD5:!ECDHE-ECDSA-AES256-GCM-SHA384"'"}}]']],
78876719 577 [0], [ignore], [ignore])
c6c17485 578on_exit 'kill `cat *.pid`'
78876719 579AT_CHECK(
56120500 580 [ovsdb-server --log-file --detach --no-chdir --pidfile \
fb6de52c
GS
581 --private-key=db:mydb,SSL,private_key \
582 --certificate=db:mydb,SSL,certificate \
583 --ca-cert=db:mydb,SSL,ca_cert \
e18a1d08
ER
584 --ssl-protocols=db:mydb,SSL,ssl_protocols \
585 --ssl-ciphers=db:mydb,SSL,ssl_ciphers \
56120500 586 --remote=pssl:0:127.0.0.1 db],
78876719 587 [0], [ignore], [ignore])
fb28ef2d 588PARSE_LISTENING_PORT([ovsdb-server.log], [SSL_PORT])
78876719
BP
589AT_CHECK(
590 [[ovsdb-client \
591 --private-key=$PKIDIR/testpki-privkey.pem \
592 --certificate=$PKIDIR/testpki-cert.pem \
593 --ca-cert=$PKIDIR/testpki-cacert.pem \
e18a1d08
ER
594 --ssl-protocols=TLSv1.2,TLSv1.1 \
595 --ssl-ciphers=HIGH:!aNULL:!MD5 \
78876719
BP
596 transact ssl:127.0.0.1:$SSL_PORT \
597 '["mydb",
598 {"op": "select",
599 "table": "SSL",
600 "where": [],
e18a1d08 601 "columns": ["private_key"]}]']],
c6c17485 602 [0], [stdout], [ignore])
78876719
BP
603cat stdout >> output
604AT_CHECK_UNQUOTED(
b33bff0f 605 [cat output], [0],
0877a018 606 [[@<:@{"rows":@<:@{"private_key":"$PKIDIR/testpki-privkey2.pem"}@:>@}@:>@
c6c17485 607]], [ignore])
e18a1d08
ER
608# Check that when the server has TLSv1.1+ and the client has
609# TLSv1 that the connection fails.
610AT_CHECK(
611 [[ovsdb-client \
612 --private-key=$PKIDIR/testpki-privkey.pem \
613 --certificate=$PKIDIR/testpki-cert.pem \
614 --ca-cert=$PKIDIR/testpki-cacert.pem \
615 --ssl-protocols=TLSv1 \
616 --ssl-ciphers=HIGH:!aNULL:!MD5 \
617 transact ssl:127.0.0.1:$SSL_PORT \
618 '["mydb",
619 {"op": "select",
620 "table": "SSL",
621 "where": [],
622 "columns": ["private_key"]}]']],
623 [1], [stdout],
c6c17485 624 [stderr])
e18a1d08
ER
625cat stderr > output
626AT_CHECK_UNQUOTED(
efd71505
BP
627 [sed -n "/failed to connect/s/ (.*)//p" output], [0],
628 [ovsdb-client: failed to connect to "ssl:127.0.0.1:$SSL_PORT"
e18a1d08 629],
c6c17485 630 [ignore])
e18a1d08
ER
631# Check that when ciphers are not compatible, that a negotiation
632# failure occurs.
633AT_CHECK(
634 [[ovsdb-client \
635 --private-key=$PKIDIR/testpki-privkey.pem \
636 --certificate=$PKIDIR/testpki-cert.pem \
637 --ca-cert=$PKIDIR/testpki-cacert.pem \
638 --ssl-protocols=TLSv1.2,TLSv1.1 \
639 --ssl-ciphers=ECDHE-ECDSA-AES256-GCM-SHA384 \
640 transact ssl:127.0.0.1:$SSL_PORT \
641 '["mydb",
642 {"op": "select",
643 "table": "SSL",
644 "where": [],
645 "columns": ["private_key"]}]']],
646 [1], [stdout],
c6c17485 647 [stderr])
e18a1d08
ER
648cat stderr > output
649AT_CHECK_UNQUOTED(
efd71505
BP
650 [sed -n "/failed to connect/s/ (.*)//p" output], [0],
651 [ovsdb-client: failed to connect to "ssl:127.0.0.1:$SSL_PORT"
e18a1d08 652],
c6c17485 653 [ignore])
e18a1d08
ER
654# The error message for being unable to negotiate a shared ciphersuite
655# is 'sslv3 alert handshake failure'. This is not the clearest message.
656AT_CHECK_UNQUOTED(
657 [grep "sslv3 alert handshake failure" output], [0],
658 [stdout],
c6c17485 659 [ignore])
78876719
BP
660OVSDB_SERVER_SHUTDOWN
661AT_CLEANUP
1b1d2e6d
BP
662\f
663OVS_START_SHELL_HELPERS
664# ovsdb_check_online_compaction MODEL
665#
666# where MODEL is "standalone" or "cluster"
667ovsdb_check_online_compaction() {
668 local model=$1
669
670 ordinal_schema > schema
671 dnl Make sure that "ovsdb-tool create" works with a dangling symlink for
672 dnl the database and the lockfile, creating the target of each symlink rather
673 dnl than replacing the symlinks with regular files.
674 mkdir dir
675 if test "$IS_WIN32" = "no"; then
5a0e4aec
BP
676 ln -s dir/db db
677 ln -s dir/.db.~lock~ .db.~lock~
678 AT_SKIP_IF([test ! -h db || test ! -h .db.~lock~])
1b1d2e6d
BP
679 fi
680 AT_CHECK([if test $model = standalone; then
681 ovsdb-tool create db schema
682 else
683 ovsdb-tool create-cluster db schema unix:s1.raft
684 fi])
685 dnl Start ovsdb-server.
686 AT_CHECK([ovsdb-server -vvlog:off -vconsole:off --detach --no-chdir --pidfile --remote=punix:socket --log-file db], [0])
d97af428 687 AT_CHECK([ovsdb_client_wait unix:socket ordinals connected])
1b1d2e6d
BP
688 AT_CAPTURE_FILE([ovsdb-server.log])
689 dnl Do a bunch of random transactions that put crap in the database log.
690 AT_CHECK(
691 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
5a0e4aec
BP
692 set -- $pair
693 ovsdb-client transact unix:socket '
694 ["ordinals",
695 {"op": "insert",
696 "table": "ordinals",
697 "row": {"name": "'$1'", "number": '$2'}},
698 {"op": "comment",
699 "comment": "add row for '"$pair"'"}]'
700 ovsdb-client transact unix:socket '
701 ["ordinals",
702 {"op": "delete",
703 "table": "ordinals",
704 "where": [["number", "==", '$2']]},
705 {"op": "comment",
706 "comment": "delete row for '"$2"'"}]'
707 ovsdb-client transact unix:socket '
708 ["ordinals",
709 {"op": "insert",
710 "table": "ordinals",
711 "row": {"name": "'$1'", "number": '$2'}},
712 {"op": "comment",
713 "comment": "add back row for '"$pair"'"}]'
714 done]],
1b1d2e6d
BP
715 [0], [stdout])
716 if test $model = standalone; then
5a0e4aec
BP
717 dnl Check that all the crap is in fact in the database log.
718 AT_CHECK([[uuidfilt db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | ovstest test-json --multiple -]], [0],
1b1d2e6d 719[[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"}
62c87d4a
BP
720{"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
721{"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
722{"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
723{"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
724{"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
725{"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
726{"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
727{"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
728{"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
729{"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
730{"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
731{"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
732{"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
733{"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
734{"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
735{"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
736{"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
737{"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
1b1d2e6d
BP
738]])
739 else
740 dnl Check that at least there's a lot of transactions.
5a0e4aec 741 AT_CHECK([test `wc -l < db` -gt 50])
1b1d2e6d
BP
742 fi
743 dnl Dump out and check the actual database contents.
744 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout])
745 AT_CHECK([uuidfilt stdout], [0], [dnl
370a11b9
BP
746ordinals table
747_uuid name number
ada496b5 748------------------------------------ ----- ------
e51d0a1d
BP
749<0> five 5
750<1> four 4
751<2> one 1
752<3> three 3
753<4> two 2
754<5> zero 0
1b1d2e6d
BP
755])
756 cp db db.pre-compaction
757 dnl Now compact the database in-place.
758 AT_CHECK([[ovs-appctl -t ovsdb-server ovsdb-server/compact]],
759 [0], [], [ignore])
760 dnl Negative test.
761 AT_CHECK([[ovs-appctl -t ovsdb-server ovsdb-server/compact _Server]],
762 [2], [], [cannot compact built-in databases
bc7bcc40
BP
763ovs-appctl: ovsdb-server: server returned an error
764])
1b1d2e6d
BP
765 dnl Make sure that "db" is still a symlink to dir/db instead of getting
766 dnl replaced by a regular file, ditto for .db.~lock~.
767 if test "$IS_WIN32" = "no"; then
5a0e4aec
BP
768 AT_CHECK([test -h db])
769 AT_CHECK([test -h .db.~lock~])
770 AT_CHECK([test -f dir/db])
771 AT_CHECK([test -f dir/.db.~lock~])
1b1d2e6d
BP
772 fi
773
774 # We can't fully re-check the contents of the database log, because the
775 # order of the records is not predictable, but there should only be 4 lines
776 # in it now in the standalone case
777 AT_CAPTURE_FILE([db])
778 compacted_lines=`wc -l < db`
779 echo compacted_lines=$compacted_lines
780 if test $model = standalone; then
781 AT_CHECK([test $compacted_lines -eq 4])
782 fi
783
784 dnl And check that the dumped data is the same too:
785 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout])
786 AT_CHECK([uuidfilt stdout], [0], [dnl
370a11b9
BP
787ordinals table
788_uuid name number
ada496b5 789------------------------------------ ----- ------
e51d0a1d
BP
790<0> five 5
791<1> four 4
792<2> one 1
793<3> three 3
794<4> two 2
795<5> zero 0
1b1d2e6d
BP
796])
797 dnl Now do some more transactions.
798 AT_CHECK(
799 [[ovsdb-client transact unix:socket '
5a0e4aec
BP
800 ["ordinals",
801 {"op": "delete",
802 "table": "ordinals",
803 "where": [["number", "<", 3]]}]']],
1b1d2e6d
BP
804 [0], [[[{"count":3}]
805]], [ignore])
806
807 dnl There should be 6 lines in the log now, for the standalone case,
808 dnl and for the clustered case the file should at least have grown.
809 updated_lines=`wc -l < db`
810 echo compacted_lines=$compacted_lines updated_lines=$updated_lines
811 if test $model = standalone; then
812 AT_CHECK([test $updated_lines -eq 6])
813 else
814 AT_CHECK([test $updated_lines -gt $compacted_lines])
815 fi
816
817 dnl Then check that the dumped data is correct. This time first kill
818 dnl and restart the database server to ensure that the data is correct on
819 dnl disk as well as in memory.
820 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
821 AT_CHECK([ovsdb-server -vvlog:off -vconsole:off --detach --no-chdir --pidfile --remote=punix:socket --log-file db])
822 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout])
823 AT_CHECK([uuidfilt stdout], [0], [dnl
370a11b9
BP
824ordinals table
825_uuid name number
ada496b5 826------------------------------------ ----- ------
e51d0a1d
BP
827<0> five 5
828<1> four 4
829<2> three 3
ada496b5 830], [], [test ! -e pid || kill `cat pid`])
1b1d2e6d
BP
831 OVSDB_SERVER_SHUTDOWN
832}
833OVS_END_SHELL_HELPERS
834
835AT_SETUP([compacting online - standalone])
836AT_KEYWORDS([ovsdb server compact])
837ovsdb_check_online_compaction standalone
ada496b5 838AT_CLEANUP
48f6e410 839
1b1d2e6d
BP
840AT_SETUP([compacting online - cluster])
841AT_KEYWORDS([ovsdb server compact])
842ovsdb_check_online_compaction cluster
843AT_CLEANUP
844\f
845OVS_START_SHELL_HELPERS
846# ovsdb_check_online_conversion MODEL
847#
848# where MODEL is "standalone" or "cluster"
849ovsdb_check_online_conversion() {
850 local model=$1
851 on_exit 'kill `cat *.pid`'
852 ordinal_schema > schema
853 AT_DATA([new-schema],
854 [[{"name": "ordinals",
53178986
BP
855 "tables": {
856 "ordinals": {
5a0e4aec
BP
857 "columns": {
858 "number": {"type": "integer"}}}}}
53178986 859]])
1b1d2e6d
BP
860 dnl Make sure that "ovsdb-tool create" works with a dangling symlink for
861 dnl the database and the lockfile, creating the target of each symlink
862 dnl rather than replacing the symlinks with regular files.
863 mkdir dir
864 if test "$IS_WIN32" = "no"; then
5a0e4aec
BP
865 ln -s dir/db db
866 ln -s dir/.db.~lock~ .db.~lock~
867 AT_SKIP_IF([test ! -h db || test ! -h .db.~lock~])
1b1d2e6d
BP
868 fi
869 AT_CHECK([if test $model = standalone; then
870 ovsdb-tool create db schema
871 else
872 ovsdb-tool create-cluster db schema unix:s1.raft
873 fi])
874
875 dnl Start the database server.
876 AT_CHECK([ovsdb-server -vfile -vvlog:off -vconsole:off --detach --no-chdir --pidfile --log-file --remote=punix:db.sock db], [0])
877 AT_CAPTURE_FILE([ovsdb-server.log])
878
879 dnl Put some data in the database.
880 AT_CHECK(
881 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
5a0e4aec
BP
882 set -- $pair
883 ovsdb-client transact '
884 ["ordinals",
885 {"op": "insert",
886 "table": "ordinals",
887 "row": {"name": "'$1'", "number": '$2'}},
888 {"op": "comment",
889 "comment": "add row for '"$pair"'"}]'
890 done | uuidfilt]], [0],
1b1d2e6d 891 [[[{"uuid":["uuid","<0>"]},{}]
53178986
BP
892[{"uuid":["uuid","<1>"]},{}]
893[{"uuid":["uuid","<2>"]},{}]
894[{"uuid":["uuid","<3>"]},{}]
895[{"uuid":["uuid","<4>"]},{}]
896[{"uuid":["uuid","<5>"]},{}]
897]], [ignore])
898
1b1d2e6d
BP
899 dnl Try "needs-conversion".
900 AT_CHECK([ovsdb-client needs-conversion schema], [0], [no
53178986 901])
1b1d2e6d 902 AT_CHECK([ovsdb-client needs-conversion new-schema], [0], [yes
53178986
BP
903])
904
1b1d2e6d
BP
905 dnl Start two monitors on the 'ordinals' db, one that is database
906 dnl change aware and one that is not.
9a403b07 907 AT_CHECK([ovsdb-client -vfile -vvlog:off --detach --no-chdir --pidfile=monitor-ordinals-aware.pid --log-file=monitor-ordinals-aware.log --db-change-aware --no-headings monitor ordinals ordinals number name > monitor-ordinals-aware.stdout 2> monitor-ordinals-aware.stderr])
1b1d2e6d
BP
908 AT_CAPTURE_FILE([monitor-ordinals-aware.stdout])
909 AT_CAPTURE_FILE([monitor-ordinals-aware.log])
910 AT_CAPTURE_FILE([monitor-ordinals-aware.stderr])
911
9a403b07 912 AT_CHECK([ovsdb-client -vfile -vvlog:off --detach --no-chdir --pidfile=monitor-ordinals-unaware.pid --log-file=monitor-ordinals-unaware.log --no-db-change-aware --no-headings monitor ordinals ordinals number name > monitor-ordinals-unaware.stdout 2> monitor-ordinals-unaware.stderr])
1b1d2e6d
BP
913 AT_CAPTURE_FILE([monitor-ordinals-unaware.stdout])
914 AT_CAPTURE_FILE([monitor-ordinals-unaware.log])
915 AT_CAPTURE_FILE([monitor-ordinals-unaware.stderr])
916
917 dnl Start two monitors on the '_Server' db, one that is database
918 dnl change aware and one that is not.
9a403b07 919 AT_CHECK([ovsdb-client -vfile -vvlog:off --detach --no-chdir --pidfile=monitor-server-aware.pid --log-file=monitor-server-aware.log --db-change-aware --no-headings monitor _Server Database name > monitor-server-aware.stdout 2> monitor-server-aware.stderr])
1b1d2e6d
BP
920 AT_CAPTURE_FILE([monitor-server-aware.stdout])
921 AT_CAPTURE_FILE([monitor-server-aware.log])
922 AT_CAPTURE_FILE([monitor-server-aware.stderr])
923
9a403b07 924 AT_CHECK([ovsdb-client -vfile -vvlog:off --detach --no-chdir --pidfile=monitor-server-unaware.pid --log-file=monitor-server-unaware.log --no-db-change-aware --no-headings monitor _Server Database name > monitor-server-unaware.stdout 2> monitor-server-unaware.stderr])
1b1d2e6d
BP
925 AT_CAPTURE_FILE([monitor-server-unaware.stdout])
926 AT_CAPTURE_FILE([monitor-server-unaware.log])
927 AT_CAPTURE_FILE([monitor-server-unaware.stderr])
928
929 dnl Start two long-running transactions (triggers) on the 'ordinals' db,
930 dnl one that is database change aware and one that is not.
931 ordinals_txn='[["ordinals",
5a0e4aec
BP
932 {"op": "wait",
933 "table": "ordinals",
934 "where": [["name", "==", "seven"]],
935 "columns": ["name", "number"],
936 "rows": [],
937 "until": "!="}]]'
9a403b07 938 AT_CHECK([ovsdb-client -vfile -vvlog:off --detach --no-chdir --pidfile=trigger-ordinals-aware.pid --log-file=trigger-ordinals-aware.log --db-change-aware transact "$ordinals_txn" > trigger-ordinals-aware.stdout 2> trigger-ordinals-aware.stderr])
1b1d2e6d
BP
939 AT_CAPTURE_FILE([trigger-ordinals-aware.stdout])
940 AT_CAPTURE_FILE([trigger-ordinals-aware.log])
941 AT_CAPTURE_FILE([trigger-ordinals-aware.stderr])
942
9a403b07 943 AT_CHECK([ovsdb-client -vfile -vvlog:off --detach --no-chdir --pidfile=trigger-ordinals-unaware.pid --log-file=trigger-ordinals-unaware.log --no-db-change-aware transact "$ordinals_txn" > trigger-ordinals-unaware.stdout 2> trigger-ordinals-unaware.stderr])
1b1d2e6d
BP
944 AT_CAPTURE_FILE([trigger-ordinals-unaware.stdout])
945 AT_CAPTURE_FILE([trigger-ordinals-unaware.log])
946 AT_CAPTURE_FILE([trigger-ordinals-unaware.stderr])
947
948 dnl Start two long-running transactions (triggers) on the _Server db,
949 dnl one that is database change aware and one that is not.
950 server_txn='[["_Server",
5a0e4aec
BP
951 {"op": "wait",
952 "table": "Database",
953 "where": [["name", "==", "xyzzy"]],
954 "columns": ["name"],
955 "rows": [],
956 "until": "!="}]]'
9a403b07 957 AT_CHECK([ovsdb-client -vfile -vvlog:off --detach --no-chdir --pidfile=trigger-server-aware.pid --log-file=trigger-server-aware.log --db-change-aware transact "$server_txn" > trigger-server-aware.stdout 2> trigger-server-aware.stderr])
1b1d2e6d
BP
958 AT_CAPTURE_FILE([trigger-server-aware.stdout])
959 AT_CAPTURE_FILE([trigger-server-aware.log])
960 AT_CAPTURE_FILE([trigger-server-aware.stderr])
961
9a403b07 962 AT_CHECK([ovsdb-client -vfile -vvlog:off --detach --no-chdir --pidfile=trigger-server-unaware.pid --log-file=trigger-server-unaware.log --no-db-change-aware transact "$server_txn" > trigger-server-unaware.stdout 2> trigger-server-unaware.stderr])
1b1d2e6d
BP
963 AT_CAPTURE_FILE([trigger-server-unaware.stdout])
964 AT_CAPTURE_FILE([trigger-server-unaware.log])
965 AT_CAPTURE_FILE([trigger-server-unaware.stderr])
966
967 dnl Dump out and check the actual database contents.
968 AT_CHECK([ovsdb-client dump unix:db.sock ordinals], [0], [stdout])
969 AT_CHECK([uuidfilt stdout], [0], [dnl
53178986
BP
970ordinals table
971_uuid name number
972------------------------------------ ----- ------
973<0> five 5
974<1> four 4
975<2> one 1
976<3> three 3
977<4> two 2
978<5> zero 0
979])
980
1b1d2e6d
BP
981 dnl Convert the database.
982 AT_CHECK([ovsdb-client convert new-schema])
53178986 983
1b1d2e6d
BP
984 dnl Try "needs-conversion".
985 AT_CHECK([ovsdb-client needs-conversion schema], [0], [yes
53178986 986])
1b1d2e6d 987 AT_CHECK([ovsdb-client needs-conversion new-schema], [0], [no
53178986
BP
988])
989
1b1d2e6d
BP
990 dnl Verify that the "ordinals" monitors behaved as they should have.
991 dnl Both should have exited, for different reasons.
992 for x in aware unaware; do
5a0e4aec
BP
993 echo $x
994 OVS_WAIT_WHILE([test -e monitor-ordinals-$x.pid])
995 AT_CHECK([sort -k 3 monitor-ordinals-$x.stdout | uuidfilt], [0],
1b1d2e6d 996 [<0> initial 0 zero
53178986
BP
997<1> initial 1 one
998<2> initial 2 two
999<3> initial 3 three
1000<4> initial 4 four
1001<5> initial 5 five
1002])
1b1d2e6d
BP
1003 done
1004 AT_CHECK([sed 's/.*: //' monitor-ordinals-unaware.stderr], [0], [receive failed (End of file)
53178986 1005])
1b1d2e6d 1006 AT_CHECK([sed 's/.*: //' monitor-ordinals-aware.stderr], [0], [ordinals database was removed
53178986
BP
1007])
1008
1b1d2e6d
BP
1009 dnl Verify that the _Server monitors behaved as they should have.
1010 dnl The db-aware monitor should still be running, but not the unaware one.
1011 for x in aware unaware; do
5a0e4aec 1012 AT_CHECK([sort -k 3 monitor-server-$x.stdout | uuidfilt], [0],
1b1d2e6d 1013 [<0> initial _Server
53178986
BP
1014<1> initial ordinals
1015])
1b1d2e6d
BP
1016 done
1017 OVS_WAIT_WHILE([test -e monitor-server-unaware.pid])
1018 AT_CHECK([sed 's/.*: //' monitor-ordinals-unaware.stderr], [0], [receive failed (End of file)
53178986 1019])
1b1d2e6d
BP
1020 AT_CHECK([test -e monitor-server-aware.pid])
1021
1022 dnl Verify that the "ordinals" triggers behaved as they should have:
1023 dnl Both should have exited, for different reasons.
1024 for x in unaware aware; do
5a0e4aec
BP
1025 OVS_WAIT_WHILE([test -e trigger-ordinals-$x.pid])
1026 AT_CHECK([cat trigger-ordinals-$x.stdout])
1b1d2e6d
BP
1027 done
1028 AT_CHECK([cat trigger-ordinals-unaware.stderr], [0], [ovsdb-client: transaction failed (End of file)
53178986 1029])
1b1d2e6d 1030 AT_CHECK([cat trigger-ordinals-aware.stderr], [0], [ovsdb-client: transaction returned error: "canceled"
53178986
BP
1031])
1032
1b1d2e6d
BP
1033 dnl Verify that the _Server triggers behaved as they should have:
1034 dnl The db-aware trigger should still be waiting, but not the unaware one.
1035 for x in aware unaware; do
5a0e4aec 1036 AT_CHECK([cat trigger-server-$x.stdout])
1b1d2e6d
BP
1037 done
1038 OVS_WAIT_WHILE([test -e trigger-server-unaware.pid])
1039 AT_CHECK([sed 's/.*: //' trigger-ordinals-unaware.stderr], [0], [transaction failed (End of file)
53178986 1040])
1b1d2e6d
BP
1041 AT_CHECK([test -e trigger-server-aware.pid])
1042
1043 AT_CAPTURE_FILE([db])
1044 if test $model = standalone; then
5a0e4aec
BP
1045 dnl We can't fully re-check the contents of the database log, because the
1046 dnl order of the records is not predictable, but there should only be 4 lines
1047 dnl in it now.
1048 AT_CHECK([test `wc -l < db` -eq 4])
1b1d2e6d
BP
1049 fi
1050 dnl Check that the dumped data is the same except for the removed column:
1051 AT_CHECK([ovsdb-client dump unix:db.sock ordinals | uuidfilt], [0], [dnl
53178986
BP
1052ordinals table
1053_uuid number
1054------------------------------------ ------
1055<0> 0
1056<1> 1
1057<2> 2
1058<3> 3
1059<4> 4
1060<5> 5
1061])
1b1d2e6d
BP
1062 dnl Now check that the converted database is still online and can be modified,
1063 dnl then check that the database log has one more record and that the data
1064 dnl is as expected.
1065 AT_CHECK(
1066 [[ovsdb-client transact '
5a0e4aec
BP
1067 ["ordinals",
1068 {"op": "insert",
1069 "table": "ordinals",
1070 "row": {"number": 6}},
1071 {"op": "comment",
1072 "comment": "add row for 6"}]' | uuidfilt]], [0],
1b1d2e6d 1073 [[[{"uuid":["uuid","<0>"]},{}]
53178986 1074]])
1b1d2e6d
BP
1075 if test $model = standalone; then
1076 AT_CHECK([test `wc -l < db` -eq 6])
1077 fi
1078 AT_CHECK([ovsdb-client dump unix:db.sock ordinals | uuidfilt], [0], [dnl
53178986
BP
1079ordinals table
1080_uuid number
1081------------------------------------ ------
1082<0> 0
1083<1> 1
1084<2> 2
1085<3> 3
1086<4> 4
1087<5> 5
1088<6> 6
1089])
1b1d2e6d
BP
1090 dnl Now kill and restart the database server to ensure that the data is
1091 dnl correct on disk as well as in memory.
1092 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
1093 AT_CHECK([[ovsdb-server -vfile -vvlog:off -vconsole:off --detach --no-chdir --pidfile --log-file --remote=punix:db.sock db]],
1094 [0])
1095 AT_CHECK([ovsdb-client dump unix:db.sock ordinals | uuidfilt], [0], [dnl
53178986
BP
1096ordinals table
1097_uuid number
1098------------------------------------ ------
1099<0> 0
1100<1> 1
1101<2> 2
1102<3> 3
1103<4> 4
1104<5> 5
1105<6> 6
1106])
1107
1b1d2e6d
BP
1108 dnl Make sure that "db" is still a symlink to dir/db instead of getting
1109 dnl replaced by a regular file, ditto for .db.~lock~.
1110 if test "$IS_WIN32" = "no"; then
5a0e4aec
BP
1111 AT_CHECK([test -h db])
1112 AT_CHECK([test -h .db.~lock~])
1113 AT_CHECK([test -f dir/db])
1114 AT_CHECK([test -f dir/.db.~lock~])
1b1d2e6d
BP
1115 fi
1116
1117 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
1118}
1119OVS_END_SHELL_HELPERS
1120
1121AT_SETUP([schema conversion online - standalone])
1122AT_KEYWORDS([ovsdb server convert needs-conversion standalone])
1123ovsdb_check_online_conversion standalone
53178986
BP
1124AT_CLEANUP
1125
1b1d2e6d
BP
1126AT_SETUP([schema conversion online - clustered])
1127AT_KEYWORDS([ovsdb server convert needs-conversion cluster])
1128ovsdb_check_online_conversion cluster
1129AT_CLEANUP
1130\f
48f6e410 1131AT_SETUP([ovsdb-server combines updates on backlogged connections])
53eb8cb8 1132on_exit 'kill `cat *.pid`'
48f6e410
BP
1133
1134# The maximum socket receive buffer size is important for this test, which
1135# tests behavior when the receive buffer overflows.
1136if test -e /proc/sys/net/core/rmem_max; then
1137 # Linux
1138 rmem_max=`cat /proc/sys/net/core/rmem_max`
1139elif rmem_max=`sysctl -n net.inet.tcp.recvbuf_max 2>/dev/null`; then
81b9d305 1140 : # FreeBSD, NetBSD
48f6e410
BP
1141else
1142 # Don't know how to get maximum socket receive buffer on this OS
1143 AT_SKIP_IF([:])
1144fi
1145
1146# Calculate the number of iterations we need to queue. Each of the
1147# iterations we execute, by itself, yields a monitor update of about
1148# 25 kB, so fill up that much space plus a few for luck.
f5ca49d8 1149n_iterations=`expr $rmem_max / 25000 + 5`
48f6e410
BP
1150echo rmem_max=$rmem_max n_iterations=$n_iterations
1151
21aa35c3
BP
1152# If there's too much queuing skip the test to avoid timing out.
1153AT_SKIP_IF([test $rmem_max -gt 1048576])
1154
48f6e410
BP
1155# Calculate the exact number of monitor updates expected for $n_iterations,
1156# assuming no updates are combined. The "extra" update is for the initial
1157# contents of the database.
1158n_updates=`expr $n_iterations \* 3 + 1`
1159
1160# Start an ovsdb-server with the vswitchd schema.
1161OVSDB_INIT([db])
1162AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --log-file --remote=punix:db.sock db],
1163 [0], [ignore], [ignore])
1164
1165# Executes a set of transactions that add a bridge with 100 ports, and
1166# then deletes that bridge. This yields three monitor updates that
1167# add up to about 25 kB in size.
1168#
1169# The update also increments a counter held in the database so that we can
1170# verify that the overall effect of the transactions took effect (e.g.
1171# monitor updates at the end weren't just dropped). We add an arbitrary
1172# string to the counter to make grepping for it more reliable.
1173counter=0
1174trigger_big_update () {
1175 counter=`expr $counter + 1`
1176 ovs-vsctl --no-wait -- set open_vswitch . system_version=xyzzy$counter
1177 ovs-vsctl --no-wait -- add-br br0 $add
1178 ovs-vsctl --no-wait -- del-br br0
1179}
1180add_ports () {
1181 for j in `seq 1 100`; do
1182 printf " -- add-port br0 p%d" $j
1183 done
1184}
1185add=`add_ports`
1186
1187AT_CAPTURE_FILE([ovsdb-client.err])
c005fd61
AZ
1188AT_CAPTURE_FILE([ovsdb-client-nonblock.err])
1189
1190
1191# Start an ovsdb-client monitoring all changes to the database,
1192# By default, it is non-blocking, and will get update message
1193# for each ovsdb-server transaactions.
1194AT_CHECK([ovsdb-client --detach --no-chdir --pidfile=nonblock.pid monitor ALL >ovsdb-client-nonblock.out 2>ovsdb-client-nonblock.err])
48f6e410
BP
1195
1196# Start an ovsdb-client monitoring all changes to the database,
1197# make it block to force the buffers to fill up, and then execute
1198# enough iterations that ovsdb-server starts combining updates.
1199AT_CHECK([ovsdb-client --detach --no-chdir --pidfile monitor ALL >ovsdb-client.out 2>ovsdb-client.err])
1200AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/block])
1201for i in `seq 1 $n_iterations`; do
1202 echo "blocked update ($i of $n_iterations)"
1203 trigger_big_update $i
1204done
1205AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/unblock])
29004db2
IM
1206OVS_WAIT_UNTIL([grep "xyzzy$counter" ovsdb-client.out])
1207OVS_WAIT_UNTIL([grep "xyzzy$counter" ovsdb-client-nonblock.out])
d9c8c57c 1208OVS_APP_EXIT_AND_WAIT([ovsdb-client])
c005fd61 1209AT_CHECK([kill `cat nonblock.pid`])
48f6e410
BP
1210
1211# Count the number of updates in the ovsdb-client output, by counting
1212# the number of changes to the Open_vSwitch table. (All of our
1213# transactions modify the Open_vSwitch table.) It should be less than
1214# $n_updates updates.
1215#
1216# Check that the counter is what we expect.
1217logged_updates=`grep -c '^Open_vSwitch' ovsdb-client.out`
c005fd61
AZ
1218logged_nonblock_updates=`grep -c '^Open_vSwitch' ovsdb-client-nonblock.out`
1219echo "logged_nonblock_updates=$logged_nonblock_updates (expected less or equal to $n_updates)"
1220echo "logged_updates=$logged_updates (expected less than $logged_nonblock_updates)"
1221AT_CHECK([test $logged_nonblock_updates -le $n_updates])
1222AT_CHECK([test $logged_updates -lt $logged_nonblock_updates])
48f6e410 1223AT_CHECK_UNQUOTED([ovs-vsctl get open_vswitch . system_version], [0],
29004db2 1224 [xyzzy$counter
48f6e410 1225])
d9c8c57c 1226OVS_APP_EXIT_AND_WAIT([ovsdb-server])
48f6e410 1227AT_CLEANUP
80d326ad 1228\f
e731d71b 1229AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv4 sockets)])
80d326ad
BP
1230
1231# OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
1232#
1233# Creates a database with the given SCHEMA, starts an ovsdb-server on
1234# that database, and runs each of the TRANSACTIONS (which should be a
1235# quoted list of quoted strings) against it with ovsdb-client one at a
1236# time.
1237#
1238# Checks that the overall output is OUTPUT, but UUIDs in the output
1239# are replaced by markers of the form <N> where N is a number. The
1240# first unique UUID is replaced by <0>, the next by <1>, and so on.
1241# If a given UUID appears more than once it is always replaced by the
1242# same marker.
1243#
1244# TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
1245m4_define([OVSDB_CHECK_EXECUTION],
1246 [AT_SETUP([$1])
1247 AT_KEYWORDS([ovsdb server positive ssl $5])
1248 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
39ab07af 1249 $2 > schema
15b619e2 1250 PKIDIR=$abs_top_builddir/tests
7c126fbb 1251 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
56120500 1252 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])
fb28ef2d 1253 PARSE_LISTENING_PORT([ovsdb-server.log], [SSL_PORT])
80d326ad 1254 m4_foreach([txn], [$3],
7c126fbb 1255 [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],
80d326ad
BP
1256 [test ! -e pid || kill `cat pid`])
1257cat stdout >> output
1258])
c724bd67 1259 AT_CHECK([uuidfilt output], [0], [$4], [ignore],
80d326ad 1260 [test ! -e pid || kill `cat pid`])
028cbd99 1261 OVSDB_SERVER_SHUTDOWN
80d326ad
BP
1262 AT_CLEANUP])
1263
e879d33e
MM
1264EXECUTION_EXAMPLES
1265
e731d71b
AS
1266AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv6 sockets)])
1267
1268# OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
1269#
1270# Creates a database with the given SCHEMA, starts an ovsdb-server on
1271# that database, and runs each of the TRANSACTIONS (which should be a
1272# quoted list of quoted strings) against it with ovsdb-client one at a
1273# time.
1274#
1275# Checks that the overall output is OUTPUT, but UUIDs in the output
1276# are replaced by markers of the form <N> where N is a number. The
1277# first unique UUID is replaced by <0>, the next by <1>, and so on.
1278# If a given UUID appears more than once it is always replaced by the
1279# same marker.
1280#
1281# TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
1282m4_define([OVSDB_CHECK_EXECUTION],
1283 [AT_SETUP([$1])
1284 AT_KEYWORDS([ovsdb server positive ssl6 $5])
1285 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
4819b3a5 1286 AT_SKIP_IF([test $HAVE_IPV6 = no])
e731d71b
AS
1287 $2 > schema
1288 PKIDIR=$abs_top_builddir/tests
1289 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
56120500 1290 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])
fb28ef2d 1291 PARSE_LISTENING_PORT([ovsdb-server.log], [SSL_PORT])
e731d71b
AS
1292 m4_foreach([txn], [$3],
1293 [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],
1294 [test ! -e pid || kill `cat pid`])
1295cat stdout >> output
1296])
c724bd67 1297 AT_CHECK([uuidfilt output], [0], [$4], [ignore],
e731d71b
AS
1298 [test ! -e pid || kill `cat pid`])
1299 OVSDB_SERVER_SHUTDOWN
1300 AT_CLEANUP])
1301
1302ONE_EXECUTION_EXAMPLE
1303
1304AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv4 sockets)])
e879d33e 1305
e879d33e
MM
1306# OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
1307#
1308# Creates a database with the given SCHEMA, starts an ovsdb-server on
1309# that database, and runs each of the TRANSACTIONS (which should be a
1310# quoted list of quoted strings) against it with ovsdb-client one at a
1311# time.
1312#
1313# Checks that the overall output is OUTPUT, but UUIDs in the output
1314# are replaced by markers of the form <N> where N is a number. The
1315# first unique UUID is replaced by <0>, the next by <1>, and so on.
1316# If a given UUID appears more than once it is always replaced by the
1317# same marker.
1318#
1319# TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
1320m4_define([OVSDB_CHECK_EXECUTION],
1321 [AT_SETUP([$1])
1322 AT_KEYWORDS([ovsdb server positive tcp $5])
1323 $2 > schema
e879d33e
MM
1324 PKIDIR=$abs_top_builddir/tests
1325 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
56120500 1326 AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile --remote=ptcp:0:127.0.0.1 db], [0], [ignore], [ignore])
fb28ef2d 1327 PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
e879d33e
MM
1328 m4_foreach([txn], [$3],
1329 [AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT 'txn'], [0], [stdout], [ignore],
1330 [test ! -e pid || kill `cat pid`])
1331cat stdout >> output
1332])
c724bd67 1333 AT_CHECK([uuidfilt output], [0], [$4], [ignore],
e879d33e
MM
1334 [test ! -e pid || kill `cat pid`])
1335 OVSDB_SERVER_SHUTDOWN
1336 AT_CLEANUP])
1337
80d326ad 1338EXECUTION_EXAMPLES
e731d71b 1339
7daaec4e
BP
1340AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv6 sockets)])
1341
e731d71b
AS
1342# OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
1343#
1344# Creates a database with the given SCHEMA, starts an ovsdb-server on
1345# that database, and runs each of the TRANSACTIONS (which should be a
1346# quoted list of quoted strings) against it with ovsdb-client one at a
1347# time.
1348#
1349# Checks that the overall output is OUTPUT, but UUIDs in the output
1350# are replaced by markers of the form <N> where N is a number. The
1351# first unique UUID is replaced by <0>, the next by <1>, and so on.
1352# If a given UUID appears more than once it is always replaced by the
1353# same marker.
1354#
1355# TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
1356m4_define([OVSDB_CHECK_EXECUTION],
1357 [AT_SETUP([$1])
1358 AT_KEYWORDS([ovsdb server positive tcp6 $5])
4819b3a5 1359 AT_SKIP_IF([test $HAVE_IPV6 = no])
e731d71b
AS
1360 $2 > schema
1361 PKIDIR=$abs_top_builddir/tests
1362 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
56120500 1363 AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile --remote=ptcp:0:[[::1]] db], [0], [ignore], [ignore])
fb28ef2d 1364 PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
e731d71b
AS
1365 m4_foreach([txn], [$3],
1366 [AT_CHECK([ovsdb-client transact tcp:[[::1]]:$TCP_PORT 'txn'], [0], [stdout], [ignore],
1367 [test ! -e pid || kill `cat pid`])
1368cat stdout >> output
1369])
c724bd67 1370 AT_CHECK([uuidfilt output], [0], [$4], [ignore],
e731d71b
AS
1371 [test ! -e pid || kill `cat pid`])
1372 OVSDB_SERVER_SHUTDOWN
1373 AT_CLEANUP])
1374
1375ONE_EXECUTION_EXAMPLE
9ff373db
BP
1376\f
1377AT_BANNER([OVSDB -- transactions on transient ovsdb-server])
1378
1379# OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
1380#
1381# Creates a database with the given SCHEMA and runs each of the
1382# TRANSACTIONS (which should be a quoted list of quoted strings)
1383# against it with ovsdb-client one at a time. Each ovsdb-client
1384# is run against a separately started ovsdb-server that executes
1385# only that single transaction. (The idea is that this should
1386# help to ferret out any differences between what ovsdb-server has
1387# in memory and what actually gets committed to disk.)
1388#
1389# Checks that the overall output is OUTPUT, but UUIDs in the output
1390# are replaced by markers of the form <N> where N is a number. The
1391# first unique UUID is replaced by <0>, the next by <1>, and so on.
1392# If a given UUID appears more than once it is always replaced by the
1393# same marker.
1394#
1395# TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
1396m4_define([OVSDB_CHECK_EXECUTION],
1397 [AT_SETUP([$1])
c17b52e8 1398 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
9ff373db 1399 AT_KEYWORDS([ovsdb server positive transient $5])
39ab07af 1400 $2 > schema
9ff373db
BP
1401 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
1402 m4_foreach([txn], [$3],
1403 [AT_DATA([txnfile], [ovsdb-client transact unix:socket 'txn'
1404])
56120500 1405 AT_CHECK([ovsdb-server --remote=punix:socket db --run="sh txnfile"], [0], [stdout], [ignore])
9ff373db
BP
1406 cat stdout >> output
1407])
c724bd67 1408 AT_CHECK([uuidfilt output], [0], [$4], [ignore])
9ff373db
BP
1409 AT_CLEANUP])
1410
1411EXECUTION_EXAMPLES
ae671c5f 1412\f
63b35ecc 1413AT_BANNER([OVSDB -- ovsdb-server replication])
ae671c5f
MC
1414
1415# OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
1416#
1417# Creates two databases with the given SCHEMA, and starts an ovsdb-server on
1418# each database.
1419# Runs each of the TRANSACTIONS (which should be a quoted list of
1420# quoted strings) against one of the servers with ovsdb-client one at a
1421# time. The server replicates its database to the other ovsdb-server.
1422#
1423# Checks that the dump of both databases are the same.
1424#
1425# TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
1426m4_define([OVSDB_CHECK_EXECUTION],
1427 [AT_SETUP([$1])
1428 AT_KEYWORDS([ovsdb server tcp replication $5])
1429 $2 > schema
1430 AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1431 AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1432
56120500 1433 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile --remote=punix:db.sock db1], [0], [ignore], [ignore])
5dd81c22
AZ
1434 i
1435 on_exit 'test ! -e pid || kill `cat pid`'
ae671c5f 1436
56120500 1437 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])
5dd81c22 1438 on_exit 'test ! -e pid2 || kill `cat pid2`'
ae671c5f
MC
1439
1440 m4_foreach([txn], [$3],
5dd81c22 1441 [AT_CHECK([ovsdb-client transact 'txn'], [0], [stdout], [ignore])
ae671c5f
MC
1442 ])
1443
5dd81c22
AZ
1444 AT_CHECK([ovsdb-client dump], [0], [stdout], [ignore])
1445 OVS_WAIT_UNTIL([ ovsdb-client dump unix:db2.sock > dump2; diff stdout dump2])
ae671c5f 1446
ae671c5f
MC
1447 OVSDB_SERVER_SHUTDOWN
1448 OVSDB_SERVER_SHUTDOWN2
1449 AT_CLEANUP])
1450
1451EXECUTION_EXAMPLES
7a9d65d2 1452
63b35ecc 1453AT_BANNER([OVSDB -- ovsdb-server replication table-exclusion])
7a9d65d2
MC
1454
1455# OVSDB_CHECK_REPLICATION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
1456#
1457# Creates two databases with the given SCHEMA, and starts an
1458# ovsdb-server on each database.
1459# Runs each of the TRANSACTIONS (which should be a quoted list of
1460# quoted strings) against one of the servers with ovsdb-client one at a
1461# time. The server replicates its database to the other ovsdb-server.
1462#
1463# Checks that the difference between the dump of the databases is
1464# OUTPUT, but UUIDs in the output are replaced by markers of the form
1465# <N> where N is a number. The first unique UUID is replaced by <0>,
1466# the next by <1>, and so on.
1467# If a given UUID appears more than once it is always replaced by the
1468# same marker.
1469#
1470# TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
1471m4_define([OVSDB_CHECK_REPLICATION],
1472 [AT_SETUP([$1])
1473 AT_KEYWORDS([ovsdb server tcp replication table-exclusion])
baee3741 1474 AT_SKIP_IF([test $DIFF_SUPPORTS_NORMAL_FORMAT = no])
7a9d65d2
MC
1475 $2 > schema
1476 AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1477 AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1478
56120500 1479 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile --remote=punix:db.sock db1], [0], [ignore], [ignore])
5dd81c22 1480 on_exit 'test ! -e pid || kill `cat pid`'
7a9d65d2 1481
56120500 1482 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])
5dd81c22 1483 on_exit 'test ! -e pid2 || kill `cat pid2`'
7a9d65d2
MC
1484
1485 m4_foreach([txn], [$3],
5dd81c22 1486 [AT_CHECK([ ovsdb-client transact 'txn' ], [0], [stdout], [ignore])
7a9d65d2
MC
1487 ])
1488
5dd81c22
AZ
1489 AT_CHECK([ovsdb-client dump], [0], [stdout], [ignore])
1490 cat stdout > dump1
7a9d65d2 1491
5dd81c22
AZ
1492 OVS_WAIT_UNTIL([ ovsdb-client dump unix:db2.sock | grep one ])
1493 AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore])
1494 cat stdout > dump2
7a9d65d2 1495
5dd81c22
AZ
1496 AT_CHECK([diff dump1 dump2], [1], [stdout], [ignore])
1497 cat stdout > output
1498
c724bd67 1499 AT_CHECK([uuidfilt output], [0], [$4], [ignore])
7a9d65d2
MC
1500
1501 OVSDB_SERVER_SHUTDOWN
1502 OVSDB_SERVER_SHUTDOWN2
1503 AT_CLEANUP])
1504
1505REPLICATION_EXAMPLES
9dc05cdc
MC
1506
1507AT_BANNER([OVSDB -- ovsdb-server replication runtime management commands])
1508
f53d7518
AZ
1509#ovsdb-server/get-active-ovsdb-server command
1510AT_SETUP([ovsdb-server/get-active-ovsdb-server])
1511AT_KEYWORDS([ovsdb server replication get-active])
9dc05cdc
MC
1512ordinal_schema > schema
1513AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
1514on_exit 'kill `cat *.pid`'
1515AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --sync-from=tcp:127.0.0.1:9999 db])
1516
f53d7518 1517AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/get-active-ovsdb-server],
9dc05cdc
MC
1518 [0], [tcp:127.0.0.1:9999
1519])
1520AT_CLEANUP
1521
f53d7518
AZ
1522#*ovsdb-server/set-active-ovsdb-server command
1523AT_SETUP([ovsdb-server/set-active-ovsdb-server])
1524AT_KEYWORDS([ovsdb server replication set-active])
9dc05cdc
MC
1525ordinal_schema > schema
1526AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
1527on_exit 'kill `cat *.pid`'
1528AT_CHECK([ovsdb-server --detach --no-chdir --pidfile db])
1529
f53d7518
AZ
1530AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/set-active-ovsdb-server tcp:127.0.0.1:9999])
1531AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/get-active-ovsdb-server],
9dc05cdc
MC
1532 [0], [tcp:127.0.0.1:9999
1533])
1534AT_CLEANUP
1535
60e0cd04
AZ
1536#ovsdb-server/get-sync-exclude-tables command
1537AT_SETUP([ovsdb-server/get-sync-exclude-tables])
1538AT_KEYWORDS([ovsdb server replication get-exclude-tables])
9dc05cdc
MC
1539ordinal_schema > schema
1540AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
1541on_exit 'kill `cat *.pid`'
1542AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --sync-exclude-tables=mydb:db1,mydb:db2 db])
1543
60e0cd04 1544AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/get-sync-exclude-tables],
3109b4e1 1545 [0], [mydb:db1,mydb:db2
9dc05cdc
MC
1546])
1547AT_CLEANUP
1548
60e0cd04
AZ
1549#ovsdb-server/set-sync-exclude-tables command
1550AT_SETUP([ovsdb-server/set-sync-exclude-tables])
1551AT_KEYWORDS([ovsdb server replication set-exclude-tables])
baee3741
BP
1552AT_SKIP_IF([test $DIFF_SUPPORTS_NORMAL_FORMAT = no])
1553
9dc05cdc
MC
1554replication_schema > schema
1555AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1556AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1557
56120500 1558AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile --remote=punix:db.sock db1], [0], [ignore], [ignore])
5dd81c22 1559on_exit 'test ! -e pid || kill `cat pid`'
9dc05cdc 1560
56120500 1561AT_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])
5dd81c22 1562on_exit 'test ! -e pid2 || kill `cat pid2`'
9dc05cdc 1563
60e0cd04 1564AT_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`])
9dc05cdc 1565
63b35ecc 1566AT_CHECK([ovsdb-client transact unix:db.sock \
9dc05cdc
MC
1567 '[["mydb",
1568 {"op": "insert",
1569 "table": "a",
1570 "row": {"number": 0, "name": "zero"}},
1571 {"op": "insert",
1572 "table": "b",
1573 "row": {"number": 1, "name": "one"}}]]'], [0], [stdout], [ignore],
1574 [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
9dc05cdc 1575
63b35ecc 1576AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout], [ignore],
9dc05cdc 1577 [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
5dd81c22
AZ
1578cat stdout > dump1
1579OVS_WAIT_UNTIL([ ovsdb-client dump unix:db2.sock | grep zero ])
1580AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore])
1581cat stdout > dump2
9dc05cdc 1582
5dd81c22
AZ
1583AT_CHECK([diff dump1 dump2], [1], [stdout], [ignore])
1584cat stdout > output
9dc05cdc 1585
c724bd67 1586AT_CHECK([uuidfilt output], [0], [7,9c7,8
9dc05cdc
MC
1587< _uuid name number
1588< ------------------------------------ ---- ------
e51d0a1d 1589< <0> one 1
9dc05cdc
MC
1590---
1591> _uuid name number
1592> ----- ---- ------
5dd81c22 1593])
9dc05cdc
MC
1594
1595OVSDB_SERVER_SHUTDOWN
1596OVSDB_SERVER_SHUTDOWN2
1597AT_CLEANUP
1598
f53d7518
AZ
1599#ovsdb-server/connect-active-ovsdb-server
1600AT_SETUP([ovsdb-server/connect-active-server])
1601AT_KEYWORDS([ovsdb server replication connect-active-server])
9dc05cdc
MC
1602replication_schema > schema
1603AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1604AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1605
56120500 1606AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile --remote=punix:db.sock db1], [0], [ignore], [ignore])
5dd81c22 1607on_exit 'test ! -e pid || kill `cat pid`'
9dc05cdc 1608
56120500 1609AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server2.log --pidfile=pid2 --remote=punix:db2.sock --unixctl=unixctl2 db2], [0], [ignore], [ignore])
5dd81c22 1610on_exit 'test ! -e pid2 || kill `cat pid2`'
9dc05cdc 1611
60e0cd04
AZ
1612dnl Try to connect without specifying the active server.
1613AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/connect-active-ovsdb-server], [0],
1614[Unable to connect: active server is not specified.
1615], [ignore])
1616
5dd81c22 1617AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/set-active-ovsdb-server unix:db.sock], [0], [stdout], [ignore])
9dc05cdc 1618
5dd81c22 1619AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/connect-active-ovsdb-server], [0], [stdout], [ignore])
9dc05cdc 1620
63b35ecc 1621AT_CHECK([ovsdb-client transact unix:db.sock \
9dc05cdc
MC
1622 '[["mydb",
1623 {"op": "insert",
1624 "table": "a",
5dd81c22 1625 "row": {"number": 0, "name": "zero"}}]]'], [0], [stdout], [ignore])
9dc05cdc 1626
5dd81c22
AZ
1627AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout], [ignore])
1628cat stdout > dump1
1629OVS_WAIT_UNTIL([ ovsdb-client dump unix:db2.sock | grep zero ])
1630AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore])
1631cat stdout > dump2
9dc05cdc 1632
5dd81c22 1633AT_CHECK([diff dump1 dump2], [0], [], [ignore])
9dc05cdc
MC
1634OVSDB_SERVER_SHUTDOWN
1635OVSDB_SERVER_SHUTDOWN2
1636AT_CLEANUP
1637
f53d7518
AZ
1638#ovsdb-server/disconnect-active-server command
1639AT_SETUP([ovsdb-server/disconnect-active-server])
1640AT_KEYWORDS([ovsdb server replication disconnect-active-server])
baee3741
BP
1641AT_SKIP_IF([test $DIFF_SUPPORTS_NORMAL_FORMAT = no])
1642
9dc05cdc
MC
1643replication_schema > schema
1644AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1645AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1646
56120500 1647AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile --remote=punix:db.sock db1], [0], [ignore], [ignore])
5dd81c22 1648on_exit 'test ! -e pid || kill `cat pid`'
9dc05cdc 1649
56120500 1650AT_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])
5dd81c22 1651on_exit 'test ! -e pid2 || kill `cat pid2`'
9dc05cdc 1652
63b35ecc 1653AT_CHECK([ovsdb-client transact unix:db.sock \
9dc05cdc
MC
1654'[["mydb",
1655 {"op": "insert",
1656 "table": "a",
5dd81c22 1657 "row": {"number": 0, "name": "zero"}}]]'], [0], [stdout], [ignore])
f7525086 1658
e51879e9
AZ
1659dnl Make sure the transaction shows up in db2. This also tests the back up server
1660dnl can be read.
63b35ecc 1661OVS_WAIT_UNTIL([ovsdb-client dump unix:db2.sock | grep zero])
9dc05cdc 1662
e51879e9
AZ
1663dnl The backup server does not accept any write transaction
1664AT_CHECK([ovsdb-client transact unix:db2.sock \
1665'[["mydb",
1666 {"op": "insert",
1667 "table": "b",
1668 "row": {"number": 1, "name": "one"}}]]'], [0],
1669 [[[{"details":"insert operation not allowed when database server is in read only mode","error":"not allowed"}]]
1670])
1671
5dd81c22 1672AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/disconnect-active-ovsdb-server], [0], [ignore], [ignore])
9dc05cdc 1673
63b35ecc 1674AT_CHECK([ovsdb-client transact unix:db.sock \
9dc05cdc
MC
1675'[["mydb",
1676 {"op": "insert",
1677 "table": "b",
5dd81c22 1678 "row": {"number": 1, "name": "one"}}]]'], [0], [stdout], [ignore])
9dc05cdc 1679
5dd81c22
AZ
1680AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout], [ignore])
1681cat stdout > dump1
9dc05cdc 1682
5dd81c22
AZ
1683sleep 1
1684AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore])
1685cat stdout > dump2
9dc05cdc 1686
5dd81c22
AZ
1687AT_CHECK([diff dump1 dump2], [1], [stdout], [ignore])
1688cat stdout > output
9dc05cdc 1689
c724bd67 1690AT_CHECK([uuidfilt output], [0], [7,9c7,8
9dc05cdc
MC
1691< _uuid name number
1692< ------------------------------------ ---- ------
e51d0a1d 1693< <0> one 1
9dc05cdc
MC
1694---
1695> _uuid name number
1696> ----- ---- ------
1697], [ignore], [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1698
e51879e9
AZ
1699dnl The backup server now become active, and can accept write transactions.
1700AT_CHECK([ovsdb-client transact unix:db2.sock \
1701'[["mydb",
1702 {"op": "insert",
1703 "table": "b",
5dd81c22 1704 "row": {"number": 1, "name": "one"}}]]'], [0], [stdout], [ignore])
e51879e9
AZ
1705
1706AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout])
1707cat stdout > output
1708
c724bd67 1709AT_CHECK([uuidfilt output], [0], [a table
e51879e9
AZ
1710_uuid name number
1711------------------------------------ ---- ------
e51d0a1d 1712<0> zero 0
e51879e9
AZ
1713
1714b table
1715_uuid name number
1716------------------------------------ ---- ------
e51d0a1d 1717<1> one 1
e51879e9
AZ
1718])
1719
9dc05cdc
MC
1720OVSDB_SERVER_SHUTDOWN
1721OVSDB_SERVER_SHUTDOWN2
1722AT_CLEANUP
60e0cd04
AZ
1723
1724#ovsdb-server/active-backup-role-switching
1725AT_SETUP([ovsdb-server/active-backup-role-switching])
1726AT_KEYWORDS([ovsdb server replication active-backup-switching])
1727replication_schema > schema
1728AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1729AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1730
1731dnl Add some data to both DBs
1732AT_CHECK([ovsdb-tool transact db1 \
1733'[["mydb",
1734 {"op": "insert",
1735 "table": "a",
1736 "row": {"number": 9, "name": "nine"}}]]'], [0], [ignore], [ignore])
1737
1738AT_CHECK([ovsdb-tool transact db2 \
1739'[["mydb",
1740 {"op": "insert",
1741 "table": "a",
1742 "row": {"number": 9, "name": "nine"}}]]'], [0], [ignore], [ignore])
1743
1744dnl Start both 'db1' and 'db2' in backup mode. Let them backup from each
1745dnl other. This is not an supported operation state, but to simulate a start
1746dnl up condition where an HA manger can select which one to be an active
1747dnl server soon after.
1748AT_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])
1749on_exit 'test ! -e pid || kill `cat pid`'
1750
1751AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/connect-active-ovsdb-server])
1752
1753AT_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])
1754on_exit 'test ! -e pid2 || kill `cat pid2`'
1755
1756dnl
1757dnl make sure both servers reached the replication state
1758OVS_WAIT_UNTIL([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/sync-status |grep replicating])
1759OVS_WAIT_UNTIL([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/sync-status |grep replicating])
1760
1761dnl Switch the 'db1' to active
1762AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/disconnect-active-ovsdb-server])
1763AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/sync-status], [0], [state: active
1764])
1765
1766dnl Issue a transaction to 'db1'
1767AT_CHECK([ovsdb-client transact unix:db.sock \
1768'[["mydb",
1769 {"op": "insert",
1770 "table": "a",
1771 "row": {"number": 0, "name": "zero"}}]]'], [0], [ignore])
1772
1773dnl It should be replicated to 'db2'
1774OVS_WAIT_UNTIL([ovsdb-client dump unix:db2.sock | grep zero])
1775
1776dnl Flip the role of 'db1' and 'db2'. 'db1' becomes backup, and db2 becomes active
1777AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/disconnect-active-ovsdb-server])
1778AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/connect-active-ovsdb-server])
1779
1780dnl Verify the change happend
1781OVS_WAIT_UNTIL([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/sync-status |grep replicating])
1782AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/sync-status], [0], [state: active
1783])
1784
1785dnl Issue an transaction to 'db2' which is now active.
1786AT_CHECK([ovsdb-client transact unix:db2.sock \
1787'[["mydb",
1788 {"op": "insert",
1789 "table": "b",
1790 "row": {"number": 1, "name": "one"}}]]'], [0], [ignore])
1791
1792dnl The transaction should be replicated to 'db1'
1793OVS_WAIT_UNTIL([ovsdb-client dump unix:db.sock | grep one])
1794
1795dnl Both servers should have the same content.
1796AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout])
1797cat stdout > dump1
1798
1799AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout])
1800cat stdout > dump2
1801
1802AT_CHECK([diff dump1 dump2])
1803
1804dnl OVSDB_SERVER_SHUTDOWN
1805dnl OVSDB_SERVER_SHUTDOWN2
1806AT_CLEANUP
9c1a1182 1807
05ac209a
AZ
1808#ovsdb-server prevent self replicating
1809AT_SETUP([ovsdb-server prevent self replicating])
1810AT_KEYWORDS([ovsdb server replication])
1811replication_schema > schema
1812AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
1813
1814dnl Add some data to both DBs
1815AT_CHECK([ovsdb-tool transact db \
1816'[["mydb",
1817 {"op": "insert",
1818 "table": "a",
1819 "row": {"number": 9, "name": "nine"}}]]'], [0], [ignore], [ignore])
1820
1821dnl Start 'db', then try to be a back up server of itself.
1822AT_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])
1823on_exit 'test ! -e pid || kill `cat pid`'
1824
1825dnl Save the current content
1826AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout])
1827cp stdout dump1
1828
1829AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/connect-active-ovsdb-server])
1830dnl Check that self replicating is blocked.
1831AT_CHECK([grep "Self replicating is not allowed" ovsdb-server.log], [0], [stdout])
1832
1833dnl Check current DB content is preserved.
1834AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout])
1835cat stdout > dump2
1836
1837AT_CHECK([diff dump1 dump2])
1838AT_CLEANUP
1839
9c1a1182
LR
1840AT_SETUP([ovsdb-server/read-only db:ptcp connection])
1841AT_KEYWORDS([ovsdb server read-only])
1842AT_DATA([schema],
1843 [[{"name": "mydb",
1844 "tables": {
1845 "Root": {
1846 "columns": {
1847 "managers": {
1848 "type": {
1849 "key": {"type": "uuid", "refTable": "Manager"},
1850 "min": 0,
1851 "max": "unlimited"}}}},
1852 "Manager": {
1853 "columns": {
1854 "target": {
1855 "type": "string"},
1856 "read_only": {
1857 "type": {
1858 "key": "boolean",
1859 "min": 0,
1860 "max": 1}},
1861 "is_connected": {
1862 "type": {
1863 "key": "boolean",
1864 "min": 0,
1865 "max": 1}}}},
1866 "ordinals": {
1867 "columns": {
1868 "number": {"type": "integer"},
1869 "name": {"type": "string"}},
1870 "indexes": [["number"]]}
1871 },
1872 "version": "5.1.3",
1873 "cksum": "12345678 9"
1874}
1875]])
1876AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
1877AT_CHECK(
1878 [[ovsdb-tool transact db \
1879 '["mydb",
1880 {"op": "insert",
1881 "table": "Root",
1882 "row": {
1883 "managers": ["set", [["named-uuid", "x"]]]}},
1884 {"op": "insert",
1885 "table": "Manager",
1886 "uuid-name": "x",
1887 "row": {"target": "ptcp:0:127.0.0.1",
1888 "read_only": true}}]']], [0], [ignore], [ignore])
1889
1890AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile --remote=db:mydb,Root,managers db], [0], [ignore], [ignore])
1891PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
1892AT_CHECK([ovsdb-client get-schema-version tcp:127.0.0.1:$TCP_PORT mydb], [0], [5.1.3
1893])
1894
1895AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT \
1896 ['["mydb",
1897 {"op": "insert",
1898 "table": "ordinals",
1899 "row": {"name": "two", "number": '2'}}
1900 ]']], [0], [stdout], [ignore])
1901cat stdout >> output
c724bd67 1902AT_CHECK([uuidfilt output], [0], [[[{"details":"insert operation not allowed when database server is in read only mode","error":"not allowed"}]]
9c1a1182
LR
1903], [ignore])
1904OVSDB_SERVER_SHUTDOWN
1905AT_CLEANUP
cec7005b
NS
1906
1907AT_SETUP([ovsdb-server replication with schema mismatch])
1908AT_KEYWORDS([ovsdb server replication])
1909replication_schema > subset_schema
1910replication_schema_v2 > superset_schema
1911
1912AT_CHECK([ovsdb-tool create db1 subset_schema], [0], [stdout], [ignore])
1913AT_CHECK([ovsdb-tool create db2 superset_schema], [0], [stdout], [ignore])
1914
1915dnl Add some data to both DBs
1916AT_CHECK([ovsdb-tool transact db1 \
1917'[["mydb",
1918 {"op": "insert",
1919 "table": "a",
1920 "row": {"number": 9, "name": "nine"}}]]'], [0], [ignore], [ignore])
1921
1922AT_CHECK([ovsdb-tool transact db2 \
1923'[["mydb",
1924 {"op": "insert",
1925 "table": "a",
1926 "row": {"number": 10, "name": "ten"}}]]'], [0], [ignore], [ignore])
1927
1928dnl Start both 'db1' and 'db2'.
1929AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile="`pwd`"/pid --remote=punix:db.sock --unixctl="`pwd`"/unixctl db1 --active ], [0], [ignore], [ignore])
1930on_exit 'test ! -e pid || kill `cat pid`'
1931
1932
1933AT_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])
1934on_exit 'test ! -e pid2 || kill `cat pid2`'
1935
1936OVS_WAIT_UNTIL([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/sync-status |grep active])
1937OVS_WAIT_UNTIL([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/sync-status |grep active])
1938
1939AT_CHECK([ovsdb-client dump unix:db.sock a number name], 0, [dnl
1940a table
1941name number
1942---- ------
1943nine 9
1944])
1945
1946AT_CHECK([ovsdb-client dump unix:db2.sock a number name], 0, [dnl
1947a table
1948name number
1949---- ------
1950ten 10
1951])
1952
1953# Replicate db1 from db2. It should fail since db2 schema
1954# doesn't match with db1 and has additional tables/columns.
1955AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/set-active-ovsdb-server unix:db2.sock])
1956AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/connect-active-ovsdb-server])
1957
1958OVS_WAIT_UNTIL(
1959 [test 1 = `cat ovsdb-server1.log | grep "Schema version mismatch, checking if mydb can still be replicated or not" | wc -l]`
1960)
1961
1962OVS_WAIT_UNTIL(
1963 [test 1 = `cat ovsdb-server1.log | grep "mydb cannot be replicated" | wc -l]`
1964)
1965
1966OVS_WAIT_UNTIL([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/sync-status |grep active])
1967
1968# Replicate db2 from db1. This should be successful.
1969AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/disconnect-active-ovsdb-server])
1970AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/set-active-ovsdb-server unix:db.sock])
1971AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/connect-active-ovsdb-server])
1972
1973OVS_WAIT_UNTIL(
1974 [test 1 = `cat ovsdb-server2.log | grep "Schema version mismatch, checking if mydb can still be replicated or not" | wc -l]`
1975)
1976
1977OVS_WAIT_UNTIL(
1978 [test 1 = `cat ovsdb-server2.log | grep "mydb can be replicated" | wc -l]`
1979)
1980
1981OVS_WAIT_UNTIL([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/sync-status |grep replicating])
1982
1983AT_CHECK([ovsdb-client dump unix:db.sock a number name], 0, [dnl
1984a table
1985name number
1986---- ------
1987nine 9
1988])
1989
1990AT_CHECK([ovsdb-client dump unix:db2.sock a number name], 0, [dnl
1991a table
1992name number
1993---- ------
1994nine 9
1995])
1996
1997AT_CHECK([ovsdb-client transact unix:db.sock \
1998'[["mydb",
1999 {"op": "insert",
2000 "table": "a",
2001 "row": {"number": 6, "name": "six"}}]]'], [0], [ignore], [ignore])
2002
2003OVS_WAIT_UNTIL([test 1 = `ovsdb-client dump unix:db2.sock a number name | grep six | wc -l`])
2004
2005AT_CHECK([
2006 ovsdb-client dump unix:db2.sock a number name], 0, [dnl
2007a table
2008name number
2009---- ------
2010nine 9
2011six 6
2012])
2013
2014AT_CLEANUP