ovsdb-idl.at: Run tests with both Python 2 and 3.
[cascardo/ovs.git] / tests / ovsdb-idl.at
1 AT_BANNER([OVSDB -- interface description language (IDL)])
2
3 # OVSDB_CHECK_IDL_C(TITLE, [PRE-IDL-TXN], TRANSACTIONS, OUTPUT, [KEYWORDS],
4 #                   [FILTER])
5 #
6 # Creates a database with a schema derived from idltest.ovsidl, runs
7 # each PRE-IDL-TXN (if any), starts an ovsdb-server on that database,
8 # and runs "test-ovsdb idl" passing each of the TRANSACTIONS along.
9 #
10 # Checks that the overall output is OUTPUT.  Before comparison, the
11 # output is sorted (using "sort") and UUIDs in the output are replaced
12 # by markers of the form <N> where N is a number.  The first unique
13 # UUID is replaced by <0>, the next by <1>, and so on.  If a given
14 # UUID appears more than once it is always replaced by the same
15 # marker.  If FILTER is supplied then the output is also filtered
16 # through the specified program.
17 #
18 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
19 m4_define([OVSDB_CHECK_IDL_C],
20   [AT_SETUP([$1 - C])
21    AT_KEYWORDS([ovsdb server idl positive $5])
22    AT_CHECK([ovsdb-tool create db $abs_srcdir/idltest.ovsschema],
23                   [0], [stdout], [ignore])
24    AT_CHECK([ovsdb-server '-vPATTERN:console:ovsdb-server|%c|%m' --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
25    m4_if([$2], [], [],
26      [AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore], [kill `cat pid`])])
27    AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 idl unix:socket $3],
28             [0], [stdout], [ignore], [kill `cat pid`])
29    AT_CHECK([sort stdout | ${PERL} $srcdir/uuidfilt.pl]m4_if([$6],,, [[| $6]]),
30             [0], [$4], [], [kill `cat pid`])
31    OVSDB_SERVER_SHUTDOWN
32    AT_CLEANUP])
33
34 # same as OVSDB_CHECK_IDL but uses the Python IDL implementation.
35 m4_define([OVSDB_CHECK_IDL_PYN],
36   [AT_SETUP([$1])
37    AT_SKIP_IF([test $7 = no])
38    AT_KEYWORDS([ovsdb server idl positive Python $5])
39    AT_CHECK([ovsdb-tool create db $abs_srcdir/idltest.ovsschema],
40                   [0], [stdout], [ignore])
41    AT_CHECK([ovsdb-server '-vPATTERN:console:ovsdb-server|%c|%m' --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
42    m4_if([$2], [], [],
43      [AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore], [kill `cat pid`])])
44    AT_CHECK([$8 $srcdir/test-ovsdb.py  -t10 idl $srcdir/idltest.ovsschema unix:socket $3],
45             [0], [stdout], [ignore], [kill `cat pid`])
46    AT_CHECK([sort stdout | ${PERL} $srcdir/uuidfilt.pl]m4_if([$6],,, [[| $6]]),
47             [0], [$4], [], [kill `cat pid`])
48    OVSDB_SERVER_SHUTDOWN
49    AT_CLEANUP])
50
51 m4_define([OVSDB_CHECK_IDL_PY],
52    [OVSDB_CHECK_IDL_PYN([$1 - Python2], [$2], [$3], [$4], [$5], [$6],
53                         [$HAVE_PYTHON], [$PYTHON])
54     OVSDB_CHECK_IDL_PYN([$1 - Python3], [$2], [$3], [$4], [$5], [$6],
55                         [$HAVE_PYTHON3], [$PYTHON3])])
56
57 m4_define([OVSDB_CHECK_IDL_REGISTER_COLUMNS_PYN],
58   [AT_SETUP([$1 - register_columns])
59    AT_SKIP_IF([test $7 = no])
60    AT_KEYWORDS([ovsdb server idl positive Python register_columns $5])
61    AT_CHECK([ovsdb-tool create db $abs_srcdir/idltest.ovsschema],
62                   [0], [stdout], [ignore])
63    AT_CHECK([ovsdb-server '-vPATTERN:console:ovsdb-server|%c|%m' --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
64    m4_if([$2], [], [],
65      [AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore], [kill `cat pid`])])
66    AT_CHECK([$8 $srcdir/test-ovsdb.py  -t10 idl $srcdir/idltest.ovsschema unix:socket ?simple:b,ba,i,ia,r,ra,s,sa,u,ua?link1:i,k,ka,l2?link2:i,l1 $3],
67             [0], [stdout], [ignore], [kill `cat pid`])
68    AT_CHECK([sort stdout | ${PERL} $srcdir/uuidfilt.pl]m4_if([$6],,, [[| $6]]),
69             [0], [$4], [], [kill `cat pid`])
70    OVSDB_SERVER_SHUTDOWN
71    AT_CLEANUP])
72
73 m4_define([OVSDB_CHECK_IDL_REGISTER_COLUMNS_PY],
74    [OVSDB_CHECK_IDL_REGISTER_COLUMNS_PYN([$1 - Python2], [$2], [$3], [$4], [$5], [$6],
75                         [$HAVE_PYTHON], [$PYTHON])
76     OVSDB_CHECK_IDL_REGISTER_COLUMNS_PYN([$1 - Python3], [$2], [$3], [$4], [$5], [$6],
77                         [$HAVE_PYTHON3], [$PYTHON3])])
78
79 # same as OVSDB_CHECK_IDL but uses the Python IDL implementation with tcp
80 m4_define([OVSDB_CHECK_IDL_TCP_PYN],
81   [AT_SETUP([$1 - tcp])
82    AT_SKIP_IF([test $7 = no])
83    AT_KEYWORDS([ovsdb server idl positive Python with tcp socket $5])
84    AT_CHECK([ovsdb-tool create db $abs_srcdir/idltest.ovsschema],
85                   [0], [stdout], [ignore])
86    AT_CHECK([ovsdb-server --log-file '-vPATTERN:console:ovsdb-server|%c|%m' --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --remote=ptcp:0:127.0.0.1 --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
87    PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
88
89    m4_if([$2], [], [],
90      [AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT $2], [0], [ignore], [ignore], [kill `cat pid`])])
91    AT_CHECK([$8 $srcdir/test-ovsdb.py  -t10 idl $srcdir/idltest.ovsschema tcp:127.0.0.1:$TCP_PORT $3],
92             [0], [stdout], [ignore], [kill `cat pid`])
93    AT_CHECK([sort stdout | ${PERL} $srcdir/uuidfilt.pl]m4_if([$6],,, [[| $6]]),
94             [0], [$4], [], [kill `cat pid`])
95    OVSDB_SERVER_SHUTDOWN
96    AT_CLEANUP])
97
98 m4_define([OVSDB_CHECK_IDL_TCP_PY],
99    [OVSDB_CHECK_IDL_TCP_PYN([$1 - Python2], [$2], [$3], [$4], [$5], [$6],
100                         [$HAVE_PYTHON], [$PYTHON])
101     OVSDB_CHECK_IDL_TCP_PYN([$1 - Python3], [$2], [$3], [$4], [$5], [$6],
102                         [$HAVE_PYTHON3], [$PYTHON3])])
103
104 # same as OVSDB_CHECK_IDL but uses the Python IDL implementation with tcp6
105 m4_define([OVSDB_CHECK_IDL_TCP6_PYN],
106   [AT_SETUP([$1 - tcp6])
107    AT_SKIP_IF([test $7 = no])
108    AT_SKIP_IF([test $HAVE_IPV6 = no])
109    AT_KEYWORDS([ovsdb server idl positive Python with tcp6 socket $5])
110    AT_CHECK([ovsdb-tool create db $abs_srcdir/idltest.ovsschema],
111                   [0], [stdout], [ignore])
112    AT_CHECK([ovsdb-server --log-file '-vPATTERN:console:ovsdb-server|%c|%m' --detach --no-chdir --pidfile="`pwd`"/pid --remote=ptcp:0:[[::1]] --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
113    PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
114    echo "TCP_PORT=$TCP_PORT"
115
116    m4_if([$2], [], [],
117      [AT_CHECK([ovsdb-client transact "tcp:[[::1]]:$TCP_PORT" $2], [0], [ignore], [ignore], [kill `cat pid`])])
118    AT_CHECK([$8 $srcdir/test-ovsdb.py  -t10 idl $srcdir/idltest.ovsschema tcp:[[::1]]:$TCP_PORT $3],
119             [0], [stdout], [ignore], [kill `cat pid`])
120    AT_CHECK([sort stdout | ${PERL} $srcdir/uuidfilt.pl]m4_if([$6],,, [[| $6]]),
121             [0], [$4], [], [kill `cat pid`])
122    OVSDB_SERVER_SHUTDOWN
123    AT_CLEANUP])
124
125 m4_define([OVSDB_CHECK_IDL_TCP6_PY],
126    [OVSDB_CHECK_IDL_TCP6_PYN([$1 - Python2], [$2], [$3], [$4], [$5], [$6],
127                         [$HAVE_PYTHON], [$PYTHON])
128     OVSDB_CHECK_IDL_TCP6_PYN([$1 - Python3], [$2], [$3], [$4], [$5], [$6],
129                         [$HAVE_PYTHON3], [$PYTHON3])])
130
131 m4_define([OVSDB_CHECK_IDL],
132   [OVSDB_CHECK_IDL_C($@)
133    OVSDB_CHECK_IDL_PY($@)
134    OVSDB_CHECK_IDL_REGISTER_COLUMNS_PY($@)
135    OVSDB_CHECK_IDL_TCP_PY($@)
136    OVSDB_CHECK_IDL_TCP6_PY($@)])
137
138 OVSDB_CHECK_IDL([simple idl, initially empty, no ops],
139   [],
140   [],
141   [000: empty
142 001: done
143 ])
144
145 OVSDB_CHECK_IDL([simple idl, initially empty, various ops],
146   [],
147   [['["idltest",
148       {"op": "insert",
149        "table": "simple",
150        "row": {"i": 1,
151                "r": 2.0,
152                "b": true,
153                "s": "mystring",
154                "u": ["uuid", "84f5c8f5-ac76-4dbc-a24f-8860eb407fc1"],
155                "ia": ["set", [1, 2, 3]],
156                "ra": ["set", [-0.5]],
157                "ba": ["set", [true]],
158                "sa": ["set", ["abc", "def"]],
159                "ua": ["set", [["uuid", "69443985-7806-45e2-b35f-574a04e720f9"],
160                               ["uuid", "aad11ef0-816a-4b01-93e6-03b8b4256b98"]]]}},
161       {"op": "insert",
162        "table": "simple",
163        "row": {}}]' \
164     '["idltest",
165       {"op": "update",
166        "table": "simple",
167        "where": [],
168        "row": {"b": true}}]' \
169     '["idltest",
170       {"op": "update",
171        "table": "simple",
172        "where": [],
173        "row": {"r": 123.5}}]' \
174     '["idltest",
175       {"op": "insert",
176        "table": "simple",
177        "row": {"i": -1,
178                "r": 125,
179                "b": false,
180                "s": "",
181                "ia": ["set", [1]],
182                "ra": ["set", [1.5]],
183                "ba": ["set", [false]],
184                "sa": ["set", []],
185                "ua": ["set", []]}}]' \
186     '["idltest",
187       {"op": "update",
188        "table": "simple",
189        "where": [["i", "<", 1]],
190        "row": {"s": "newstring"}}]' \
191     '["idltest",
192       {"op": "delete",
193        "table": "simple",
194        "where": [["i", "==", 0]]}]' \
195     'reconnect']],
196   [[000: empty
197 001: {"error":null,"result":[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]}]}
198 002: i=0 r=0 b=false s= u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
199 002: i=1 r=2 b=true s=mystring u=<3> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<4> <5>] uuid=<0>
200 003: {"error":null,"result":[{"count":2}]}
201 004: i=0 r=0 b=true s= u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
202 004: i=1 r=2 b=true s=mystring u=<3> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<4> <5>] uuid=<0>
203 005: {"error":null,"result":[{"count":2}]}
204 006: i=0 r=123.5 b=true s= u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
205 006: i=1 r=123.5 b=true s=mystring u=<3> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<4> <5>] uuid=<0>
206 007: {"error":null,"result":[{"uuid":["uuid","<6>"]}]}
207 008: i=-1 r=125 b=false s= u=<2> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[] uuid=<6>
208 008: i=0 r=123.5 b=true s= u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
209 008: i=1 r=123.5 b=true s=mystring u=<3> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<4> <5>] uuid=<0>
210 009: {"error":null,"result":[{"count":2}]}
211 010: i=-1 r=125 b=false s=newstring u=<2> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[] uuid=<6>
212 010: i=0 r=123.5 b=true s=newstring u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
213 010: i=1 r=123.5 b=true s=mystring u=<3> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<4> <5>] uuid=<0>
214 011: {"error":null,"result":[{"count":1}]}
215 012: i=-1 r=125 b=false s=newstring u=<2> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[] uuid=<6>
216 012: i=1 r=123.5 b=true s=mystring u=<3> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<4> <5>] uuid=<0>
217 013: reconnect
218 014: i=-1 r=125 b=false s=newstring u=<2> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[] uuid=<6>
219 014: i=1 r=123.5 b=true s=mystring u=<3> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<4> <5>] uuid=<0>
220 015: done
221 ]])
222
223 OVSDB_CHECK_IDL([simple idl, initially populated],
224   [['["idltest",
225       {"op": "insert",
226        "table": "simple",
227        "row": {"i": 1,
228                "r": 2.0,
229                "b": true,
230                "s": "mystring",
231                "u": ["uuid", "84f5c8f5-ac76-4dbc-a24f-8860eb407fc1"],
232                "ia": ["set", [1, 2, 3]],
233                "ra": ["set", [-0.5]],
234                "ba": ["set", [true]],
235                "sa": ["set", ["abc", "def"]],
236                "ua": ["set", [["uuid", "69443985-7806-45e2-b35f-574a04e720f9"],
237                               ["uuid", "aad11ef0-816a-4b01-93e6-03b8b4256b98"]]]}},
238       {"op": "insert",
239        "table": "simple",
240        "row": {}}]']],
241   [['["idltest",
242       {"op": "update",
243        "table": "simple",
244        "where": [],
245        "row": {"b": true}}]']],
246   [[000: i=0 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
247 000: i=1 r=2 b=true s=mystring u=<2> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<3> <4>] uuid=<5>
248 001: {"error":null,"result":[{"count":2}]}
249 002: i=0 r=0 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
250 002: i=1 r=2 b=true s=mystring u=<2> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<3> <4>] uuid=<5>
251 003: done
252 ]])
253
254 OVSDB_CHECK_IDL([simple idl, writing via IDL],
255   [['["idltest",
256       {"op": "insert",
257        "table": "simple",
258        "row": {"i": 1,
259                "r": 2.0,
260                "b": true,
261                "s": "mystring",
262                "u": ["uuid", "84f5c8f5-ac76-4dbc-a24f-8860eb407fc1"],
263                "ia": ["set", [1, 2, 3]],
264                "ra": ["set", [-0.5]],
265                "ba": ["set", [true]],
266                "sa": ["set", ["abc", "def"]],
267                "ua": ["set", [["uuid", "69443985-7806-45e2-b35f-574a04e720f9"],
268                               ["uuid", "aad11ef0-816a-4b01-93e6-03b8b4256b98"]]]}},
269       {"op": "insert",
270        "table": "simple",
271        "row": {}}]']],
272   [['verify 0 b, verify 1 r, set 0 b 1, set 1 r 3.5' \
273     'insert 2, verify 2 i, verify 1 b, delete 1']],
274   [[000: i=0 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
275 000: i=1 r=2 b=true s=mystring u=<2> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<3> <4>] uuid=<5>
276 001: commit, status=success
277 002: i=0 r=0 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
278 002: i=1 r=3.5 b=true s=mystring u=<2> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<3> <4>] uuid=<5>
279 003: commit, status=success
280 004: i=0 r=0 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
281 004: i=2 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<6>
282 005: done
283 ]])
284
285 OVSDB_CHECK_IDL([simple idl, handling verification failure],
286   [['["idltest",
287       {"op": "insert",
288        "table": "simple",
289        "row": {"i": 1,
290                "r": 2.0}},
291       {"op": "insert",
292        "table": "simple",
293        "row": {}}]']],
294   [['set 0 b 1' \
295     '+["idltest",
296        {"op": "update",
297         "table": "simple",
298         "where": [["i", "==", 1]],
299         "row": {"r": 5.0}}]' \
300     '+verify 1 r, set 1 r 3' \
301     'verify 1 r, set 1 r 3' \
302     ]],
303   [[000: i=0 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
304 000: i=1 r=2 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<2>
305 001: commit, status=success
306 002: {"error":null,"result":[{"count":1}]}
307 003: commit, status=try again
308 004: i=0 r=0 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
309 004: i=1 r=5 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<2>
310 005: commit, status=success
311 006: i=0 r=0 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
312 006: i=1 r=3 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<2>
313 007: done
314 ]])
315
316 OVSDB_CHECK_IDL([simple idl, increment operation],
317   [['["idltest",
318       {"op": "insert",
319        "table": "simple",
320        "row": {}}]']],
321   [['set 0 r 2.0, increment 0']],
322   [[000: i=0 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
323 001: commit, status=success, increment=1
324 002: i=1 r=2 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
325 003: done
326 ]])
327
328 OVSDB_CHECK_IDL([simple idl, aborting],
329   [['["idltest",
330       {"op": "insert",
331        "table": "simple",
332        "row": {}}]']],
333   [['set 0 r 2.0, abort' \
334 '+set 0 b 1']],
335   [[000: i=0 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
336 001: commit, status=aborted
337 002: commit, status=success
338 003: i=0 r=0 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
339 004: done
340 ]])
341
342 OVSDB_CHECK_IDL([simple idl, destroy without commit or abort],
343   [['["idltest",
344       {"op": "insert",
345        "table": "simple",
346        "row": {}}]']],
347   [['set 0 r 2.0, destroy' \
348 '+set 0 b 1']],
349   [[000: i=0 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
350 001: destroy
351 002: commit, status=success
352 003: i=0 r=0 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
353 004: done
354 ]])
355
356 OVSDB_CHECK_IDL([self-linking idl, consistent ops],
357   [],
358   [['["idltest",
359       {"op": "insert",
360        "table": "link1",
361        "row": {"i": 0, "k": ["named-uuid", "self"]},
362        "uuid-name": "self"}]' \
363     '["idltest",
364       {"op": "insert",
365        "table": "link1",
366        "row": {"i": 1, "k": ["named-uuid", "row2"]},
367        "uuid-name": "row1"},
368       {"op": "insert",
369        "table": "link1",
370        "row": {"i": 2, "k": ["named-uuid", "row1"]},
371        "uuid-name": "row2"}]' \
372     '["idltest",
373       {"op": "update",
374        "table": "link1",
375        "where": [["i", "==", 1]],
376        "row": {"k": ["uuid", "#1#"]}}]' \
377     '["idltest",
378       {"op": "update",
379        "table": "link1",
380        "where": [],
381        "row": {"k": ["uuid", "#0#"]}}]']],
382   [[000: empty
383 001: {"error":null,"result":[{"uuid":["uuid","<0>"]}]}
384 002: i=0 k=0 ka=[] l2= uuid=<0>
385 003: {"error":null,"result":[{"uuid":["uuid","<1>"]},{"uuid":["uuid","<2>"]}]}
386 004: i=0 k=0 ka=[] l2= uuid=<0>
387 004: i=1 k=2 ka=[] l2= uuid=<1>
388 004: i=2 k=1 ka=[] l2= uuid=<2>
389 005: {"error":null,"result":[{"count":1}]}
390 006: i=0 k=0 ka=[] l2= uuid=<0>
391 006: i=1 k=1 ka=[] l2= uuid=<1>
392 006: i=2 k=1 ka=[] l2= uuid=<2>
393 007: {"error":null,"result":[{"count":3}]}
394 008: i=0 k=0 ka=[] l2= uuid=<0>
395 008: i=1 k=0 ka=[] l2= uuid=<1>
396 008: i=2 k=0 ka=[] l2= uuid=<2>
397 009: done
398 ]])
399
400 OVSDB_CHECK_IDL([self-linking idl, inconsistent ops],
401   [],
402   [['["idltest",
403       {"op": "insert",
404        "table": "link1",
405        "row": {"i": 0, "k": ["uuid", "cf197cc5-c8c9-42f5-82d5-c71a9f2cb96b"]}}]' \
406     '+["idltest",
407       {"op": "insert",
408        "table": "link1",
409        "uuid-name": "one",
410        "row": {"i": 1, "k": ["named-uuid", "one"]}},
411       {"op": "insert",
412        "table": "link1",
413        "row": {"i": 2, "k": ["named-uuid", "one"]}}]' \
414      '["idltest",
415       {"op": "update",
416        "table": "link1",
417        "where": [],
418        "row": {"k": ["uuid", "c2fca39a-e69a-42a4-9c56-5eca85839ce9"]}}]' \
419      '+["idltest",
420       {"op": "delete",
421        "table": "link1",
422        "where": [["_uuid", "==", ["uuid", "#1#"]]]}]' \
423      '+["idltest",
424       {"op": "delete",
425        "table": "link1",
426        "where": [["_uuid", "==", ["uuid", "#2#"]]]}]' \
427      '["idltest",
428       {"op": "delete",
429        "table": "link1",
430        "where": []}]' \
431 ]],
432   [[000: empty
433 001: {"error":null,"result":[{"uuid":["uuid","<0>"]},{"details":"Table link1 column k row <0> references nonexistent row <1> in table link1.","error":"referential integrity violation"}]}
434 002: {"error":null,"result":[{"uuid":["uuid","<2>"]},{"uuid":["uuid","<3>"]}]}
435 003: i=1 k=1 ka=[] l2= uuid=<2>
436 003: i=2 k=1 ka=[] l2= uuid=<3>
437 004: {"error":null,"result":[{"count":2},{"details":"Table link1 column k row <x> references nonexistent row <4> in table link1.","error":"referential integrity violation"}]}
438 005: {"error":null,"result":[{"count":1},{"details":"cannot delete link1 row <2> because of 1 remaining reference(s)","error":"referential integrity violation"}]}
439 006: {"error":null,"result":[{"count":1}]}
440 007: i=1 k=1 ka=[] l2= uuid=<2>
441 008: {"error":null,"result":[{"count":1}]}
442 009: empty
443 010: done
444 ]],
445   [],
446   [[sed -e '/004:/s/row <[23]> references/row <x> references/']])
447
448 OVSDB_CHECK_IDL([self-linking idl, sets],
449   [],
450   [['["idltest",
451       {"op": "insert",
452        "table": "link1",
453        "row": {"i": 0, "k": ["named-uuid", "i0"], "ka": ["set", [["named-uuid", "i0"]]]},
454        "uuid-name": "i0"},
455       {"op": "insert",
456        "table": "link1",
457        "row": {"i": 1, "k": ["named-uuid", "i0"], "ka": ["set", [["named-uuid", "i1"]]]},
458        "uuid-name": "i1"},
459       {"op": "insert",
460        "table": "link1",
461        "row": {"i": 2, "k": ["named-uuid", "i0"], "ka": ["set", [["named-uuid", "i2"]]]},
462        "uuid-name": "i2"},
463       {"op": "insert",
464        "table": "link1",
465        "row": {"i": 3, "k": ["named-uuid", "i0"], "ka": ["set", [["named-uuid", "i3"]]]},
466        "uuid-name": "i3"}]' \
467     '["idltest",
468       {"op": "update",
469        "table": "link1",
470        "where": [],
471        "row": {"ka": ["set", [["uuid", "#0#"], ["uuid", "#1#"], ["uuid", "#2#"], ["uuid", "#3#"]]]}}]' \
472     '["idltest",
473       {"op": "update",
474        "table": "link1",
475        "where": [["i", "==", 2]],
476        "row": {"ka": ["set", [["uuid", "#0#"], ["uuid", "88702e78-845b-4a6e-ad08-cf68922ae84a"], ["uuid", "#2#"]]]}}]' \
477     '+["idltest",
478       {"op": "delete",
479        "table": "link1",
480        "where": []}]']],
481   [[000: empty
482 001: {"error":null,"result":[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]},{"uuid":["uuid","<2>"]},{"uuid":["uuid","<3>"]}]}
483 002: i=0 k=0 ka=[0] l2= uuid=<0>
484 002: i=1 k=0 ka=[1] l2= uuid=<1>
485 002: i=2 k=0 ka=[2] l2= uuid=<2>
486 002: i=3 k=0 ka=[3] l2= uuid=<3>
487 003: {"error":null,"result":[{"count":4}]}
488 004: i=0 k=0 ka=[0 1 2 3] l2= uuid=<0>
489 004: i=1 k=0 ka=[0 1 2 3] l2= uuid=<1>
490 004: i=2 k=0 ka=[0 1 2 3] l2= uuid=<2>
491 004: i=3 k=0 ka=[0 1 2 3] l2= uuid=<3>
492 005: {"error":null,"result":[{"count":1},{"details":"Table link1 column ka row <2> references nonexistent row <4> in table link1.","error":"referential integrity violation"}]}
493 006: {"error":null,"result":[{"count":4}]}
494 007: empty
495 008: done
496 ]])
497
498 OVSDB_CHECK_IDL([external-linking idl, consistent ops],
499   [],
500   [['["idltest",
501       {"op": "insert",
502        "table": "link2",
503        "row": {"i": 0},
504        "uuid-name": "row0"},
505       {"op": "insert",
506        "table": "link1",
507        "row": {"i": 1, "k": ["named-uuid", "row1"], "l2": ["set", [["named-uuid", "row0"]]]},
508        "uuid-name": "row1"}]']],
509   [[000: empty
510 001: {"error":null,"result":[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]}]}
511 002: i=0 l1= uuid=<0>
512 002: i=1 k=1 ka=[] l2=0 uuid=<1>
513 003: done
514 ]])
515
516 OVSDB_CHECK_IDL_PY([external-linking idl, insert ops],
517   [],
518   [['linktest']],
519   [[000: empty
520 001: commit, status=success
521 002: i=1 k=1 ka=[1] l2= uuid=<0>
522 002: i=2 k=1 ka=[1 2] l2= uuid=<1>
523 003: done
524 ]])
525
526 OVSDB_CHECK_IDL_PY([getattr idl, insert ops],
527   [],
528   [['getattrtest']],
529   [[000: empty
530 001: commit, status=success
531 002: i=2 k=2 ka=[] l2= uuid=<0>
532 003: done
533 ]])
534
535 OVSDB_CHECK_IDL_PY([row-from-json idl, whats this],
536   [['["idltest",
537       {"op": "insert",
538        "table": "simple",
539        "row": {"i": 1}},
540       {"op": "insert",
541        "table": "simple",
542        "row": {}}]']],
543   [['notifytest insert 2, notifytest set 1 b 1, notifytest delete 0']],
544   [[000: i=0 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
545 000: i=1 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<2>
546 001: commit, status=success, events=create|2|None, delete|0|None, update|1|b
547 002: i=1 r=0 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<2>
548 002: i=2 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<3>
549 003: done
550 ]])
551
552 AT_SETUP([idl handling of missing tables and columns - C])
553 AT_KEYWORDS([ovsdb server idl positive])
554
555 # idltest2.ovsschema is the same as idltest.ovsschema, except that
556 # table link2 and column l2 have been deleted.  But the IDL still
557 # expects them to be there, so this test checks that it properly
558 # tolerates them being missing.
559 AT_CHECK([ovsdb-tool create db $abs_srcdir/idltest2.ovsschema],
560     [0], [stdout], [ignore])
561 AT_CHECK([ovsdb-server '-vPATTERN:console:ovsdb-server|%c|%m' --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
562 AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 idl unix:socket ['["idltest",
563       {"op": "insert",
564        "table": "link1",
565        "row": {"i": 0, "k": ["named-uuid", "self"]},
566        "uuid-name": "self"}]' \
567     '["idltest",
568       {"op": "insert",
569        "table": "link1",
570        "row": {"i": 1, "k": ["named-uuid", "row2"]},
571        "uuid-name": "row1"},
572       {"op": "insert",
573        "table": "link1",
574        "row": {"i": 2, "k": ["named-uuid", "row1"]},
575        "uuid-name": "row2"}]' \
576     '["idltest",
577       {"op": "update",
578        "table": "link1",
579        "where": [["i", "==", 1]],
580        "row": {"k": ["uuid", "#1#"]}}]' \
581     '["idltest",
582       {"op": "update",
583        "table": "link1",
584        "where": [],
585        "row": {"k": ["uuid", "#0#"]}}]']],
586          [0], [stdout], [stderr], [kill `cat pid`])
587 AT_CHECK([sort stdout | ${PERL} $srcdir/uuidfilt.pl], [0],
588     [[000: empty
589 001: {"error":null,"result":[{"uuid":["uuid","<0>"]}]}
590 002: i=0 k=0 ka=[] l2= uuid=<0>
591 003: {"error":null,"result":[{"uuid":["uuid","<1>"]},{"uuid":["uuid","<2>"]}]}
592 004: i=0 k=0 ka=[] l2= uuid=<0>
593 004: i=1 k=2 ka=[] l2= uuid=<1>
594 004: i=2 k=1 ka=[] l2= uuid=<2>
595 005: {"error":null,"result":[{"count":1}]}
596 006: i=0 k=0 ka=[] l2= uuid=<0>
597 006: i=1 k=1 ka=[] l2= uuid=<1>
598 006: i=2 k=1 ka=[] l2= uuid=<2>
599 007: {"error":null,"result":[{"count":3}]}
600 008: i=0 k=0 ka=[] l2= uuid=<0>
601 008: i=1 k=0 ka=[] l2= uuid=<1>
602 008: i=2 k=0 ka=[] l2= uuid=<2>
603 009: done
604 ]], [], [kill `cat pid`])
605
606 # Check that ovsdb-idl figured out that table link2 and column l2 are missing.
607 AT_CHECK([grep ovsdb_idl stderr | sort], [0], [dnl
608 test-ovsdb|ovsdb_idl|idltest database lacks link2 table (database needs upgrade?)
609 test-ovsdb|ovsdb_idl|link1 table in idltest database lacks l2 column (database needs upgrade?)
610 ])
611
612 # Check that ovsdb-idl sent on "monitor" request and that it didn't
613 # mention that table or column, and (for paranoia) that it did mention another
614 # table and column.
615 AT_CHECK([grep -c '"monitor\|monitor2"' stderr], [0], [1
616 ])
617 AT_CHECK([grep '"monitor\|monitor2"' stderr | grep link2], [1])
618 AT_CHECK([grep '"monitor\|monitor2"' stderr | grep l2], [1])
619 AT_CHECK([grep '"monitor\|monitor2"' stderr | grep -c '"link1"'], [0], [1
620 ])
621 AT_CHECK([grep '"monitor\|monitor2"' stderr | grep -c '"ua"'], [0], [1
622 ])
623 OVSDB_SERVER_SHUTDOWN
624 AT_CLEANUP
625
626 m4_define([OVSDB_CHECK_IDL_FETCH_COLUMNS_PY],
627   [AT_SETUP([$1 - Python fetch])
628    AT_SKIP_IF([test $HAVE_PYTHON = no])
629    AT_KEYWORDS([ovsdb server idl positive Python increment fetch $6])
630    AT_CHECK([ovsdb-tool create db $abs_srcdir/idltest.ovsschema],
631                   [0], [stdout], [ignore])
632    AT_CHECK([ovsdb-server '-vPATTERN:console:ovsdb-server|%c|%m' --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
633    m4_if([$2], [], [],
634      [AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore], [kill `cat pid`])])
635    AT_CHECK([$PYTHON $srcdir/test-ovsdb.py  -t10 idl $srcdir/idltest.ovsschema unix:socket [$3] $4],
636             [0], [stdout], [ignore], [kill `cat pid`])
637    AT_CHECK([sort stdout | ${PERL} $srcdir/uuidfilt.pl]m4_if([$7],,, [[| $7]]),
638             [0], [$5], [], [kill `cat pid`])
639    OVSDB_SERVER_SHUTDOWN
640    AT_CLEANUP])
641
642 m4_define([OVSDB_CHECK_IDL_FETCH_COLUMNS],
643    [OVSDB_CHECK_IDL_FETCH_COLUMNS_PY($@)])
644
645 OVSDB_CHECK_IDL_FETCH_COLUMNS([simple idl, initially populated],
646   [['["idltest",
647       {"op": "insert",
648        "table": "simple",
649        "row": {"i": 1,
650                "r": 2.0,
651                "b": true,
652                "s": "mystring",
653                "u": ["uuid", "84f5c8f5-ac76-4dbc-a24f-8860eb407fc1"],
654                "ia": ["set", [1, 2, 3]],
655                "ra": ["set", [-0.5]],
656                "ba": ["set", [true]],
657                "sa": ["set", ["abc", "def"]],
658                "ua": ["set", [["uuid", "69443985-7806-45e2-b35f-574a04e720f9"],
659                               ["uuid", "aad11ef0-816a-4b01-93e6-03b8b4256b98"]]]}},
660       {"op": "insert",
661        "table": "simple",
662        "row": {}}]']],
663   [?simple:i,r!],
664   ['fetch 0 r'],
665   [[000: i=0 uuid=<0>
666 000: i=1 uuid=<1>
667 001: commit, status=success
668 002: i=0 r=0 uuid=<0>
669 002: i=1 uuid=<1>
670 003: done
671 ]])
672
673 m4_define([OVSDB_CHECK_IDL_TRACK_C],
674   [AT_SETUP([$1 - C])
675    AT_KEYWORDS([ovsdb server idl tracking positive $5])
676    AT_CHECK([ovsdb-tool create db $abs_srcdir/idltest.ovsschema],
677                   [0], [stdout], [ignore])
678    AT_CHECK([ovsdb-server '-vPATTERN:console:ovsdb-server|%c|%m' --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore])
679    m4_if([$2], [], [],
680      [AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore], [kill `cat pid`])])
681    AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 -c idl unix:socket $3],
682             [0], [stdout], [ignore], [kill `cat pid`])
683    AT_CHECK([sort stdout | ${PERL} $srcdir/uuidfilt.pl]m4_if([$6],,, [[| $6]]),
684             [0], [$4], [], [kill `cat pid`])
685    OVSDB_SERVER_SHUTDOWN
686    AT_CLEANUP])
687
688 m4_define([OVSDB_CHECK_IDL_TRACK],
689   [OVSDB_CHECK_IDL_TRACK_C($@)])
690
691 OVSDB_CHECK_IDL_TRACK([track, simple idl, initially populated],
692   [['["idltest",
693       {"op": "insert",
694        "table": "simple",
695        "row": {"i": 1,
696                "r": 2.0,
697                "b": true,
698                "s": "mystring",
699                "u": ["uuid", "84f5c8f5-ac76-4dbc-a24f-8860eb407fc1"],
700                "ia": ["set", [1, 2, 3]],
701                "ra": ["set", [-0.5]],
702                "ba": ["set", [true]],
703                "sa": ["set", ["abc", "def"]],
704                "ua": ["set", [["uuid", "69443985-7806-45e2-b35f-574a04e720f9"],
705                               ["uuid", "aad11ef0-816a-4b01-93e6-03b8b4256b98"]]]}},
706       {"op": "insert",
707        "table": "simple",
708        "row": {}}]']],
709   [['["idltest",
710       {"op": "update",
711        "table": "simple",
712        "where": [],
713        "row": {"b": true}}]']],
714   [[000: i=1 r=2 b=true s=mystring u=<0> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<1> <2>] uuid=<3>
715 000: updated columns: b ba i ia r ra s sa u ua
716 001: {"error":null,"result":[{"count":2}]}
717 002: i=0 r=0 b=true s= u=<4> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<5>
718 002: i=1 r=2 b=true s=mystring u=<0> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<1> <2>] uuid=<3>
719 002: updated columns: b
720 003: done
721 ]])
722
723 OVSDB_CHECK_IDL_TRACK([track, simple idl, initially empty, various ops],
724   [],
725   [['["idltest",
726       {"op": "insert",
727        "table": "simple",
728        "row": {"i": 1,
729                "r": 2.0,
730                "b": true,
731                "s": "mystring",
732                "u": ["uuid", "84f5c8f5-ac76-4dbc-a24f-8860eb407fc1"],
733                "ia": ["set", [1, 2, 3]],
734                "ra": ["set", [-0.5]],
735                "ba": ["set", [true]],
736                "sa": ["set", ["abc", "def"]],
737                "ua": ["set", [["uuid", "69443985-7806-45e2-b35f-574a04e720f9"],
738                               ["uuid", "aad11ef0-816a-4b01-93e6-03b8b4256b98"]]]}},
739       {"op": "insert",
740        "table": "simple",
741        "row": {}}]' \
742     '["idltest",
743       {"op": "update",
744        "table": "simple",
745        "where": [],
746        "row": {"b": true}}]' \
747     '["idltest",
748       {"op": "update",
749        "table": "simple",
750        "where": [],
751        "row": {"r": 123.5}}]' \
752     '["idltest",
753       {"op": "insert",
754        "table": "simple",
755        "row": {"i": -1,
756                "r": 125,
757                "b": false,
758                "s": "",
759                "ia": ["set", [1]],
760                "ra": ["set", [1.5]],
761                "ba": ["set", [false]],
762                "sa": ["set", []],
763                "ua": ["set", []]}}]' \
764     '["idltest",
765       {"op": "update",
766        "table": "simple",
767        "where": [["i", "<", 1]],
768        "row": {"s": "newstring"}}]' \
769     '["idltest",
770       {"op": "delete",
771        "table": "simple",
772        "where": [["i", "==", 0]]}]' \
773     'reconnect']],
774   [[000: empty
775 001: {"error":null,"result":[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]}]}
776 002: i=1 r=2 b=true s=mystring u=<2> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<3> <4>] uuid=<0>
777 002: updated columns: b ba i ia r ra s sa u ua
778 003: {"error":null,"result":[{"count":2}]}
779 004: i=0 r=0 b=true s= u=<5> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
780 004: updated columns: b
781 005: {"error":null,"result":[{"count":2}]}
782 006: i=0 r=123.5 b=true s= u=<5> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
783 006: i=1 r=123.5 b=true s=mystring u=<2> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<3> <4>] uuid=<0>
784 006: updated columns: r
785 006: updated columns: r
786 007: {"error":null,"result":[{"uuid":["uuid","<6>"]}]}
787 008: i=-1 r=125 b=false s= u=<5> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[] uuid=<6>
788 008: updated columns: ba i ia r ra
789 009: {"error":null,"result":[{"count":2}]}
790 010: i=-1 r=125 b=false s=newstring u=<5> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[] uuid=<6>
791 010: i=0 r=123.5 b=true s=newstring u=<5> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
792 010: updated columns: s
793 010: updated columns: s
794 011: {"error":null,"result":[{"count":1}]}
795 012: ##deleted## uuid=<1>
796 013: reconnect
797 014: i=-1 r=125 b=false s=newstring u=<5> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[] uuid=<6>
798 014: i=1 r=123.5 b=true s=mystring u=<2> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<3> <4>] uuid=<0>
799 014: updated columns: b ba i ia r ra s sa u ua
800 014: updated columns: ba i ia r ra s
801 015: done
802 ]])