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