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