]> git.proxmox.com Git - mirror_ovs.git/blame - tests/ovsdb-tool.at
Rename NOT_REACHED to OVS_NOT_REACHED
[mirror_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])
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])
25cat stdout >> output
26])
5c6d0628 27 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4])
1e19e50e
BP
28 AT_CLEANUP])
29
30EXECUTION_EXAMPLES
31
32AT_SETUP([transaction comments])
33AT_KEYWORDS([ovsdb file positive])
39ab07af 34ordinal_schema > schema
1e19e50e
BP
35touch .db.~lock~
36AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
37AT_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 44AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0],
1e19e50e
BP
45 [[[{"uuid":["uuid","<0>"]},{}]
46]])
00961f7c 47AT_CHECK([grep "add row for 5" db], [0], [ignore])
1e19e50e
BP
48AT_CLEANUP
49
50AT_SETUP([ovsdb-tool compact])
51AT_KEYWORDS([ovsdb file positive])
2c487bc8 52OVS_RUNDIR=`pwd`; export OVS_RUNDIR
39ab07af 53ordinal_schema > schema
a35ae81c
BP
54dnl Make sure that "ovsdb-tool create" works with a dangling symlink,
55dnl creating the target of the symlink rather than replacing the symlink
56dnl with a regular file, and that the lockfile gets created relative to
57dnl the symlink's target.
58mkdir dir
59: > dir/.db.~lock~
60ln -s dir/db db
61AT_SKIP_IF([test ! -h db])
1e19e50e 62AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
a35ae81c
BP
63AT_CHECK([test ! -e .db.~lock])
64AT_CHECK([test -h db])
65AT_CHECK([test -f dir/db])
1e19e50e
BP
66dnl Do a bunch of random transactions that put crap in the database log.
67AT_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])
93dnl Check that all the crap is in fact in the database log.
5c6d0628 94AT_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]])
115dnl Dump out and check the actual database contents.
37d03458 116AT_CHECK([[ovsdb-server --unixctl="`pwd`"/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
1e19e50e 117 [0], [stdout], [ignore])
5c6d0628 118AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
370a11b9
BP
119ordinals 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])
129dnl Now compact the database in-place.
130touch .db.tmp.~lock~
131AT_CHECK([[ovsdb-tool compact db]], [0], [], [ignore])
a35ae81c
BP
132dnl Make sure that "db" is still a symlink to dir/db instead of getting
133dnl replaced by a regular file.
134AT_CHECK([test ! -e .db.~lock])
135AT_CHECK([test -h db])
136AT_CHECK([test -f dir/db])
1e19e50e
BP
137dnl We can't fully re-check the contents of the database log, because the
138dnl order of the records is not predictable, but there should only be 4 lines
139dnl in it now.
140AT_CAPTURE_FILE([db])
e0c7697c 141AT_CHECK([test `wc -l < db` -eq 4])
1e19e50e 142dnl And check that the dumped data is the same too:
37d03458 143AT_CHECK([[ovsdb-server --unixctl="`pwd`"/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
1e19e50e 144 [0], [stdout], [ignore])
5c6d0628 145AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
370a11b9
BP
146ordinals 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])
156AT_CLEANUP
157
158AT_SETUP([ovsdb-tool convert -- removing a column])
159AT_KEYWORDS([ovsdb file positive])
2c487bc8 160OVS_RUNDIR=`pwd`; export OVS_RUNDIR
39ab07af 161ordinal_schema > schema
1e19e50e
BP
162AT_DATA([new-schema],
163 [[{"name": "ordinals",
164 "tables": {
165 "ordinals": {
166 "columns": {
167 "number": {"type": "integer"}}}}}
168]])
169touch .db.~lock~
170AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
171dnl Put some data in the database.
172AT_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])
184dnl Dump out and check the actual database contents.
37d03458 185AT_CHECK([[ovsdb-server --unixctl="`pwd`"/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
1e19e50e 186 [0], [stdout], [ignore])
5c6d0628 187AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
370a11b9
BP
188ordinals 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])
198dnl Now convert the database in-place.
199touch .db.tmp.~lock~
200AT_CHECK([[ovsdb-tool convert db new-schema]], [0], [], [ignore])
201dnl We can't fully re-check the contents of the database log, because the
202dnl order of the records is not predictable, but there should only be 4 lines
203dnl in it now.
204AT_CAPTURE_FILE([db])
e0c7697c 205AT_CHECK([test `wc -l < db` -eq 4])
1e19e50e 206dnl And check that the dumped data is the same except for the removed column:
37d03458 207AT_CHECK([[ovsdb-server --unixctl="`pwd`"/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
1e19e50e 208 [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])
220AT_CLEANUP
221
222AT_SETUP([ovsdb-tool convert -- adding a column])
223AT_KEYWORDS([ovsdb file positive])
2c487bc8 224OVS_RUNDIR=`pwd`; export OVS_RUNDIR
1e19e50e
BP
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.
37d03458 248AT_CHECK([[ovsdb-server --unixctl="`pwd`"/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
1e19e50e 249 [0], [stdout], [ignore])
5c6d0628 250AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
370a11b9
BP
251ordinals 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])
261dnl Now convert the database in-place.
262touch .db.tmp.~lock~
263AT_CHECK([[ovsdb-tool convert db new-schema]], [0], [], [ignore])
264dnl We can't fully re-check the contents of the database log, because the
265dnl order of the records is not predictable, but there should only be 4 lines
266dnl in it now.
267AT_CAPTURE_FILE([db])
e0c7697c 268AT_CHECK([test `wc -l < db` -eq 4])
1e19e50e 269dnl And check that the dumped data is the same except for the added column:
37d03458 270AT_CHECK([[ovsdb-server --unixctl="`pwd`"/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
1e19e50e 271 [0], [stdout], [ignore])
5c6d0628 272AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
370a11b9
BP
273ordinals 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])
283AT_CLEANUP
8159b984
BP
284
285AT_SETUP([ovsdb-tool schema-version])
286AT_KEYWORDS([ovsdb file positive])
39ab07af 287ordinal_schema > schema
8159b984
BP
288AT_CHECK([ovsdb-tool schema-version schema], [0], [5.1.3
289])
290AT_CLEANUP
291
292AT_SETUP([ovsdb-tool db-version])
293AT_KEYWORDS([ovsdb file positive])
39ab07af 294ordinal_schema > schema
8159b984
BP
295touch .db.~lock~
296AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
297AT_CHECK([ovsdb-tool db-version db], [0], [5.1.3
298])
299AT_CLEANUP
6aa09313
BP
300
301AT_SETUP([ovsdb-tool schema-cksum])
302AT_KEYWORDS([ovsdb file positive])
39ab07af 303ordinal_schema > schema
6aa09313
BP
304AT_CHECK([ovsdb-tool schema-cksum schema], [0], [12345678 9
305])
306AT_CLEANUP
307
308AT_SETUP([ovsdb-tool db-cksum])
309AT_KEYWORDS([ovsdb file positive])
39ab07af 310ordinal_schema > schema
6aa09313
BP
311touch .db.~lock~
312AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
313AT_CHECK([ovsdb-tool db-cksum db], [0], [12345678 9
314])
315AT_CLEANUP
403e3a25
BP
316
317AT_SETUP([ovsdb-tool needs-conversion (no conversion needed)])
318AT_KEYWORDS([ovsdb file positive])
39ab07af 319ordinal_schema > schema
403e3a25
BP
320touch .db.~lock~
321AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
322AT_CHECK([ovsdb-tool needs-conversion db schema], [0], [no
323])
324AT_CLEANUP
325
326AT_SETUP([ovsdb-tool needs-conversion (conversion needed)])
327AT_KEYWORDS([ovsdb file positive])
39ab07af 328ordinal_schema > schema
403e3a25
BP
329touch .db.~lock~
330AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
331sed 's/5\.1\.3/5.1.4/' < schema > schema2
332AT_CHECK([diff schema schema2], [1], [ignore])
333AT_CHECK([ovsdb-tool needs-conversion db schema2], [0], [yes
334])
335AT_CLEANUP