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