Merge "master" into "next".
[cascardo/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 $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 "{"syntax":"[\"nonexistent\"]","details":"get_schema request specifies unknown database nonexistent","error":"unknown database"}": 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 \f
93 AT_BANNER([OVSDB -- ovsdb-server transactions (SSL sockets)])
94
95 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
96 #
97 # Creates a database with the given SCHEMA, starts an ovsdb-server on
98 # that database, and runs each of the TRANSACTIONS (which should be a
99 # quoted list of quoted strings) against it with ovsdb-client one at a
100 # time.
101 #
102 # Checks that the overall output is OUTPUT, but UUIDs in the output
103 # are replaced by markers of the form <N> where N is a number.  The
104 # first unique UUID is replaced by <0>, the next by <1>, and so on.
105 # If a given UUID appears more than once it is always replaced by the
106 # same marker.
107 #
108 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
109 m4_define([OVSDB_CHECK_EXECUTION], 
110   [AT_SETUP([$1])
111    AT_KEYWORDS([ovsdb server positive ssl $5])
112    AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
113    AT_SKIP_IF([test "x$RANDOM" = x])
114    AT_DATA([schema], [$2
115 ])
116    SSL_PORT=`expr 32767 + \( $RANDOM % 32767 \)`
117    PKIDIR=$abs_top_srcdir/tests
118    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
119    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])
120    m4_foreach([txn], [$3], 
121      [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],
122      [test ! -e pid || kill `cat pid`])
123 cat stdout >> output
124 ])
125    AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
126             [test ! -e pid || kill `cat pid`])
127    OVSDB_SERVER_SHUTDOWN
128    AT_CLEANUP])
129
130 EXECUTION_EXAMPLES