dff19ecc56f649c341be301093da1419647a3c7e
[sliver-openvswitch.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([truncating corrupted database log])
42 AT_KEYWORDS([ovsdb server positive unix])
43 AT_DATA([schema], [ORDINAL_SCHEMA
44 ])
45 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
46 dnl Do one transaction and save the output.
47 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
48 '["ordinals",
49   {"op": "insert",
50    "table": "ordinals",
51    "row": {"number": 0, "name": "zero"}}]'
52 ]])
53 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl=$PWD/unixctl db --run="sh txnfile"], [0], [stdout], [])
54 cat stdout >> output
55 dnl Add some crap to the database log and run another transaction, which should
56 dnl ignore the crap and truncate it out of the log.
57 echo 'xxx' >> db
58 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
59 '["ordinals",
60   {"op": "insert",
61    "table": "ordinals",
62    "row": {"number": 1, "name": "one"}}]'
63 ]])
64 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl=$PWD/unixctl db --run="sh txnfile"], [0], [stdout], [stderr])
65 AT_CHECK([grep 'syntax error: db: parse error.* in header line "xxx"' stderr],
66   [0], [ignore])
67 cat stdout >> output
68 dnl Run a final transaction to verify that both transactions succeeeded.
69 dnl The crap that we added should have been truncated by the previous run,
70 dnl so ovsdb-server shouldn't log a warning this time.
71 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
72 '["ordinals",
73   {"op": "select",
74    "table": "ordinals",
75    "where": [],
76    "sort": ["number"]}]'
77 ]])
78 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl=$PWD/unixctl db --run="sh txnfile"], [0], [stdout], [])
79 cat stdout >> output
80 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0],
81   [[[{"uuid":["uuid","<0>"]}]
82 [{"uuid":["uuid","<1>"]}]
83 [{"rows":[{"_uuid":["uuid","<0>"],"_version":["uuid","<2>"],"name":"zero","number":0},{"_uuid":["uuid","<1>"],"_version":["uuid","<3>"],"name":"one","number":1}]}]
84 ]], [],
85          [test ! -e pid || kill `cat pid`])
86 AT_CLEANUP
87
88 AT_SETUP([ovsdb-client get-schema-version])
89 AT_KEYWORDS([ovsdb server positive])
90 AT_DATA([schema], [ORDINAL_SCHEMA
91 ])
92 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
93 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --unixctl=$PWD/unixctl --remote=punix:socket db], [0], [ignore], [ignore])
94 AT_CHECK([ovsdb-client get-schema-version unix:socket ordinals], [0], [5.1.3
95 ])
96 OVSDB_SERVER_SHUTDOWN
97 AT_CLEANUP
98
99 AT_SETUP([database multiplexing implementation])
100 AT_KEYWORDS([ovsdb server positive])
101 AT_DATA([schema], [ORDINAL_SCHEMA
102 ])
103 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
104 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --unixctl=$PWD/unixctl --remote=punix:socket db], [0], [ignore], [ignore])
105 AT_CHECK(
106   [[ovsdb-client list-dbs unix:socket]], 
107   [0], [ordinals
108 ], [ignore], [test ! -e pid || kill `cat pid`])
109 AT_CHECK(
110   [[ovsdb-client get-schema unix:socket nonexistent]], 
111   [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.
112 ]], [test ! -e pid || kill `cat pid`])
113 OVSDB_SERVER_SHUTDOWN
114 AT_CLEANUP
115
116 AT_SETUP([--remote=db: implementation])
117 AT_KEYWORDS([ovsdb server positive])
118 AT_DATA([schema],
119   [[{"name": "mydb",
120      "tables": {
121        "Manager": {
122          "columns": {
123            "manager": {"type": "string"}}}}}
124 ]])
125 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
126 AT_CHECK(
127   [[ovsdb-tool transact db \
128      '["mydb",
129        {"op": "insert",
130         "table": "Manager",
131         "row": {"manager": "punix:socket"}}]']], [0], [ignore], [ignore])
132 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --remote=db:Manager,manager --unixctl=$PWD/unixctl db], [0], [ignore], [ignore])
133 AT_CHECK(
134   [[ovsdb-client transact unix:socket \
135      '["mydb",
136        {"op": "select",
137         "table": "Manager",
138         "where": [],
139         "columns": ["manager"]}]']], 
140   [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
141 AT_CHECK(
142   [perl $srcdir/uuidfilt.pl stdout], 
143   [0], 
144   [[[{"rows":[{"manager":"punix:socket"}]}]
145 ]], 
146   [ignore], 
147   [test ! -e pid || kill `cat pid`])
148 OVSDB_SERVER_SHUTDOWN
149 AT_CLEANUP
150
151 AT_SETUP([SSL db: implementation])
152 AT_KEYWORDS([ovsdb server positive ssl $5])
153 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
154 AT_SKIP_IF([test "x$RANDOM" = x])
155 SSL_PORT=`expr 32767 + \( $RANDOM % 32767 \)`
156 PKIDIR=$abs_top_builddir/tests
157 AT_SKIP_IF([expr "$PKIDIR" : ".*[       '\"
158 \r\\]"])
159 AT_DATA([schema],
160   [[{"name": "mydb",
161      "tables": {
162        "SSL": {
163          "columns": {
164            "private_key": {"type": "string"},
165            "certificate": {"type": "string"},
166            "ca_cert": {"type": "string"}}}}}
167 ]])
168 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
169 AT_CHECK(
170   [[ovsdb-tool transact db \
171      '["mydb",
172        {"op": "insert",
173         "table": "SSL",
174         "row": {"private_key": "'"$PKIDIR/testpki-privkey2.pem"'",
175                 "certificate": "'"$PKIDIR/testpki-cert2.pem"'",
176                 "ca_cert": "'"$PKIDIR/testpki-cacert.pem"'"}}]']],
177   [0], [ignore], [ignore])
178 AT_CHECK(
179   [ovsdb-server --detach --pidfile=$PWD/pid \
180         --private-key=db:SSL,private_key \
181         --certificate=db:SSL,certificate \
182         --ca-cert=db:SSL,ca_cert \
183          --remote=pssl:$SSL_PORT:127.0.0.1 --unixctl=$PWD/unixctl db],
184   [0], [ignore], [ignore])
185 AT_CHECK(
186   [[ovsdb-client \
187         --private-key=$PKIDIR/testpki-privkey.pem \
188         --certificate=$PKIDIR/testpki-cert.pem \
189         --ca-cert=$PKIDIR/testpki-cacert.pem \
190         transact ssl:127.0.0.1:$SSL_PORT \
191         '["mydb",
192           {"op": "select",
193            "table": "SSL",
194            "where": [],
195            "columns": ["private_key"]}]']], 
196   [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
197 cat stdout >> output
198 AT_CHECK_UNQUOTED(
199   [perl $srcdir/uuidfilt.pl output], [0], 
200   [[[{"rows":[{"private_key":"$PKIDIR/testpki-privkey2.pem"}]}]
201 ]], [ignore], [test ! -e pid || kill `cat pid`])
202 OVSDB_SERVER_SHUTDOWN
203 AT_CLEANUP
204
205 AT_SETUP([compacting online])
206 AT_KEYWORDS([ovsdb server compact])
207 AT_DATA([schema], [ORDINAL_SCHEMA
208 ])
209 touch .db.~lock~
210 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
211 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --unixctl=$PWD/unixctl --remote=punix:socket --log-file=$PWD/ovsdb-server.log db], [0], [ignore], [ignore])
212 AT_CAPTURE_FILE([ovsdb-server.log])
213 dnl Do a bunch of random transactions that put crap in the database log.
214 AT_CHECK(
215   [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
216       set -- $pair
217       ovsdb-client transact unix:socket '
218         ["ordinals",
219          {"op": "insert",
220           "table": "ordinals",
221           "row": {"name": "'$1'", "number": '$2'}},
222          {"op": "comment",
223           "comment": "add row for '"$pair"'"}]'
224       ovsdb-client transact unix:socket '
225         ["ordinals",
226          {"op": "delete",
227           "table": "ordinals",
228           "where": [["number", "==", '$2']]},
229          {"op": "comment",
230           "comment": "delete row for '"$2"'"}]'
231       ovsdb-client transact unix:socket '
232         ["ordinals",
233          {"op": "insert",
234           "table": "ordinals",
235           "row": {"name": "'$1'", "number": '$2'}},
236          {"op": "comment",
237           "comment": "add back row for '"$pair"'"}]'
238     done]],
239   [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
240 dnl Check that all the crap is in fact in the database log.
241 AT_CHECK([[perl $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | test-json --multiple -]], [0],
242   [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}}}},"version":"5.1.3"}
243 {"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
244 {"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
245 {"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
246 {"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
247 {"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
248 {"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
249 {"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
250 {"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
251 {"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
252 {"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
253 {"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
254 {"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
255 {"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
256 {"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
257 {"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
258 {"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
259 {"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
260 {"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
261 ]], [], [test ! -e pid || kill `cat pid`])
262 dnl Dump out and check the actual database contents.
263 AT_CHECK([[ovsdb-client dump unix:socket ordinals]],
264   [0], [stdout], [ignore])
265 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
266 ordinals table
267 _uuid                                name  number
268 ------------------------------------ ----- ------
269 <0> five  5     @&t@
270 <1> four  4     @&t@
271 <2> one   1     @&t@
272 <3> three 3     @&t@
273 <4> two   2     @&t@
274 <5> zero  0     @&t@
275 ], [], [test ! -e pid || kill `cat pid`])
276 dnl Now compact the database in-place.
277 AT_CHECK([[ovs-appctl -t $PWD/unixctl ovsdb-server/compact]],
278   [0], [], [ignore], [test ! -e pid || kill `cat pid`])
279 dnl We can't fully re-check the contents of the database log, because the
280 dnl order of the records is not predictable, but there should only be 4 lines
281 dnl in it now.
282 AT_CAPTURE_FILE([db])
283 AT_CHECK([wc -l < db], [0], [4
284 ], [], [test ! -e pid || kill `cat pid`])
285 dnl And check that the dumped data is the same too:
286 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
287   [test ! -e pid || kill `cat pid`])
288 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
289 ordinals table
290 _uuid                                name  number
291 ------------------------------------ ----- ------
292 <0> five  5     @&t@
293 <1> four  4     @&t@
294 <2> one   1     @&t@
295 <3> three 3     @&t@
296 <4> two   2     @&t@
297 <5> zero  0     @&t@
298 ], [], [test ! -e pid || kill `cat pid`])
299 dnl Now do some more transactions.
300 AT_CHECK(
301   [[ovsdb-client transact unix:socket '
302      ["ordinals",
303       {"op": "delete",
304        "table": "ordinals",
305        "where": [["number", "<", 3]]}]']],
306   [0], [[[{"count":3}]
307 ]], [ignore], [test ! -e pid || kill `cat pid`])
308 dnl There should be 6 lines in the log now.
309 AT_CHECK([wc -l < db], [0], [6
310 ], [], [test ! -e pid || kill `cat pid`])
311 dnl Then check that the dumped data is correct.
312 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
313   [test ! -e pid || kill `cat pid`])
314 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
315 ordinals table
316 _uuid                                name  number
317 ------------------------------------ ----- ------
318 <0> five  5     @&t@
319 <1> four  4     @&t@
320 <2> three 3     @&t@
321 ], [], [test ! -e pid || kill `cat pid`])
322 OVSDB_SERVER_SHUTDOWN
323 AT_CLEANUP
324 \f
325 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL sockets)])
326
327 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
328 #
329 # Creates a database with the given SCHEMA, starts an ovsdb-server on
330 # that database, and runs each of the TRANSACTIONS (which should be a
331 # quoted list of quoted strings) against it with ovsdb-client one at a
332 # time.
333 #
334 # Checks that the overall output is OUTPUT, but UUIDs in the output
335 # are replaced by markers of the form <N> where N is a number.  The
336 # first unique UUID is replaced by <0>, the next by <1>, and so on.
337 # If a given UUID appears more than once it is always replaced by the
338 # same marker.
339 #
340 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
341 m4_define([OVSDB_CHECK_EXECUTION], 
342   [AT_SETUP([$1])
343    AT_KEYWORDS([ovsdb server positive ssl $5])
344    AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
345    AT_SKIP_IF([test "x$RANDOM" = x])
346    AT_DATA([schema], [$2
347 ])
348    SSL_PORT=`expr 32767 + \( $RANDOM % 32767 \)`
349    PKIDIR=$abs_top_builddir/tests
350    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
351    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])
352    m4_foreach([txn], [$3], 
353      [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],
354      [test ! -e pid || kill `cat pid`])
355 cat stdout >> output
356 ])
357    AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
358             [test ! -e pid || kill `cat pid`])
359    OVSDB_SERVER_SHUTDOWN
360    AT_CLEANUP])
361
362 EXECUTION_EXAMPLES
363 \f
364 AT_BANNER([OVSDB -- transactions on transient ovsdb-server])
365
366 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
367 #
368 # Creates a database with the given SCHEMA and runs each of the
369 # TRANSACTIONS (which should be a quoted list of quoted strings)
370 # against it with ovsdb-client one at a time.  Each ovsdb-client
371 # is run against a separately started ovsdb-server that executes
372 # only that single transaction.  (The idea is that this should
373 # help to ferret out any differences between what ovsdb-server has
374 # in memory and what actually gets committed to disk.)
375 #
376 # Checks that the overall output is OUTPUT, but UUIDs in the output
377 # are replaced by markers of the form <N> where N is a number.  The
378 # first unique UUID is replaced by <0>, the next by <1>, and so on.
379 # If a given UUID appears more than once it is always replaced by the
380 # same marker.
381 #
382 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
383 m4_define([OVSDB_CHECK_EXECUTION], 
384   [AT_SETUP([$1])
385    AT_KEYWORDS([ovsdb server positive transient $5])
386    AT_DATA([schema], [$2
387 ])
388    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
389    m4_foreach([txn], [$3], 
390      [AT_DATA([txnfile], [ovsdb-client transact unix:socket 'txn'
391 ])
392       AT_CHECK([ovsdb-server --remote=punix:socket --unixctl=$PWD/unixctl db --run="sh txnfile"], [0], [stdout], [ignore])
393       cat stdout >> output
394 ])
395    AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore])
396    AT_CLEANUP])
397
398 EXECUTION_EXAMPLES