]>
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]) | |
2c487bc8 | 19 | OVS_RUNDIR=`pwd`; export OVS_RUNDIR |
39ab07af | 20 | $2 > schema |
1e19e50e BP |
21 | touch .db.~lock~ |
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]) | |
25 | cat stdout >> output | |
26 | ]) | |
5c6d0628 | 27 | AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4]) |
1e19e50e BP |
28 | AT_CLEANUP]) |
29 | ||
30 | EXECUTION_EXAMPLES | |
31 | ||
32 | AT_SETUP([transaction comments]) | |
33 | AT_KEYWORDS([ovsdb file positive]) | |
39ab07af | 34 | ordinal_schema > schema |
1e19e50e BP |
35 | touch .db.~lock~ |
36 | AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore]) | |
37 | AT_CHECK([[ovsdb-tool transact db ' | |
38 | ["ordinals", | |
39 | {"op": "insert", | |
40 | "table": "ordinals", | |
41 | "row": {"name": "five", "number": 5}}, | |
42 | {"op": "comment", | |
43 | "comment": "add row for 5"}]']], [0], [stdout], [ignore]) | |
5c6d0628 | 44 | AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], |
1e19e50e BP |
45 | [[[{"uuid":["uuid","<0>"]},{}] |
46 | ]]) | |
00961f7c | 47 | AT_CHECK([grep "add row for 5" db], [0], [ignore]) |
1e19e50e BP |
48 | AT_CLEANUP |
49 | ||
50 | AT_SETUP([ovsdb-tool compact]) | |
51 | AT_KEYWORDS([ovsdb file positive]) | |
2c487bc8 | 52 | OVS_RUNDIR=`pwd`; export OVS_RUNDIR |
39ab07af | 53 | ordinal_schema > schema |
a35ae81c BP |
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. | |
58 | mkdir dir | |
59 | : > dir/.db.~lock~ | |
60 | ln -s dir/db db | |
61 | AT_SKIP_IF([test ! -h db]) | |
1e19e50e | 62 | AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore]) |
a35ae81c BP |
63 | AT_CHECK([test ! -e .db.~lock]) |
64 | AT_CHECK([test -h db]) | |
65 | AT_CHECK([test -f dir/db]) | |
1e19e50e BP |
66 | dnl Do a bunch of random transactions that put crap in the database log. |
67 | AT_CHECK( | |
68 | [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do | |
69 | set -- $pair | |
70 | ovsdb-tool transact db ' | |
71 | ["ordinals", | |
72 | {"op": "insert", | |
73 | "table": "ordinals", | |
74 | "row": {"name": "'$1'", "number": '$2'}}, | |
75 | {"op": "comment", | |
76 | "comment": "add row for '"$pair"'"}]' | |
77 | ovsdb-tool transact db ' | |
78 | ["ordinals", | |
79 | {"op": "delete", | |
80 | "table": "ordinals", | |
81 | "where": [["number", "==", '$2']]}, | |
82 | {"op": "comment", | |
83 | "comment": "delete row for '"$2"'"}]' | |
84 | ovsdb-tool transact db ' | |
85 | ["ordinals", | |
86 | {"op": "insert", | |
87 | "table": "ordinals", | |
88 | "row": {"name": "'$1'", "number": '$2'}}, | |
89 | {"op": "comment", | |
90 | "comment": "add back row for '"$pair"'"}]' | |
91 | done]], | |
92 | [0], [stdout], [ignore]) | |
93 | dnl Check that all the crap is in fact in the database log. | |
eadd1644 | 94 | AT_CHECK([[${PERL} $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | ovstest test-json --multiple -]], [0], |
6910a6e6 | 95 | [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"} |
e86dd676 BP |
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}}} | |
1e19e50e BP |
114 | ]]) |
115 | dnl Dump out and check the actual database contents. | |
37d03458 | 116 | AT_CHECK([[ovsdb-server --unixctl="`pwd`"/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]], |
1e19e50e | 117 | [0], [stdout], [ignore]) |
5c6d0628 | 118 | AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl |
370a11b9 BP |
119 | ordinals table |
120 | _uuid name number | |
1e19e50e BP |
121 | ------------------------------------ ----- ------ |
122 | <0> five 5 @&t@ | |
123 | <1> four 4 @&t@ | |
124 | <2> one 1 @&t@ | |
125 | <3> three 3 @&t@ | |
126 | <4> two 2 @&t@ | |
127 | <5> zero 0 @&t@ | |
128 | ]) | |
129 | dnl Now compact the database in-place. | |
130 | touch .db.tmp.~lock~ | |
131 | AT_CHECK([[ovsdb-tool compact db]], [0], [], [ignore]) | |
a35ae81c BP |
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]) | |
1e19e50e BP |
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 | |
139 | dnl in it now. | |
140 | AT_CAPTURE_FILE([db]) | |
e0c7697c | 141 | AT_CHECK([test `wc -l < db` -eq 4]) |
1e19e50e | 142 | dnl And check that the dumped data is the same too: |
37d03458 | 143 | AT_CHECK([[ovsdb-server --unixctl="`pwd`"/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]], |
1e19e50e | 144 | [0], [stdout], [ignore]) |
5c6d0628 | 145 | AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl |
370a11b9 BP |
146 | ordinals table |
147 | _uuid name number | |
1e19e50e BP |
148 | ------------------------------------ ----- ------ |
149 | <0> five 5 @&t@ | |
150 | <1> four 4 @&t@ | |
151 | <2> one 1 @&t@ | |
152 | <3> three 3 @&t@ | |
153 | <4> two 2 @&t@ | |
154 | <5> zero 0 @&t@ | |
155 | ]) | |
156 | AT_CLEANUP | |
157 | ||
158 | AT_SETUP([ovsdb-tool convert -- removing a column]) | |
159 | AT_KEYWORDS([ovsdb file positive]) | |
2c487bc8 | 160 | OVS_RUNDIR=`pwd`; export OVS_RUNDIR |
39ab07af | 161 | ordinal_schema > schema |
1e19e50e BP |
162 | AT_DATA([new-schema], |
163 | [[{"name": "ordinals", | |
164 | "tables": { | |
165 | "ordinals": { | |
166 | "columns": { | |
167 | "number": {"type": "integer"}}}}} | |
168 | ]]) | |
169 | touch .db.~lock~ | |
170 | AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore]) | |
171 | dnl Put some data in the database. | |
172 | AT_CHECK( | |
173 | [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do | |
174 | set -- $pair | |
175 | ovsdb-tool transact db ' | |
176 | ["ordinals", | |
177 | {"op": "insert", | |
178 | "table": "ordinals", | |
179 | "row": {"name": "'$1'", "number": '$2'}}, | |
180 | {"op": "comment", | |
181 | "comment": "add row for '"$pair"'"}]' | |
182 | done]], | |
183 | [0], [stdout], [ignore]) | |
184 | dnl Dump out and check the actual database contents. | |
10c119c3 GS |
185 | AT_CHECK([[ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db]], |
186 | [0]) | |
187 | AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore]) | |
5c6d0628 | 188 | AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl |
370a11b9 BP |
189 | ordinals table |
190 | _uuid name number | |
1e19e50e BP |
191 | ------------------------------------ ----- ------ |
192 | <0> five 5 @&t@ | |
193 | <1> four 4 @&t@ | |
194 | <2> one 1 @&t@ | |
195 | <3> three 3 @&t@ | |
196 | <4> two 2 @&t@ | |
197 | <5> zero 0 @&t@ | |
198 | ]) | |
10c119c3 | 199 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) |
1e19e50e BP |
200 | dnl Now convert the database in-place. |
201 | touch .db.tmp.~lock~ | |
202 | AT_CHECK([[ovsdb-tool convert db new-schema]], [0], [], [ignore]) | |
203 | dnl We can't fully re-check the contents of the database log, because the | |
204 | dnl order of the records is not predictable, but there should only be 4 lines | |
205 | dnl in it now. | |
206 | AT_CAPTURE_FILE([db]) | |
e0c7697c | 207 | AT_CHECK([test `wc -l < db` -eq 4]) |
1e19e50e | 208 | dnl And check that the dumped data is the same except for the removed column: |
10c119c3 GS |
209 | AT_CHECK([[ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db]], |
210 | [0]) | |
211 | AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore]) | |
5c6d0628 | 212 | AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl |
370a11b9 BP |
213 | ordinals table |
214 | _uuid number | |
1e19e50e BP |
215 | ------------------------------------ ------ |
216 | <0> 0 @&t@ | |
217 | <1> 1 @&t@ | |
218 | <2> 2 @&t@ | |
219 | <3> 3 @&t@ | |
220 | <4> 4 @&t@ | |
221 | <5> 5 @&t@ | |
222 | ]) | |
10c119c3 | 223 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) |
1e19e50e BP |
224 | AT_CLEANUP |
225 | ||
226 | AT_SETUP([ovsdb-tool convert -- adding a column]) | |
227 | AT_KEYWORDS([ovsdb file positive]) | |
2c487bc8 | 228 | OVS_RUNDIR=`pwd`; export OVS_RUNDIR |
1e19e50e BP |
229 | AT_DATA([schema], |
230 | [[{"name": "ordinals", | |
231 | "tables": { | |
232 | "ordinals": { | |
233 | "columns": { | |
234 | "number": {"type": "integer"}}}}} | |
235 | ]]) | |
39ab07af | 236 | ordinal_schema > new-schema |
1e19e50e BP |
237 | touch .db.~lock~ |
238 | AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore]) | |
239 | dnl Put some data in the database. | |
240 | AT_CHECK( | |
241 | [[for number in 0 1 2 3 4 5; do | |
242 | ovsdb-tool transact db ' | |
243 | ["ordinals", | |
244 | {"op": "insert", | |
245 | "table": "ordinals", | |
246 | "row": {"number": '$number'}}, | |
247 | {"op": "comment", | |
248 | "comment": "add row for '"$number"'"}]' | |
249 | done]], | |
250 | [0], [stdout], [ignore]) | |
251 | dnl Dump out and check the actual database contents. | |
10c119c3 GS |
252 | AT_CHECK([[ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db]], |
253 | [0]) | |
254 | AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore]) | |
5c6d0628 | 255 | AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl |
370a11b9 BP |
256 | ordinals table |
257 | _uuid number | |
1e19e50e BP |
258 | ------------------------------------ ------ |
259 | <0> 0 @&t@ | |
260 | <1> 1 @&t@ | |
261 | <2> 2 @&t@ | |
262 | <3> 3 @&t@ | |
263 | <4> 4 @&t@ | |
264 | <5> 5 @&t@ | |
265 | ]) | |
10c119c3 | 266 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) |
1e19e50e BP |
267 | dnl Now convert the database in-place. |
268 | touch .db.tmp.~lock~ | |
269 | AT_CHECK([[ovsdb-tool convert db new-schema]], [0], [], [ignore]) | |
270 | dnl We can't fully re-check the contents of the database log, because the | |
271 | dnl order of the records is not predictable, but there should only be 4 lines | |
272 | dnl in it now. | |
273 | AT_CAPTURE_FILE([db]) | |
e0c7697c | 274 | AT_CHECK([test `wc -l < db` -eq 4]) |
1e19e50e | 275 | dnl And check that the dumped data is the same except for the added column: |
10c119c3 GS |
276 | AT_CHECK([[ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db]], |
277 | [0]) | |
278 | AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore]) | |
5c6d0628 | 279 | AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl |
370a11b9 BP |
280 | ordinals table |
281 | _uuid name number | |
1e19e50e BP |
282 | ------------------------------------ ---- ------ |
283 | <0> "" 0 @&t@ | |
284 | <1> "" 1 @&t@ | |
285 | <2> "" 2 @&t@ | |
286 | <3> "" 3 @&t@ | |
287 | <4> "" 4 @&t@ | |
288 | <5> "" 5 @&t@ | |
289 | ]) | |
10c119c3 | 290 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) |
1e19e50e | 291 | AT_CLEANUP |
8159b984 BP |
292 | |
293 | AT_SETUP([ovsdb-tool schema-version]) | |
294 | AT_KEYWORDS([ovsdb file positive]) | |
39ab07af | 295 | ordinal_schema > schema |
8159b984 BP |
296 | AT_CHECK([ovsdb-tool schema-version schema], [0], [5.1.3 |
297 | ]) | |
298 | AT_CLEANUP | |
299 | ||
300 | AT_SETUP([ovsdb-tool db-version]) | |
301 | AT_KEYWORDS([ovsdb file positive]) | |
39ab07af | 302 | ordinal_schema > schema |
8159b984 BP |
303 | touch .db.~lock~ |
304 | AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore]) | |
305 | AT_CHECK([ovsdb-tool db-version db], [0], [5.1.3 | |
306 | ]) | |
307 | AT_CLEANUP | |
6aa09313 BP |
308 | |
309 | AT_SETUP([ovsdb-tool schema-cksum]) | |
310 | AT_KEYWORDS([ovsdb file positive]) | |
39ab07af | 311 | ordinal_schema > schema |
6aa09313 BP |
312 | AT_CHECK([ovsdb-tool schema-cksum schema], [0], [12345678 9 |
313 | ]) | |
314 | AT_CLEANUP | |
315 | ||
316 | AT_SETUP([ovsdb-tool db-cksum]) | |
317 | AT_KEYWORDS([ovsdb file positive]) | |
39ab07af | 318 | ordinal_schema > schema |
6aa09313 BP |
319 | touch .db.~lock~ |
320 | AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore]) | |
321 | AT_CHECK([ovsdb-tool db-cksum db], [0], [12345678 9 | |
322 | ]) | |
323 | AT_CLEANUP | |
403e3a25 BP |
324 | |
325 | AT_SETUP([ovsdb-tool needs-conversion (no conversion needed)]) | |
326 | AT_KEYWORDS([ovsdb file positive]) | |
39ab07af | 327 | ordinal_schema > schema |
403e3a25 BP |
328 | touch .db.~lock~ |
329 | AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore]) | |
330 | AT_CHECK([ovsdb-tool needs-conversion db schema], [0], [no | |
331 | ]) | |
332 | AT_CLEANUP | |
333 | ||
334 | AT_SETUP([ovsdb-tool needs-conversion (conversion needed)]) | |
335 | AT_KEYWORDS([ovsdb file positive]) | |
39ab07af | 336 | ordinal_schema > schema |
403e3a25 BP |
337 | touch .db.~lock~ |
338 | AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore]) | |
339 | sed 's/5\.1\.3/5.1.4/' < schema > schema2 | |
340 | AT_CHECK([diff schema schema2], [1], [ignore]) | |
341 | AT_CHECK([ovsdb-tool needs-conversion db schema2], [0], [yes | |
342 | ]) | |
343 | AT_CLEANUP |