python: Implement write support in Python IDL for OVSDB.
[sliver-openvswitch.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 --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 --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],
52   [OVSDB_CHECK_IDL_C($@)
53    OVSDB_CHECK_IDL_PY($@)])
54
55 OVSDB_CHECK_IDL([simple idl, initially empty, no ops],
56   [],
57   [],
58   [000: empty
59 001: done
60 ])
61
62 OVSDB_CHECK_IDL([simple idl, initially empty, various ops],
63   [],
64   [['["idltest",
65       {"op": "insert",
66        "table": "simple",
67        "row": {"i": 1,
68                "r": 2.0,
69                "b": true,
70                "s": "mystring",
71                "u": ["uuid", "84f5c8f5-ac76-4dbc-a24f-8860eb407fc1"],
72                "ia": ["set", [1, 2, 3]],
73                "ra": ["set", [-0.5]],
74                "ba": ["set", [true]],
75                "sa": ["set", ["abc", "def"]],
76                "ua": ["set", [["uuid", "69443985-7806-45e2-b35f-574a04e720f9"],
77                               ["uuid", "aad11ef0-816a-4b01-93e6-03b8b4256b98"]]]}},
78       {"op": "insert",
79        "table": "simple",
80        "row": {}}]' \
81     '["idltest",
82       {"op": "update",
83        "table": "simple",
84        "where": [],
85        "row": {"b": true}}]' \
86     '["idltest",
87       {"op": "update",
88        "table": "simple",
89        "where": [],
90        "row": {"r": 123.5}}]' \
91     '["idltest",
92       {"op": "insert",
93        "table": "simple",
94        "row": {"i": -1,
95                "r": 125,
96                "b": false,
97                "s": "",
98                "ia": ["set", [1]],
99                "ra": ["set", [1.5]],
100                "ba": ["set", [false]],
101                "sa": ["set", []],
102                "ua": ["set", []]}}]' \
103     '["idltest",
104       {"op": "update",
105        "table": "simple",
106        "where": [["i", "<", 1]],
107        "row": {"s": "newstring"}}]' \
108     '["idltest",
109       {"op": "delete",
110        "table": "simple",
111        "where": [["i", "==", 0]]}]' \
112     'reconnect']],
113   [[000: empty
114 001: {"error":null,"result":[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]}]}
115 002: i=0 r=0 b=false s= u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
116 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>
117 003: {"error":null,"result":[{"count":2}]}
118 004: i=0 r=0 b=true s= u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
119 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>
120 005: {"error":null,"result":[{"count":2}]}
121 006: i=0 r=123.5 b=true s= u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
122 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>
123 007: {"error":null,"result":[{"uuid":["uuid","<6>"]}]}
124 008: i=-1 r=125 b=false s= u=<2> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[] uuid=<6>
125 008: i=0 r=123.5 b=true s= u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
126 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>
127 009: {"error":null,"result":[{"count":2}]}
128 010: i=-1 r=125 b=false s=newstring u=<2> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[] uuid=<6>
129 010: i=0 r=123.5 b=true s=newstring u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
130 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>
131 011: {"error":null,"result":[{"count":1}]}
132 012: i=-1 r=125 b=false s=newstring u=<2> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[] uuid=<6>
133 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>
134 013: reconnect
135 014: i=-1 r=125 b=false s=newstring u=<2> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[] uuid=<6>
136 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>
137 015: done
138 ]])
139
140 OVSDB_CHECK_IDL([simple idl, initially populated],
141   [['["idltest",
142       {"op": "insert",
143        "table": "simple",
144        "row": {"i": 1,
145                "r": 2.0,
146                "b": true,
147                "s": "mystring",
148                "u": ["uuid", "84f5c8f5-ac76-4dbc-a24f-8860eb407fc1"],
149                "ia": ["set", [1, 2, 3]],
150                "ra": ["set", [-0.5]],
151                "ba": ["set", [true]],
152                "sa": ["set", ["abc", "def"]],
153                "ua": ["set", [["uuid", "69443985-7806-45e2-b35f-574a04e720f9"],
154                               ["uuid", "aad11ef0-816a-4b01-93e6-03b8b4256b98"]]]}},
155       {"op": "insert",
156        "table": "simple",
157        "row": {}}]']],
158   [['["idltest",
159       {"op": "update",
160        "table": "simple",
161        "where": [],
162        "row": {"b": true}}]']],
163   [[000: i=0 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
164 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>
165 001: {"error":null,"result":[{"count":2}]}
166 002: i=0 r=0 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
167 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>
168 003: done
169 ]])
170
171 OVSDB_CHECK_IDL([simple idl, writing via IDL],
172   [['["idltest",
173       {"op": "insert",
174        "table": "simple",
175        "row": {"i": 1,
176                "r": 2.0,
177                "b": true,
178                "s": "mystring",
179                "u": ["uuid", "84f5c8f5-ac76-4dbc-a24f-8860eb407fc1"],
180                "ia": ["set", [1, 2, 3]],
181                "ra": ["set", [-0.5]],
182                "ba": ["set", [true]],
183                "sa": ["set", ["abc", "def"]],
184                "ua": ["set", [["uuid", "69443985-7806-45e2-b35f-574a04e720f9"],
185                               ["uuid", "aad11ef0-816a-4b01-93e6-03b8b4256b98"]]]}},
186       {"op": "insert",
187        "table": "simple",
188        "row": {}}]']],
189   [['verify 0 b, verify 1 r, set 0 b 1, set 1 r 3.5' \
190     'insert 2, verify 2 i, verify 1 b, delete 1']],
191   [[000: i=0 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
192 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>
193 001: commit, status=success
194 002: i=0 r=0 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
195 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>
196 003: commit, status=success
197 004: i=0 r=0 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
198 004: i=2 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<6>
199 005: done
200 ]])
201
202 OVSDB_CHECK_IDL([simple idl, handling verification failure],
203   [['["idltest",
204       {"op": "insert",
205        "table": "simple",
206        "row": {"i": 1,
207                "r": 2.0}},
208       {"op": "insert",
209        "table": "simple",
210        "row": {}}]']],
211   [['set 0 b 1' \
212     '+["idltest",
213        {"op": "update",
214         "table": "simple",
215         "where": [["i", "==", 1]],
216         "row": {"r": 5.0}}]' \
217     '+verify 1 r, set 1 r 3' \
218     'verify 1 r, set 1 r 3' \
219     ]],
220   [[000: i=0 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
221 000: i=1 r=2 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<2>
222 001: commit, status=success
223 002: {"error":null,"result":[{"count":1}]}
224 003: commit, status=try again
225 004: i=0 r=0 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
226 004: i=1 r=5 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<2>
227 005: commit, status=success
228 006: i=0 r=0 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
229 006: i=1 r=3 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<2>
230 007: done
231 ]])
232
233 OVSDB_CHECK_IDL([simple idl, increment operation],
234   [['["idltest",
235       {"op": "insert",
236        "table": "simple",
237        "row": {}}]']],
238   [['set 0 r 2.0, increment simple i']],
239   [[000: i=0 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
240 001: commit, status=success, increment=1
241 002: i=1 r=2 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
242 003: done
243 ]])
244
245 OVSDB_CHECK_IDL([simple idl, aborting],
246   [['["idltest",
247       {"op": "insert",
248        "table": "simple",
249        "row": {}}]']],
250   [['set 0 r 2.0, abort' \
251 '+set 0 b 1']],
252   [[000: i=0 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
253 001: commit, status=aborted
254 002: commit, status=success
255 003: i=0 r=0 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
256 004: done
257 ]])
258
259 OVSDB_CHECK_IDL([simple idl, destroy without commit or abort],
260   [['["idltest",
261       {"op": "insert",
262        "table": "simple",
263        "row": {}}]']],
264   [['set 0 r 2.0, destroy' \
265 '+set 0 b 1']],
266   [[000: i=0 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
267 001: destroy
268 002: commit, status=success
269 003: i=0 r=0 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
270 004: done
271 ]])
272
273 OVSDB_CHECK_IDL([self-linking idl, consistent ops],
274   [],
275   [['["idltest",
276       {"op": "insert",
277        "table": "link1",
278        "row": {"i": 0, "k": ["named-uuid", "self"]},
279        "uuid-name": "self"}]' \
280     '["idltest",
281       {"op": "insert",
282        "table": "link1",
283        "row": {"i": 1, "k": ["named-uuid", "row2"]},
284        "uuid-name": "row1"},
285       {"op": "insert",
286        "table": "link1",
287        "row": {"i": 2, "k": ["named-uuid", "row1"]},
288        "uuid-name": "row2"}]' \
289     '["idltest",
290       {"op": "update",
291        "table": "link1",
292        "where": [["i", "==", 1]],
293        "row": {"k": ["uuid", "#1#"]}}]' \
294     '["idltest",
295       {"op": "update",
296        "table": "link1",
297        "where": [],
298        "row": {"k": ["uuid", "#0#"]}}]']],
299   [[000: empty
300 001: {"error":null,"result":[{"uuid":["uuid","<0>"]}]}
301 002: i=0 k=0 ka=[] l2= uuid=<0>
302 003: {"error":null,"result":[{"uuid":["uuid","<1>"]},{"uuid":["uuid","<2>"]}]}
303 004: i=0 k=0 ka=[] l2= uuid=<0>
304 004: i=1 k=2 ka=[] l2= uuid=<1>
305 004: i=2 k=1 ka=[] l2= uuid=<2>
306 005: {"error":null,"result":[{"count":1}]}
307 006: i=0 k=0 ka=[] l2= uuid=<0>
308 006: i=1 k=1 ka=[] l2= uuid=<1>
309 006: i=2 k=1 ka=[] l2= uuid=<2>
310 007: {"error":null,"result":[{"count":3}]}
311 008: i=0 k=0 ka=[] l2= uuid=<0>
312 008: i=1 k=0 ka=[] l2= uuid=<1>
313 008: i=2 k=0 ka=[] l2= uuid=<2>
314 009: done
315 ]])
316
317 OVSDB_CHECK_IDL([self-linking idl, inconsistent ops],
318   [],
319   [['["idltest",
320       {"op": "insert",
321        "table": "link1",
322        "row": {"i": 0, "k": ["uuid", "cf197cc5-c8c9-42f5-82d5-c71a9f2cb96b"]}}]' \
323     '+["idltest",
324       {"op": "insert",
325        "table": "link1",
326        "uuid-name": "one",
327        "row": {"i": 1, "k": ["named-uuid", "one"]}},
328       {"op": "insert",
329        "table": "link1",
330        "row": {"i": 2, "k": ["named-uuid", "one"]}}]' \
331      '["idltest",
332       {"op": "update",
333        "table": "link1",
334        "where": [],
335        "row": {"k": ["uuid", "c2fca39a-e69a-42a4-9c56-5eca85839ce9"]}}]' \
336      '+["idltest",
337       {"op": "delete",
338        "table": "link1",
339        "where": [["_uuid", "==", ["uuid", "#1#"]]]}]' \
340      '+["idltest",
341       {"op": "delete",
342        "table": "link1",
343        "where": [["_uuid", "==", ["uuid", "#2#"]]]}]' \
344      '["idltest",
345       {"op": "delete",
346        "table": "link1",
347        "where": []}]' \
348 ]],
349   [[000: empty
350 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"}]}
351 002: {"error":null,"result":[{"uuid":["uuid","<2>"]},{"uuid":["uuid","<3>"]}]}
352 003: i=1 k=1 ka=[] l2= uuid=<2>
353 003: i=2 k=1 ka=[] l2= uuid=<3>
354 004: {"error":null,"result":[{"count":2},{"details":"Table link1 column k row <x> references nonexistent row <4> in table link1.","error":"referential integrity violation"}]}
355 005: {"error":null,"result":[{"count":1},{"details":"cannot delete link1 row <2> because of 1 remaining reference(s)","error":"referential integrity violation"}]}
356 006: {"error":null,"result":[{"count":1}]}
357 007: i=1 k=1 ka=[] l2= uuid=<2>
358 008: {"error":null,"result":[{"count":1}]}
359 009: empty
360 010: done
361 ]],
362   [],
363   [[sed -e '/004:/s/row <[23]> references/row <x> references/']])
364
365 OVSDB_CHECK_IDL([self-linking idl, sets],
366   [],
367   [['["idltest",
368       {"op": "insert",
369        "table": "link1",
370        "row": {"i": 0, "k": ["named-uuid", "i0"], "ka": ["set", [["named-uuid", "i0"]]]},
371        "uuid-name": "i0"},
372       {"op": "insert",
373        "table": "link1",
374        "row": {"i": 1, "k": ["named-uuid", "i0"], "ka": ["set", [["named-uuid", "i1"]]]},
375        "uuid-name": "i1"},
376       {"op": "insert",
377        "table": "link1",
378        "row": {"i": 2, "k": ["named-uuid", "i0"], "ka": ["set", [["named-uuid", "i2"]]]},
379        "uuid-name": "i2"},
380       {"op": "insert",
381        "table": "link1",
382        "row": {"i": 3, "k": ["named-uuid", "i0"], "ka": ["set", [["named-uuid", "i3"]]]},
383        "uuid-name": "i3"}]' \
384     '["idltest",
385       {"op": "update",
386        "table": "link1",
387        "where": [],
388        "row": {"ka": ["set", [["uuid", "#0#"], ["uuid", "#1#"], ["uuid", "#2#"], ["uuid", "#3#"]]]}}]' \
389     '["idltest",
390       {"op": "update",
391        "table": "link1",
392        "where": [["i", "==", 2]],
393        "row": {"ka": ["set", [["uuid", "#0#"], ["uuid", "88702e78-845b-4a6e-ad08-cf68922ae84a"], ["uuid", "#2#"]]]}}]' \
394     '+["idltest",
395       {"op": "delete",
396        "table": "link1",
397        "where": []}]']],
398   [[000: empty
399 001: {"error":null,"result":[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]},{"uuid":["uuid","<2>"]},{"uuid":["uuid","<3>"]}]}
400 002: i=0 k=0 ka=[0] l2= uuid=<0>
401 002: i=1 k=0 ka=[1] l2= uuid=<1>
402 002: i=2 k=0 ka=[2] l2= uuid=<2>
403 002: i=3 k=0 ka=[3] l2= uuid=<3>
404 003: {"error":null,"result":[{"count":4}]}
405 004: i=0 k=0 ka=[0 1 2 3] l2= uuid=<0>
406 004: i=1 k=0 ka=[0 1 2 3] l2= uuid=<1>
407 004: i=2 k=0 ka=[0 1 2 3] l2= uuid=<2>
408 004: i=3 k=0 ka=[0 1 2 3] l2= uuid=<3>
409 005: {"error":null,"result":[{"count":1},{"details":"Table link1 column ka row <2> references nonexistent row <4> in table link1.","error":"referential integrity violation"}]}
410 006: {"error":null,"result":[{"count":4}]}
411 007: empty
412 008: done
413 ]])
414
415 OVSDB_CHECK_IDL([external-linking idl, consistent ops],
416   [],
417   [['["idltest",
418       {"op": "insert",
419        "table": "link2",
420        "row": {"i": 0},
421        "uuid-name": "row0"},
422       {"op": "insert",
423        "table": "link1",
424        "row": {"i": 1, "k": ["named-uuid", "row1"], "l2": ["set", [["named-uuid", "row0"]]]},
425        "uuid-name": "row1"}]']],
426   [[000: empty
427 001: {"error":null,"result":[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]}]}
428 002: i=0 l1= uuid=<0>
429 002: i=1 k=1 ka=[] l2=0 uuid=<1>
430 003: done
431 ]])