netlink-protocol: Add more definitions.
[cascardo/ovs.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, [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    OVS_RUNDIR=`pwd`; export OVS_RUNDIR
23    $2 > schema
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 --no-chdir --pidfile="`pwd`"/server-pid --remote=punix:socket --unixctl="`pwd`"/unixctl --log-file="`pwd`"/ovsdb-server-log db >/dev/null 2>&1],
29             [0], [], [])
30    if test "$IS_WIN32" = "yes"; then
31      AT_CHECK([ovsdb-client -vjsonrpc --pidfile="`pwd`"/client-pid -d json monitor --format=csv unix:socket $4 $5 $8 > output &],
32               [0], [ignore], [ignore], [kill `cat server-pid`])
33      sleep 1
34    else
35      AT_CHECK([ovsdb-client -vjsonrpc --detach --no-chdir --pidfile="`pwd`"/client-pid -d json monitor --format=csv unix:socket $4 $5 $8 > output],
36             [0], [ignore], [ignore], [kill `cat server-pid`])
37    fi
38    m4_foreach([txn], [$6],
39      [AT_CHECK([ovsdb-client transact unix:socket 'txn'], [0],
40                      [ignore], [ignore], [kill `cat server-pid client-pid`])])
41    AT_CHECK([ovsdb-client transact unix:socket '[["$4"]]'], [0],
42             [ignore], [ignore], [kill `cat server-pid client-pid`])
43    AT_CHECK([ovs-appctl -t "`pwd`"/unixctl -e exit], [0], [ignore], [ignore])
44    OVS_WAIT_UNTIL([test ! -e server-pid && test ! -e client-pid])
45    AT_CHECK([${PERL} $srcdir/ovsdb-monitor-sort.pl < output | ${PERL} $srcdir/uuidfilt.pl], [0], [$7], [ignore])
46    AT_CLEANUP])
47
48 OVSDB_CHECK_MONITOR([monitor insert into empty table],
49   [ordinal_schema],
50   [],
51   [ordinals], [ordinals],
52   [[[["ordinals",
53       {"op": "insert",
54        "table": "ordinals",
55        "row": {"number": 0, "name": "zero"}}]]]],
56   [[row,action,name,number,_version
57 <0>,insert,"""zero""",0,"[""uuid"",""<1>""]"
58 ]])
59
60 OVSDB_CHECK_MONITOR([monitor insert into populated table],
61   [ordinal_schema],
62   [[[["ordinals",
63       {"op": "insert",
64        "table": "ordinals",
65        "row": {"number": 10, "name": "ten"}}]]]],
66   [ordinals], [ordinals],
67   [[[["ordinals",
68       {"op": "insert",
69        "table": "ordinals",
70        "row": {"number": 0, "name": "zero"}}]]]],
71   [[row,action,name,number,_version
72 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
73
74 row,action,name,number,_version
75 <2>,insert,"""zero""",0,"[""uuid"",""<3>""]"
76 ]])
77
78 OVSDB_CHECK_MONITOR([monitor delete],
79   [ordinal_schema],
80   [[[["ordinals",
81       {"op": "insert",
82        "table": "ordinals",
83        "row": {"number": 10, "name": "ten"}}]]]],
84   [ordinals], [ordinals],
85   [[[["ordinals",
86       {"op": "delete",
87        "table": "ordinals",
88        "where": [["number", "==", 10]]}]]]],
89   [[row,action,name,number,_version
90 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
91
92 row,action,name,number,_version
93 <0>,delete,"""ten""",10,"[""uuid"",""<1>""]"
94 ]])
95
96 OVSDB_CHECK_MONITOR([monitor row update],
97   [ordinal_schema],
98   [[[["ordinals",
99       {"op": "insert",
100        "table": "ordinals",
101        "row": {"number": 10, "name": "ten"}}]]]],
102   [ordinals], [ordinals],
103   [[[["ordinals",
104       {"op": "update",
105        "table": "ordinals",
106        "where": [["number", "==", 10]],
107        "row": {"name": "five plus five"}}]]]],
108   [[row,action,name,number,_version
109 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
110
111 row,action,name,number,_version
112 <0>,old,"""ten""",,"[""uuid"",""<1>""]"
113 ,new,"""five plus five""",10,"[""uuid"",""<2>""]"
114 ]])
115
116 OVSDB_CHECK_MONITOR([monitor no-op row updates],
117   [ordinal_schema],
118   [[[["ordinals",
119       {"op": "insert",
120        "table": "ordinals",
121        "row": {"number": 10, "name": "ten"}}]]]],
122   [ordinals], [ordinals],
123   [[[["ordinals",
124       {"op": "update",
125        "table": "ordinals",
126        "where": [["number", "==", 10]],
127        "row": {"number": 10, "name": "ten"}}]]],
128    [[["ordinals",
129       {"op": "insert",
130        "table": "ordinals",
131        "row": {"number": 9, "name": "nine"}}]]]],
132   [[row,action,name,number,_version
133 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
134
135 row,action,name,number,_version
136 <2>,insert,"""nine""",9,"[""uuid"",""<3>""]"
137 ]])
138
139 OVSDB_CHECK_MONITOR([monitor insert-and-update transaction],
140   [ordinal_schema],
141   [[[["ordinals",
142       {"op": "insert",
143        "table": "ordinals",
144        "row": {"number": 10, "name": "ten"}}]]]],
145   [ordinals], [ordinals],
146   [[[["ordinals",
147       {"op": "insert",
148        "table": "ordinals",
149        "row": {"number": 9, "name": "nine"},
150        "uuid-name": "nine"},
151       {"op": "update",
152        "table": "ordinals",
153        "where": [["_uuid", "==", ["named-uuid", "nine"]]],
154        "row": {"name": "three squared"}}]]]],
155   [[row,action,name,number,_version
156 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
157
158 row,action,name,number,_version
159 <2>,insert,"""three squared""",9,"[""uuid"",""<3>""]"
160 ]])
161
162 OVSDB_CHECK_MONITOR([monitor insert-update-and-delete transaction],
163   [ordinal_schema],
164   [[[["ordinals",
165       {"op": "insert",
166        "table": "ordinals",
167        "row": {"number": 10, "name": "ten"}}]]]],
168   [ordinals], [ordinals],
169   [[[["ordinals",
170       {"op": "insert",
171        "table": "ordinals",
172        "row": {"number": 9, "name": "nine"},
173        "uuid-name": "nine"},
174       {"op": "update",
175        "table": "ordinals",
176        "where": [["_uuid", "==", ["named-uuid", "nine"]]],
177        "row": {"name": "three squared"}},
178       {"op": "delete",
179        "table": "ordinals",
180        "where": [["_uuid", "==", ["named-uuid", "nine"]]]},
181       {"op": "insert",
182        "table": "ordinals",
183        "row": {"number": 7, "name": "seven"}}]]]],
184   [[row,action,name,number,_version
185 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
186
187 row,action,name,number,_version
188 <2>,insert,"""seven""",7,"[""uuid"",""<3>""]"
189 ]])
190
191 OVSDB_CHECK_MONITOR([monitor weak reference change],
192   [weak_schema],
193   [[[["weak",
194       {"op": "insert",
195        "table": "a",
196        "row": {"a": 0,
197                "a2a1": ["named-uuid", "a0"],
198                "a2b": ["named-uuid", "b2"]},
199        "uuid-name": "a0"},
200       {"op": "insert",
201        "table": "a",
202        "row": {"a": 1,
203                "a2a": ["named-uuid", "a0"],
204                "a2a1": ["named-uuid", "a1"],
205                "a2b": ["named-uuid", "b2"]},
206        "uuid-name": "a1"},
207       {"op": "insert",
208        "table": "b",
209        "row": {"b": 2},
210        "uuid-name": "b2"}]]]],
211   [weak], [a],
212   [[[["weak",
213       {"op": "delete",
214        "table": "a",
215        "where": [["a", "==", 0]]}]]]],
216   [[row,action,a,a2a,a2a1,a2b,_version
217 <0>,initial,0,"[""set"",[]]","[""uuid"",""<0>""]","[""uuid"",""<1>""]","[""uuid"",""<2>""]"
218 <3>,initial,1,"[""uuid"",""<0>""]","[""uuid"",""<3>""]","[""uuid"",""<1>""]","[""uuid"",""<4>""]"
219
220 row,action,a,a2a,a2a1,a2b,_version
221 <0>,delete,0,"[""set"",[]]","[""uuid"",""<0>""]","[""uuid"",""<1>""]","[""uuid"",""<2>""]"
222 <3>,old,,"[""uuid"",""<0>""]",,,"[""uuid"",""<4>""]"
223 ,new,1,"[""set"",[]]","[""uuid"",""<3>""]","[""uuid"",""<1>""]","[""uuid"",""<5>""]"
224 ]])
225
226 OVSDB_CHECK_MONITOR([monitor insert-update-and-delete transaction],
227   [ordinal_schema],
228   [[[["ordinals",
229       {"op": "insert",
230        "table": "ordinals",
231        "row": {"number": 10, "name": "ten"}}]]]],
232   [ordinals], [ordinals],
233   [[[["ordinals",
234       {"op": "insert",
235        "table": "ordinals",
236        "row": {"number": 9, "name": "nine"},
237        "uuid-name": "nine"},
238       {"op": "update",
239        "table": "ordinals",
240        "where": [["_uuid", "==", ["named-uuid", "nine"]]],
241        "row": {"name": "three squared"}},
242       {"op": "delete",
243        "table": "ordinals",
244        "where": [["_uuid", "==", ["named-uuid", "nine"]]]},
245       {"op": "insert",
246        "table": "ordinals",
247        "row": {"number": 7, "name": "seven"}}]]]],
248   [[row,action,name,number,_version
249 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
250
251 row,action,name,number,_version
252 <2>,insert,"""seven""",7,"[""uuid"",""<3>""]"
253 ]])
254 \f
255 AT_BANNER([ovsdb -- ovsdb-monitor monitor only some operations])
256
257 m4_define([OVSDB_MONITOR_INITIAL],
258   [[[["ordinals",
259       {"op": "insert",
260        "table": "ordinals",
261        "row": {"number": 10, "name": "ten"}}]]]])
262 m4_define([OVSDB_MONITOR_TXNS],
263   [[[["ordinals",
264       {"op": "insert",
265        "table": "ordinals",
266        "row": {"number": 5, "name": "five"}}]]],
267    [[["ordinals",
268       {"op": "update",
269        "table": "ordinals",
270        "where": [["name", "==", "five"]],
271        "row": {"name": "FIVE"}}]]],
272    [[["ordinals",
273       {"op": "delete",
274        "table": "ordinals",
275        "where": []}]]]])
276
277 OVSDB_CHECK_MONITOR([monitor all operations],
278   [ordinal_schema], [OVSDB_MONITOR_INITIAL],
279   [ordinals], [ordinals], [OVSDB_MONITOR_TXNS],
280   [[row,action,name,number,_version
281 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
282
283 row,action,name,number,_version
284 <2>,insert,"""five""",5,"[""uuid"",""<3>""]"
285
286 row,action,name,number,_version
287 <2>,old,"""five""",,"[""uuid"",""<3>""]"
288 ,new,"""FIVE""",5,"[""uuid"",""<4>""]"
289
290 row,action,name,number,_version
291 <2>,delete,"""FIVE""",5,"[""uuid"",""<4>""]"
292 <0>,delete,"""ten""",10,"[""uuid"",""<1>""]"
293 ]])
294
295 dnl A monitor with "initial" only doesn't really make sense,
296 dnl but it's still allowed and should work.
297 OVSDB_CHECK_MONITOR([monitor initial only],
298   [ordinal_schema], [OVSDB_MONITOR_INITIAL],
299   [ordinals], [ordinals], [OVSDB_MONITOR_TXNS],
300   [[row,action,name,number,_version
301 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
302 ]], [!insert,!delete,!modify])
303
304 OVSDB_CHECK_MONITOR([monitor insert only],
305   [ordinal_schema], [OVSDB_MONITOR_INITIAL],
306   [ordinals], [ordinals], [OVSDB_MONITOR_TXNS],
307   [[row,action,name,number,_version
308 <0>,insert,"""five""",5,"[""uuid"",""<1>""]"
309 ]], [!initial,!delete,!modify])
310
311 OVSDB_CHECK_MONITOR([monitor delete only],
312   [ordinal_schema], [OVSDB_MONITOR_INITIAL],
313   [ordinals], [ordinals], [OVSDB_MONITOR_TXNS],
314   [[row,action,name,number,_version
315 <0>,delete,"""FIVE""",5,"[""uuid"",""<1>""]"
316 <2>,delete,"""ten""",10,"[""uuid"",""<3>""]"
317 ]], [!initial,!insert,!modify])
318
319 OVSDB_CHECK_MONITOR([monitor modify only],
320   [ordinal_schema], [OVSDB_MONITOR_INITIAL],
321   [ordinals], [ordinals], [OVSDB_MONITOR_TXNS],
322   [[row,action,name,number,_version
323 <0>,old,"""five""",,"[""uuid"",""<1>""]"
324 ,new,"""FIVE""",5,"[""uuid"",""<2>""]"
325 ]], [!initial,!insert,!delete])