1 AT_BANNER([OVSDB -- ovsdb-tool])
3 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
5 # Creates a database with the given SCHEMA and runs each of the
6 # TRANSACTIONS (which should be a quoted list of quoted strings)
7 # against it with ovsdb-tool one at a time.
9 # Checks that the overall output is OUTPUT, but UUIDs in the output
10 # are replaced by markers of the form <N> where N is a number. The
11 # first unique UUID is replaced by <0>, the next by <1>, and so on.
12 # If a given UUID appears more than once it is always replaced by the
15 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
16 m4_define([OVSDB_CHECK_EXECUTION],
18 AT_KEYWORDS([ovsdb file positive $5])
21 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
22 m4_foreach([txn], [$3],
23 [AT_CHECK([ovsdb-tool transact db 'txn'], [0], [stdout], [ignore])
26 AT_CHECK([uuidfilt output], [0], [$4])
31 AT_SETUP([transaction comments])
32 AT_KEYWORDS([ovsdb file positive])
33 ordinal_schema > schema
35 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
36 AT_CHECK([[ovsdb-tool transact db '
40 "row": {"name": "five", "number": 5}},
42 "comment": "add row for 5"}]']], [0], [stdout], [ignore])
43 AT_CHECK([uuidfilt stdout], [0],
44 [[[{"uuid":["uuid","<0>"]},{}]
46 AT_CHECK([grep "add row for 5" db], [0], [ignore])
49 AT_SETUP([ovsdb-tool compact])
50 AT_KEYWORDS([ovsdb file positive])
51 ordinal_schema > schema
52 dnl Make sure that "ovsdb-tool create" works with a dangling symlink,
53 dnl creating the target of the symlink rather than replacing the symlink
54 dnl with a regular file, and that the lockfile gets created relative to
55 dnl the symlink's target.
58 if test "$IS_WIN32" = "no"; then
60 AT_SKIP_IF([test ! -h db])
62 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
63 if test "$IS_WIN32" = "no"; then
64 AT_CHECK([test ! -e .db.~lock])
65 AT_CHECK([test -h db])
66 AT_CHECK([test -f dir/db])
68 dnl Do a bunch of random transactions that put crap in the database log.
70 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
72 ovsdb-tool transact db '
76 "row": {"name": "'$1'", "number": '$2'}},
78 "comment": "add row for '"$pair"'"}]'
79 ovsdb-tool transact db '
83 "where": [["number", "==", '$2']]},
85 "comment": "delete row for '"$2"'"}]'
86 ovsdb-tool transact db '
90 "row": {"name": "'$1'", "number": '$2'}},
92 "comment": "add back row for '"$pair"'"}]'
94 [0], [stdout], [ignore])
95 dnl Check that all the crap is in fact in the database log.
96 AT_CHECK([[uuidfilt db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | ovstest test-json --multiple -]], [0],
97 [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"}
98 {"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
99 {"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
100 {"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
101 {"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
102 {"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
103 {"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
104 {"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
105 {"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
106 {"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
107 {"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
108 {"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
109 {"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
110 {"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
111 {"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
112 {"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
113 {"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
114 {"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
115 {"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
118 dnl Dump out and check the actual database contents.
119 on_exit 'kill `cat ovsdb-server.pid`'
120 AT_CHECK([[ovsdb-server --detach --pidfile --no-chdir --remote=punix:socket db]],
121 [0], [stdout], [ignore])
122 AT_CHECK([[ovsdb-client dump unix:socket ordinals]],
123 [0], [stdout], [ignore])
124 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
126 AT_CHECK([uuidfilt stdout], [0], [dnl
129 ------------------------------------ ----- ------
137 dnl Now compact the database in-place.
139 AT_CHECK([[ovsdb-tool compact db]], [0], [], [ignore])
140 dnl Make sure that "db" is still a symlink to dir/db instead of getting
141 dnl replaced by a regular file.
142 if test "$IS_WIN32" = "no"; then
143 AT_CHECK([test ! -e .db.~lock])
144 AT_CHECK([test -h db])
145 AT_CHECK([test -f dir/db])
147 dnl We can't fully re-check the contents of the database log, because the
148 dnl order of the records is not predictable, but there should only be 4 lines
150 AT_CAPTURE_FILE([db])
151 AT_CHECK([test `wc -l < db` -eq 4])
152 dnl And check that the dumped data is the same too:
153 AT_CHECK([[ovsdb-server --detach --pidfile --no-chdir --remote=punix:socket db]],
154 [0], [stdout], [ignore])
155 AT_CHECK([[ovsdb-client dump unix:socket ordinals]],
156 [0], [stdout], [ignore])
157 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
159 AT_CHECK([uuidfilt stdout], [0], [dnl
162 ------------------------------------ ----- ------
172 AT_SETUP([ovsdb-tool convert -- removing a column])
173 AT_KEYWORDS([ovsdb file positive])
174 ordinal_schema > schema
175 AT_DATA([new-schema],
176 [[{"name": "ordinals",
180 "number": {"type": "integer"}}}}}
183 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
184 dnl Put some data in the database.
186 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
188 ovsdb-tool transact db '
192 "row": {"name": "'$1'", "number": '$2'}},
194 "comment": "add row for '"$pair"'"}]'
196 [0], [stdout], [ignore])
197 dnl Dump out and check the actual database contents.
198 AT_CHECK([[ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db]],
200 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore])
201 AT_CHECK([uuidfilt stdout], [0], [dnl
204 ------------------------------------ ----- ------
212 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
213 dnl Now convert the database in-place.
215 AT_CHECK([[ovsdb-tool convert db new-schema]], [0], [], [ignore])
216 dnl We can't fully re-check the contents of the database log, because the
217 dnl order of the records is not predictable, but there should only be 4 lines
219 AT_CAPTURE_FILE([db])
220 AT_CHECK([test `wc -l < db` -eq 4])
221 dnl And check that the dumped data is the same except for the removed column:
222 AT_CHECK([[ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db]],
224 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore])
225 AT_CHECK([uuidfilt stdout], [0], [dnl
228 ------------------------------------ ------
236 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
239 AT_SETUP([ovsdb-tool convert -- adding a column])
240 AT_KEYWORDS([ovsdb file positive])
242 [[{"name": "ordinals",
246 "number": {"type": "integer"}}}}}
248 ordinal_schema > new-schema
250 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
251 dnl Put some data in the database.
253 [[for number in 0 1 2 3 4 5; do
254 ovsdb-tool transact db '
258 "row": {"number": '$number'}},
260 "comment": "add row for '"$number"'"}]'
262 [0], [stdout], [ignore])
263 dnl Dump out and check the actual database contents.
264 AT_CHECK([[ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db]],
266 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore])
267 AT_CHECK([uuidfilt stdout], [0], [dnl
270 ------------------------------------ ------
278 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
279 dnl Now convert the database in-place.
281 AT_CHECK([[ovsdb-tool convert db new-schema]], [0], [], [ignore])
282 dnl We can't fully re-check the contents of the database log, because the
283 dnl order of the records is not predictable, but there should only be 4 lines
285 AT_CAPTURE_FILE([db])
286 AT_CHECK([test `wc -l < db` -eq 4])
287 dnl And check that the dumped data is the same except for the added column:
288 AT_CHECK([[ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db]],
290 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore])
291 AT_CHECK([uuidfilt stdout], [0], [dnl
294 ------------------------------------ ---- ------
302 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
305 AT_SETUP([ovsdb-tool unsupported cluster operations])
306 AT_KEYWORDS([ovsdb file negative compact query transact convert])
307 ordinal_schema > schema
308 AT_CHECK([ovsdb-tool create-cluster db schema unix:s1.raft])
309 AT_CHECK([ovsdb-tool compact db], [1], [], [ovsdb-tool: ovsdb error: db: cannot apply this operation to clustered database file
311 AT_CHECK([ovsdb-tool convert db schema], [1], [], [ovsdb-tool: ovsdb error: db: cannot apply this operation to clustered database file
313 AT_CHECK([ovsdb-tool needs-conversion db schema], [1], [], [ovsdb-tool: ovsdb error: db: cannot apply this operation to clustered database file
315 AT_CHECK([ovsdb-tool query db '[[]]'], [1], [], [ovsdb-tool: ovsdb error: db: cannot apply this operation to clustered database file
317 AT_CHECK([ovsdb-tool transact db '[[]]'], [1], [], [ovsdb-tool: ovsdb error: db: cannot apply this operation to clustered database file
321 AT_SETUP([ovsdb-tool schema-version, schema-cksum, schema-name])
322 AT_KEYWORDS([ovsdb file positive schema-version schema-cksum])
323 ordinal_schema > schema
324 AT_CHECK([ovsdb-tool schema-version schema], [0], [5.1.3
326 AT_CHECK([ovsdb-tool schema-cksum schema], [0], [12345678 9
328 AT_CHECK([ovsdb-tool schema-name schema], [0], [ordinals
332 AT_SETUP([ovsdb-tool database inspection commands - standalone])
333 AT_KEYWORDS([ovsdb file positive db-version db-cksum db-name db-cid db-sid db-local-address])
334 ordinal_schema > schema
336 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
337 AT_CHECK([ovsdb-tool db-version db], [0], [5.1.3
339 AT_CHECK([ovsdb-tool db-cksum db], [0], [12345678 9
341 AT_CHECK([ovsdb-tool db-name db], [0], [ordinals
343 AT_CHECK([ovsdb-tool db-cid db], [1], [], [ovsdb-tool: db: not a clustered database
345 AT_CHECK([ovsdb-tool db-sid db], [1], [], [ovsdb-tool: db: not a clustered database
347 AT_CHECK([ovsdb-tool db-local-address db], [1], [], [ovsdb-tool: db: not a clustered database
351 AT_SETUP([ovsdb-tool database inspection commands - clustered])
352 AT_KEYWORDS([ovsdb file negative db-version db-cksum db-name db-cid db-sid db-local-address cluster])
353 ordinal_schema > schema
355 AT_CHECK([ovsdb-tool create-cluster db schema tcp:1.2.3.4:1234])
356 AT_CHECK([ovsdb-tool db-version db], [1], [], [ovsdb-tool: ovsdb error: db: cannot apply this operation to clustered database file
358 AT_CHECK([ovsdb-tool db-cksum db], [1], [], [ovsdb-tool: ovsdb error: db: cannot apply this operation to clustered database file
360 AT_CHECK([ovsdb-tool db-name db], [0], [ordinals
362 AT_CHECK([(ovsdb-tool db-cid db; ovsdb-tool db-sid db) | uuidfilt], [0], [<0>
365 AT_CHECK([ovsdb-tool db-local-address db], [0], [tcp:1.2.3.4:1234
369 AT_SETUP([ovsdb-tool database inspection commands - joining a cluster])
370 AT_KEYWORDS([ovsdb file positive db-version db-cksum db-name db-cid db-sid db-local-address cluster join joining])
371 ordinal_schema > schema
373 for cid in '' 520cf525-3772-43cc-8268-23bf5b548cf4; do
374 if test -z "$cid"; then
377 cid_option=--cid=$cid
379 AT_CHECK([rm -f db && ovsdb-tool $cid_option join-cluster db ordinals tcp:1.2.3.4:1234 tcp:2.3.4.5:1234], [0], [], [ignore])
380 AT_CHECK([ovsdb-tool db-version db], [1], [], [ovsdb-tool: ovsdb error: db: cannot apply this operation to clustered database file
382 AT_CHECK([ovsdb-tool db-cksum db], [1], [], [ovsdb-tool: ovsdb error: db: cannot apply this operation to clustered database file
384 AT_CHECK([ovsdb-tool db-name db], [0], [ordinals
386 if test -z "$cid"; then
387 AT_CHECK([ovsdb-tool db-cid db], [2], [], [db: cluster ID not yet known
390 AT_CHECK_UNQUOTED([ovsdb-tool db-cid db], [0], [$cid
393 AT_CHECK([ovsdb-tool db-sid db | uuidfilt], [0], [<0>
395 AT_CHECK([ovsdb-tool db-local-address db], [0], [tcp:1.2.3.4:1234
400 AT_SETUP([ovsdb-tool needs-conversion (no conversion needed)])
401 AT_KEYWORDS([ovsdb file positive])
402 ordinal_schema > schema
404 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
405 AT_CHECK([ovsdb-tool needs-conversion db schema], [0], [no
409 AT_SETUP([ovsdb-tool needs-conversion (conversion needed)])
410 AT_KEYWORDS([ovsdb file positive])
411 ordinal_schema > schema
413 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
414 sed 's/5\.1\.3/5.1.4/' < schema > schema2
415 AT_CHECK([diff schema schema2], [1], [ignore])
416 AT_CHECK([ovsdb-tool needs-conversion db schema2], [0], [yes
420 AT_SETUP([ovsdb-tool create-cluster with initial data])
421 AT_KEYWORDS([ovsdb file positive])
423 # Create a standalone database and put some data in it.
424 ordinal_schema > schema
425 ovsdb-tool create db1 schema
427 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
429 ovsdb-tool transact db1 '
433 "row": {"name": "'$1'", "number": '$2'}},
435 "comment": "add row for '"$pair"'"}]'
436 done | uuidfilt]], [0],
437 [[[{"uuid":["uuid","<0>"]},{}]
438 [{"uuid":["uuid","<1>"]},{}]
439 [{"uuid":["uuid","<2>"]},{}]
440 [{"uuid":["uuid","<3>"]},{}]
441 [{"uuid":["uuid","<4>"]},{}]
442 [{"uuid":["uuid","<5>"]},{}]
446 AT_CHECK([ovsdb-server -vfile -vvlog:off --detach --no-chdir --pidfile --log-file --remote=punix:db.sock db1])
447 AT_CHECK([ovsdb-client dump > expout])
448 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
450 # Create a clustered database from the standalone one.
451 ovsdb-tool create-cluster db2 db1 unix:s1.raft
454 AT_CHECK([ovsdb-server -vconsole:off -vfile -vvlog:off --detach --no-chdir --pidfile --log-file --remote=punix:db.sock db2])
455 AT_CHECK([ovsdb-client wait ordinals connected])
456 AT_CHECK([ovsdb-client dump > dump2])
457 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
459 # Make sure that the clustered data matched the standalone data.
460 AT_CHECK([cat dump2], [0], [expout])