]>
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. | |
5c6d0628 | 94 | AT_CHECK([[${PERL} $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | 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. | |
37d03458 | 185 | AT_CHECK([[ovsdb-server --unixctl="`pwd`"/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]], |
1e19e50e | 186 | [0], [stdout], [ignore]) |
5c6d0628 | 187 | AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl |
370a11b9 BP |
188 | ordinals table |
189 | _uuid name number | |
1e19e50e BP |
190 | ------------------------------------ ----- ------ |
191 | <0> five 5 @&t@ | |
192 | <1> four 4 @&t@ | |
193 | <2> one 1 @&t@ | |
194 | <3> three 3 @&t@ | |
195 | <4> two 2 @&t@ | |
196 | <5> zero 0 @&t@ | |
197 | ]) | |
198 | dnl Now convert the database in-place. | |
199 | touch .db.tmp.~lock~ | |
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 | |
203 | dnl in it now. | |
204 | AT_CAPTURE_FILE([db]) | |
e0c7697c | 205 | AT_CHECK([test `wc -l < db` -eq 4]) |
1e19e50e | 206 | dnl And check that the dumped data is the same except for the removed column: |
37d03458 | 207 | AT_CHECK([[ovsdb-server --unixctl="`pwd`"/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]], |
1e19e50e | 208 | [0], [stdout], [ignore]) |
5c6d0628 | 209 | AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl |
370a11b9 BP |
210 | ordinals table |
211 | _uuid number | |
1e19e50e BP |
212 | ------------------------------------ ------ |
213 | <0> 0 @&t@ | |
214 | <1> 1 @&t@ | |
215 | <2> 2 @&t@ | |
216 | <3> 3 @&t@ | |
217 | <4> 4 @&t@ | |
218 | <5> 5 @&t@ | |
219 | ]) | |
220 | AT_CLEANUP | |
221 | ||
222 | AT_SETUP([ovsdb-tool convert -- adding a column]) | |
223 | AT_KEYWORDS([ovsdb file positive]) | |
2c487bc8 | 224 | OVS_RUNDIR=`pwd`; export OVS_RUNDIR |
1e19e50e BP |
225 | AT_DATA([schema], |
226 | [[{"name": "ordinals", | |
227 | "tables": { | |
228 | "ordinals": { | |
229 | "columns": { | |
230 | "number": {"type": "integer"}}}}} | |
231 | ]]) | |
39ab07af | 232 | ordinal_schema > new-schema |
1e19e50e BP |
233 | touch .db.~lock~ |
234 | AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore]) | |
235 | dnl Put some data in the database. | |
236 | AT_CHECK( | |
237 | [[for number in 0 1 2 3 4 5; do | |
238 | ovsdb-tool transact db ' | |
239 | ["ordinals", | |
240 | {"op": "insert", | |
241 | "table": "ordinals", | |
242 | "row": {"number": '$number'}}, | |
243 | {"op": "comment", | |
244 | "comment": "add row for '"$number"'"}]' | |
245 | done]], | |
246 | [0], [stdout], [ignore]) | |
247 | dnl Dump out and check the actual database contents. | |
37d03458 | 248 | AT_CHECK([[ovsdb-server --unixctl="`pwd`"/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]], |
1e19e50e | 249 | [0], [stdout], [ignore]) |
5c6d0628 | 250 | AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl |
370a11b9 BP |
251 | ordinals table |
252 | _uuid number | |
1e19e50e BP |
253 | ------------------------------------ ------ |
254 | <0> 0 @&t@ | |
255 | <1> 1 @&t@ | |
256 | <2> 2 @&t@ | |
257 | <3> 3 @&t@ | |
258 | <4> 4 @&t@ | |
259 | <5> 5 @&t@ | |
260 | ]) | |
261 | dnl Now convert the database in-place. | |
262 | touch .db.tmp.~lock~ | |
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 | |
266 | dnl in it now. | |
267 | AT_CAPTURE_FILE([db]) | |
e0c7697c | 268 | AT_CHECK([test `wc -l < db` -eq 4]) |
1e19e50e | 269 | dnl And check that the dumped data is the same except for the added column: |
37d03458 | 270 | AT_CHECK([[ovsdb-server --unixctl="`pwd`"/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]], |
1e19e50e | 271 | [0], [stdout], [ignore]) |
5c6d0628 | 272 | AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl |
370a11b9 BP |
273 | ordinals table |
274 | _uuid name number | |
1e19e50e BP |
275 | ------------------------------------ ---- ------ |
276 | <0> "" 0 @&t@ | |
277 | <1> "" 1 @&t@ | |
278 | <2> "" 2 @&t@ | |
279 | <3> "" 3 @&t@ | |
280 | <4> "" 4 @&t@ | |
281 | <5> "" 5 @&t@ | |
282 | ]) | |
283 | AT_CLEANUP | |
8159b984 BP |
284 | |
285 | AT_SETUP([ovsdb-tool schema-version]) | |
286 | AT_KEYWORDS([ovsdb file positive]) | |
39ab07af | 287 | ordinal_schema > schema |
8159b984 BP |
288 | AT_CHECK([ovsdb-tool schema-version schema], [0], [5.1.3 |
289 | ]) | |
290 | AT_CLEANUP | |
291 | ||
292 | AT_SETUP([ovsdb-tool db-version]) | |
293 | AT_KEYWORDS([ovsdb file positive]) | |
39ab07af | 294 | ordinal_schema > schema |
8159b984 BP |
295 | touch .db.~lock~ |
296 | AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore]) | |
297 | AT_CHECK([ovsdb-tool db-version db], [0], [5.1.3 | |
298 | ]) | |
299 | AT_CLEANUP | |
6aa09313 BP |
300 | |
301 | AT_SETUP([ovsdb-tool schema-cksum]) | |
302 | AT_KEYWORDS([ovsdb file positive]) | |
39ab07af | 303 | ordinal_schema > schema |
6aa09313 BP |
304 | AT_CHECK([ovsdb-tool schema-cksum schema], [0], [12345678 9 |
305 | ]) | |
306 | AT_CLEANUP | |
307 | ||
308 | AT_SETUP([ovsdb-tool db-cksum]) | |
309 | AT_KEYWORDS([ovsdb file positive]) | |
39ab07af | 310 | ordinal_schema > schema |
6aa09313 BP |
311 | touch .db.~lock~ |
312 | AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore]) | |
313 | AT_CHECK([ovsdb-tool db-cksum db], [0], [12345678 9 | |
314 | ]) | |
315 | AT_CLEANUP | |
403e3a25 BP |
316 | |
317 | AT_SETUP([ovsdb-tool needs-conversion (no conversion needed)]) | |
318 | AT_KEYWORDS([ovsdb file positive]) | |
39ab07af | 319 | ordinal_schema > schema |
403e3a25 BP |
320 | touch .db.~lock~ |
321 | AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore]) | |
322 | AT_CHECK([ovsdb-tool needs-conversion db schema], [0], [no | |
323 | ]) | |
324 | AT_CLEANUP | |
325 | ||
326 | AT_SETUP([ovsdb-tool needs-conversion (conversion needed)]) | |
327 | AT_KEYWORDS([ovsdb file positive]) | |
39ab07af | 328 | ordinal_schema > schema |
403e3a25 BP |
329 | touch .db.~lock~ |
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 | |
334 | ]) | |
335 | AT_CLEANUP |