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