]> git.proxmox.com Git - ovs.git/blame - tests/ovsdb-tool.at
ofp-prop: Add generic functions for working with 16- and 32-bit properties.
[ovs.git] / tests / ovsdb-tool.at
CommitLineData
1e19e50e
BP
1AT_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.
16m4_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])
24cat stdout >> output
25])
5c6d0628 26 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4])
1e19e50e
BP
27 AT_CLEANUP])
28
29EXECUTION_EXAMPLES
30
31AT_SETUP([transaction comments])
32AT_KEYWORDS([ovsdb file positive])
39ab07af 33ordinal_schema > schema
1e19e50e
BP
34touch .db.~lock~
35AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
36AT_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 43AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0],
1e19e50e
BP
44 [[[{"uuid":["uuid","<0>"]},{}]
45]])
00961f7c 46AT_CHECK([grep "add row for 5" db], [0], [ignore])
1e19e50e
BP
47AT_CLEANUP
48
49AT_SETUP([ovsdb-tool compact])
50AT_KEYWORDS([ovsdb file positive])
39ab07af 51ordinal_schema > schema
a35ae81c
BP
52dnl Make sure that "ovsdb-tool create" works with a dangling symlink,
53dnl creating the target of the symlink rather than replacing the symlink
54dnl with a regular file, and that the lockfile gets created relative to
55dnl the symlink's target.
56mkdir dir
57: > dir/.db.~lock~
58ln -s dir/db db
59AT_SKIP_IF([test ! -h db])
1e19e50e 60AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
a35ae81c
BP
61AT_CHECK([test ! -e .db.~lock])
62AT_CHECK([test -h db])
63AT_CHECK([test -f dir/db])
1e19e50e
BP
64dnl Do a bunch of random transactions that put crap in the database log.
65AT_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])
91dnl Check that all the crap is in fact in the database log.
eadd1644 92AT_CHECK([[${PERL} $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | ovstest test-json --multiple -]], [0],
6910a6e6 93 [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"}
e86dd676
BP
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}}}
1e19e50e
BP
112]])
113dnl Dump out and check the actual database contents.
37d03458 114AT_CHECK([[ovsdb-server --unixctl="`pwd`"/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
1e19e50e 115 [0], [stdout], [ignore])
5c6d0628 116AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
370a11b9
BP
117ordinals table
118_uuid name number
1e19e50e
BP
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])
127dnl Now compact the database in-place.
128touch .db.tmp.~lock~
129AT_CHECK([[ovsdb-tool compact db]], [0], [], [ignore])
a35ae81c
BP
130dnl Make sure that "db" is still a symlink to dir/db instead of getting
131dnl replaced by a regular file.
132AT_CHECK([test ! -e .db.~lock])
133AT_CHECK([test -h db])
134AT_CHECK([test -f dir/db])
1e19e50e
BP
135dnl We can't fully re-check the contents of the database log, because the
136dnl order of the records is not predictable, but there should only be 4 lines
137dnl in it now.
138AT_CAPTURE_FILE([db])
e0c7697c 139AT_CHECK([test `wc -l < db` -eq 4])
1e19e50e 140dnl And check that the dumped data is the same too:
37d03458 141AT_CHECK([[ovsdb-server --unixctl="`pwd`"/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
1e19e50e 142 [0], [stdout], [ignore])
5c6d0628 143AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
370a11b9
BP
144ordinals table
145_uuid name number
1e19e50e
BP
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])
154AT_CLEANUP
155
156AT_SETUP([ovsdb-tool convert -- removing a column])
157AT_KEYWORDS([ovsdb file positive])
39ab07af 158ordinal_schema > schema
1e19e50e
BP
159AT_DATA([new-schema],
160 [[{"name": "ordinals",
161 "tables": {
162 "ordinals": {
163 "columns": {
164 "number": {"type": "integer"}}}}}
165]])
166touch .db.~lock~
167AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
168dnl Put some data in the database.
169AT_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])
181dnl Dump out and check the actual database contents.
10c119c3
GS
182AT_CHECK([[ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db]],
183 [0])
184AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore])
5c6d0628 185AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
370a11b9
BP
186ordinals table
187_uuid name number
1e19e50e
BP
188------------------------------------ ----- ------
189<0> five 5 @&t@
190<1> four 4 @&t@
191<2> one 1 @&t@
192<3> three 3 @&t@
193<4> two 2 @&t@
194<5> zero 0 @&t@
195])
10c119c3 196OVS_APP_EXIT_AND_WAIT([ovsdb-server])
1e19e50e
BP
197dnl Now convert the database in-place.
198touch .db.tmp.~lock~
199AT_CHECK([[ovsdb-tool convert db new-schema]], [0], [], [ignore])
200dnl We can't fully re-check the contents of the database log, because the
201dnl order of the records is not predictable, but there should only be 4 lines
202dnl in it now.
203AT_CAPTURE_FILE([db])
e0c7697c 204AT_CHECK([test `wc -l < db` -eq 4])
1e19e50e 205dnl And check that the dumped data is the same except for the removed column:
10c119c3
GS
206AT_CHECK([[ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db]],
207 [0])
208AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore])
5c6d0628 209AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
370a11b9
BP
210ordinals 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])
10c119c3 220OVS_APP_EXIT_AND_WAIT([ovsdb-server])
1e19e50e
BP
221AT_CLEANUP
222
223AT_SETUP([ovsdb-tool convert -- adding a column])
224AT_KEYWORDS([ovsdb file positive])
225AT_DATA([schema],
226 [[{"name": "ordinals",
227 "tables": {
228 "ordinals": {
229 "columns": {
230 "number": {"type": "integer"}}}}}
231]])
39ab07af 232ordinal_schema > new-schema
1e19e50e
BP
233touch .db.~lock~
234AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
235dnl Put some data in the database.
236AT_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])
247dnl Dump out and check the actual database contents.
10c119c3
GS
248AT_CHECK([[ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db]],
249 [0])
250AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore])
5c6d0628 251AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
370a11b9
BP
252ordinals table
253_uuid number
1e19e50e
BP
254------------------------------------ ------
255<0> 0 @&t@
256<1> 1 @&t@
257<2> 2 @&t@
258<3> 3 @&t@
259<4> 4 @&t@
260<5> 5 @&t@
261])
10c119c3 262OVS_APP_EXIT_AND_WAIT([ovsdb-server])
1e19e50e
BP
263dnl Now convert the database in-place.
264touch .db.tmp.~lock~
265AT_CHECK([[ovsdb-tool convert db new-schema]], [0], [], [ignore])
266dnl We can't fully re-check the contents of the database log, because the
267dnl order of the records is not predictable, but there should only be 4 lines
268dnl in it now.
269AT_CAPTURE_FILE([db])
e0c7697c 270AT_CHECK([test `wc -l < db` -eq 4])
1e19e50e 271dnl And check that the dumped data is the same except for the added column:
10c119c3
GS
272AT_CHECK([[ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db]],
273 [0])
274AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore])
5c6d0628 275AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
370a11b9
BP
276ordinals table
277_uuid name number
1e19e50e
BP
278------------------------------------ ---- ------
279<0> "" 0 @&t@
280<1> "" 1 @&t@
281<2> "" 2 @&t@
282<3> "" 3 @&t@
283<4> "" 4 @&t@
284<5> "" 5 @&t@
285])
10c119c3 286OVS_APP_EXIT_AND_WAIT([ovsdb-server])
1e19e50e 287AT_CLEANUP
8159b984
BP
288
289AT_SETUP([ovsdb-tool schema-version])
290AT_KEYWORDS([ovsdb file positive])
39ab07af 291ordinal_schema > schema
8159b984
BP
292AT_CHECK([ovsdb-tool schema-version schema], [0], [5.1.3
293])
294AT_CLEANUP
295
296AT_SETUP([ovsdb-tool db-version])
297AT_KEYWORDS([ovsdb file positive])
39ab07af 298ordinal_schema > schema
8159b984
BP
299touch .db.~lock~
300AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
301AT_CHECK([ovsdb-tool db-version db], [0], [5.1.3
302])
303AT_CLEANUP
6aa09313
BP
304
305AT_SETUP([ovsdb-tool schema-cksum])
306AT_KEYWORDS([ovsdb file positive])
39ab07af 307ordinal_schema > schema
6aa09313
BP
308AT_CHECK([ovsdb-tool schema-cksum schema], [0], [12345678 9
309])
310AT_CLEANUP
311
312AT_SETUP([ovsdb-tool db-cksum])
313AT_KEYWORDS([ovsdb file positive])
39ab07af 314ordinal_schema > schema
6aa09313
BP
315touch .db.~lock~
316AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
317AT_CHECK([ovsdb-tool db-cksum db], [0], [12345678 9
318])
319AT_CLEANUP
403e3a25
BP
320
321AT_SETUP([ovsdb-tool needs-conversion (no conversion needed)])
322AT_KEYWORDS([ovsdb file positive])
39ab07af 323ordinal_schema > schema
403e3a25
BP
324touch .db.~lock~
325AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
326AT_CHECK([ovsdb-tool needs-conversion db schema], [0], [no
327])
328AT_CLEANUP
329
330AT_SETUP([ovsdb-tool needs-conversion (conversion needed)])
331AT_KEYWORDS([ovsdb file positive])
39ab07af 332ordinal_schema > schema
403e3a25
BP
333touch .db.~lock~
334AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
335sed 's/5\.1\.3/5.1.4/' < schema > schema2
336AT_CHECK([diff schema schema2], [1], [ignore])
337AT_CHECK([ovsdb-tool needs-conversion db schema2], [0], [yes
338])
339AT_CLEANUP