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