ovsdb: Free "error" string in ovsdb_execute_insert().
[openvswitch] / tests / ovsdb-monitor.at
1 AT_BANNER([OVSDB -- ovsdb-server monitors])
2
3 # OVSDB_CHECK_MONITOR(TITLE, SCHEMA, [PRE-MONITOR-TXN], DB, TABLE,
4 #                     TRANSACTIONS, OUTPUT, [COLUMNS], [KEYWORDS])
5 #
6 # Creates a database with the given SCHEMA, starts an ovsdb-server on
7 # that database, and runs each of the TRANSACTIONS (which should be a
8 # quoted list of quoted strings) against it with ovsdb-client one at a
9 # time.  COLUMNS, if specified, is passed to ovsdb-client as the set
10 # of columns and operations to select.
11 #
12 # Checks that the overall output is OUTPUT, but UUIDs in the output
13 # are replaced by markers of the form <N> where N is a number.  The
14 # first unique UUID is replaced by <0>, the next by <1>, and so on.
15 # If a given UUID appears more than once it is always replaced by the
16 # same marker.
17 #
18 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
19 m4_define([OVSDB_CHECK_MONITOR], 
20   [AT_SETUP([$1])
21    AT_KEYWORDS([ovsdb server monitor positive $9])
22    AT_DATA([schema], [$2
23 ])
24    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
25    m4_foreach([txn], [$3],
26      [AT_CHECK([ovsdb-tool transact db 'txn'], [0], [ignore], [ignore])])
27    AT_CAPTURE_FILE([ovsdb-server-log])
28    AT_CHECK([ovsdb-server --detach --pidfile=$PWD/server-pid --remote=punix:socket --unixctl=$PWD/unixctl --log-file=$PWD/ovsdb-server-log db >/dev/null 2>&1],
29             [0], [], [])
30    AT_CHECK([ovsdb-client -vjsonrpc --detach --pidfile=$PWD/client-pid -d json monitor --format=csv unix:socket $4 $5 $8 > output], 
31             [0], [ignore], [ignore], [kill `cat server-pid`])
32    m4_foreach([txn], [$6],
33      [AT_CHECK([ovsdb-client transact unix:socket 'txn'], [0],
34                      [ignore], [ignore], [kill `cat server-pid client-pid`])])
35    AT_CHECK([ovsdb-client transact unix:socket '[["$4"]]'], [0],
36             [ignore], [ignore], [kill `cat server-pid client-pid`])
37    AT_CHECK([ovs-appctl -t $PWD/unixctl -e exit], [0], [ignore], [ignore])
38    OVS_WAIT_UNTIL([test ! -e server-pid && test ! -e client-pid])
39    AT_CHECK([perl $srcdir/ovsdb-monitor-sort.pl < output | perl $srcdir/uuidfilt.pl], [0], [$7], [ignore])
40    AT_CLEANUP])
41
42 OVSDB_CHECK_MONITOR([monitor insert into empty table],
43   [ORDINAL_SCHEMA],
44   [],
45   [ordinals], [ordinals],
46   [[[["ordinals",
47       {"op": "insert",
48        "table": "ordinals",
49        "row": {"number": 0, "name": "zero"}}]]]],
50   [[row,action,name,number,_version
51 <0>,insert,"""zero""",0,"[""uuid"",""<1>""]"
52 ]])
53
54 OVSDB_CHECK_MONITOR([monitor insert into populated table],
55   [ORDINAL_SCHEMA],
56   [[[["ordinals",
57       {"op": "insert",
58        "table": "ordinals",
59        "row": {"number": 10, "name": "ten"}}]]]],
60   [ordinals], [ordinals],
61   [[[["ordinals",
62       {"op": "insert",
63        "table": "ordinals",
64        "row": {"number": 0, "name": "zero"}}]]]],
65   [[row,action,name,number,_version
66 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
67
68 row,action,name,number,_version
69 <2>,insert,"""zero""",0,"[""uuid"",""<3>""]"
70 ]])
71
72 OVSDB_CHECK_MONITOR([monitor delete],
73   [ORDINAL_SCHEMA],
74   [[[["ordinals",
75       {"op": "insert",
76        "table": "ordinals",
77        "row": {"number": 10, "name": "ten"}}]]]],
78   [ordinals], [ordinals],
79   [[[["ordinals",
80       {"op": "delete",
81        "table": "ordinals",
82        "where": [["number", "==", 10]]}]]]],
83   [[row,action,name,number,_version
84 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
85
86 row,action,name,number,_version
87 <0>,delete,"""ten""",10,"[""uuid"",""<1>""]"
88 ]])
89
90 OVSDB_CHECK_MONITOR([monitor row update],
91   [ORDINAL_SCHEMA],
92   [[[["ordinals",
93       {"op": "insert",
94        "table": "ordinals",
95        "row": {"number": 10, "name": "ten"}}]]]],
96   [ordinals], [ordinals],
97   [[[["ordinals",
98       {"op": "update",
99        "table": "ordinals",
100        "where": [["number", "==", 10]],
101        "row": {"name": "five plus five"}}]]]],
102   [[row,action,name,number,_version
103 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
104
105 row,action,name,number,_version
106 <0>,old,"""ten""",,"[""uuid"",""<1>""]"
107 ,new,"""five plus five""",10,"[""uuid"",""<2>""]"
108 ]])
109
110 OVSDB_CHECK_MONITOR([monitor no-op row updates],
111   [ORDINAL_SCHEMA],
112   [[[["ordinals",
113       {"op": "insert",
114        "table": "ordinals",
115        "row": {"number": 10, "name": "ten"}}]]]],
116   [ordinals], [ordinals],
117   [[[["ordinals",
118       {"op": "update",
119        "table": "ordinals",
120        "where": [["number", "==", 10]],
121        "row": {"number": 10, "name": "ten"}}]]],
122    [[["ordinals",
123       {"op": "insert",
124        "table": "ordinals",
125        "row": {"number": 9, "name": "nine"}}]]]],
126   [[row,action,name,number,_version
127 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
128
129 row,action,name,number,_version
130 <2>,insert,"""nine""",9,"[""uuid"",""<3>""]"
131 ]])
132
133 OVSDB_CHECK_MONITOR([monitor insert-and-update transaction],
134   [ORDINAL_SCHEMA],
135   [[[["ordinals",
136       {"op": "insert",
137        "table": "ordinals",
138        "row": {"number": 10, "name": "ten"}}]]]],
139   [ordinals], [ordinals],
140   [[[["ordinals",
141       {"op": "insert",
142        "table": "ordinals",
143        "row": {"number": 9, "name": "nine"},
144        "uuid-name": "nine"},
145       {"op": "update",
146        "table": "ordinals",
147        "where": [["_uuid", "==", ["named-uuid", "nine"]]],
148        "row": {"name": "three squared"}}]]]],
149   [[row,action,name,number,_version
150 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
151
152 row,action,name,number,_version
153 <2>,insert,"""three squared""",9,"[""uuid"",""<3>""]"
154 ]])
155
156 OVSDB_CHECK_MONITOR([monitor insert-update-and-delete transaction],
157   [ORDINAL_SCHEMA],
158   [[[["ordinals",
159       {"op": "insert",
160        "table": "ordinals",
161        "row": {"number": 10, "name": "ten"}}]]]],
162   [ordinals], [ordinals],
163   [[[["ordinals",
164       {"op": "insert",
165        "table": "ordinals",
166        "row": {"number": 9, "name": "nine"},
167        "uuid-name": "nine"},
168       {"op": "update",
169        "table": "ordinals",
170        "where": [["_uuid", "==", ["named-uuid", "nine"]]],
171        "row": {"name": "three squared"}},
172       {"op": "delete",
173        "table": "ordinals",
174        "where": [["_uuid", "==", ["named-uuid", "nine"]]]},
175       {"op": "insert",
176        "table": "ordinals",
177        "row": {"number": 7, "name": "seven"}}]]]],
178   [[row,action,name,number,_version
179 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
180
181 row,action,name,number,_version
182 <2>,insert,"""seven""",7,"[""uuid"",""<3>""]"
183 ]])
184
185 OVSDB_CHECK_MONITOR([monitor weak reference change],
186   [WEAK_SCHEMA],
187   [[[["weak",
188       {"op": "insert",
189        "table": "a",
190        "row": {"a": 0,
191                "a2a1": ["named-uuid", "a0"],
192                "a2b": ["named-uuid", "b2"]},
193        "uuid-name": "a0"},
194       {"op": "insert",
195        "table": "a",
196        "row": {"a": 1,
197                "a2a": ["named-uuid", "a0"],
198                "a2a1": ["named-uuid", "a1"],
199                "a2b": ["named-uuid", "b2"]},
200        "uuid-name": "a1"},
201       {"op": "insert",
202        "table": "b",
203        "row": {"b": 2},
204        "uuid-name": "b2"}]]]],
205   [weak], [a],
206   [[[["weak",
207       {"op": "delete",
208        "table": "a",
209        "where": [["a", "==", 0]]}]]]],
210   [[row,action,a,a2a,a2a1,a2b,_version
211 <0>,initial,0,"[""set"",[]]","[""uuid"",""<0>""]","[""uuid"",""<1>""]","[""uuid"",""<2>""]"
212 <3>,initial,1,"[""uuid"",""<0>""]","[""uuid"",""<3>""]","[""uuid"",""<1>""]","[""uuid"",""<4>""]"
213
214 row,action,a,a2a,a2a1,a2b,_version
215 <0>,delete,0,"[""set"",[]]","[""uuid"",""<0>""]","[""uuid"",""<1>""]","[""uuid"",""<2>""]"
216 <3>,old,,"[""uuid"",""<0>""]",,,
217 ,new,1,"[""set"",[]]","[""uuid"",""<3>""]","[""uuid"",""<1>""]","[""uuid"",""<5>""]"
218 ]])
219
220 OVSDB_CHECK_MONITOR([monitor insert-update-and-delete transaction],
221   [ORDINAL_SCHEMA],
222   [[[["ordinals",
223       {"op": "insert",
224        "table": "ordinals",
225        "row": {"number": 10, "name": "ten"}}]]]],
226   [ordinals], [ordinals],
227   [[[["ordinals",
228       {"op": "insert",
229        "table": "ordinals",
230        "row": {"number": 9, "name": "nine"},
231        "uuid-name": "nine"},
232       {"op": "update",
233        "table": "ordinals",
234        "where": [["_uuid", "==", ["named-uuid", "nine"]]],
235        "row": {"name": "three squared"}},
236       {"op": "delete",
237        "table": "ordinals",
238        "where": [["_uuid", "==", ["named-uuid", "nine"]]]},
239       {"op": "insert",
240        "table": "ordinals",
241        "row": {"number": 7, "name": "seven"}}]]]],
242   [[row,action,name,number,_version
243 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
244
245 row,action,name,number,_version
246 <2>,insert,"""seven""",7,"[""uuid"",""<3>""]"
247 ]])
248 \f
249 AT_BANNER([ovsdb -- ovsdb-monitor monitor only some operations])
250
251 m4_define([OVSDB_MONITOR_INITIAL],
252   [[[["ordinals",
253       {"op": "insert",
254        "table": "ordinals",
255        "row": {"number": 10, "name": "ten"}}]]]])
256 m4_define([OVSDB_MONITOR_TXNS],
257   [[[["ordinals",
258       {"op": "insert",
259        "table": "ordinals",
260        "row": {"number": 5, "name": "five"}}]]],
261    [[["ordinals",
262       {"op": "update",
263        "table": "ordinals",
264        "where": [["name", "==", "five"]],
265        "row": {"name": "FIVE"}}]]],
266    [[["ordinals",
267       {"op": "delete",
268        "table": "ordinals",
269        "where": []}]]]])
270
271 OVSDB_CHECK_MONITOR([monitor all operations],
272   [ORDINAL_SCHEMA], [OVSDB_MONITOR_INITIAL],
273   [ordinals], [ordinals], [OVSDB_MONITOR_TXNS],
274   [[row,action,name,number,_version
275 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
276
277 row,action,name,number,_version
278 <2>,insert,"""five""",5,"[""uuid"",""<3>""]"
279
280 row,action,name,number,_version
281 <2>,old,"""five""",,"[""uuid"",""<3>""]"
282 ,new,"""FIVE""",5,"[""uuid"",""<4>""]"
283
284 row,action,name,number,_version
285 <2>,delete,"""FIVE""",5,"[""uuid"",""<4>""]"
286 <0>,delete,"""ten""",10,"[""uuid"",""<1>""]"
287 ]])
288
289 dnl A monitor with "initial" only doesn't really make sense,
290 dnl but it's still allowed and should work.
291 OVSDB_CHECK_MONITOR([monitor initial only],
292   [ORDINAL_SCHEMA], [OVSDB_MONITOR_INITIAL],
293   [ordinals], [ordinals], [OVSDB_MONITOR_TXNS],
294   [[row,action,name,number,_version
295 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
296 ]], [!insert,!delete,!modify])
297
298 OVSDB_CHECK_MONITOR([monitor insert only],
299   [ORDINAL_SCHEMA], [OVSDB_MONITOR_INITIAL],
300   [ordinals], [ordinals], [OVSDB_MONITOR_TXNS],
301   [[row,action,name,number,_version
302 <0>,insert,"""five""",5,"[""uuid"",""<1>""]"
303 ]], [!initial,!delete,!modify])
304
305 OVSDB_CHECK_MONITOR([monitor delete only],
306   [ORDINAL_SCHEMA], [OVSDB_MONITOR_INITIAL],
307   [ordinals], [ordinals], [OVSDB_MONITOR_TXNS],
308   [[row,action,name,number,_version
309 <0>,delete,"""FIVE""",5,"[""uuid"",""<1>""]"
310 <2>,delete,"""ten""",10,"[""uuid"",""<3>""]"
311 ]], [!initial,!insert,!modify])
312
313 OVSDB_CHECK_MONITOR([monitor modify only],
314   [ORDINAL_SCHEMA], [OVSDB_MONITOR_INITIAL],
315   [ordinals], [ordinals], [OVSDB_MONITOR_TXNS],
316   [[row,action,name,number,_version
317 <0>,old,"""five""",,"[""uuid"",""<1>""]"
318 ,new,"""FIVE""",5,"[""uuid"",""<2>""]"
319 ]], [!initial,!insert,!delete])