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