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