]>
Commit | Line | Data |
---|---|---|
1e19e50e BP |
1 | AT_BANNER([OVSDB -- ovsdb-tool]) |
2 | ||
3 | # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS]) | |
4 | # | |
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. | |
8 | # | |
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 | |
13 | # same marker. | |
14 | # | |
15 | # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS. | |
16 | m4_define([OVSDB_CHECK_EXECUTION], | |
17 | [AT_SETUP([$1]) | |
18 | AT_KEYWORDS([ovsdb file positive $5]) | |
39ab07af | 19 | $2 > schema |
1e19e50e BP |
20 | touch .db.~lock~ |
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]) | |
24 | cat stdout >> output | |
25 | ]) | |
5c6d0628 | 26 | AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4]) |
1e19e50e BP |
27 | AT_CLEANUP]) |
28 | ||
29 | EXECUTION_EXAMPLES | |
30 | ||
31 | AT_SETUP([transaction comments]) | |
32 | AT_KEYWORDS([ovsdb file positive]) | |
39ab07af | 33 | ordinal_schema > schema |
1e19e50e BP |
34 | touch .db.~lock~ |
35 | AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore]) | |
36 | AT_CHECK([[ovsdb-tool transact db ' | |
37 | ["ordinals", | |
38 | {"op": "insert", | |
39 | "table": "ordinals", | |
40 | "row": {"name": "five", "number": 5}}, | |
41 | {"op": "comment", | |
42 | "comment": "add row for 5"}]']], [0], [stdout], [ignore]) | |
5c6d0628 | 43 | AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], |
1e19e50e BP |
44 | [[[{"uuid":["uuid","<0>"]},{}] |
45 | ]]) | |
00961f7c | 46 | AT_CHECK([grep "add row for 5" db], [0], [ignore]) |
1e19e50e BP |
47 | AT_CLEANUP |
48 | ||
49 | AT_SETUP([ovsdb-tool compact]) | |
50 | AT_KEYWORDS([ovsdb file positive]) | |
39ab07af | 51 | ordinal_schema > schema |
a35ae81c BP |
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. | |
56 | mkdir dir | |
57 | : > dir/.db.~lock~ | |
1ae1933f AS |
58 | if test "$IS_WIN32" = "no"; then |
59 | ln -s dir/db db | |
60 | AT_SKIP_IF([test ! -h db]) | |
61 | fi | |
1e19e50e | 62 | AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore]) |
1ae1933f AS |
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]) | |
67 | fi | |
1e19e50e BP |
68 | dnl Do a bunch of random transactions that put crap in the database log. |
69 | AT_CHECK( | |
70 | [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do | |
71 | set -- $pair | |
72 | ovsdb-tool transact db ' | |
73 | ["ordinals", | |
74 | {"op": "insert", | |
75 | "table": "ordinals", | |
76 | "row": {"name": "'$1'", "number": '$2'}}, | |
77 | {"op": "comment", | |
78 | "comment": "add row for '"$pair"'"}]' | |
79 | ovsdb-tool transact db ' | |
80 | ["ordinals", | |
81 | {"op": "delete", | |
82 | "table": "ordinals", | |
83 | "where": [["number", "==", '$2']]}, | |
84 | {"op": "comment", | |
85 | "comment": "delete row for '"$2"'"}]' | |
86 | ovsdb-tool transact db ' | |
87 | ["ordinals", | |
88 | {"op": "insert", | |
89 | "table": "ordinals", | |
90 | "row": {"name": "'$1'", "number": '$2'}}, | |
91 | {"op": "comment", | |
92 | "comment": "add back row for '"$pair"'"}]' | |
93 | done]], | |
94 | [0], [stdout], [ignore]) | |
95 | dnl Check that all the crap is in fact in the database log. | |
eadd1644 | 96 | AT_CHECK([[${PERL} $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | ovstest test-json --multiple -]], [0], |
6910a6e6 | 97 | [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"} |
e86dd676 BP |
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}}} | |
1e19e50e | 116 | ]]) |
1ae1933f | 117 | |
1e19e50e | 118 | dnl Dump out and check the actual database contents. |
1ae1933f AS |
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]) | |
125 | ||
5c6d0628 | 126 | AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl |
370a11b9 BP |
127 | ordinals table |
128 | _uuid name number | |
1e19e50e | 129 | ------------------------------------ ----- ------ |
e51d0a1d BP |
130 | <0> five 5 |
131 | <1> four 4 | |
132 | <2> one 1 | |
133 | <3> three 3 | |
134 | <4> two 2 | |
135 | <5> zero 0 | |
1e19e50e BP |
136 | ]) |
137 | dnl Now compact the database in-place. | |
138 | touch .db.tmp.~lock~ | |
139 | AT_CHECK([[ovsdb-tool compact db]], [0], [], [ignore]) | |
a35ae81c BP |
140 | dnl Make sure that "db" is still a symlink to dir/db instead of getting |
141 | dnl replaced by a regular file. | |
1ae1933f AS |
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]) | |
146 | fi | |
1e19e50e BP |
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 | |
149 | dnl in it now. | |
150 | AT_CAPTURE_FILE([db]) | |
e0c7697c | 151 | AT_CHECK([test `wc -l < db` -eq 4]) |
1e19e50e | 152 | dnl And check that the dumped data is the same too: |
1ae1933f AS |
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]) | |
158 | ||
5c6d0628 | 159 | AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl |
370a11b9 BP |
160 | ordinals table |
161 | _uuid name number | |
1e19e50e | 162 | ------------------------------------ ----- ------ |
e51d0a1d BP |
163 | <0> five 5 |
164 | <1> four 4 | |
165 | <2> one 1 | |
166 | <3> three 3 | |
167 | <4> two 2 | |
168 | <5> zero 0 | |
1e19e50e BP |
169 | ]) |
170 | AT_CLEANUP | |
171 | ||
172 | AT_SETUP([ovsdb-tool convert -- removing a column]) | |
173 | AT_KEYWORDS([ovsdb file positive]) | |
39ab07af | 174 | ordinal_schema > schema |
1e19e50e BP |
175 | AT_DATA([new-schema], |
176 | [[{"name": "ordinals", | |
177 | "tables": { | |
178 | "ordinals": { | |
179 | "columns": { | |
180 | "number": {"type": "integer"}}}}} | |
181 | ]]) | |
182 | touch .db.~lock~ | |
183 | AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore]) | |
184 | dnl Put some data in the database. | |
185 | AT_CHECK( | |
186 | [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do | |
187 | set -- $pair | |
188 | ovsdb-tool transact db ' | |
189 | ["ordinals", | |
190 | {"op": "insert", | |
191 | "table": "ordinals", | |
192 | "row": {"name": "'$1'", "number": '$2'}}, | |
193 | {"op": "comment", | |
194 | "comment": "add row for '"$pair"'"}]' | |
195 | done]], | |
196 | [0], [stdout], [ignore]) | |
197 | dnl Dump out and check the actual database contents. | |
10c119c3 GS |
198 | AT_CHECK([[ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db]], |
199 | [0]) | |
200 | AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore]) | |
5c6d0628 | 201 | AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl |
370a11b9 BP |
202 | ordinals table |
203 | _uuid name number | |
1e19e50e | 204 | ------------------------------------ ----- ------ |
e51d0a1d BP |
205 | <0> five 5 |
206 | <1> four 4 | |
207 | <2> one 1 | |
208 | <3> three 3 | |
209 | <4> two 2 | |
210 | <5> zero 0 | |
1e19e50e | 211 | ]) |
10c119c3 | 212 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) |
1e19e50e BP |
213 | dnl Now convert the database in-place. |
214 | touch .db.tmp.~lock~ | |
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 | |
218 | dnl in it now. | |
219 | AT_CAPTURE_FILE([db]) | |
e0c7697c | 220 | AT_CHECK([test `wc -l < db` -eq 4]) |
1e19e50e | 221 | dnl And check that the dumped data is the same except for the removed column: |
10c119c3 GS |
222 | AT_CHECK([[ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db]], |
223 | [0]) | |
224 | AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore]) | |
5c6d0628 | 225 | AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl |
370a11b9 BP |
226 | ordinals table |
227 | _uuid number | |
1e19e50e | 228 | ------------------------------------ ------ |
e51d0a1d BP |
229 | <0> 0 |
230 | <1> 1 | |
231 | <2> 2 | |
232 | <3> 3 | |
233 | <4> 4 | |
234 | <5> 5 | |
1e19e50e | 235 | ]) |
10c119c3 | 236 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) |
1e19e50e BP |
237 | AT_CLEANUP |
238 | ||
239 | AT_SETUP([ovsdb-tool convert -- adding a column]) | |
240 | AT_KEYWORDS([ovsdb file positive]) | |
241 | AT_DATA([schema], | |
242 | [[{"name": "ordinals", | |
243 | "tables": { | |
244 | "ordinals": { | |
245 | "columns": { | |
246 | "number": {"type": "integer"}}}}} | |
247 | ]]) | |
39ab07af | 248 | ordinal_schema > new-schema |
1e19e50e BP |
249 | touch .db.~lock~ |
250 | AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore]) | |
251 | dnl Put some data in the database. | |
252 | AT_CHECK( | |
253 | [[for number in 0 1 2 3 4 5; do | |
254 | ovsdb-tool transact db ' | |
255 | ["ordinals", | |
256 | {"op": "insert", | |
257 | "table": "ordinals", | |
258 | "row": {"number": '$number'}}, | |
259 | {"op": "comment", | |
260 | "comment": "add row for '"$number"'"}]' | |
261 | done]], | |
262 | [0], [stdout], [ignore]) | |
263 | dnl Dump out and check the actual database contents. | |
10c119c3 GS |
264 | AT_CHECK([[ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db]], |
265 | [0]) | |
266 | AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore]) | |
5c6d0628 | 267 | AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl |
370a11b9 BP |
268 | ordinals table |
269 | _uuid number | |
1e19e50e | 270 | ------------------------------------ ------ |
e51d0a1d BP |
271 | <0> 0 |
272 | <1> 1 | |
273 | <2> 2 | |
274 | <3> 3 | |
275 | <4> 4 | |
276 | <5> 5 | |
1e19e50e | 277 | ]) |
10c119c3 | 278 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) |
1e19e50e BP |
279 | dnl Now convert the database in-place. |
280 | touch .db.tmp.~lock~ | |
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 | |
284 | dnl in it now. | |
285 | AT_CAPTURE_FILE([db]) | |
e0c7697c | 286 | AT_CHECK([test `wc -l < db` -eq 4]) |
1e19e50e | 287 | dnl And check that the dumped data is the same except for the added column: |
10c119c3 GS |
288 | AT_CHECK([[ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db]], |
289 | [0]) | |
290 | AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore]) | |
5c6d0628 | 291 | AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl |
370a11b9 BP |
292 | ordinals table |
293 | _uuid name number | |
1e19e50e | 294 | ------------------------------------ ---- ------ |
e51d0a1d BP |
295 | <0> "" 0 |
296 | <1> "" 1 | |
297 | <2> "" 2 | |
298 | <3> "" 3 | |
299 | <4> "" 4 | |
300 | <5> "" 5 | |
1e19e50e | 301 | ]) |
10c119c3 | 302 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) |
1e19e50e | 303 | AT_CLEANUP |
8159b984 BP |
304 | |
305 | AT_SETUP([ovsdb-tool schema-version]) | |
306 | AT_KEYWORDS([ovsdb file positive]) | |
39ab07af | 307 | ordinal_schema > schema |
8159b984 BP |
308 | AT_CHECK([ovsdb-tool schema-version schema], [0], [5.1.3 |
309 | ]) | |
310 | AT_CLEANUP | |
311 | ||
312 | AT_SETUP([ovsdb-tool db-version]) | |
313 | AT_KEYWORDS([ovsdb file positive]) | |
39ab07af | 314 | ordinal_schema > schema |
8159b984 BP |
315 | touch .db.~lock~ |
316 | AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore]) | |
317 | AT_CHECK([ovsdb-tool db-version db], [0], [5.1.3 | |
318 | ]) | |
319 | AT_CLEANUP | |
6aa09313 BP |
320 | |
321 | AT_SETUP([ovsdb-tool schema-cksum]) | |
322 | AT_KEYWORDS([ovsdb file positive]) | |
39ab07af | 323 | ordinal_schema > schema |
6aa09313 BP |
324 | AT_CHECK([ovsdb-tool schema-cksum schema], [0], [12345678 9 |
325 | ]) | |
326 | AT_CLEANUP | |
327 | ||
328 | AT_SETUP([ovsdb-tool db-cksum]) | |
329 | AT_KEYWORDS([ovsdb file positive]) | |
39ab07af | 330 | ordinal_schema > schema |
6aa09313 BP |
331 | touch .db.~lock~ |
332 | AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore]) | |
333 | AT_CHECK([ovsdb-tool db-cksum db], [0], [12345678 9 | |
334 | ]) | |
335 | AT_CLEANUP | |
403e3a25 BP |
336 | |
337 | AT_SETUP([ovsdb-tool needs-conversion (no conversion needed)]) | |
338 | AT_KEYWORDS([ovsdb file positive]) | |
39ab07af | 339 | ordinal_schema > schema |
403e3a25 BP |
340 | touch .db.~lock~ |
341 | AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore]) | |
342 | AT_CHECK([ovsdb-tool needs-conversion db schema], [0], [no | |
343 | ]) | |
344 | AT_CLEANUP | |
345 | ||
346 | AT_SETUP([ovsdb-tool needs-conversion (conversion needed)]) | |
347 | AT_KEYWORDS([ovsdb file positive]) | |
39ab07af | 348 | ordinal_schema > schema |
403e3a25 BP |
349 | touch .db.~lock~ |
350 | AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore]) | |
351 | sed 's/5\.1\.3/5.1.4/' < schema > schema2 | |
352 | AT_CHECK([diff schema schema2], [1], [ignore]) | |
353 | AT_CHECK([ovsdb-tool needs-conversion db schema2], [0], [yes | |
354 | ]) | |
355 | AT_CLEANUP |