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