Merge branch '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 $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   [[[[{"op": "insert",
44        "table": "ordinals",
45        "row": {"number": 0, "name": "zero"}}]]]],
46   [[row,action,name,number,_version
47 <0>,insert,"""zero""",0,"[""uuid"",""<1>""]"
48 ]])
49
50 OVSDB_CHECK_MONITOR([monitor insert into populated table],
51   [ORDINAL_SCHEMA],
52   [[[[{"op": "insert",
53        "table": "ordinals",
54        "row": {"number": 10, "name": "ten"}}]]]],
55   [ordinals],
56   [[[[{"op": "insert",
57        "table": "ordinals",
58        "row": {"number": 0, "name": "zero"}}]]]],
59   [[row,action,name,number,_version
60 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
61 row,action,name,number,_version
62 <2>,insert,"""zero""",0,"[""uuid"",""<3>""]"
63 ]])
64
65 OVSDB_CHECK_MONITOR([monitor delete],
66   [ORDINAL_SCHEMA],
67   [[[[{"op": "insert",
68        "table": "ordinals",
69        "row": {"number": 10, "name": "ten"}}]]]],
70   [ordinals],
71   [[[[{"op": "delete",
72        "table": "ordinals",
73        "where": [["number", "==", 10]]}]]]],
74   [[row,action,name,number,_version
75 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
76 row,action,name,number,_version
77 <0>,delete,"""ten""",10,"[""uuid"",""<1>""]"
78 ]])
79
80 OVSDB_CHECK_MONITOR([monitor row update],
81   [ORDINAL_SCHEMA],
82   [[[[{"op": "insert",
83        "table": "ordinals",
84        "row": {"number": 10, "name": "ten"}}]]]],
85   [ordinals],
86   [[[[{"op": "update",
87        "table": "ordinals",
88        "where": [["number", "==", 10]],
89        "row": {"name": "five plus five"}}]]]],
90   [[row,action,name,number,_version
91 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
92 row,action,name,number,_version
93 <0>,old,"""ten""",,"[""uuid"",""<1>""]"
94 ,new,"""five plus five""",10,"[""uuid"",""<2>""]"
95 ]])
96
97 OVSDB_CHECK_MONITOR([monitor no-op row updates],
98   [ORDINAL_SCHEMA],
99   [[[[{"op": "insert",
100        "table": "ordinals",
101        "row": {"number": 10, "name": "ten"}}]]]],
102   [ordinals],
103   [[[[{"op": "update",
104        "table": "ordinals",
105        "where": [["number", "==", 10]],
106        "row": {"number": 10, "name": "ten"}}]]],
107    [[[{"op": "insert",
108        "table": "ordinals",
109        "row": {"number": 9, "name": "nine"}}]]]],
110   [[row,action,name,number,_version
111 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
112 row,action,name,number,_version
113 <2>,insert,"""nine""",9,"[""uuid"",""<3>""]"
114 ]])
115
116 OVSDB_CHECK_MONITOR([monitor insert-and-update transaction],
117   [ORDINAL_SCHEMA],
118   [[[[{"op": "insert",
119        "table": "ordinals",
120        "row": {"number": 10, "name": "ten"}}]]]],
121   [ordinals],
122   [[[[{"op": "insert",
123        "table": "ordinals",
124        "row": {"number": 9, "name": "nine"},
125        "uuid-name": "nine"},
126       {"op": "update",
127        "table": "ordinals",
128        "where": [["_uuid", "==", ["named-uuid", "nine"]]],
129        "row": {"name": "three squared"}}]]]],
130   [[row,action,name,number,_version
131 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
132 row,action,name,number,_version
133 <2>,insert,"""three squared""",9,"[""uuid"",""<3>""]"
134 ]])
135
136
137 OVSDB_CHECK_MONITOR([monitor insert-update-and-delete transaction],
138   [ORDINAL_SCHEMA],
139   [[[[{"op": "insert",
140        "table": "ordinals",
141        "row": {"number": 10, "name": "ten"}}]]]],
142   [ordinals],
143   [[[[{"op": "insert",
144        "table": "ordinals",
145        "row": {"number": 9, "name": "nine"},
146        "uuid-name": "nine"},
147       {"op": "update",
148        "table": "ordinals",
149        "where": [["_uuid", "==", ["named-uuid", "nine"]]],
150        "row": {"name": "three squared"}},
151       {"op": "delete",
152        "table": "ordinals",
153        "where": [["_uuid", "==", ["named-uuid", "nine"]]]},
154       {"op": "insert",
155        "table": "ordinals",
156        "row": {"number": 7, "name": "seven"}}]]]],
157   [[row,action,name,number,_version
158 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
159 row,action,name,number,_version
160 <2>,insert,"""seven""",7,"[""uuid"",""<3>""]"
161 ]])
162