ovsdb: Add more tests for "monitor" feature.
[openvswitch] / tests / ovsdb-monitor.at
1 AT_BANNER([OVSDB -- ovsdb-server monitors])
2
3 # OVSDB_CHECK_MONITOR(TITLE, SCHEMA, [PRE-MONITOR-TXN], MONITOR-ARGS,
4 #                     TRANSACTIONS, OUTPUT, [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.
10 #
11 # Checks that the overall output is OUTPUT, but UUIDs in the output
12 # are replaced by markers of the form <N> where N is a number.  The
13 # first unique UUID is replaced by <0>, the next by <1>, and so on.
14 # If a given UUID appears more than once it is always replaced by the
15 # same marker.
16 #
17 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
18 m4_define([OVSDB_CHECK_MONITOR], 
19   [AT_SETUP([$1])
20    AT_KEYWORDS([ovsdb server monitor positive $7])
21    AT_DATA([schema], [$2
22 ])
23    OVS_CHECK_LCOV([ovsdb-tool create db schema], [0], [stdout], [ignore])
24    m4_foreach([txn], [$3],
25      [OVS_CHECK_LCOV([ovsdb-tool transact db 'txn'], [0], [ignore], [ignore])])
26    AT_CHECK([ovsdb-server --detach --pidfile=$PWD/server-pid --listen=punix:socket --unixctl=$PWD/unixctl db])
27    AT_CHECK([ovsdb-client monitor --format=csv unix:socket $4 > output & echo $! > monitor-pid], 
28             [0], [ignore], [ignore], [kill `cat server-pid`])
29    m4_foreach([txn], [$5],
30      [OVS_CHECK_LCOV([ovsdb-client transact unix:socket 'txn'], [0],
31                      [ignore], [ignore], [kill `cat server-pid monitor-pid`])])
32    AT_CHECK([ovs-appctl -t $PWD/unixctl -e exit], [0], [ignore], [ignore])
33    wait
34    AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$6])
35    AT_CLEANUP])
36
37 OVSDB_CHECK_MONITOR([monitor insert into empty table],
38   [ORDINAL_SCHEMA],
39   [],
40   [ordinals],
41   [[[[{"op": "insert",
42        "table": "ordinals",
43        "row": {"number": 0, "name": "zero"}}]]]],
44   [[row,action,name,number,_version
45 <0>,insert,"""zero""",0,"[""uuid"",""<1>""]"
46 ]])
47
48 OVSDB_CHECK_MONITOR([monitor insert into populated table],
49   [ORDINAL_SCHEMA],
50   [[[[{"op": "insert",
51        "table": "ordinals",
52        "row": {"number": 10, "name": "ten"}}]]]],
53   [ordinals],
54   [[[[{"op": "insert",
55        "table": "ordinals",
56        "row": {"number": 0, "name": "zero"}}]]]],
57   [[row,action,name,number,_version
58 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
59 row,action,name,number,_version
60 <2>,insert,"""zero""",0,"[""uuid"",""<3>""]"
61 ]])
62
63 OVSDB_CHECK_MONITOR([monitor delete],
64   [ORDINAL_SCHEMA],
65   [[[[{"op": "insert",
66        "table": "ordinals",
67        "row": {"number": 10, "name": "ten"}}]]]],
68   [ordinals],
69   [[[[{"op": "delete",
70        "table": "ordinals",
71        "where": [["number", "==", 10]]}]]]],
72   [[row,action,name,number,_version
73 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
74 row,action,name,number,_version
75 <0>,delete,"""ten""",10,"[""uuid"",""<1>""]"
76 ]])
77
78 OVSDB_CHECK_MONITOR([monitor row update],
79   [ORDINAL_SCHEMA],
80   [[[[{"op": "insert",
81        "table": "ordinals",
82        "row": {"number": 10, "name": "ten"}}]]]],
83   [ordinals],
84   [[[[{"op": "update",
85        "table": "ordinals",
86        "where": [["number", "==", 10]],
87        "row": {"name": "five plus five"}}]]]],
88   [[row,action,name,number,_version
89 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
90 row,action,name,number,_version
91 <0>,old,"""ten""",,"[""uuid"",""<1>""]"
92 ,new,"""five plus five""",10,"[""uuid"",""<2>""]"
93 ]])
94
95 OVSDB_CHECK_MONITOR([monitor no-op row updates],
96   [ORDINAL_SCHEMA],
97   [[[[{"op": "insert",
98        "table": "ordinals",
99        "row": {"number": 10, "name": "ten"}}]]]],
100   [ordinals],
101   [[[[{"op": "update",
102        "table": "ordinals",
103        "where": [["number", "==", 10]],
104        "row": {"number": 10, "name": "ten"}}]]],
105    [[[{"op": "insert",
106        "table": "ordinals",
107        "row": {"number": 9, "name": "nine"}}]]]],
108   [[row,action,name,number,_version
109 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
110 row,action,name,number,_version
111 <2>,insert,"""nine""",9,"[""uuid"",""<3>""]"
112 ]])
113
114 OVSDB_CHECK_MONITOR([monitor insert-and-update transaction],
115   [ORDINAL_SCHEMA],
116   [[[[{"op": "insert",
117        "table": "ordinals",
118        "row": {"number": 10, "name": "ten"}}]]]],
119   [ordinals],
120   [[[[{"op": "insert",
121        "table": "ordinals",
122        "row": {"number": 9, "name": "nine"},
123        "uuid-name": "nine"},
124       {"op": "update",
125        "table": "ordinals",
126        "where": [["_uuid", "==", ["named-uuid", "nine"]]],
127        "row": {"name": "three squared"}}]]]],
128   [[row,action,name,number,_version
129 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
130 row,action,name,number,_version
131 <2>,insert,"""three squared""",9,"[""uuid"",""<3>""]"
132 ]])
133
134
135 OVSDB_CHECK_MONITOR([monitor insert-update-and-delete transaction],
136   [ORDINAL_SCHEMA],
137   [[[[{"op": "insert",
138        "table": "ordinals",
139        "row": {"number": 10, "name": "ten"}}]]]],
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       {"op": "delete",
150        "table": "ordinals",
151        "where": [["_uuid", "==", ["named-uuid", "nine"]]]},
152       {"op": "insert",
153        "table": "ordinals",
154        "row": {"number": 7, "name": "seven"}}]]]],
155   [[row,action,name,number,_version
156 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
157 row,action,name,number,_version
158 <2>,insert,"""seven""",7,"[""uuid"",""<3>""]"
159 ]])
160