]> git.proxmox.com Git - ovs.git/blame - tests/ovsdb-tool.at
ovsdb-tool: Workaround inability to replace existing file on Windows.
[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.
eadd1644 94AT_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]])
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.
10c119c3
GS
185AT_CHECK([[ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db]],
186 [0])
187AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore])
5c6d0628 188AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
370a11b9
BP
189ordinals 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 199OVS_APP_EXIT_AND_WAIT([ovsdb-server])
1e19e50e
BP
200dnl Now convert the database in-place.
201touch .db.tmp.~lock~
202AT_CHECK([[ovsdb-tool convert db new-schema]], [0], [], [ignore])
203dnl We can't fully re-check the contents of the database log, because the
204dnl order of the records is not predictable, but there should only be 4 lines
205dnl in it now.
206AT_CAPTURE_FILE([db])
e0c7697c 207AT_CHECK([test `wc -l < db` -eq 4])
1e19e50e 208dnl And check that the dumped data is the same except for the removed column:
10c119c3
GS
209AT_CHECK([[ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db]],
210 [0])
211AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore])
5c6d0628 212AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
370a11b9
BP
213ordinals 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 223OVS_APP_EXIT_AND_WAIT([ovsdb-server])
1e19e50e
BP
224AT_CLEANUP
225
226AT_SETUP([ovsdb-tool convert -- adding a column])
227AT_KEYWORDS([ovsdb file positive])
2c487bc8 228OVS_RUNDIR=`pwd`; export OVS_RUNDIR
1e19e50e
BP
229AT_DATA([schema],
230 [[{"name": "ordinals",
231 "tables": {
232 "ordinals": {
233 "columns": {
234 "number": {"type": "integer"}}}}}
235]])
39ab07af 236ordinal_schema > new-schema
1e19e50e
BP
237touch .db.~lock~
238AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
239dnl Put some data in the database.
240AT_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])
251dnl Dump out and check the actual database contents.
10c119c3
GS
252AT_CHECK([[ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db]],
253 [0])
254AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore])
5c6d0628 255AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
370a11b9
BP
256ordinals 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 266OVS_APP_EXIT_AND_WAIT([ovsdb-server])
1e19e50e
BP
267dnl Now convert the database in-place.
268touch .db.tmp.~lock~
269AT_CHECK([[ovsdb-tool convert db new-schema]], [0], [], [ignore])
270dnl We can't fully re-check the contents of the database log, because the
271dnl order of the records is not predictable, but there should only be 4 lines
272dnl in it now.
273AT_CAPTURE_FILE([db])
e0c7697c 274AT_CHECK([test `wc -l < db` -eq 4])
1e19e50e 275dnl And check that the dumped data is the same except for the added column:
10c119c3
GS
276AT_CHECK([[ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db]],
277 [0])
278AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore])
5c6d0628 279AT_CHECK([${PERL} $srcdir/uuidfilt.pl stdout], [0], [dnl
370a11b9
BP
280ordinals 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 290OVS_APP_EXIT_AND_WAIT([ovsdb-server])
1e19e50e 291AT_CLEANUP
8159b984
BP
292
293AT_SETUP([ovsdb-tool schema-version])
294AT_KEYWORDS([ovsdb file positive])
39ab07af 295ordinal_schema > schema
8159b984
BP
296AT_CHECK([ovsdb-tool schema-version schema], [0], [5.1.3
297])
298AT_CLEANUP
299
300AT_SETUP([ovsdb-tool db-version])
301AT_KEYWORDS([ovsdb file positive])
39ab07af 302ordinal_schema > schema
8159b984
BP
303touch .db.~lock~
304AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
305AT_CHECK([ovsdb-tool db-version db], [0], [5.1.3
306])
307AT_CLEANUP
6aa09313
BP
308
309AT_SETUP([ovsdb-tool schema-cksum])
310AT_KEYWORDS([ovsdb file positive])
39ab07af 311ordinal_schema > schema
6aa09313
BP
312AT_CHECK([ovsdb-tool schema-cksum schema], [0], [12345678 9
313])
314AT_CLEANUP
315
316AT_SETUP([ovsdb-tool db-cksum])
317AT_KEYWORDS([ovsdb file positive])
39ab07af 318ordinal_schema > schema
6aa09313
BP
319touch .db.~lock~
320AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
321AT_CHECK([ovsdb-tool db-cksum db], [0], [12345678 9
322])
323AT_CLEANUP
403e3a25
BP
324
325AT_SETUP([ovsdb-tool needs-conversion (no conversion needed)])
326AT_KEYWORDS([ovsdb file positive])
39ab07af 327ordinal_schema > schema
403e3a25
BP
328touch .db.~lock~
329AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
330AT_CHECK([ovsdb-tool needs-conversion db schema], [0], [no
331])
332AT_CLEANUP
333
334AT_SETUP([ovsdb-tool needs-conversion (conversion needed)])
335AT_KEYWORDS([ovsdb file positive])
39ab07af 336ordinal_schema > schema
403e3a25
BP
337touch .db.~lock~
338AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
339sed 's/5\.1\.3/5.1.4/' < schema > schema2
340AT_CHECK([diff schema schema2], [1], [ignore])
341AT_CHECK([ovsdb-tool needs-conversion db schema2], [0], [yes
342])
343AT_CLEANUP