tests: Always make ovsdb-server exit cleanly, to better find memory leaks.
[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 $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([--remote=db: implementation])
42 AT_KEYWORDS([ovsdb server positive])
43 AT_DATA([schema],
44   [[{"name": "mydb",
45      "tables": {
46        "Manager": {
47          "columns": {
48            "manager": {"type": "string"}}}}}
49 ]])
50 AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
51 AT_CHECK(
52   [[ovsdb-tool transact db \
53      '[{"op": "insert",
54         "table": "Manager",
55         "row": {"manager": "punix:socket"}}]']], [0], [ignore], [ignore])
56 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --remote=db:Manager,manager --unixctl=$PWD/unixctl db], [0], [ignore], [ignore])
57 AT_CHECK(
58   [[ovsdb-client transact unix:socket \
59      '[{"op": "select",
60         "table": "Manager",
61         "where": [],
62         "columns": ["manager"]}]']], 
63   [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
64 AT_CHECK(
65   [perl $srcdir/uuidfilt.pl stdout], 
66   [0], 
67   [[[{"rows":[{"manager":"punix:socket"}]}]
68 ]], 
69   [ignore], 
70   [test ! -e pid || kill `cat pid`])
71 OVSDB_SERVER_SHUTDOWN
72 AT_CLEANUP
73 \f
74 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL sockets)])
75
76 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
77 #
78 # Creates a database with the given SCHEMA, starts an ovsdb-server on
79 # that database, and runs each of the TRANSACTIONS (which should be a
80 # quoted list of quoted strings) against it with ovsdb-client one at a
81 # time.
82 #
83 # Checks that the overall output is OUTPUT, but UUIDs in the output
84 # are replaced by markers of the form <N> where N is a number.  The
85 # first unique UUID is replaced by <0>, the next by <1>, and so on.
86 # If a given UUID appears more than once it is always replaced by the
87 # same marker.
88 #
89 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
90 m4_define([OVSDB_CHECK_EXECUTION], 
91   [AT_SETUP([$1])
92    AT_KEYWORDS([ovsdb server positive ssl $5])
93    AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
94    AT_SKIP_IF([test "x$RANDOM" = x])
95    AT_DATA([schema], [$2
96 ])
97    SSL_PORT=`expr 32767 + \( $RANDOM % 32767 \)`
98    PKIDIR=$abs_top_srcdir/tests
99    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
100    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])
101    m4_foreach([txn], [$3], 
102      [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],
103      [test ! -e pid || kill `cat pid`])
104 cat stdout >> output
105 ])
106    AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
107             [test ! -e pid || kill `cat pid`])
108    OVSDB_SERVER_SHUTDOWN
109    AT_CLEANUP])
110
111 EXECUTION_EXAMPLES