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])
19 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
22 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
23 m4_foreach([txn], [$3],
24 [AT_CHECK([ovsdb-tool transact db 'txn'], [0], [stdout], [ignore])
27 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4])
32 AT_SETUP([transaction comments])
33 AT_KEYWORDS([ovsdb file positive])
34 ordinal_schema > schema
36 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
37 AT_CHECK([[ovsdb-tool transact db '
41 "row": {"name": "five", "number": 5}},
43 "comment": "add row for 5"}]']], [0], [stdout], [ignore])
44 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0],
45 [[[{"uuid":["uuid","<0>"]},{}]
47 AT_CHECK([grep "add row for 5" db], [0], [ignore])
50 AT_SETUP([ovsdb-tool compact])
51 AT_KEYWORDS([ovsdb file positive])
52 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
53 ordinal_schema > schema
54 dnl Make sure that "ovsdb-tool create" works with a dangling symlink,
55 dnl creating the target of the symlink rather than replacing the symlink
56 dnl with a regular file, and that the lockfile gets created relative to
57 dnl the symlink's target.
61 AT_SKIP_IF([test ! -h db])
62 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
63 AT_CHECK([test ! -e .db.~lock])
64 AT_CHECK([test -h db])
65 AT_CHECK([test -f dir/db])
66 dnl Do a bunch of random transactions that put crap in the database log.
68 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
70 ovsdb-tool transact db '
74 "row": {"name": "'$1'", "number": '$2'}},
76 "comment": "add row for '"$pair"'"}]'
77 ovsdb-tool transact db '
81 "where": [["number", "==", '$2']]},
83 "comment": "delete row for '"$2"'"}]'
84 ovsdb-tool transact db '
88 "row": {"name": "'$1'", "number": '$2'}},
90 "comment": "add back row for '"$pair"'"}]'
92 [0], [stdout], [ignore])
93 dnl Check that all the crap is in fact in the database log.
94 AT_CHECK([[${PERL} $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | test-json --multiple -]], [0],
95 [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"}
96 {"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
97 {"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
98 {"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
99 {"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
100 {"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
101 {"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
102 {"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
103 {"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
104 {"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
105 {"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
106 {"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
107 {"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
108 {"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
109 {"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
110 {"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
111 {"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
112 {"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
113 {"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
115 dnl Dump out and check the actual database contents.
116 AT_CHECK([[ovsdb-server --unixctl="`pwd`"/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
117 [0], [stdout], [ignore])
118 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
121 ------------------------------------ ----- ------
129 dnl Now compact the database in-place.
131 AT_CHECK([[ovsdb-tool compact db]], [0], [], [ignore])
132 dnl Make sure that "db" is still a symlink to dir/db instead of getting
133 dnl replaced by a regular file.
134 AT_CHECK([test ! -e .db.~lock])
135 AT_CHECK([test -h db])
136 AT_CHECK([test -f dir/db])
137 dnl We can't fully re-check the contents of the database log, because the
138 dnl order of the records is not predictable, but there should only be 4 lines
140 AT_CAPTURE_FILE([db])
141 AT_CHECK([test `wc -l < db` -eq 4])
142 dnl And check that the dumped data is the same too:
143 AT_CHECK([[ovsdb-server --unixctl="`pwd`"/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
144 [0], [stdout], [ignore])
145 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
148 ------------------------------------ ----- ------
158 AT_SETUP([ovsdb-tool convert -- removing a column])
159 AT_KEYWORDS([ovsdb file positive])
160 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
161 ordinal_schema > schema
162 AT_DATA([new-schema],
163 [[{"name": "ordinals",
167 "number": {"type": "integer"}}}}}
170 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
171 dnl Put some data in the database.
173 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
175 ovsdb-tool transact db '
179 "row": {"name": "'$1'", "number": '$2'}},
181 "comment": "add row for '"$pair"'"}]'
183 [0], [stdout], [ignore])
184 dnl Dump out and check the actual database contents.
185 AT_CHECK([[ovsdb-server --unixctl="`pwd`"/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
186 [0], [stdout], [ignore])
187 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
190 ------------------------------------ ----- ------
198 dnl Now convert the database in-place.
200 AT_CHECK([[ovsdb-tool convert db new-schema]], [0], [], [ignore])
201 dnl We can't fully re-check the contents of the database log, because the
202 dnl order of the records is not predictable, but there should only be 4 lines
204 AT_CAPTURE_FILE([db])
205 AT_CHECK([test `wc -l < db` -eq 4])
206 dnl And check that the dumped data is the same except for the removed column:
207 AT_CHECK([[ovsdb-server --unixctl="`pwd`"/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
208 [0], [stdout], [ignore])
209 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
212 ------------------------------------ ------
222 AT_SETUP([ovsdb-tool convert -- adding a column])
223 AT_KEYWORDS([ovsdb file positive])
224 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
226 [[{"name": "ordinals",
230 "number": {"type": "integer"}}}}}
232 ordinal_schema > new-schema
234 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
235 dnl Put some data in the database.
237 [[for number in 0 1 2 3 4 5; do
238 ovsdb-tool transact db '
242 "row": {"number": '$number'}},
244 "comment": "add row for '"$number"'"}]'
246 [0], [stdout], [ignore])
247 dnl Dump out and check the actual database contents.
248 AT_CHECK([[ovsdb-server --unixctl="`pwd`"/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
249 [0], [stdout], [ignore])
250 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
253 ------------------------------------ ------
261 dnl Now convert the database in-place.
263 AT_CHECK([[ovsdb-tool convert db new-schema]], [0], [], [ignore])
264 dnl We can't fully re-check the contents of the database log, because the
265 dnl order of the records is not predictable, but there should only be 4 lines
267 AT_CAPTURE_FILE([db])
268 AT_CHECK([test `wc -l < db` -eq 4])
269 dnl And check that the dumped data is the same except for the added column:
270 AT_CHECK([[ovsdb-server --unixctl="`pwd`"/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
271 [0], [stdout], [ignore])
272 AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
275 ------------------------------------ ---- ------
285 AT_SETUP([ovsdb-tool schema-version])
286 AT_KEYWORDS([ovsdb file positive])
287 ordinal_schema > schema
288 AT_CHECK([ovsdb-tool schema-version schema], [0], [5.1.3
292 AT_SETUP([ovsdb-tool db-version])
293 AT_KEYWORDS([ovsdb file positive])
294 ordinal_schema > schema
296 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
297 AT_CHECK([ovsdb-tool db-version db], [0], [5.1.3
301 AT_SETUP([ovsdb-tool schema-cksum])
302 AT_KEYWORDS([ovsdb file positive])
303 ordinal_schema > schema
304 AT_CHECK([ovsdb-tool schema-cksum schema], [0], [12345678 9
308 AT_SETUP([ovsdb-tool db-cksum])
309 AT_KEYWORDS([ovsdb file positive])
310 ordinal_schema > schema
312 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
313 AT_CHECK([ovsdb-tool db-cksum db], [0], [12345678 9
317 AT_SETUP([ovsdb-tool needs-conversion (no conversion needed)])
318 AT_KEYWORDS([ovsdb file positive])
319 ordinal_schema > schema
321 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
322 AT_CHECK([ovsdb-tool needs-conversion db schema], [0], [no
326 AT_SETUP([ovsdb-tool needs-conversion (conversion needed)])
327 AT_KEYWORDS([ovsdb file positive])
328 ordinal_schema > schema
330 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
331 sed 's/5\.1\.3/5.1.4/' < schema > schema2
332 AT_CHECK([diff schema schema2], [1], [ignore])
333 AT_CHECK([ovsdb-tool needs-conversion db schema2], [0], [yes