]> git.proxmox.com Git - ovs.git/blob - tests/ovsdb-server.at
tests: Update expected test result to match "ovsdb-client dump" changes.
[ovs.git] / tests / ovsdb-server.at
1 AT_BANNER([OVSDB -- ovsdb-server transactions (Unix sockets)])
2
3 m4_define([OVSDB_SERVER_SHUTDOWN],
4 [cp pid savepid
5 AT_CHECK([ovs-appctl -t $PWD/unixctl -e exit], [0], [ignore], [ignore])
6 OVS_WAIT_WHILE([kill -0 `cat savepid`], [kill `cat savepid`])])
7
8 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
9 #
10 # Creates a database with the given SCHEMA, starts an ovsdb-server on
11 # that database, and runs each of the TRANSACTIONS (which should be a
12 # quoted list of quoted strings) against it with ovsdb-client one at a
13 # time.
14 #
15 # Checks that the overall output is OUTPUT, but UUIDs in the output
16 # are replaced by markers of the form <N> where N is a number. The
17 # first unique UUID is replaced by <0>, the next by <1>, and so on.
18 # If a given UUID appears more than once it is always replaced by the
19 # same marker.
20 #
21 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
22 m4_define([OVSDB_CHECK_EXECUTION],
23 [AT_SETUP([$1])
24 AT_KEYWORDS([ovsdb server positive unix $5])
25 AT_DATA([schema], [$2
26 ])
27 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
28 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --remote=punix:socket --unixctl=$PWD/unixctl db], [0], [ignore], [ignore])
29 m4_foreach([txn], [$3],
30 [AT_CHECK([ovsdb-client transact unix:socket 'txn'], [0], [stdout], [ignore],
31 [test ! -e pid || kill `cat pid`])
32 cat stdout >> output
33 ])
34 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
35 [test ! -e pid || kill `cat pid`])
36 OVSDB_SERVER_SHUTDOWN
37 AT_CLEANUP])
38
39 EXECUTION_EXAMPLES
40 \f
41 AT_SETUP([database multiplexing implementation])
42 AT_KEYWORDS([ovsdb server positive])
43 AT_DATA([schema], [ORDINAL_SCHEMA
44 ])
45 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
46 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --unixctl=$PWD/unixctl --remote=punix:socket db], [0], [ignore], [ignore])
47 AT_CHECK(
48 [[ovsdb-client list-dbs unix:socket]],
49 [0], [ordinals
50 ], [ignore], [test ! -e pid || kill `cat pid`])
51 AT_CHECK(
52 [[ovsdb-client get-schema unix:socket nonexistent]],
53 [1], [], [[ovsdb-client: syntax "{"details":"get_schema request specifies unknown database nonexistent","error":"unknown database","syntax":"[\"nonexistent\"]"}": syntax error: Parsing database schema failed: Required 'name' member is missing.
54 ]], [test ! -e pid || kill `cat pid`])
55 OVSDB_SERVER_SHUTDOWN
56 AT_CLEANUP
57
58 AT_SETUP([--remote=db: implementation])
59 AT_KEYWORDS([ovsdb server positive])
60 AT_DATA([schema],
61 [[{"name": "mydb",
62 "tables": {
63 "Manager": {
64 "columns": {
65 "manager": {"type": "string"}}}}}
66 ]])
67 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
68 AT_CHECK(
69 [[ovsdb-tool transact db \
70 '["mydb",
71 {"op": "insert",
72 "table": "Manager",
73 "row": {"manager": "punix:socket"}}]']], [0], [ignore], [ignore])
74 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --remote=db:Manager,manager --unixctl=$PWD/unixctl db], [0], [ignore], [ignore])
75 AT_CHECK(
76 [[ovsdb-client transact unix:socket \
77 '["mydb",
78 {"op": "select",
79 "table": "Manager",
80 "where": [],
81 "columns": ["manager"]}]']],
82 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
83 AT_CHECK(
84 [perl $srcdir/uuidfilt.pl stdout],
85 [0],
86 [[[{"rows":[{"manager":"punix:socket"}]}]
87 ]],
88 [ignore],
89 [test ! -e pid || kill `cat pid`])
90 OVSDB_SERVER_SHUTDOWN
91 AT_CLEANUP
92
93 AT_SETUP([SSL db: implementation])
94 AT_KEYWORDS([ovsdb server positive ssl $5])
95 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
96 AT_SKIP_IF([test "x$RANDOM" = x])
97 SSL_PORT=`expr 32767 + \( $RANDOM % 32767 \)`
98 PKIDIR=$abs_top_srcdir/tests
99 AT_SKIP_IF([expr "$PKIDIR" : ".*[ '\"
100 \\]"])
101 AT_DATA([schema],
102 [[{"name": "mydb",
103 "tables": {
104 "SSL": {
105 "columns": {
106 "private_key": {"type": "string"},
107 "certificate": {"type": "string"},
108 "ca_cert": {"type": "string"}}}}}
109 ]])
110 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
111 AT_CHECK(
112 [[ovsdb-tool transact db \
113 '["mydb",
114 {"op": "insert",
115 "table": "SSL",
116 "row": {"private_key": "'"$PKIDIR/testpki-privkey2.pem"'",
117 "certificate": "'"$PKIDIR/testpki-cert2.pem"'",
118 "ca_cert": "'"$PKIDIR/testpki-cacert.pem"'"}}]']],
119 [0], [ignore], [ignore])
120 AT_CHECK(
121 [ovsdb-server --detach --pidfile=$PWD/pid \
122 --private-key=db:SSL,private_key \
123 --certificate=db:SSL,certificate \
124 --ca-cert=db:SSL,ca_cert \
125 --remote=pssl:$SSL_PORT:127.0.0.1 --unixctl=$PWD/unixctl db],
126 [0], [ignore], [ignore])
127 AT_CHECK(
128 [[ovsdb-client \
129 --private-key=$PKIDIR/testpki-privkey.pem \
130 --certificate=$PKIDIR/testpki-cert.pem \
131 --ca-cert=$PKIDIR/testpki-cacert.pem \
132 transact ssl:127.0.0.1:$SSL_PORT \
133 '["mydb",
134 {"op": "select",
135 "table": "SSL",
136 "where": [],
137 "columns": ["private_key"]}]']],
138 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
139 cat stdout >> output
140 AT_CHECK_UNQUOTED(
141 [perl $srcdir/uuidfilt.pl output], [0],
142 [[[{"rows":[{"private_key":"$PKIDIR/testpki-privkey2.pem"}]}]
143 ]], [ignore], [test ! -e pid || kill `cat pid`])
144 OVSDB_SERVER_SHUTDOWN
145 AT_CLEANUP
146
147 AT_SETUP([compacting online])
148 AT_KEYWORDS([ovsdb server compact])
149 AT_DATA([schema], [ORDINAL_SCHEMA
150 ])
151 touch .db.~lock~
152 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
153 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --unixctl=$PWD/unixctl --remote=punix:socket --log-file=$PWD/ovsdb-server.log db], [0], [ignore], [ignore])
154 AT_CAPTURE_FILE([ovsdb-server.log])
155 dnl Do a bunch of random transactions that put crap in the database log.
156 AT_CHECK(
157 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
158 set -- $pair
159 ovsdb-client transact unix:socket '
160 ["ordinals",
161 {"op": "insert",
162 "table": "ordinals",
163 "row": {"name": "'$1'", "number": '$2'}},
164 {"op": "comment",
165 "comment": "add row for '"$pair"'"}]'
166 ovsdb-client transact unix:socket '
167 ["ordinals",
168 {"op": "delete",
169 "table": "ordinals",
170 "where": [["number", "==", '$2']]},
171 {"op": "comment",
172 "comment": "delete row for '"$2"'"}]'
173 ovsdb-client transact unix:socket '
174 ["ordinals",
175 {"op": "insert",
176 "table": "ordinals",
177 "row": {"name": "'$1'", "number": '$2'}},
178 {"op": "comment",
179 "comment": "add back row for '"$pair"'"}]'
180 done]],
181 [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
182 dnl Check that all the crap is in fact in the database log.
183 AT_CHECK([[perl $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | test-json --multiple -]], [0],
184 [[{"name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}}}}}
185 {"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
186 {"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
187 {"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
188 {"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
189 {"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
190 {"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
191 {"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
192 {"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
193 {"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
194 {"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
195 {"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
196 {"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
197 {"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
198 {"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
199 {"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
200 {"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
201 {"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
202 {"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
203 ]], [], [test ! -e pid || kill `cat pid`])
204 dnl Dump out and check the actual database contents.
205 AT_CHECK([[ovsdb-client dump unix:socket ordinals]],
206 [0], [stdout], [ignore])
207 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
208 ordinals table
209 _uuid name number
210 ------------------------------------ ----- ------
211 <0> five 5 @&t@
212 <1> four 4 @&t@
213 <2> one 1 @&t@
214 <3> three 3 @&t@
215 <4> two 2 @&t@
216 <5> zero 0 @&t@
217 ], [], [test ! -e pid || kill `cat pid`])
218 dnl Now compact the database in-place.
219 AT_CHECK([[ovs-appctl -t $PWD/unixctl ovsdb-server/compact]],
220 [0], [], [ignore], [test ! -e pid || kill `cat pid`])
221 dnl We can't fully re-check the contents of the database log, because the
222 dnl order of the records is not predictable, but there should only be 4 lines
223 dnl in it now.
224 AT_CAPTURE_FILE([db])
225 AT_CHECK([wc -l < db], [0], [4
226 ], [], [test ! -e pid || kill `cat pid`])
227 dnl And check that the dumped data is the same too:
228 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
229 [test ! -e pid || kill `cat pid`])
230 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
231 ordinals table
232 _uuid name number
233 ------------------------------------ ----- ------
234 <0> five 5 @&t@
235 <1> four 4 @&t@
236 <2> one 1 @&t@
237 <3> three 3 @&t@
238 <4> two 2 @&t@
239 <5> zero 0 @&t@
240 ], [], [test ! -e pid || kill `cat pid`])
241 dnl Now do some more transactions.
242 AT_CHECK(
243 [[ovsdb-client transact unix:socket '
244 ["ordinals",
245 {"op": "delete",
246 "table": "ordinals",
247 "where": [["number", "<", 3]]}]']],
248 [0], [[[{"count":3}]
249 ]], [ignore], [test ! -e pid || kill `cat pid`])
250 dnl There should be 6 lines in the log now.
251 AT_CHECK([wc -l < db], [0], [6
252 ], [], [test ! -e pid || kill `cat pid`])
253 dnl Then check that the dumped data is correct.
254 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
255 [test ! -e pid || kill `cat pid`])
256 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
257 ordinals table
258 _uuid name number
259 ------------------------------------ ----- ------
260 <0> five 5 @&t@
261 <1> four 4 @&t@
262 <2> three 3 @&t@
263 ], [], [test ! -e pid || kill `cat pid`])
264 OVSDB_SERVER_SHUTDOWN
265 AT_CLEANUP
266 \f
267 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL sockets)])
268
269 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
270 #
271 # Creates a database with the given SCHEMA, starts an ovsdb-server on
272 # that database, and runs each of the TRANSACTIONS (which should be a
273 # quoted list of quoted strings) against it with ovsdb-client one at a
274 # time.
275 #
276 # Checks that the overall output is OUTPUT, but UUIDs in the output
277 # are replaced by markers of the form <N> where N is a number. The
278 # first unique UUID is replaced by <0>, the next by <1>, and so on.
279 # If a given UUID appears more than once it is always replaced by the
280 # same marker.
281 #
282 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
283 m4_define([OVSDB_CHECK_EXECUTION],
284 [AT_SETUP([$1])
285 AT_KEYWORDS([ovsdb server positive ssl $5])
286 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
287 AT_SKIP_IF([test "x$RANDOM" = x])
288 AT_DATA([schema], [$2
289 ])
290 SSL_PORT=`expr 32767 + \( $RANDOM % 32767 \)`
291 PKIDIR=$abs_top_srcdir/tests
292 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
293 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --private-key=$PKIDIR/testpki-privkey2.pem --certificate=$PKIDIR/testpki-cert2.pem --ca-cert=$PKIDIR/testpki-cacert.pem --remote=pssl:$SSL_PORT:127.0.0.1 --unixctl=$PWD/unixctl db], [0], [ignore], [ignore])
294 m4_foreach([txn], [$3],
295 [AT_CHECK([ovsdb-client --private-key=$PKIDIR/testpki-privkey.pem --certificate=$PKIDIR/testpki-cert.pem --ca-cert=$PKIDIR/testpki-cacert.pem transact ssl:127.0.0.1:$SSL_PORT 'txn'], [0], [stdout], [ignore],
296 [test ! -e pid || kill `cat pid`])
297 cat stdout >> output
298 ])
299 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
300 [test ! -e pid || kill `cat pid`])
301 OVSDB_SERVER_SHUTDOWN
302 AT_CLEANUP])
303
304 EXECUTION_EXAMPLES
305 \f
306 AT_BANNER([OVSDB -- transactions on transient ovsdb-server])
307
308 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
309 #
310 # Creates a database with the given SCHEMA and runs each of the
311 # TRANSACTIONS (which should be a quoted list of quoted strings)
312 # against it with ovsdb-client one at a time. Each ovsdb-client
313 # is run against a separately started ovsdb-server that executes
314 # only that single transaction. (The idea is that this should
315 # help to ferret out any differences between what ovsdb-server has
316 # in memory and what actually gets committed to disk.)
317 #
318 # Checks that the overall output is OUTPUT, but UUIDs in the output
319 # are replaced by markers of the form <N> where N is a number. The
320 # first unique UUID is replaced by <0>, the next by <1>, and so on.
321 # If a given UUID appears more than once it is always replaced by the
322 # same marker.
323 #
324 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
325 m4_define([OVSDB_CHECK_EXECUTION],
326 [AT_SETUP([$1])
327 AT_KEYWORDS([ovsdb server positive transient $5])
328 AT_DATA([schema], [$2
329 ])
330 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
331 m4_foreach([txn], [$3],
332 [AT_DATA([txnfile], [ovsdb-client transact unix:socket 'txn'
333 ])
334 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl=$PWD/unixctl db --run="sh txnfile"], [0], [stdout], [ignore])
335 cat stdout >> output
336 ])
337 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore])
338 AT_CLEANUP])
339
340 EXECUTION_EXAMPLES