Merge "master" into "next".
[sliver-openvswitch.git] / 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    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
24    m4_foreach([txn], [$3],
25      [AT_CHECK([ovsdb-tool transact db 'txn'], [0], [ignore], [ignore])])
26    AT_CHECK([ovsdb-server --detach --pidfile=$PWD/server-pid --remote=punix:socket --unixctl=$PWD/unixctl db], [0], [ignore], [ignore])
27    AT_CHECK([ovsdb-client --detach --pidfile=$PWD/client-pid monitor --format=csv unix:socket ordinals $4 > output], 
28             [0], [ignore], [ignore], [kill `cat server-pid`])
29    m4_foreach([txn], [$5],
30      [AT_CHECK([ovsdb-client transact unix:socket 'txn'], [0],
31                      [ignore], [ignore], [kill `cat server-pid client-pid`])])
32    AT_CHECK([ovsdb-client transact unix:socket '[[]]'], [0],
33             [ignore], [ignore], [kill `cat server-pid client-pid`])
34    AT_CHECK([ovs-appctl -t $PWD/unixctl -e exit], [0], [ignore], [ignore])
35    OVS_WAIT_UNTIL([test ! -e server-pid && test ! -e client-pid])
36    AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$6], [ignore])
37    AT_CLEANUP])
38
39 OVSDB_CHECK_MONITOR([monitor insert into empty table],
40   [ORDINAL_SCHEMA],
41   [],
42   [ordinals],
43   [[[["ordinals",
44       {"op": "insert",
45        "table": "ordinals",
46        "row": {"number": 0, "name": "zero"}}]]]],
47   [[row,action,name,number,_version
48 <0>,insert,"""zero""",0,"[""uuid"",""<1>""]"
49 ]])
50
51 OVSDB_CHECK_MONITOR([monitor insert into populated table],
52   [ORDINAL_SCHEMA],
53   [[[["ordinals",
54       {"op": "insert",
55        "table": "ordinals",
56        "row": {"number": 10, "name": "ten"}}]]]],
57   [ordinals],
58   [[[["ordinals",
59       {"op": "insert",
60        "table": "ordinals",
61        "row": {"number": 0, "name": "zero"}}]]]],
62   [[row,action,name,number,_version
63 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
64 row,action,name,number,_version
65 <2>,insert,"""zero""",0,"[""uuid"",""<3>""]"
66 ]])
67
68 OVSDB_CHECK_MONITOR([monitor delete],
69   [ORDINAL_SCHEMA],
70   [[[["ordinals",
71       {"op": "insert",
72        "table": "ordinals",
73        "row": {"number": 10, "name": "ten"}}]]]],
74   [ordinals],
75   [[[["ordinals",
76       {"op": "delete",
77        "table": "ordinals",
78        "where": [["number", "==", 10]]}]]]],
79   [[row,action,name,number,_version
80 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
81 row,action,name,number,_version
82 <0>,delete,"""ten""",10,"[""uuid"",""<1>""]"
83 ]])
84
85 OVSDB_CHECK_MONITOR([monitor row update],
86   [ORDINAL_SCHEMA],
87   [[[["ordinals",
88       {"op": "insert",
89        "table": "ordinals",
90        "row": {"number": 10, "name": "ten"}}]]]],
91   [ordinals],
92   [[[["ordinals",
93       {"op": "update",
94        "table": "ordinals",
95        "where": [["number", "==", 10]],
96        "row": {"name": "five plus five"}}]]]],
97   [[row,action,name,number,_version
98 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
99 row,action,name,number,_version
100 <0>,old,"""ten""",,"[""uuid"",""<1>""]"
101 ,new,"""five plus five""",10,"[""uuid"",""<2>""]"
102 ]])
103
104 OVSDB_CHECK_MONITOR([monitor no-op row updates],
105   [ORDINAL_SCHEMA],
106   [[[["ordinals",
107       {"op": "insert",
108        "table": "ordinals",
109        "row": {"number": 10, "name": "ten"}}]]]],
110   [ordinals],
111   [[[["ordinals",
112       {"op": "update",
113        "table": "ordinals",
114        "where": [["number", "==", 10]],
115        "row": {"number": 10, "name": "ten"}}]]],
116    [[["ordinals",
117       {"op": "insert",
118        "table": "ordinals",
119        "row": {"number": 9, "name": "nine"}}]]]],
120   [[row,action,name,number,_version
121 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
122 row,action,name,number,_version
123 <2>,insert,"""nine""",9,"[""uuid"",""<3>""]"
124 ]])
125
126 OVSDB_CHECK_MONITOR([monitor insert-and-update transaction],
127   [ORDINAL_SCHEMA],
128   [[[["ordinals",
129       {"op": "insert",
130        "table": "ordinals",
131        "row": {"number": 10, "name": "ten"}}]]]],
132   [ordinals],
133   [[[["ordinals",
134       {"op": "insert",
135        "table": "ordinals",
136        "row": {"number": 9, "name": "nine"},
137        "uuid-name": "nine"},
138       {"op": "update",
139        "table": "ordinals",
140        "where": [["_uuid", "==", ["named-uuid", "nine"]]],
141        "row": {"name": "three squared"}}]]]],
142   [[row,action,name,number,_version
143 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
144 row,action,name,number,_version
145 <2>,insert,"""three squared""",9,"[""uuid"",""<3>""]"
146 ]])
147
148
149 OVSDB_CHECK_MONITOR([monitor insert-update-and-delete transaction],
150   [ORDINAL_SCHEMA],
151   [[[["ordinals",
152       {"op": "insert",
153        "table": "ordinals",
154        "row": {"number": 10, "name": "ten"}}]]]],
155   [ordinals],
156   [[[["ordinals",
157       {"op": "insert",
158        "table": "ordinals",
159        "row": {"number": 9, "name": "nine"},
160        "uuid-name": "nine"},
161       {"op": "update",
162        "table": "ordinals",
163        "where": [["_uuid", "==", ["named-uuid", "nine"]]],
164        "row": {"name": "three squared"}},
165       {"op": "delete",
166        "table": "ordinals",
167        "where": [["_uuid", "==", ["named-uuid", "nine"]]]},
168       {"op": "insert",
169        "table": "ordinals",
170        "row": {"number": 7, "name": "seven"}}]]]],
171   [[row,action,name,number,_version
172 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
173 row,action,name,number,_version
174 <2>,insert,"""seven""",7,"[""uuid"",""<3>""]"
175 ]])
176