Describe dummy test model. Work on OpenFlow intro.
[openvswitch] / 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    $2 > schema
26    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
27    AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
28    m4_foreach([txn], [$3], 
29      [AT_CHECK([ovsdb-client transact unix:socket 'txn'], [0], [stdout], [ignore],
30      [test ! -e pid || kill `cat pid`])
31 cat stdout >> output
32 ])
33    AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
34             [test ! -e pid || kill `cat pid`])
35    OVSDB_SERVER_SHUTDOWN
36    AT_CLEANUP])
37
38 EXECUTION_EXAMPLES
39 \f
40 AT_SETUP([truncating corrupted database log])
41 AT_KEYWORDS([ovsdb server positive unix])
42 ordinal_schema > schema
43 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
44 dnl Do one transaction and save the output.
45 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
46 '["ordinals",
47   {"op": "insert",
48    "table": "ordinals",
49    "row": {"number": 0, "name": "zero"}}]'
50 ]])
51 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
52 cat stdout >> output
53 dnl Add some crap to the database log and run another transaction, which should
54 dnl ignore the crap and truncate it out of the log.
55 echo 'xxx' >> db
56 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
57 '["ordinals",
58   {"op": "insert",
59    "table": "ordinals",
60    "row": {"number": 1, "name": "one"}}]'
61 ]])
62 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [stderr])
63 AT_CHECK([grep 'syntax error: db: parse error.* in header line "xxx"' stderr],
64   [0], [ignore])
65 cat stdout >> output
66 dnl Run a final transaction to verify that both transactions succeeeded.
67 dnl The crap that we added should have been truncated by the previous run,
68 dnl so ovsdb-server shouldn't log a warning this time.
69 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
70 '["ordinals",
71   {"op": "select",
72    "table": "ordinals",
73    "where": [],
74    "sort": ["number"]}]'
75 ]])
76 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
77 cat stdout >> output
78 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0],
79   [[[{"uuid":["uuid","<0>"]}]
80 [{"uuid":["uuid","<1>"]}]
81 [{"rows":[{"_uuid":["uuid","<0>"],"_version":["uuid","<2>"],"name":"zero","number":0},{"_uuid":["uuid","<1>"],"_version":["uuid","<3>"],"name":"one","number":1}]}]
82 ]], [],
83          [test ! -e pid || kill `cat pid`])
84 AT_CLEANUP
85
86 AT_SETUP([truncating database log with bad transaction])
87 AT_KEYWORDS([ovsdb server positive unix])
88 ordinal_schema > schema
89 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
90 dnl Do one transaction and save the output.
91 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
92 '["ordinals",
93   {"op": "insert",
94    "table": "ordinals",
95    "row": {"number": 0, "name": "zero"}}]'
96 ]])
97 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
98 cat stdout >> output
99 dnl Add some crap to the database log and run another transaction, which should
100 dnl ignore the crap and truncate it out of the log.
101 echo 'OVSDB JSON 15 ffbcdae4b0386265f9ea3280dd7c8f0b72a20e56
102 {"invalid":{}}' >> db
103 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
104 '["ordinals",
105   {"op": "insert",
106    "table": "ordinals",
107    "row": {"number": 1, "name": "one"}}]'
108 ]])
109 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [stderr])
110 AT_CHECK([grep 'syntax "{"invalid":{}}": unknown table: No table named invalid.' stderr],
111   [0], [ignore])
112 cat stdout >> output
113 dnl Run a final transaction to verify that both transactions succeeeded.
114 dnl The crap that we added should have been truncated by the previous run,
115 dnl so ovsdb-server shouldn't log a warning this time.
116 AT_DATA([txnfile], [[ovsdb-client transact unix:socket \
117 '["ordinals",
118   {"op": "select",
119    "table": "ordinals",
120    "where": [],
121    "sort": ["number"]}]'
122 ]])
123 AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [])
124 cat stdout >> output
125 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0],
126   [[[{"uuid":["uuid","<0>"]}]
127 [{"uuid":["uuid","<1>"]}]
128 [{"rows":[{"_uuid":["uuid","<0>"],"_version":["uuid","<2>"],"name":"zero","number":0},{"_uuid":["uuid","<1>"],"_version":["uuid","<3>"],"name":"one","number":1}]}]
129 ]], [],
130          [test ! -e pid || kill `cat pid`])
131 AT_CLEANUP
132
133 AT_SETUP([ovsdb-client get-schema-version])
134 AT_KEYWORDS([ovsdb server positive])
135 ordinal_schema > schema
136 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
137 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=punix:socket db], [0], [ignore], [ignore])
138 AT_CHECK([ovsdb-client get-schema-version unix:socket ordinals], [0], [5.1.3
139 ])
140 OVSDB_SERVER_SHUTDOWN
141 AT_CLEANUP
142
143 AT_SETUP([database multiplexing implementation])
144 AT_KEYWORDS([ovsdb server positive])
145 ordinal_schema > schema1
146 constraint_schema > schema2
147 AT_CHECK([ovsdb-tool create db1 schema1], [0], [ignore], [ignore])
148 AT_CHECK([ovsdb-tool create db2 schema2], [0], [ignore], [ignore])
149 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=punix:socket db1 db2], [0], [ignore], [ignore])
150 AT_CHECK(
151   [[ovsdb-client list-dbs unix:socket]], 
152   [0], [constraints
153 ordinals
154 ], [ignore], [test ! -e pid || kill `cat pid`])
155 AT_CHECK(
156   [[test-jsonrpc request unix:socket get_schema [\"nonexistent\"]]], [0],
157   [[{"error":null,"id":0,"result":{"details":"get_schema request specifies unknown database nonexistent","error":"unknown database","syntax":"[\"nonexistent\"]"}}
158 ]], [], [test ! -e pid || kill `cat pid`])
159 OVSDB_SERVER_SHUTDOWN
160 AT_CLEANUP
161
162 AT_SETUP([--remote=db: implementation])
163 AT_KEYWORDS([ovsdb server positive])
164 OVS_RUNDIR=`pwd`; export OVS_RUNDIR
165 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
166 AT_DATA([schema],
167   [[{"name": "mydb",
168      "tables": {
169        "Root": {
170          "columns": {
171            "managers": {
172              "type": {
173                "key": "string",
174                "min": 0,
175                "max": "unlimited"}},
176            "manager_options": {
177              "type": {
178                "key": {"type": "uuid", "refTable": "Manager"},
179                "min": 0,
180                "max": "unlimited"}}}},
181        "Manager": {
182          "columns": {
183            "target": {
184              "type": "string"},
185            "is_connected": {
186              "type": {
187                "key": "boolean",
188                "min": 0,
189                "max": 1}}}}}}
190 ]])
191 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
192 AT_CHECK(
193   [[ovsdb-tool transact db \
194      '["mydb",
195        {"op": "insert",
196         "table": "Root",
197         "row": {
198           "managers": "punix:socket1",
199           "manager_options": ["set", [["named-uuid", "x"]]]}},
200        {"op": "insert",
201         "table": "Manager",
202         "uuid-name": "x",
203         "row": {"target": "punix:socket2"}}]']], [0], [ignore], [ignore])
204 ON_EXIT([kill `cat ovsdb-server.pid`])
205 AT_CHECK([ovsdb-server --enable-dummy --detach --no-chdir --pidfile --remote=db:Root,managers --remote=db:Root,manager_options --log-file db], [0], [ignore], [ignore])
206 for i in 1 2 3 4 5 6; do ovs-appctl -t ovsdb-server time/warp 1000; done
207 AT_CHECK(
208   [[ovsdb-client transact unix:socket1 \
209      '["mydb",
210        {"op": "select",
211         "table": "Root",
212         "where": [],
213         "columns": ["managers"]},
214        {"op": "select",
215         "table": "Manager",
216         "where": [],
217         "columns": ["target", "is_connected"]}]']],
218   [0], [stdout], [ignore])
219 AT_CHECK(
220   [perl $srcdir/uuidfilt.pl stdout], 
221   [0], 
222   [[[{"rows":[{"managers":"punix:socket1"}]},{"rows":[{"is_connected":false,"target":"punix:socket2"}]}]
223 ]], 
224   [ignore])
225 AT_CLEANUP
226
227 AT_SETUP([SSL db: implementation])
228 AT_KEYWORDS([ovsdb server positive ssl $5])
229 AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
230 PKIDIR=$abs_top_builddir/tests
231 AT_SKIP_IF([expr "$PKIDIR" : ".*[       '\"
232 \r\\]"])
233 AT_DATA([schema],
234   [[{"name": "mydb",
235      "tables": {
236        "SSL": {
237          "columns": {
238            "private_key": {"type": "string"},
239            "certificate": {"type": "string"},
240            "ca_cert": {"type": "string"}}}}}
241 ]])
242 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
243 AT_CHECK(
244   [[ovsdb-tool transact db \
245      '["mydb",
246        {"op": "insert",
247         "table": "SSL",
248         "row": {"private_key": "'"$PKIDIR/testpki-privkey2.pem"'",
249                 "certificate": "'"$PKIDIR/testpki-cert2.pem"'",
250                 "ca_cert": "'"$PKIDIR/testpki-cacert.pem"'"}}]']],
251   [0], [ignore], [ignore])
252 AT_CHECK([perl $srcdir/choose-port.pl], [0], [stdout])
253 SSL_PORT=`cat stdout`
254 AT_CHECK(
255   [ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid \
256         --private-key=db:SSL,private_key \
257         --certificate=db:SSL,certificate \
258         --ca-cert=db:SSL,ca_cert \
259          --remote=pssl:$SSL_PORT:127.0.0.1 --unixctl="`pwd`"/unixctl db],
260   [0], [ignore], [ignore])
261 AT_CHECK(
262   [[ovsdb-client \
263         --private-key=$PKIDIR/testpki-privkey.pem \
264         --certificate=$PKIDIR/testpki-cert.pem \
265         --ca-cert=$PKIDIR/testpki-cacert.pem \
266         transact ssl:127.0.0.1:$SSL_PORT \
267         '["mydb",
268           {"op": "select",
269            "table": "SSL",
270            "where": [],
271            "columns": ["private_key"]}]']], 
272   [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
273 cat stdout >> output
274 AT_CHECK_UNQUOTED(
275   [perl $srcdir/uuidfilt.pl output], [0], 
276   [[[{"rows":[{"private_key":"$PKIDIR/testpki-privkey2.pem"}]}]
277 ]], [ignore], [test ! -e pid || kill `cat pid`])
278 OVSDB_SERVER_SHUTDOWN
279 AT_CLEANUP
280
281 AT_SETUP([compacting online])
282 AT_KEYWORDS([ovsdb server compact])
283 ordinal_schema > schema
284 dnl Make sure that "ovsdb-tool create" works with a dangling symlink for
285 dnl the database and the lockfile, creating the target of each symlink rather
286 dnl than replacing the symlinks with regular files.
287 mkdir dir
288 ln -s dir/db db
289 ln -s dir/.db.~lock~ .db.~lock~
290 AT_SKIP_IF([test ! -h db || test ! -h .db.~lock~])
291 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
292 dnl Start ovsdb-server.
293 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=punix:socket --log-file="`pwd`"/ovsdb-server.log db], [0], [ignore], [ignore])
294 AT_CAPTURE_FILE([ovsdb-server.log])
295 dnl Do a bunch of random transactions that put crap in the database log.
296 AT_CHECK(
297   [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
298       set -- $pair
299       ovsdb-client transact unix:socket '
300         ["ordinals",
301          {"op": "insert",
302           "table": "ordinals",
303           "row": {"name": "'$1'", "number": '$2'}},
304          {"op": "comment",
305           "comment": "add row for '"$pair"'"}]'
306       ovsdb-client transact unix:socket '
307         ["ordinals",
308          {"op": "delete",
309           "table": "ordinals",
310           "where": [["number", "==", '$2']]},
311          {"op": "comment",
312           "comment": "delete row for '"$2"'"}]'
313       ovsdb-client transact unix:socket '
314         ["ordinals",
315          {"op": "insert",
316           "table": "ordinals",
317           "row": {"name": "'$1'", "number": '$2'}},
318          {"op": "comment",
319           "comment": "add back row for '"$pair"'"}]'
320     done]],
321   [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
322 dnl Check that all the crap is in fact in the database log.
323 AT_CHECK([[perl $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | test-json --multiple -]], [0],
324   [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"}
325 {"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
326 {"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
327 {"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
328 {"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
329 {"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
330 {"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
331 {"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
332 {"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
333 {"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
334 {"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
335 {"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
336 {"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
337 {"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
338 {"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
339 {"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
340 {"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
341 {"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
342 {"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
343 ]], [], [test ! -e pid || kill `cat pid`])
344 dnl Dump out and check the actual database contents.
345 AT_CHECK([[ovsdb-client dump unix:socket ordinals]],
346   [0], [stdout], [ignore])
347 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
348 ordinals table
349 _uuid                                name  number
350 ------------------------------------ ----- ------
351 <0> five  5     @&t@
352 <1> four  4     @&t@
353 <2> one   1     @&t@
354 <3> three 3     @&t@
355 <4> two   2     @&t@
356 <5> zero  0     @&t@
357 ], [], [test ! -e pid || kill `cat pid`])
358 dnl Now compact the database in-place.
359 AT_CHECK([[ovs-appctl -t "`pwd`"/unixctl ovsdb-server/compact]],
360   [0], [], [ignore], [test ! -e pid || kill `cat pid`])
361 dnl Make sure that "db" is still a symlink to dir/db instead of getting
362 dnl replaced by a regular file, ditto for .db.~lock~.
363 AT_CHECK([test -h db])
364 AT_CHECK([test -h .db.~lock~])
365 AT_CHECK([test -f dir/db])
366 AT_CHECK([test -f dir/.db.~lock~])
367 dnl We can't fully re-check the contents of the database log, because the
368 dnl order of the records is not predictable, but there should only be 4 lines
369 dnl in it now.
370 AT_CAPTURE_FILE([db])
371 AT_CHECK([test `wc -l < db` -eq 4], [0], [], [],
372   [test ! -e pid || kill `cat pid`])
373 dnl And check that the dumped data is the same too:
374 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
375   [test ! -e pid || kill `cat pid`])
376 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
377 ordinals table
378 _uuid                                name  number
379 ------------------------------------ ----- ------
380 <0> five  5     @&t@
381 <1> four  4     @&t@
382 <2> one   1     @&t@
383 <3> three 3     @&t@
384 <4> two   2     @&t@
385 <5> zero  0     @&t@
386 ], [], [test ! -e pid || kill `cat pid`])
387 dnl Now do some more transactions.
388 AT_CHECK(
389   [[ovsdb-client transact unix:socket '
390      ["ordinals",
391       {"op": "delete",
392        "table": "ordinals",
393        "where": [["number", "<", 3]]}]']],
394   [0], [[[{"count":3}]
395 ]], [ignore], [test ! -e pid || kill `cat pid`])
396 dnl There should be 6 lines in the log now.
397 AT_CHECK([test `wc -l < db` -eq 6], [0], [], [],
398   [test ! -e pid || kill `cat pid`])
399 dnl Then check that the dumped data is correct.
400 AT_CHECK([ovsdb-client dump unix:socket ordinals], [0], [stdout], [ignore],
401   [test ! -e pid || kill `cat pid`])
402 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [dnl
403 ordinals table
404 _uuid                                name  number
405 ------------------------------------ ----- ------
406 <0> five  5     @&t@
407 <1> four  4     @&t@
408 <2> three 3     @&t@
409 ], [], [test ! -e pid || kill `cat pid`])
410 OVSDB_SERVER_SHUTDOWN
411 AT_CLEANUP
412 \f
413 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL sockets)])
414
415 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
416 #
417 # Creates a database with the given SCHEMA, starts an ovsdb-server on
418 # that database, and runs each of the TRANSACTIONS (which should be a
419 # quoted list of quoted strings) against it with ovsdb-client one at a
420 # time.
421 #
422 # Checks that the overall output is OUTPUT, but UUIDs in the output
423 # are replaced by markers of the form <N> where N is a number.  The
424 # first unique UUID is replaced by <0>, the next by <1>, and so on.
425 # If a given UUID appears more than once it is always replaced by the
426 # same marker.
427 #
428 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
429 m4_define([OVSDB_CHECK_EXECUTION], 
430   [AT_SETUP([$1])
431    AT_KEYWORDS([ovsdb server positive ssl $5])
432    AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
433    $2 > schema
434    AT_CHECK([perl $srcdir/choose-port.pl], [0], [stdout])
435    SSL_PORT=`cat stdout`
436    PKIDIR=$abs_top_builddir/tests
437    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
438    AT_CHECK([ovsdb-server --detach --no-chdir --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])
439    m4_foreach([txn], [$3], 
440      [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],
441      [test ! -e pid || kill `cat pid`])
442 cat stdout >> output
443 ])
444    AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
445             [test ! -e pid || kill `cat pid`])
446    OVSDB_SERVER_SHUTDOWN
447    AT_CLEANUP])
448
449 EXECUTION_EXAMPLES
450
451 AT_BANNER([OVSDB -- ovsdb-server transactions (TCP sockets)])
452
453 AT_SETUP([ovsdb-client get-schema-version - tcp socket])
454 AT_KEYWORDS([ovsdb server positive tcp])
455 ordinal_schema > schema
456 AT_CHECK([perl $srcdir/choose-port.pl], [0], [stdout])
457 TCP_PORT=`cat stdout`
458 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
459 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=ptcp:$TCP_PORT:127.0.0.1 db], [0], [ignore], [ignore])
460 AT_CHECK([ovsdb-client get-schema-version tcp:127.0.0.1:$TCP_PORT ordinals], [0], [5.1.3
461 ])
462 OVSDB_SERVER_SHUTDOWN
463 AT_CLEANUP])
464
465 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
466 #
467 # Creates a database with the given SCHEMA, starts an ovsdb-server on
468 # that database, and runs each of the TRANSACTIONS (which should be a
469 # quoted list of quoted strings) against it with ovsdb-client one at a
470 # time.
471 #
472 # Checks that the overall output is OUTPUT, but UUIDs in the output
473 # are replaced by markers of the form <N> where N is a number.  The
474 # first unique UUID is replaced by <0>, the next by <1>, and so on.
475 # If a given UUID appears more than once it is always replaced by the
476 # same marker.
477 #
478 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
479 m4_define([OVSDB_CHECK_EXECUTION],
480   [AT_SETUP([$1])
481    AT_KEYWORDS([ovsdb server positive tcp $5])
482    $2 > schema
483    AT_CHECK([perl $srcdir/choose-port.pl], [0], [stdout])
484    TCP_PORT=`cat stdout`
485    PKIDIR=$abs_top_builddir/tests
486    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
487    AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --remote=ptcp:$TCP_PORT:127.0.0.1 --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
488    m4_foreach([txn], [$3],
489      [AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT 'txn'], [0], [stdout], [ignore],
490      [test ! -e pid || kill `cat pid`])
491 cat stdout >> output
492 ])
493    AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
494             [test ! -e pid || kill `cat pid`])
495    OVSDB_SERVER_SHUTDOWN
496    AT_CLEANUP])
497
498 EXECUTION_EXAMPLES
499 \f
500 AT_BANNER([OVSDB -- transactions on transient ovsdb-server])
501
502 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
503 #
504 # Creates a database with the given SCHEMA and runs each of the
505 # TRANSACTIONS (which should be a quoted list of quoted strings)
506 # against it with ovsdb-client one at a time.  Each ovsdb-client
507 # is run against a separately started ovsdb-server that executes
508 # only that single transaction.  (The idea is that this should
509 # help to ferret out any differences between what ovsdb-server has
510 # in memory and what actually gets committed to disk.)
511 #
512 # Checks that the overall output is OUTPUT, but UUIDs in the output
513 # are replaced by markers of the form <N> where N is a number.  The
514 # first unique UUID is replaced by <0>, the next by <1>, and so on.
515 # If a given UUID appears more than once it is always replaced by the
516 # same marker.
517 #
518 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
519 m4_define([OVSDB_CHECK_EXECUTION], 
520   [AT_SETUP([$1])
521    AT_KEYWORDS([ovsdb server positive transient $5])
522    $2 > schema
523    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
524    m4_foreach([txn], [$3], 
525      [AT_DATA([txnfile], [ovsdb-client transact unix:socket 'txn'
526 ])
527       AT_CHECK([ovsdb-server --remote=punix:socket --unixctl="`pwd`"/unixctl db --run="sh txnfile"], [0], [stdout], [ignore])
528       cat stdout >> output
529 ])
530    AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore])
531    AT_CLEANUP])
532
533 EXECUTION_EXAMPLES