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([perl $srcdir/uuidfilt.pl 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([perl $srcdir/uuidfilt.pl 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
53 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
54 dnl Do a bunch of random transactions that put crap in the database log.
56 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
58 ovsdb-tool transact db '
62 "row": {"name": "'$1'", "number": '$2'}},
64 "comment": "add row for '"$pair"'"}]'
65 ovsdb-tool transact db '
69 "where": [["number", "==", '$2']]},
71 "comment": "delete row for '"$2"'"}]'
72 ovsdb-tool transact db '
76 "row": {"name": "'$1'", "number": '$2'}},
78 "comment": "add back row for '"$pair"'"}]'
80 [0], [stdout], [ignore])
81 dnl Check that all the crap is in fact in the database log.
82 AT_CHECK([[perl $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | test-json --multiple -]], [0],
83 [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"}
84 {"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
85 {"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
86 {"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
87 {"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
88 {"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
89 {"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
90 {"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
91 {"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
92 {"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
93 {"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
94 {"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
95 {"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
96 {"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
97 {"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
98 {"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
99 {"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
100 {"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
101 {"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
103 dnl Dump out and check the actual database contents.
104 AT_CHECK([[ovsdb-server --unixctl="`pwd`"/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
105 [0], [stdout], [ignore])
106 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
109 ------------------------------------ ----- ------
117 dnl Now compact the database in-place.
119 AT_CHECK([[ovsdb-tool compact db]], [0], [], [ignore])
120 dnl We can't fully re-check the contents of the database log, because the
121 dnl order of the records is not predictable, but there should only be 4 lines
123 AT_CAPTURE_FILE([db])
124 AT_CHECK([test `wc -l < db` -eq 4])
125 dnl And check that the dumped data is the same too:
126 AT_CHECK([[ovsdb-server --unixctl="`pwd`"/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
127 [0], [stdout], [ignore])
128 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
131 ------------------------------------ ----- ------
141 AT_SETUP([ovsdb-tool convert -- removing a column])
142 AT_KEYWORDS([ovsdb file positive])
143 ordinal_schema > schema
144 AT_DATA([new-schema],
145 [[{"name": "ordinals",
149 "number": {"type": "integer"}}}}}
152 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
153 dnl Put some data in the database.
155 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
157 ovsdb-tool transact db '
161 "row": {"name": "'$1'", "number": '$2'}},
163 "comment": "add row for '"$pair"'"}]'
165 [0], [stdout], [ignore])
166 dnl Dump out and check the actual database contents.
167 AT_CHECK([[ovsdb-server --unixctl="`pwd`"/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
168 [0], [stdout], [ignore])
169 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
172 ------------------------------------ ----- ------
180 dnl Now convert the database in-place.
182 AT_CHECK([[ovsdb-tool convert db new-schema]], [0], [], [ignore])
183 dnl We can't fully re-check the contents of the database log, because the
184 dnl order of the records is not predictable, but there should only be 4 lines
186 AT_CAPTURE_FILE([db])
187 AT_CHECK([test `wc -l < db` -eq 4])
188 dnl And check that the dumped data is the same except for the removed column:
189 AT_CHECK([[ovsdb-server --unixctl="`pwd`"/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
190 [0], [stdout], [ignore])
191 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
194 ------------------------------------ ------
204 AT_SETUP([ovsdb-tool convert -- adding a column])
205 AT_KEYWORDS([ovsdb file positive])
207 [[{"name": "ordinals",
211 "number": {"type": "integer"}}}}}
213 ordinal_schema > new-schema
215 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
216 dnl Put some data in the database.
218 [[for number in 0 1 2 3 4 5; do
219 ovsdb-tool transact db '
223 "row": {"number": '$number'}},
225 "comment": "add row for '"$number"'"}]'
227 [0], [stdout], [ignore])
228 dnl Dump out and check the actual database contents.
229 AT_CHECK([[ovsdb-server --unixctl="`pwd`"/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
230 [0], [stdout], [ignore])
231 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
234 ------------------------------------ ------
242 dnl Now convert the database in-place.
244 AT_CHECK([[ovsdb-tool convert db new-schema]], [0], [], [ignore])
245 dnl We can't fully re-check the contents of the database log, because the
246 dnl order of the records is not predictable, but there should only be 4 lines
248 AT_CAPTURE_FILE([db])
249 AT_CHECK([test `wc -l < db` -eq 4])
250 dnl And check that the dumped data is the same except for the added column:
251 AT_CHECK([[ovsdb-server --unixctl="`pwd`"/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
252 [0], [stdout], [ignore])
253 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
256 ------------------------------------ ---- ------
266 AT_SETUP([ovsdb-tool schema-version])
267 AT_KEYWORDS([ovsdb file positive])
268 ordinal_schema > schema
269 AT_CHECK([ovsdb-tool schema-version schema], [0], [5.1.3
273 AT_SETUP([ovsdb-tool db-version])
274 AT_KEYWORDS([ovsdb file positive])
275 ordinal_schema > schema
277 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
278 AT_CHECK([ovsdb-tool db-version db], [0], [5.1.3
282 AT_SETUP([ovsdb-tool schema-cksum])
283 AT_KEYWORDS([ovsdb file positive])
284 ordinal_schema > schema
285 AT_CHECK([ovsdb-tool schema-cksum schema], [0], [12345678 9
289 AT_SETUP([ovsdb-tool db-cksum])
290 AT_KEYWORDS([ovsdb file positive])
291 ordinal_schema > schema
293 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
294 AT_CHECK([ovsdb-tool db-cksum db], [0], [12345678 9
298 AT_SETUP([ovsdb-tool needs-conversion (no conversion needed)])
299 AT_KEYWORDS([ovsdb file positive])
300 ordinal_schema > schema
302 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
303 AT_CHECK([ovsdb-tool needs-conversion db schema], [0], [no
307 AT_SETUP([ovsdb-tool needs-conversion (conversion needed)])
308 AT_KEYWORDS([ovsdb file positive])
309 ordinal_schema > schema
311 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
312 sed 's/5\.1\.3/5.1.4/' < schema > schema2
313 AT_CHECK([diff schema schema2], [1], [ignore])
314 AT_CHECK([ovsdb-tool needs-conversion db schema2], [0], [yes