]> git.proxmox.com Git - mirror_ovs.git/blob - tests/ovsdb-tool.at
Avoid using "grep -q" outside of GNU/Linux specific utilities.
[mirror_ovs.git] / tests / ovsdb-tool.at
1 AT_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.
16 m4_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])
25 cat stdout >> output
26 ])
27 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4])
28 AT_CLEANUP])
29
30 EXECUTION_EXAMPLES
31
32 AT_SETUP([transaction comments])
33 AT_KEYWORDS([ovsdb file positive])
34 AT_DATA([schema], [ORDINAL_SCHEMA
35 ])
36 touch .db.~lock~
37 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
38 AT_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])
45 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0],
46 [[[{"uuid":["uuid","<0>"]},{}]
47 ]])
48 AT_CHECK([grep "add row for 5" db], [0], [ignore])
49 AT_CLEANUP
50
51 AT_SETUP([ovsdb-tool compact])
52 AT_KEYWORDS([ovsdb file positive])
53 AT_DATA([schema], [ORDINAL_SCHEMA
54 ])
55 touch .db.~lock~
56 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
57 dnl Do a bunch of random transactions that put crap in the database log.
58 AT_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])
84 dnl Check that all the crap is in fact in the database log.
85 AT_CHECK([[perl $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | test-json --multiple -]], [0],
86 [[{"name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}}}}}
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}}}
105 ]])
106 dnl Dump out and check the actual database contents.
107 AT_CHECK([[ovsdb-server --unixctl=$PWD/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
108 [0], [stdout], [ignore])
109 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
110 ordinals table
111 _uuid name number
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 ])
120 dnl Now compact the database in-place.
121 touch .db.tmp.~lock~
122 AT_CHECK([[ovsdb-tool compact db]], [0], [], [ignore])
123 dnl We can't fully re-check the contents of the database log, because the
124 dnl order of the records is not predictable, but there should only be 4 lines
125 dnl in it now.
126 AT_CAPTURE_FILE([db])
127 AT_CHECK([wc -l < db], [0], [4
128 ])
129 dnl And check that the dumped data is the same too:
130 AT_CHECK([[ovsdb-server --unixctl=$PWD/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
131 [0], [stdout], [ignore])
132 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
133 ordinals table
134 _uuid name number
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 ])
143 AT_CLEANUP
144
145 AT_SETUP([ovsdb-tool convert -- removing a column])
146 AT_KEYWORDS([ovsdb file positive])
147 AT_DATA([schema], [ORDINAL_SCHEMA
148 ])
149 AT_DATA([new-schema],
150 [[{"name": "ordinals",
151 "tables": {
152 "ordinals": {
153 "columns": {
154 "number": {"type": "integer"}}}}}
155 ]])
156 touch .db.~lock~
157 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
158 dnl Put some data in the database.
159 AT_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])
171 dnl Dump out and check the actual database contents.
172 AT_CHECK([[ovsdb-server --unixctl=$PWD/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
173 [0], [stdout], [ignore])
174 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
175 ordinals table
176 _uuid name number
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 ])
185 dnl Now convert the database in-place.
186 touch .db.tmp.~lock~
187 AT_CHECK([[ovsdb-tool convert db new-schema]], [0], [], [ignore])
188 dnl We can't fully re-check the contents of the database log, because the
189 dnl order of the records is not predictable, but there should only be 4 lines
190 dnl in it now.
191 AT_CAPTURE_FILE([db])
192 AT_CHECK([wc -l < db], [0], [4
193 ])
194 dnl And check that the dumped data is the same except for the removed column:
195 AT_CHECK([[ovsdb-server --unixctl=$PWD/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
196 [0], [stdout], [ignore])
197 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
198 ordinals table
199 _uuid number
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 ])
208 AT_CLEANUP
209
210 AT_SETUP([ovsdb-tool convert -- adding a column])
211 AT_KEYWORDS([ovsdb file positive])
212 AT_DATA([schema],
213 [[{"name": "ordinals",
214 "tables": {
215 "ordinals": {
216 "columns": {
217 "number": {"type": "integer"}}}}}
218 ]])
219 AT_DATA([new-schema], [ORDINAL_SCHEMA
220 ])
221 touch .db.~lock~
222 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
223 dnl Put some data in the database.
224 AT_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])
235 dnl Dump out and check the actual database contents.
236 AT_CHECK([[ovsdb-server --unixctl=$PWD/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
237 [0], [stdout], [ignore])
238 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
239 ordinals table
240 _uuid number
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 ])
249 dnl Now convert the database in-place.
250 touch .db.tmp.~lock~
251 AT_CHECK([[ovsdb-tool convert db new-schema]], [0], [], [ignore])
252 dnl We can't fully re-check the contents of the database log, because the
253 dnl order of the records is not predictable, but there should only be 4 lines
254 dnl in it now.
255 AT_CAPTURE_FILE([db])
256 AT_CHECK([wc -l < db], [0], [4
257 ])
258 dnl And check that the dumped data is the same except for the added column:
259 AT_CHECK([[ovsdb-server --unixctl=$PWD/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
260 [0], [stdout], [ignore])
261 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
262 ordinals table
263 _uuid name number
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 ])
272 AT_CLEANUP