]> git.proxmox.com Git - ovs.git/blame - tests/ovsdb-server.at
Fix ovs-dpctl-top by removing 3 wrong hunks in py3-compat.patch.
[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 717 dnl Check that all the crap is in fact in the database log.
2ccd66f5
IM
718 AT_CHECK([[uuidfilt db | grep -v ^OVSDB | \
719 sed 's/"_date":[0-9]*/"_date":0/' | sed 's/"_is_diff":true,//' | \
720 ovstest test-json --multiple -]], [0],
1b1d2e6d 721[[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"}
62c87d4a
BP
722{"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
723{"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
724{"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
725{"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
726{"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
727{"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
728{"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
729{"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
730{"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
731{"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
732{"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
733{"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
734{"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
735{"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
736{"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
737{"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
738{"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
739{"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
1b1d2e6d
BP
740]])
741 else
742 dnl Check that at least there's a lot of transactions.
5a0e4aec 743 AT_CHECK([test `wc -l < db` -gt 50])
1b1d2e6d
BP
744 fi
745 dnl Dump out and check the actual database contents.
746 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout])
747 AT_CHECK([uuidfilt stdout], [0], [dnl
370a11b9
BP
748ordinals table
749_uuid name number
ada496b5 750------------------------------------ ----- ------
e51d0a1d
BP
751<0> five 5
752<1> four 4
753<2> one 1
754<3> three 3
755<4> two 2
756<5> zero 0
1b1d2e6d
BP
757])
758 cp db db.pre-compaction
759 dnl Now compact the database in-place.
760 AT_CHECK([[ovs-appctl -t ovsdb-server ovsdb-server/compact]],
761 [0], [], [ignore])
762 dnl Negative test.
763 AT_CHECK([[ovs-appctl -t ovsdb-server ovsdb-server/compact _Server]],
764 [2], [], [cannot compact built-in databases
bc7bcc40
BP
765ovs-appctl: ovsdb-server: server returned an error
766])
1b1d2e6d
BP
767 dnl Make sure that "db" is still a symlink to dir/db instead of getting
768 dnl replaced by a regular file, ditto for .db.~lock~.
769 if test "$IS_WIN32" = "no"; then
5a0e4aec
BP
770 AT_CHECK([test -h db])
771 AT_CHECK([test -h .db.~lock~])
772 AT_CHECK([test -f dir/db])
773 AT_CHECK([test -f dir/.db.~lock~])
1b1d2e6d
BP
774 fi
775
776 # We can't fully re-check the contents of the database log, because the
777 # order of the records is not predictable, but there should only be 4 lines
778 # in it now in the standalone case
779 AT_CAPTURE_FILE([db])
780 compacted_lines=`wc -l < db`
781 echo compacted_lines=$compacted_lines
782 if test $model = standalone; then
783 AT_CHECK([test $compacted_lines -eq 4])
784 fi
785
786 dnl And check that the dumped data is the same too:
787 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout])
788 AT_CHECK([uuidfilt stdout], [0], [dnl
370a11b9
BP
789ordinals table
790_uuid name number
ada496b5 791------------------------------------ ----- ------
e51d0a1d
BP
792<0> five 5
793<1> four 4
794<2> one 1
795<3> three 3
796<4> two 2
797<5> zero 0
1b1d2e6d
BP
798])
799 dnl Now do some more transactions.
800 AT_CHECK(
801 [[ovsdb-client transact unix:socket '
5a0e4aec
BP
802 ["ordinals",
803 {"op": "delete",
804 "table": "ordinals",
805 "where": [["number", "<", 3]]}]']],
1b1d2e6d
BP
806 [0], [[[{"count":3}]
807]], [ignore])
808
809 dnl There should be 6 lines in the log now, for the standalone case,
810 dnl and for the clustered case the file should at least have grown.
811 updated_lines=`wc -l < db`
812 echo compacted_lines=$compacted_lines updated_lines=$updated_lines
813 if test $model = standalone; then
814 AT_CHECK([test $updated_lines -eq 6])
815 else
816 AT_CHECK([test $updated_lines -gt $compacted_lines])
817 fi
818
819 dnl Then check that the dumped data is correct. This time first kill
820 dnl and restart the database server to ensure that the data is correct on
821 dnl disk as well as in memory.
822 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
823 AT_CHECK([ovsdb-server -vvlog:off -vconsole:off --detach --no-chdir --pidfile --remote=punix:socket --log-file db])
824 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout])
825 AT_CHECK([uuidfilt stdout], [0], [dnl
370a11b9
BP
826ordinals table
827_uuid name number
ada496b5 828------------------------------------ ----- ------
e51d0a1d
BP
829<0> five 5
830<1> four 4
831<2> three 3
ada496b5 832], [], [test ! -e pid || kill `cat pid`])
1b1d2e6d
BP
833 OVSDB_SERVER_SHUTDOWN
834}
835OVS_END_SHELL_HELPERS
836
837AT_SETUP([compacting online - standalone])
838AT_KEYWORDS([ovsdb server compact])
839ovsdb_check_online_compaction standalone
ada496b5 840AT_CLEANUP
48f6e410 841
1b1d2e6d
BP
842AT_SETUP([compacting online - cluster])
843AT_KEYWORDS([ovsdb server compact])
844ovsdb_check_online_compaction cluster
845AT_CLEANUP
846\f
847OVS_START_SHELL_HELPERS
848# ovsdb_check_online_conversion MODEL
849#
850# where MODEL is "standalone" or "cluster"
851ovsdb_check_online_conversion() {
852 local model=$1
853 on_exit 'kill `cat *.pid`'
854 ordinal_schema > schema
855 AT_DATA([new-schema],
856 [[{"name": "ordinals",
53178986
BP
857 "tables": {
858 "ordinals": {
5a0e4aec
BP
859 "columns": {
860 "number": {"type": "integer"}}}}}
53178986 861]])
1b1d2e6d
BP
862 dnl Make sure that "ovsdb-tool create" works with a dangling symlink for
863 dnl the database and the lockfile, creating the target of each symlink
864 dnl rather than replacing the symlinks with regular files.
865 mkdir dir
866 if test "$IS_WIN32" = "no"; then
5a0e4aec
BP
867 ln -s dir/db db
868 ln -s dir/.db.~lock~ .db.~lock~
869 AT_SKIP_IF([test ! -h db || test ! -h .db.~lock~])
1b1d2e6d
BP
870 fi
871 AT_CHECK([if test $model = standalone; then
872 ovsdb-tool create db schema
873 else
874 ovsdb-tool create-cluster db schema unix:s1.raft
875 fi])
876
877 dnl Start the database server.
878 AT_CHECK([ovsdb-server -vfile -vvlog:off -vconsole:off --detach --no-chdir --pidfile --log-file --remote=punix:db.sock db], [0])
879 AT_CAPTURE_FILE([ovsdb-server.log])
880
881 dnl Put some data in the database.
882 AT_CHECK(
883 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
5a0e4aec
BP
884 set -- $pair
885 ovsdb-client transact '
886 ["ordinals",
887 {"op": "insert",
888 "table": "ordinals",
889 "row": {"name": "'$1'", "number": '$2'}},
890 {"op": "comment",
891 "comment": "add row for '"$pair"'"}]'
892 done | uuidfilt]], [0],
1b1d2e6d 893 [[[{"uuid":["uuid","<0>"]},{}]
53178986
BP
894[{"uuid":["uuid","<1>"]},{}]
895[{"uuid":["uuid","<2>"]},{}]
896[{"uuid":["uuid","<3>"]},{}]
897[{"uuid":["uuid","<4>"]},{}]
898[{"uuid":["uuid","<5>"]},{}]
899]], [ignore])
900
1b1d2e6d
BP
901 dnl Try "needs-conversion".
902 AT_CHECK([ovsdb-client needs-conversion schema], [0], [no
53178986 903])
1b1d2e6d 904 AT_CHECK([ovsdb-client needs-conversion new-schema], [0], [yes
53178986
BP
905])
906
1b1d2e6d
BP
907 dnl Start two monitors on the 'ordinals' db, one that is database
908 dnl change aware and one that is not.
9a403b07 909 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
910 AT_CAPTURE_FILE([monitor-ordinals-aware.stdout])
911 AT_CAPTURE_FILE([monitor-ordinals-aware.log])
912 AT_CAPTURE_FILE([monitor-ordinals-aware.stderr])
913
9a403b07 914 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
915 AT_CAPTURE_FILE([monitor-ordinals-unaware.stdout])
916 AT_CAPTURE_FILE([monitor-ordinals-unaware.log])
917 AT_CAPTURE_FILE([monitor-ordinals-unaware.stderr])
918
919 dnl Start two monitors on the '_Server' db, one that is database
920 dnl change aware and one that is not.
9a403b07 921 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
922 AT_CAPTURE_FILE([monitor-server-aware.stdout])
923 AT_CAPTURE_FILE([monitor-server-aware.log])
924 AT_CAPTURE_FILE([monitor-server-aware.stderr])
925
9a403b07 926 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
927 AT_CAPTURE_FILE([monitor-server-unaware.stdout])
928 AT_CAPTURE_FILE([monitor-server-unaware.log])
929 AT_CAPTURE_FILE([monitor-server-unaware.stderr])
930
931 dnl Start two long-running transactions (triggers) on the 'ordinals' db,
932 dnl one that is database change aware and one that is not.
933 ordinals_txn='[["ordinals",
5a0e4aec
BP
934 {"op": "wait",
935 "table": "ordinals",
936 "where": [["name", "==", "seven"]],
937 "columns": ["name", "number"],
938 "rows": [],
939 "until": "!="}]]'
9a403b07 940 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
941 AT_CAPTURE_FILE([trigger-ordinals-aware.stdout])
942 AT_CAPTURE_FILE([trigger-ordinals-aware.log])
943 AT_CAPTURE_FILE([trigger-ordinals-aware.stderr])
944
9a403b07 945 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
946 AT_CAPTURE_FILE([trigger-ordinals-unaware.stdout])
947 AT_CAPTURE_FILE([trigger-ordinals-unaware.log])
948 AT_CAPTURE_FILE([trigger-ordinals-unaware.stderr])
949
950 dnl Start two long-running transactions (triggers) on the _Server db,
951 dnl one that is database change aware and one that is not.
952 server_txn='[["_Server",
5a0e4aec
BP
953 {"op": "wait",
954 "table": "Database",
955 "where": [["name", "==", "xyzzy"]],
956 "columns": ["name"],
957 "rows": [],
958 "until": "!="}]]'
9a403b07 959 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
960 AT_CAPTURE_FILE([trigger-server-aware.stdout])
961 AT_CAPTURE_FILE([trigger-server-aware.log])
962 AT_CAPTURE_FILE([trigger-server-aware.stderr])
963
9a403b07 964 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
965 AT_CAPTURE_FILE([trigger-server-unaware.stdout])
966 AT_CAPTURE_FILE([trigger-server-unaware.log])
967 AT_CAPTURE_FILE([trigger-server-unaware.stderr])
968
969 dnl Dump out and check the actual database contents.
970 AT_CHECK([ovsdb-client dump unix:db.sock ordinals], [0], [stdout])
971 AT_CHECK([uuidfilt stdout], [0], [dnl
53178986
BP
972ordinals table
973_uuid name number
974------------------------------------ ----- ------
975<0> five 5
976<1> four 4
977<2> one 1
978<3> three 3
979<4> two 2
980<5> zero 0
981])
982
1b1d2e6d
BP
983 dnl Convert the database.
984 AT_CHECK([ovsdb-client convert new-schema])
53178986 985
1b1d2e6d
BP
986 dnl Try "needs-conversion".
987 AT_CHECK([ovsdb-client needs-conversion schema], [0], [yes
53178986 988])
1b1d2e6d 989 AT_CHECK([ovsdb-client needs-conversion new-schema], [0], [no
53178986
BP
990])
991
1b1d2e6d
BP
992 dnl Verify that the "ordinals" monitors behaved as they should have.
993 dnl Both should have exited, for different reasons.
994 for x in aware unaware; do
5a0e4aec
BP
995 echo $x
996 OVS_WAIT_WHILE([test -e monitor-ordinals-$x.pid])
997 AT_CHECK([sort -k 3 monitor-ordinals-$x.stdout | uuidfilt], [0],
1b1d2e6d 998 [<0> initial 0 zero
53178986
BP
999<1> initial 1 one
1000<2> initial 2 two
1001<3> initial 3 three
1002<4> initial 4 four
1003<5> initial 5 five
1004])
1b1d2e6d
BP
1005 done
1006 AT_CHECK([sed 's/.*: //' monitor-ordinals-unaware.stderr], [0], [receive failed (End of file)
53178986 1007])
1b1d2e6d 1008 AT_CHECK([sed 's/.*: //' monitor-ordinals-aware.stderr], [0], [ordinals database was removed
53178986
BP
1009])
1010
1b1d2e6d
BP
1011 dnl Verify that the _Server monitors behaved as they should have.
1012 dnl The db-aware monitor should still be running, but not the unaware one.
1013 for x in aware unaware; do
5a0e4aec 1014 AT_CHECK([sort -k 3 monitor-server-$x.stdout | uuidfilt], [0],
1b1d2e6d 1015 [<0> initial _Server
53178986
BP
1016<1> initial ordinals
1017])
1b1d2e6d
BP
1018 done
1019 OVS_WAIT_WHILE([test -e monitor-server-unaware.pid])
1020 AT_CHECK([sed 's/.*: //' monitor-ordinals-unaware.stderr], [0], [receive failed (End of file)
53178986 1021])
1b1d2e6d
BP
1022 AT_CHECK([test -e monitor-server-aware.pid])
1023
1024 dnl Verify that the "ordinals" triggers behaved as they should have:
1025 dnl Both should have exited, for different reasons.
1026 for x in unaware aware; do
5a0e4aec
BP
1027 OVS_WAIT_WHILE([test -e trigger-ordinals-$x.pid])
1028 AT_CHECK([cat trigger-ordinals-$x.stdout])
1b1d2e6d
BP
1029 done
1030 AT_CHECK([cat trigger-ordinals-unaware.stderr], [0], [ovsdb-client: transaction failed (End of file)
53178986 1031])
1b1d2e6d 1032 AT_CHECK([cat trigger-ordinals-aware.stderr], [0], [ovsdb-client: transaction returned error: "canceled"
53178986
BP
1033])
1034
1b1d2e6d
BP
1035 dnl Verify that the _Server triggers behaved as they should have:
1036 dnl The db-aware trigger should still be waiting, but not the unaware one.
1037 for x in aware unaware; do
5a0e4aec 1038 AT_CHECK([cat trigger-server-$x.stdout])
1b1d2e6d
BP
1039 done
1040 OVS_WAIT_WHILE([test -e trigger-server-unaware.pid])
1041 AT_CHECK([sed 's/.*: //' trigger-ordinals-unaware.stderr], [0], [transaction failed (End of file)
53178986 1042])
1b1d2e6d
BP
1043 AT_CHECK([test -e trigger-server-aware.pid])
1044
1045 AT_CAPTURE_FILE([db])
1046 if test $model = standalone; then
5a0e4aec
BP
1047 dnl We can't fully re-check the contents of the database log, because the
1048 dnl order of the records is not predictable, but there should only be 4 lines
1049 dnl in it now.
1050 AT_CHECK([test `wc -l < db` -eq 4])
1b1d2e6d
BP
1051 fi
1052 dnl Check that the dumped data is the same except for the removed column:
1053 AT_CHECK([ovsdb-client dump unix:db.sock ordinals | uuidfilt], [0], [dnl
53178986
BP
1054ordinals table
1055_uuid number
1056------------------------------------ ------
1057<0> 0
1058<1> 1
1059<2> 2
1060<3> 3
1061<4> 4
1062<5> 5
1063])
1b1d2e6d
BP
1064 dnl Now check that the converted database is still online and can be modified,
1065 dnl then check that the database log has one more record and that the data
1066 dnl is as expected.
1067 AT_CHECK(
1068 [[ovsdb-client transact '
5a0e4aec
BP
1069 ["ordinals",
1070 {"op": "insert",
1071 "table": "ordinals",
1072 "row": {"number": 6}},
1073 {"op": "comment",
1074 "comment": "add row for 6"}]' | uuidfilt]], [0],
1b1d2e6d 1075 [[[{"uuid":["uuid","<0>"]},{}]
53178986 1076]])
1b1d2e6d
BP
1077 if test $model = standalone; then
1078 AT_CHECK([test `wc -l < db` -eq 6])
1079 fi
1080 AT_CHECK([ovsdb-client dump unix:db.sock ordinals | uuidfilt], [0], [dnl
53178986
BP
1081ordinals table
1082_uuid number
1083------------------------------------ ------
1084<0> 0
1085<1> 1
1086<2> 2
1087<3> 3
1088<4> 4
1089<5> 5
1090<6> 6
1091])
1b1d2e6d
BP
1092 dnl Now kill and restart the database server to ensure that the data is
1093 dnl correct on disk as well as in memory.
1094 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
1095 AT_CHECK([[ovsdb-server -vfile -vvlog:off -vconsole:off --detach --no-chdir --pidfile --log-file --remote=punix:db.sock db]],
1096 [0])
1097 AT_CHECK([ovsdb-client dump unix:db.sock ordinals | uuidfilt], [0], [dnl
53178986
BP
1098ordinals table
1099_uuid number
1100------------------------------------ ------
1101<0> 0
1102<1> 1
1103<2> 2
1104<3> 3
1105<4> 4
1106<5> 5
1107<6> 6
1108])
1109
1b1d2e6d
BP
1110 dnl Make sure that "db" is still a symlink to dir/db instead of getting
1111 dnl replaced by a regular file, ditto for .db.~lock~.
1112 if test "$IS_WIN32" = "no"; then
5a0e4aec
BP
1113 AT_CHECK([test -h db])
1114 AT_CHECK([test -h .db.~lock~])
1115 AT_CHECK([test -f dir/db])
1116 AT_CHECK([test -f dir/.db.~lock~])
1b1d2e6d
BP
1117 fi
1118
1119 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
1120}
1121OVS_END_SHELL_HELPERS
1122
1123AT_SETUP([schema conversion online - standalone])
1124AT_KEYWORDS([ovsdb server convert needs-conversion standalone])
1125ovsdb_check_online_conversion standalone
53178986
BP
1126AT_CLEANUP
1127
1b1d2e6d
BP
1128AT_SETUP([schema conversion online - clustered])
1129AT_KEYWORDS([ovsdb server convert needs-conversion cluster])
1130ovsdb_check_online_conversion cluster
1131AT_CLEANUP
1132\f
48f6e410 1133AT_SETUP([ovsdb-server combines updates on backlogged connections])
53eb8cb8 1134on_exit 'kill `cat *.pid`'
48f6e410
BP
1135
1136# The maximum socket receive buffer size is important for this test, which
1137# tests behavior when the receive buffer overflows.
1138if test -e /proc/sys/net/core/rmem_max; then
1139 # Linux
1140 rmem_max=`cat /proc/sys/net/core/rmem_max`
1141elif rmem_max=`sysctl -n net.inet.tcp.recvbuf_max 2>/dev/null`; then
81b9d305 1142 : # FreeBSD, NetBSD
48f6e410
BP
1143else
1144 # Don't know how to get maximum socket receive buffer on this OS
1145 AT_SKIP_IF([:])
1146fi
1147
1148# Calculate the number of iterations we need to queue. Each of the
1149# iterations we execute, by itself, yields a monitor update of about
1150# 25 kB, so fill up that much space plus a few for luck.
f5ca49d8 1151n_iterations=`expr $rmem_max / 25000 + 5`
48f6e410
BP
1152echo rmem_max=$rmem_max n_iterations=$n_iterations
1153
21aa35c3
BP
1154# If there's too much queuing skip the test to avoid timing out.
1155AT_SKIP_IF([test $rmem_max -gt 1048576])
1156
48f6e410
BP
1157# Calculate the exact number of monitor updates expected for $n_iterations,
1158# assuming no updates are combined. The "extra" update is for the initial
1159# contents of the database.
1160n_updates=`expr $n_iterations \* 3 + 1`
1161
1162# Start an ovsdb-server with the vswitchd schema.
1163OVSDB_INIT([db])
1164AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --log-file --remote=punix:db.sock db],
1165 [0], [ignore], [ignore])
1166
1167# Executes a set of transactions that add a bridge with 100 ports, and
1168# then deletes that bridge. This yields three monitor updates that
1169# add up to about 25 kB in size.
1170#
1171# The update also increments a counter held in the database so that we can
1172# verify that the overall effect of the transactions took effect (e.g.
1173# monitor updates at the end weren't just dropped). We add an arbitrary
1174# string to the counter to make grepping for it more reliable.
1175counter=0
1176trigger_big_update () {
1177 counter=`expr $counter + 1`
1178 ovs-vsctl --no-wait -- set open_vswitch . system_version=xyzzy$counter
1179 ovs-vsctl --no-wait -- add-br br0 $add
1180 ovs-vsctl --no-wait -- del-br br0
1181}
1182add_ports () {
1183 for j in `seq 1 100`; do
1184 printf " -- add-port br0 p%d" $j
1185 done
1186}
1187add=`add_ports`
1188
1189AT_CAPTURE_FILE([ovsdb-client.err])
c005fd61
AZ
1190AT_CAPTURE_FILE([ovsdb-client-nonblock.err])
1191
1192
1193# Start an ovsdb-client monitoring all changes to the database,
1194# By default, it is non-blocking, and will get update message
1195# for each ovsdb-server transaactions.
1196AT_CHECK([ovsdb-client --detach --no-chdir --pidfile=nonblock.pid monitor ALL >ovsdb-client-nonblock.out 2>ovsdb-client-nonblock.err])
48f6e410
BP
1197
1198# Start an ovsdb-client monitoring all changes to the database,
1199# make it block to force the buffers to fill up, and then execute
1200# enough iterations that ovsdb-server starts combining updates.
1201AT_CHECK([ovsdb-client --detach --no-chdir --pidfile monitor ALL >ovsdb-client.out 2>ovsdb-client.err])
1202AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/block])
1203for i in `seq 1 $n_iterations`; do
1204 echo "blocked update ($i of $n_iterations)"
1205 trigger_big_update $i
1206done
1207AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/unblock])
29004db2
IM
1208OVS_WAIT_UNTIL([grep "xyzzy$counter" ovsdb-client.out])
1209OVS_WAIT_UNTIL([grep "xyzzy$counter" ovsdb-client-nonblock.out])
d9c8c57c 1210OVS_APP_EXIT_AND_WAIT([ovsdb-client])
c005fd61 1211AT_CHECK([kill `cat nonblock.pid`])
48f6e410
BP
1212
1213# Count the number of updates in the ovsdb-client output, by counting
1214# the number of changes to the Open_vSwitch table. (All of our
1215# transactions modify the Open_vSwitch table.) It should be less than
1216# $n_updates updates.
1217#
1218# Check that the counter is what we expect.
1219logged_updates=`grep -c '^Open_vSwitch' ovsdb-client.out`
c005fd61
AZ
1220logged_nonblock_updates=`grep -c '^Open_vSwitch' ovsdb-client-nonblock.out`
1221echo "logged_nonblock_updates=$logged_nonblock_updates (expected less or equal to $n_updates)"
1222echo "logged_updates=$logged_updates (expected less than $logged_nonblock_updates)"
1223AT_CHECK([test $logged_nonblock_updates -le $n_updates])
1224AT_CHECK([test $logged_updates -lt $logged_nonblock_updates])
48f6e410 1225AT_CHECK_UNQUOTED([ovs-vsctl get open_vswitch . system_version], [0],
29004db2 1226 [xyzzy$counter
48f6e410 1227])
d9c8c57c 1228OVS_APP_EXIT_AND_WAIT([ovsdb-server])
48f6e410 1229AT_CLEANUP
80d326ad 1230\f
e731d71b 1231AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv4 sockets)])
80d326ad
BP
1232
1233# OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
1234#
1235# Creates a database with the given SCHEMA, starts an ovsdb-server on
1236# that database, and runs each of the TRANSACTIONS (which should be a
1237# quoted list of quoted strings) against it with ovsdb-client one at a
1238# time.
1239#
1240# Checks that the overall output is OUTPUT, but UUIDs in the output
1241# are replaced by markers of the form <N> where N is a number. The
1242# first unique UUID is replaced by <0>, the next by <1>, and so on.
1243# If a given UUID appears more than once it is always replaced by the
1244# same marker.
1245#
1246# TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
1247m4_define([OVSDB_CHECK_EXECUTION],
1248 [AT_SETUP([$1])
1249 AT_KEYWORDS([ovsdb server positive ssl $5])
1250 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
39ab07af 1251 $2 > schema
15b619e2 1252 PKIDIR=$abs_top_builddir/tests
7c126fbb 1253 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
56120500 1254 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 1255 PARSE_LISTENING_PORT([ovsdb-server.log], [SSL_PORT])
80d326ad 1256 m4_foreach([txn], [$3],
7c126fbb 1257 [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
1258 [test ! -e pid || kill `cat pid`])
1259cat stdout >> output
1260])
c724bd67 1261 AT_CHECK([uuidfilt output], [0], [$4], [ignore],
80d326ad 1262 [test ! -e pid || kill `cat pid`])
028cbd99 1263 OVSDB_SERVER_SHUTDOWN
80d326ad
BP
1264 AT_CLEANUP])
1265
e879d33e
MM
1266EXECUTION_EXAMPLES
1267
e731d71b
AS
1268AT_BANNER([OVSDB -- ovsdb-server transactions (SSL IPv6 sockets)])
1269
1270# OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
1271#
1272# Creates a database with the given SCHEMA, starts an ovsdb-server on
1273# that database, and runs each of the TRANSACTIONS (which should be a
1274# quoted list of quoted strings) against it with ovsdb-client one at a
1275# time.
1276#
1277# Checks that the overall output is OUTPUT, but UUIDs in the output
1278# are replaced by markers of the form <N> where N is a number. The
1279# first unique UUID is replaced by <0>, the next by <1>, and so on.
1280# If a given UUID appears more than once it is always replaced by the
1281# same marker.
1282#
1283# TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
1284m4_define([OVSDB_CHECK_EXECUTION],
1285 [AT_SETUP([$1])
1286 AT_KEYWORDS([ovsdb server positive ssl6 $5])
1287 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
4819b3a5 1288 AT_SKIP_IF([test $HAVE_IPV6 = no])
e731d71b
AS
1289 $2 > schema
1290 PKIDIR=$abs_top_builddir/tests
1291 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
56120500 1292 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 1293 PARSE_LISTENING_PORT([ovsdb-server.log], [SSL_PORT])
e731d71b
AS
1294 m4_foreach([txn], [$3],
1295 [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],
1296 [test ! -e pid || kill `cat pid`])
1297cat stdout >> output
1298])
c724bd67 1299 AT_CHECK([uuidfilt output], [0], [$4], [ignore],
e731d71b
AS
1300 [test ! -e pid || kill `cat pid`])
1301 OVSDB_SERVER_SHUTDOWN
1302 AT_CLEANUP])
1303
1304ONE_EXECUTION_EXAMPLE
1305
1306AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv4 sockets)])
e879d33e 1307
e879d33e
MM
1308# OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
1309#
1310# Creates a database with the given SCHEMA, starts an ovsdb-server on
1311# that database, and runs each of the TRANSACTIONS (which should be a
1312# quoted list of quoted strings) against it with ovsdb-client one at a
1313# time.
1314#
1315# Checks that the overall output is OUTPUT, but UUIDs in the output
1316# are replaced by markers of the form <N> where N is a number. The
1317# first unique UUID is replaced by <0>, the next by <1>, and so on.
1318# If a given UUID appears more than once it is always replaced by the
1319# same marker.
1320#
1321# TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
1322m4_define([OVSDB_CHECK_EXECUTION],
1323 [AT_SETUP([$1])
1324 AT_KEYWORDS([ovsdb server positive tcp $5])
1325 $2 > schema
e879d33e
MM
1326 PKIDIR=$abs_top_builddir/tests
1327 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
56120500 1328 AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile --remote=ptcp:0:127.0.0.1 db], [0], [ignore], [ignore])
fb28ef2d 1329 PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
e879d33e
MM
1330 m4_foreach([txn], [$3],
1331 [AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT 'txn'], [0], [stdout], [ignore],
1332 [test ! -e pid || kill `cat pid`])
1333cat stdout >> output
1334])
c724bd67 1335 AT_CHECK([uuidfilt output], [0], [$4], [ignore],
e879d33e
MM
1336 [test ! -e pid || kill `cat pid`])
1337 OVSDB_SERVER_SHUTDOWN
1338 AT_CLEANUP])
1339
80d326ad 1340EXECUTION_EXAMPLES
e731d71b 1341
7daaec4e
BP
1342AT_BANNER([OVSDB -- ovsdb-server transactions (TCP IPv6 sockets)])
1343
e731d71b
AS
1344# OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
1345#
1346# Creates a database with the given SCHEMA, starts an ovsdb-server on
1347# that database, and runs each of the TRANSACTIONS (which should be a
1348# quoted list of quoted strings) against it with ovsdb-client one at a
1349# time.
1350#
1351# Checks that the overall output is OUTPUT, but UUIDs in the output
1352# are replaced by markers of the form <N> where N is a number. The
1353# first unique UUID is replaced by <0>, the next by <1>, and so on.
1354# If a given UUID appears more than once it is always replaced by the
1355# same marker.
1356#
1357# TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
1358m4_define([OVSDB_CHECK_EXECUTION],
1359 [AT_SETUP([$1])
1360 AT_KEYWORDS([ovsdb server positive tcp6 $5])
4819b3a5 1361 AT_SKIP_IF([test $HAVE_IPV6 = no])
e731d71b
AS
1362 $2 > schema
1363 PKIDIR=$abs_top_builddir/tests
1364 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
56120500 1365 AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile --remote=ptcp:0:[[::1]] db], [0], [ignore], [ignore])
fb28ef2d 1366 PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
e731d71b
AS
1367 m4_foreach([txn], [$3],
1368 [AT_CHECK([ovsdb-client transact tcp:[[::1]]:$TCP_PORT 'txn'], [0], [stdout], [ignore],
1369 [test ! -e pid || kill `cat pid`])
1370cat stdout >> output
1371])
c724bd67 1372 AT_CHECK([uuidfilt output], [0], [$4], [ignore],
e731d71b
AS
1373 [test ! -e pid || kill `cat pid`])
1374 OVSDB_SERVER_SHUTDOWN
1375 AT_CLEANUP])
1376
1377ONE_EXECUTION_EXAMPLE
9ff373db
BP
1378\f
1379AT_BANNER([OVSDB -- transactions on transient ovsdb-server])
1380
1381# OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
1382#
1383# Creates a database with the given SCHEMA and runs each of the
1384# TRANSACTIONS (which should be a quoted list of quoted strings)
1385# against it with ovsdb-client one at a time. Each ovsdb-client
1386# is run against a separately started ovsdb-server that executes
1387# only that single transaction. (The idea is that this should
1388# help to ferret out any differences between what ovsdb-server has
1389# in memory and what actually gets committed to disk.)
1390#
1391# Checks that the overall output is OUTPUT, but UUIDs in the output
1392# are replaced by markers of the form <N> where N is a number. The
1393# first unique UUID is replaced by <0>, the next by <1>, and so on.
1394# If a given UUID appears more than once it is always replaced by the
1395# same marker.
1396#
1397# TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
1398m4_define([OVSDB_CHECK_EXECUTION],
1399 [AT_SETUP([$1])
c17b52e8 1400 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
9ff373db 1401 AT_KEYWORDS([ovsdb server positive transient $5])
39ab07af 1402 $2 > schema
9ff373db
BP
1403 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
1404 m4_foreach([txn], [$3],
1405 [AT_DATA([txnfile], [ovsdb-client transact unix:socket 'txn'
1406])
56120500 1407 AT_CHECK([ovsdb-server --remote=punix:socket db --run="sh txnfile"], [0], [stdout], [ignore])
9ff373db
BP
1408 cat stdout >> output
1409])
c724bd67 1410 AT_CHECK([uuidfilt output], [0], [$4], [ignore])
9ff373db
BP
1411 AT_CLEANUP])
1412
1413EXECUTION_EXAMPLES
ae671c5f 1414\f
63b35ecc 1415AT_BANNER([OVSDB -- ovsdb-server replication])
ae671c5f
MC
1416
1417# OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
1418#
1419# Creates two databases with the given SCHEMA, and starts an ovsdb-server on
1420# each database.
1421# Runs each of the TRANSACTIONS (which should be a quoted list of
1422# quoted strings) against one of the servers with ovsdb-client one at a
1423# time. The server replicates its database to the other ovsdb-server.
1424#
1425# Checks that the dump of both databases are the same.
1426#
1427# TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
1428m4_define([OVSDB_CHECK_EXECUTION],
1429 [AT_SETUP([$1])
1430 AT_KEYWORDS([ovsdb server tcp replication $5])
1431 $2 > schema
1432 AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1433 AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1434
56120500 1435 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile --remote=punix:db.sock db1], [0], [ignore], [ignore])
5dd81c22
AZ
1436 i
1437 on_exit 'test ! -e pid || kill `cat pid`'
ae671c5f 1438
56120500 1439 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 1440 on_exit 'test ! -e pid2 || kill `cat pid2`'
ae671c5f
MC
1441
1442 m4_foreach([txn], [$3],
5dd81c22 1443 [AT_CHECK([ovsdb-client transact 'txn'], [0], [stdout], [ignore])
ae671c5f
MC
1444 ])
1445
5dd81c22
AZ
1446 AT_CHECK([ovsdb-client dump], [0], [stdout], [ignore])
1447 OVS_WAIT_UNTIL([ ovsdb-client dump unix:db2.sock > dump2; diff stdout dump2])
ae671c5f 1448
ae671c5f
MC
1449 OVSDB_SERVER_SHUTDOWN
1450 OVSDB_SERVER_SHUTDOWN2
1451 AT_CLEANUP])
1452
1453EXECUTION_EXAMPLES
7a9d65d2 1454
63b35ecc 1455AT_BANNER([OVSDB -- ovsdb-server replication table-exclusion])
7a9d65d2
MC
1456
1457# OVSDB_CHECK_REPLICATION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
1458#
1459# Creates two databases with the given SCHEMA, and starts an
1460# ovsdb-server on each database.
1461# Runs each of the TRANSACTIONS (which should be a quoted list of
1462# quoted strings) against one of the servers with ovsdb-client one at a
1463# time. The server replicates its database to the other ovsdb-server.
1464#
1465# Checks that the difference between the dump of the databases is
1466# OUTPUT, but UUIDs in the output are replaced by markers of the form
1467# <N> where N is a number. The first unique UUID is replaced by <0>,
1468# the next by <1>, and so on.
1469# If a given UUID appears more than once it is always replaced by the
1470# same marker.
1471#
1472# TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
1473m4_define([OVSDB_CHECK_REPLICATION],
1474 [AT_SETUP([$1])
1475 AT_KEYWORDS([ovsdb server tcp replication table-exclusion])
baee3741 1476 AT_SKIP_IF([test $DIFF_SUPPORTS_NORMAL_FORMAT = no])
7a9d65d2
MC
1477 $2 > schema
1478 AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1479 AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1480
56120500 1481 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile --remote=punix:db.sock db1], [0], [ignore], [ignore])
5dd81c22 1482 on_exit 'test ! -e pid || kill `cat pid`'
7a9d65d2 1483
56120500 1484 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 1485 on_exit 'test ! -e pid2 || kill `cat pid2`'
7a9d65d2
MC
1486
1487 m4_foreach([txn], [$3],
5dd81c22 1488 [AT_CHECK([ ovsdb-client transact 'txn' ], [0], [stdout], [ignore])
7a9d65d2
MC
1489 ])
1490
5dd81c22
AZ
1491 AT_CHECK([ovsdb-client dump], [0], [stdout], [ignore])
1492 cat stdout > dump1
7a9d65d2 1493
5dd81c22
AZ
1494 OVS_WAIT_UNTIL([ ovsdb-client dump unix:db2.sock | grep one ])
1495 AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore])
1496 cat stdout > dump2
7a9d65d2 1497
5dd81c22
AZ
1498 AT_CHECK([diff dump1 dump2], [1], [stdout], [ignore])
1499 cat stdout > output
1500
c724bd67 1501 AT_CHECK([uuidfilt output], [0], [$4], [ignore])
7a9d65d2
MC
1502
1503 OVSDB_SERVER_SHUTDOWN
1504 OVSDB_SERVER_SHUTDOWN2
1505 AT_CLEANUP])
1506
1507REPLICATION_EXAMPLES
9dc05cdc
MC
1508
1509AT_BANNER([OVSDB -- ovsdb-server replication runtime management commands])
1510
f53d7518
AZ
1511#ovsdb-server/get-active-ovsdb-server command
1512AT_SETUP([ovsdb-server/get-active-ovsdb-server])
1513AT_KEYWORDS([ovsdb server replication get-active])
9dc05cdc
MC
1514ordinal_schema > schema
1515AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
1516on_exit 'kill `cat *.pid`'
1517AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --sync-from=tcp:127.0.0.1:9999 db])
1518
f53d7518 1519AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/get-active-ovsdb-server],
9dc05cdc
MC
1520 [0], [tcp:127.0.0.1:9999
1521])
1522AT_CLEANUP
1523
f53d7518
AZ
1524#*ovsdb-server/set-active-ovsdb-server command
1525AT_SETUP([ovsdb-server/set-active-ovsdb-server])
1526AT_KEYWORDS([ovsdb server replication set-active])
9dc05cdc
MC
1527ordinal_schema > schema
1528AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
1529on_exit 'kill `cat *.pid`'
1530AT_CHECK([ovsdb-server --detach --no-chdir --pidfile db])
1531
f53d7518
AZ
1532AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/set-active-ovsdb-server tcp:127.0.0.1:9999])
1533AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/get-active-ovsdb-server],
9dc05cdc
MC
1534 [0], [tcp:127.0.0.1:9999
1535])
1536AT_CLEANUP
1537
60e0cd04
AZ
1538#ovsdb-server/get-sync-exclude-tables command
1539AT_SETUP([ovsdb-server/get-sync-exclude-tables])
1540AT_KEYWORDS([ovsdb server replication get-exclude-tables])
9dc05cdc
MC
1541ordinal_schema > schema
1542AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
1543on_exit 'kill `cat *.pid`'
1544AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --sync-exclude-tables=mydb:db1,mydb:db2 db])
1545
60e0cd04 1546AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/get-sync-exclude-tables],
3109b4e1 1547 [0], [mydb:db1,mydb:db2
9dc05cdc
MC
1548])
1549AT_CLEANUP
1550
60e0cd04
AZ
1551#ovsdb-server/set-sync-exclude-tables command
1552AT_SETUP([ovsdb-server/set-sync-exclude-tables])
1553AT_KEYWORDS([ovsdb server replication set-exclude-tables])
baee3741
BP
1554AT_SKIP_IF([test $DIFF_SUPPORTS_NORMAL_FORMAT = no])
1555
9dc05cdc
MC
1556replication_schema > schema
1557AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1558AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1559
56120500 1560AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile --remote=punix:db.sock db1], [0], [ignore], [ignore])
5dd81c22 1561on_exit 'test ! -e pid || kill `cat pid`'
9dc05cdc 1562
56120500 1563AT_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 1564on_exit 'test ! -e pid2 || kill `cat pid2`'
9dc05cdc 1565
60e0cd04 1566AT_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 1567
63b35ecc 1568AT_CHECK([ovsdb-client transact unix:db.sock \
9dc05cdc
MC
1569 '[["mydb",
1570 {"op": "insert",
1571 "table": "a",
1572 "row": {"number": 0, "name": "zero"}},
1573 {"op": "insert",
1574 "table": "b",
1575 "row": {"number": 1, "name": "one"}}]]'], [0], [stdout], [ignore],
1576 [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
9dc05cdc 1577
63b35ecc 1578AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout], [ignore],
9dc05cdc 1579 [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
5dd81c22
AZ
1580cat stdout > dump1
1581OVS_WAIT_UNTIL([ ovsdb-client dump unix:db2.sock | grep zero ])
1582AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore])
1583cat stdout > dump2
9dc05cdc 1584
5dd81c22
AZ
1585AT_CHECK([diff dump1 dump2], [1], [stdout], [ignore])
1586cat stdout > output
9dc05cdc 1587
c724bd67 1588AT_CHECK([uuidfilt output], [0], [7,9c7,8
9dc05cdc
MC
1589< _uuid name number
1590< ------------------------------------ ---- ------
e51d0a1d 1591< <0> one 1
9dc05cdc
MC
1592---
1593> _uuid name number
1594> ----- ---- ------
5dd81c22 1595])
9dc05cdc
MC
1596
1597OVSDB_SERVER_SHUTDOWN
1598OVSDB_SERVER_SHUTDOWN2
1599AT_CLEANUP
1600
f53d7518
AZ
1601#ovsdb-server/connect-active-ovsdb-server
1602AT_SETUP([ovsdb-server/connect-active-server])
1603AT_KEYWORDS([ovsdb server replication connect-active-server])
9dc05cdc
MC
1604replication_schema > schema
1605AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1606AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1607
56120500 1608AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile --remote=punix:db.sock db1], [0], [ignore], [ignore])
5dd81c22 1609on_exit 'test ! -e pid || kill `cat pid`'
9dc05cdc 1610
56120500 1611AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server2.log --pidfile=pid2 --remote=punix:db2.sock --unixctl=unixctl2 db2], [0], [ignore], [ignore])
5dd81c22 1612on_exit 'test ! -e pid2 || kill `cat pid2`'
9dc05cdc 1613
60e0cd04
AZ
1614dnl Try to connect without specifying the active server.
1615AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/connect-active-ovsdb-server], [0],
1616[Unable to connect: active server is not specified.
1617], [ignore])
1618
5dd81c22 1619AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/set-active-ovsdb-server unix:db.sock], [0], [stdout], [ignore])
9dc05cdc 1620
5dd81c22 1621AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/connect-active-ovsdb-server], [0], [stdout], [ignore])
9dc05cdc 1622
63b35ecc 1623AT_CHECK([ovsdb-client transact unix:db.sock \
9dc05cdc
MC
1624 '[["mydb",
1625 {"op": "insert",
1626 "table": "a",
5dd81c22 1627 "row": {"number": 0, "name": "zero"}}]]'], [0], [stdout], [ignore])
9dc05cdc 1628
5dd81c22
AZ
1629AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout], [ignore])
1630cat stdout > dump1
1631OVS_WAIT_UNTIL([ ovsdb-client dump unix:db2.sock | grep zero ])
1632AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore])
1633cat stdout > dump2
9dc05cdc 1634
5dd81c22 1635AT_CHECK([diff dump1 dump2], [0], [], [ignore])
9dc05cdc
MC
1636OVSDB_SERVER_SHUTDOWN
1637OVSDB_SERVER_SHUTDOWN2
1638AT_CLEANUP
1639
f53d7518
AZ
1640#ovsdb-server/disconnect-active-server command
1641AT_SETUP([ovsdb-server/disconnect-active-server])
1642AT_KEYWORDS([ovsdb server replication disconnect-active-server])
baee3741
BP
1643AT_SKIP_IF([test $DIFF_SUPPORTS_NORMAL_FORMAT = no])
1644
9dc05cdc
MC
1645replication_schema > schema
1646AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1647AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1648
56120500 1649AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile --remote=punix:db.sock db1], [0], [ignore], [ignore])
5dd81c22 1650on_exit 'test ! -e pid || kill `cat pid`'
9dc05cdc 1651
56120500 1652AT_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 1653on_exit 'test ! -e pid2 || kill `cat pid2`'
9dc05cdc 1654
63b35ecc 1655AT_CHECK([ovsdb-client transact unix:db.sock \
9dc05cdc
MC
1656'[["mydb",
1657 {"op": "insert",
1658 "table": "a",
5dd81c22 1659 "row": {"number": 0, "name": "zero"}}]]'], [0], [stdout], [ignore])
f7525086 1660
e51879e9
AZ
1661dnl Make sure the transaction shows up in db2. This also tests the back up server
1662dnl can be read.
63b35ecc 1663OVS_WAIT_UNTIL([ovsdb-client dump unix:db2.sock | grep zero])
9dc05cdc 1664
e51879e9
AZ
1665dnl The backup server does not accept any write transaction
1666AT_CHECK([ovsdb-client transact unix:db2.sock \
1667'[["mydb",
1668 {"op": "insert",
1669 "table": "b",
1670 "row": {"number": 1, "name": "one"}}]]'], [0],
1671 [[[{"details":"insert operation not allowed when database server is in read only mode","error":"not allowed"}]]
1672])
1673
5dd81c22 1674AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/disconnect-active-ovsdb-server], [0], [ignore], [ignore])
9dc05cdc 1675
63b35ecc 1676AT_CHECK([ovsdb-client transact unix:db.sock \
9dc05cdc
MC
1677'[["mydb",
1678 {"op": "insert",
1679 "table": "b",
5dd81c22 1680 "row": {"number": 1, "name": "one"}}]]'], [0], [stdout], [ignore])
9dc05cdc 1681
5dd81c22
AZ
1682AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout], [ignore])
1683cat stdout > dump1
9dc05cdc 1684
5dd81c22
AZ
1685sleep 1
1686AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore])
1687cat stdout > dump2
9dc05cdc 1688
5dd81c22
AZ
1689AT_CHECK([diff dump1 dump2], [1], [stdout], [ignore])
1690cat stdout > output
9dc05cdc 1691
c724bd67 1692AT_CHECK([uuidfilt output], [0], [7,9c7,8
9dc05cdc
MC
1693< _uuid name number
1694< ------------------------------------ ---- ------
e51d0a1d 1695< <0> one 1
9dc05cdc
MC
1696---
1697> _uuid name number
1698> ----- ---- ------
1699], [ignore], [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
1700
e51879e9
AZ
1701dnl The backup server now become active, and can accept write transactions.
1702AT_CHECK([ovsdb-client transact unix:db2.sock \
1703'[["mydb",
1704 {"op": "insert",
1705 "table": "b",
5dd81c22 1706 "row": {"number": 1, "name": "one"}}]]'], [0], [stdout], [ignore])
e51879e9
AZ
1707
1708AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout])
1709cat stdout > output
1710
c724bd67 1711AT_CHECK([uuidfilt output], [0], [a table
e51879e9
AZ
1712_uuid name number
1713------------------------------------ ---- ------
e51d0a1d 1714<0> zero 0
e51879e9
AZ
1715
1716b table
1717_uuid name number
1718------------------------------------ ---- ------
e51d0a1d 1719<1> one 1
e51879e9
AZ
1720])
1721
9dc05cdc
MC
1722OVSDB_SERVER_SHUTDOWN
1723OVSDB_SERVER_SHUTDOWN2
1724AT_CLEANUP
60e0cd04
AZ
1725
1726#ovsdb-server/active-backup-role-switching
1727AT_SETUP([ovsdb-server/active-backup-role-switching])
1728AT_KEYWORDS([ovsdb server replication active-backup-switching])
1729replication_schema > schema
1730AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
1731AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
1732
1733dnl Add some data to both DBs
1734AT_CHECK([ovsdb-tool transact db1 \
1735'[["mydb",
1736 {"op": "insert",
1737 "table": "a",
1738 "row": {"number": 9, "name": "nine"}}]]'], [0], [ignore], [ignore])
1739
1740AT_CHECK([ovsdb-tool transact db2 \
1741'[["mydb",
1742 {"op": "insert",
1743 "table": "a",
1744 "row": {"number": 9, "name": "nine"}}]]'], [0], [ignore], [ignore])
1745
1746dnl Start both 'db1' and 'db2' in backup mode. Let them backup from each
1747dnl other. This is not an supported operation state, but to simulate a start
1748dnl up condition where an HA manger can select which one to be an active
1749dnl server soon after.
1750AT_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])
1751on_exit 'test ! -e pid || kill `cat pid`'
1752
1753AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/connect-active-ovsdb-server])
1754
1755AT_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])
1756on_exit 'test ! -e pid2 || kill `cat pid2`'
1757
1758dnl
1759dnl make sure both servers reached the replication state
1760OVS_WAIT_UNTIL([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/sync-status |grep replicating])
1761OVS_WAIT_UNTIL([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/sync-status |grep replicating])
1762
1763dnl Switch the 'db1' to active
1764AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/disconnect-active-ovsdb-server])
1765AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/sync-status], [0], [state: active
1766])
1767
1768dnl Issue a transaction to 'db1'
1769AT_CHECK([ovsdb-client transact unix:db.sock \
1770'[["mydb",
1771 {"op": "insert",
1772 "table": "a",
1773 "row": {"number": 0, "name": "zero"}}]]'], [0], [ignore])
1774
1775dnl It should be replicated to 'db2'
1776OVS_WAIT_UNTIL([ovsdb-client dump unix:db2.sock | grep zero])
1777
1778dnl Flip the role of 'db1' and 'db2'. 'db1' becomes backup, and db2 becomes active
1779AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/disconnect-active-ovsdb-server])
1780AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/connect-active-ovsdb-server])
1781
1782dnl Verify the change happend
1783OVS_WAIT_UNTIL([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/sync-status |grep replicating])
1784AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/sync-status], [0], [state: active
1785])
1786
1787dnl Issue an transaction to 'db2' which is now active.
1788AT_CHECK([ovsdb-client transact unix:db2.sock \
1789'[["mydb",
1790 {"op": "insert",
1791 "table": "b",
1792 "row": {"number": 1, "name": "one"}}]]'], [0], [ignore])
1793
1794dnl The transaction should be replicated to 'db1'
1795OVS_WAIT_UNTIL([ovsdb-client dump unix:db.sock | grep one])
1796
1797dnl Both servers should have the same content.
1798AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout])
1799cat stdout > dump1
1800
1801AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout])
1802cat stdout > dump2
1803
1804AT_CHECK([diff dump1 dump2])
1805
1806dnl OVSDB_SERVER_SHUTDOWN
1807dnl OVSDB_SERVER_SHUTDOWN2
1808AT_CLEANUP
9c1a1182 1809
05ac209a
AZ
1810#ovsdb-server prevent self replicating
1811AT_SETUP([ovsdb-server prevent self replicating])
1812AT_KEYWORDS([ovsdb server replication])
1813replication_schema > schema
1814AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
1815
1816dnl Add some data to both DBs
1817AT_CHECK([ovsdb-tool transact db \
1818'[["mydb",
1819 {"op": "insert",
1820 "table": "a",
1821 "row": {"number": 9, "name": "nine"}}]]'], [0], [ignore], [ignore])
1822
1823dnl Start 'db', then try to be a back up server of itself.
1824AT_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])
1825on_exit 'test ! -e pid || kill `cat pid`'
1826
1827dnl Save the current content
1828AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout])
1829cp stdout dump1
1830
1831AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/connect-active-ovsdb-server])
1832dnl Check that self replicating is blocked.
1833AT_CHECK([grep "Self replicating is not allowed" ovsdb-server.log], [0], [stdout])
1834
1835dnl Check current DB content is preserved.
1836AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout])
1837cat stdout > dump2
1838
1839AT_CHECK([diff dump1 dump2])
1840AT_CLEANUP
1841
9c1a1182
LR
1842AT_SETUP([ovsdb-server/read-only db:ptcp connection])
1843AT_KEYWORDS([ovsdb server read-only])
1844AT_DATA([schema],
1845 [[{"name": "mydb",
1846 "tables": {
1847 "Root": {
1848 "columns": {
1849 "managers": {
1850 "type": {
1851 "key": {"type": "uuid", "refTable": "Manager"},
1852 "min": 0,
1853 "max": "unlimited"}}}},
1854 "Manager": {
1855 "columns": {
1856 "target": {
1857 "type": "string"},
1858 "read_only": {
1859 "type": {
1860 "key": "boolean",
1861 "min": 0,
1862 "max": 1}},
1863 "is_connected": {
1864 "type": {
1865 "key": "boolean",
1866 "min": 0,
1867 "max": 1}}}},
1868 "ordinals": {
1869 "columns": {
1870 "number": {"type": "integer"},
1871 "name": {"type": "string"}},
1872 "indexes": [["number"]]}
1873 },
1874 "version": "5.1.3",
1875 "cksum": "12345678 9"
1876}
1877]])
1878AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
1879AT_CHECK(
1880 [[ovsdb-tool transact db \
1881 '["mydb",
1882 {"op": "insert",
1883 "table": "Root",
1884 "row": {
1885 "managers": ["set", [["named-uuid", "x"]]]}},
1886 {"op": "insert",
1887 "table": "Manager",
1888 "uuid-name": "x",
1889 "row": {"target": "ptcp:0:127.0.0.1",
1890 "read_only": true}}]']], [0], [ignore], [ignore])
1891
1892AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile --remote=db:mydb,Root,managers db], [0], [ignore], [ignore])
1893PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
1894AT_CHECK([ovsdb-client get-schema-version tcp:127.0.0.1:$TCP_PORT mydb], [0], [5.1.3
1895])
1896
1897AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT \
1898 ['["mydb",
1899 {"op": "insert",
1900 "table": "ordinals",
1901 "row": {"name": "two", "number": '2'}}
1902 ]']], [0], [stdout], [ignore])
1903cat stdout >> output
c724bd67 1904AT_CHECK([uuidfilt output], [0], [[[{"details":"insert operation not allowed when database server is in read only mode","error":"not allowed"}]]
9c1a1182
LR
1905], [ignore])
1906OVSDB_SERVER_SHUTDOWN
1907AT_CLEANUP
cec7005b
NS
1908
1909AT_SETUP([ovsdb-server replication with schema mismatch])
1910AT_KEYWORDS([ovsdb server replication])
1911replication_schema > subset_schema
1912replication_schema_v2 > superset_schema
1913
1914AT_CHECK([ovsdb-tool create db1 subset_schema], [0], [stdout], [ignore])
1915AT_CHECK([ovsdb-tool create db2 superset_schema], [0], [stdout], [ignore])
1916
1917dnl Add some data to both DBs
1918AT_CHECK([ovsdb-tool transact db1 \
1919'[["mydb",
1920 {"op": "insert",
1921 "table": "a",
1922 "row": {"number": 9, "name": "nine"}}]]'], [0], [ignore], [ignore])
1923
1924AT_CHECK([ovsdb-tool transact db2 \
1925'[["mydb",
1926 {"op": "insert",
1927 "table": "a",
1928 "row": {"number": 10, "name": "ten"}}]]'], [0], [ignore], [ignore])
1929
1930dnl Start both 'db1' and 'db2'.
1931AT_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])
1932on_exit 'test ! -e pid || kill `cat pid`'
1933
1934
1935AT_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])
1936on_exit 'test ! -e pid2 || kill `cat pid2`'
1937
1938OVS_WAIT_UNTIL([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/sync-status |grep active])
1939OVS_WAIT_UNTIL([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/sync-status |grep active])
1940
1941AT_CHECK([ovsdb-client dump unix:db.sock a number name], 0, [dnl
1942a table
1943name number
1944---- ------
1945nine 9
1946])
1947
1948AT_CHECK([ovsdb-client dump unix:db2.sock a number name], 0, [dnl
1949a table
1950name number
1951---- ------
1952ten 10
1953])
1954
1955# Replicate db1 from db2. It should fail since db2 schema
1956# doesn't match with db1 and has additional tables/columns.
1957AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/set-active-ovsdb-server unix:db2.sock])
1958AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/connect-active-ovsdb-server])
1959
1960OVS_WAIT_UNTIL(
1961 [test 1 = `cat ovsdb-server1.log | grep "Schema version mismatch, checking if mydb can still be replicated or not" | wc -l]`
1962)
1963
1964OVS_WAIT_UNTIL(
1965 [test 1 = `cat ovsdb-server1.log | grep "mydb cannot be replicated" | wc -l]`
1966)
1967
1968OVS_WAIT_UNTIL([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/sync-status |grep active])
1969
1970# Replicate db2 from db1. This should be successful.
1971AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/disconnect-active-ovsdb-server])
1972AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/set-active-ovsdb-server unix:db.sock])
1973AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/connect-active-ovsdb-server])
1974
1975OVS_WAIT_UNTIL(
1976 [test 1 = `cat ovsdb-server2.log | grep "Schema version mismatch, checking if mydb can still be replicated or not" | wc -l]`
1977)
1978
1979OVS_WAIT_UNTIL(
1980 [test 1 = `cat ovsdb-server2.log | grep "mydb can be replicated" | wc -l]`
1981)
1982
1983OVS_WAIT_UNTIL([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/sync-status |grep replicating])
1984
1985AT_CHECK([ovsdb-client dump unix:db.sock a number name], 0, [dnl
1986a table
1987name number
1988---- ------
1989nine 9
1990])
1991
1992AT_CHECK([ovsdb-client dump unix:db2.sock a number name], 0, [dnl
1993a table
1994name number
1995---- ------
1996nine 9
1997])
1998
1999AT_CHECK([ovsdb-client transact unix:db.sock \
2000'[["mydb",
2001 {"op": "insert",
2002 "table": "a",
2003 "row": {"number": 6, "name": "six"}}]]'], [0], [ignore], [ignore])
2004
2005OVS_WAIT_UNTIL([test 1 = `ovsdb-client dump unix:db2.sock a number name | grep six | wc -l`])
2006
2007AT_CHECK([
2008 ovsdb-client dump unix:db2.sock a number name], 0, [dnl
2009a table
2010name number
2011---- ------
2012nine 9
2013six 6
2014])
2015
2016AT_CLEANUP