Catalli's threaded switch
[sliver-openvswitch.git] / tests / ovsdb-tool.at
1 AT_BANNER([OVSDB -- ovsdb-tool])
2
3 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
4 #
5 # Creates a database with the given SCHEMA and runs each of the
6 # TRANSACTIONS (which should be a quoted list of quoted strings)
7 # against it with ovsdb-tool one at a time.  
8 #
9 # Checks that the overall output is OUTPUT, but UUIDs in the output
10 # are replaced by markers of the form <N> where N is a number.  The
11 # first unique UUID is replaced by <0>, the next by <1>, and so on.
12 # If a given UUID appears more than once it is always replaced by the
13 # same marker.
14 #
15 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
16 m4_define([OVSDB_CHECK_EXECUTION], 
17   [AT_SETUP([$1])
18    AT_KEYWORDS([ovsdb file positive $5])
19    AT_DATA([schema], [$2
20 ])
21    touch .db.~lock~
22    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
23    m4_foreach([txn], [$3], 
24      [AT_CHECK([ovsdb-tool transact db 'txn'], [0], [stdout], [ignore])
25 cat stdout >> output
26 ])
27    AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4])
28    AT_CLEANUP])
29
30 EXECUTION_EXAMPLES
31
32 AT_SETUP([transaction comments])
33 AT_KEYWORDS([ovsdb file positive])
34 AT_DATA([schema], [ORDINAL_SCHEMA
35 ])
36 touch .db.~lock~
37 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
38 AT_CHECK([[ovsdb-tool transact db '
39     ["ordinals",
40      {"op": "insert",
41       "table": "ordinals",
42       "row": {"name": "five", "number": 5}},
43      {"op": "comment",
44       "comment": "add row for 5"}]']], [0], [stdout], [ignore])
45 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0],
46  [[[{"uuid":["uuid","<0>"]},{}]
47 ]])
48 AT_CHECK([grep -q "add row for 5" db])
49 AT_CLEANUP
50
51 AT_SETUP([ovsdb-tool compact])
52 AT_KEYWORDS([ovsdb file positive])
53 AT_DATA([schema], [ORDINAL_SCHEMA
54 ])
55 touch .db.~lock~
56 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
57 dnl Do a bunch of random transactions that put crap in the database log.
58 AT_CHECK(
59   [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
60       set -- $pair
61       ovsdb-tool transact db '
62         ["ordinals",
63          {"op": "insert",
64           "table": "ordinals",
65           "row": {"name": "'$1'", "number": '$2'}},
66          {"op": "comment",
67           "comment": "add row for '"$pair"'"}]'
68       ovsdb-tool transact db '
69         ["ordinals",
70          {"op": "delete",
71           "table": "ordinals",
72           "where": [["number", "==", '$2']]},
73          {"op": "comment",
74           "comment": "delete row for '"$2"'"}]'
75       ovsdb-tool transact db '
76         ["ordinals",
77          {"op": "insert",
78           "table": "ordinals",
79           "row": {"name": "'$1'", "number": '$2'}},
80          {"op": "comment",
81           "comment": "add back row for '"$pair"'"}]'
82     done]],
83   [0], [stdout], [ignore])
84 dnl Check that all the crap is in fact in the database log.
85 AT_CHECK([[perl $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | test-json --multiple -]], [0],
86   [[{"name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}}}}}
87 {"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
88 {"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
89 {"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
90 {"_comment":"add row for one 1","_date":0,"ordinals":{"<2>":{"name":"one","number":1}}}
91 {"_comment":"delete row for 1","_date":0,"ordinals":{"<2>":null}}
92 {"_comment":"add back row for one 1","_date":0,"ordinals":{"<3>":{"name":"one","number":1}}}
93 {"_comment":"add row for two 2","_date":0,"ordinals":{"<4>":{"name":"two","number":2}}}
94 {"_comment":"delete row for 2","_date":0,"ordinals":{"<4>":null}}
95 {"_comment":"add back row for two 2","_date":0,"ordinals":{"<5>":{"name":"two","number":2}}}
96 {"_comment":"add row for three 3","_date":0,"ordinals":{"<6>":{"name":"three","number":3}}}
97 {"_comment":"delete row for 3","_date":0,"ordinals":{"<6>":null}}
98 {"_comment":"add back row for three 3","_date":0,"ordinals":{"<7>":{"name":"three","number":3}}}
99 {"_comment":"add row for four 4","_date":0,"ordinals":{"<8>":{"name":"four","number":4}}}
100 {"_comment":"delete row for 4","_date":0,"ordinals":{"<8>":null}}
101 {"_comment":"add back row for four 4","_date":0,"ordinals":{"<9>":{"name":"four","number":4}}}
102 {"_comment":"add row for five 5","_date":0,"ordinals":{"<10>":{"name":"five","number":5}}}
103 {"_comment":"delete row for 5","_date":0,"ordinals":{"<10>":null}}
104 {"_comment":"add back row for five 5","_date":0,"ordinals":{"<11>":{"name":"five","number":5}}}
105 ]])
106 dnl Dump out and check the actual database contents.
107 AT_CHECK([[ovsdb-server --unixctl=$PWD/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
108   [0], [stdout], [ignore])
109 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0],
110   [_uuid                                name  number
111 ------------------------------------ ----- ------
112 <0> five  5     @&t@
113 <1> four  4     @&t@
114 <2> one   1     @&t@
115 <3> three 3     @&t@
116 <4> two   2     @&t@
117 <5> zero  0     @&t@
118 ])
119 dnl Now compact the database in-place.
120 touch .db.tmp.~lock~
121 AT_CHECK([[ovsdb-tool compact db]], [0], [], [ignore])
122 dnl We can't fully re-check the contents of the database log, because the
123 dnl order of the records is not predictable, but there should only be 4 lines
124 dnl in it now.
125 AT_CAPTURE_FILE([db])
126 AT_CHECK([wc -l < db], [0], [4
127 ])
128 dnl And check that the dumped data is the same too:
129 AT_CHECK([[ovsdb-server --unixctl=$PWD/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
130   [0], [stdout], [ignore])
131 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0],
132   [_uuid                                name  number
133 ------------------------------------ ----- ------
134 <0> five  5     @&t@
135 <1> four  4     @&t@
136 <2> one   1     @&t@
137 <3> three 3     @&t@
138 <4> two   2     @&t@
139 <5> zero  0     @&t@
140 ])
141 AT_CLEANUP
142
143 AT_SETUP([ovsdb-tool convert -- removing a column])
144 AT_KEYWORDS([ovsdb file positive])
145 AT_DATA([schema], [ORDINAL_SCHEMA
146 ])
147 AT_DATA([new-schema], 
148   [[{"name": "ordinals",
149      "tables": {
150        "ordinals": {
151          "columns": {
152            "number": {"type": "integer"}}}}}
153 ]])
154 touch .db.~lock~
155 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
156 dnl Put some data in the database.
157 AT_CHECK(
158   [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
159       set -- $pair
160       ovsdb-tool transact db '
161         ["ordinals",
162          {"op": "insert",
163           "table": "ordinals",
164           "row": {"name": "'$1'", "number": '$2'}},
165          {"op": "comment",
166           "comment": "add row for '"$pair"'"}]'
167     done]],
168   [0], [stdout], [ignore])
169 dnl Dump out and check the actual database contents.
170 AT_CHECK([[ovsdb-server --unixctl=$PWD/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
171   [0], [stdout], [ignore])
172 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0],
173   [_uuid                                name  number
174 ------------------------------------ ----- ------
175 <0> five  5     @&t@
176 <1> four  4     @&t@
177 <2> one   1     @&t@
178 <3> three 3     @&t@
179 <4> two   2     @&t@
180 <5> zero  0     @&t@
181 ])
182 dnl Now convert the database in-place.
183 touch .db.tmp.~lock~
184 AT_CHECK([[ovsdb-tool convert db new-schema]], [0], [], [ignore])
185 dnl We can't fully re-check the contents of the database log, because the
186 dnl order of the records is not predictable, but there should only be 4 lines
187 dnl in it now.
188 AT_CAPTURE_FILE([db])
189 AT_CHECK([wc -l < db], [0], [4
190 ])
191 dnl And check that the dumped data is the same except for the removed column:
192 AT_CHECK([[ovsdb-server --unixctl=$PWD/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
193   [0], [stdout], [ignore])
194 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0],
195   [_uuid                                number
196 ------------------------------------ ------
197 <0> 0     @&t@
198 <1> 1     @&t@
199 <2> 2     @&t@
200 <3> 3     @&t@
201 <4> 4     @&t@
202 <5> 5     @&t@
203 ])
204 AT_CLEANUP
205
206 AT_SETUP([ovsdb-tool convert -- adding a column])
207 AT_KEYWORDS([ovsdb file positive])
208 AT_DATA([schema], 
209   [[{"name": "ordinals",
210      "tables": {
211        "ordinals": {
212          "columns": {
213            "number": {"type": "integer"}}}}}
214 ]])
215 AT_DATA([new-schema], [ORDINAL_SCHEMA
216 ])
217 touch .db.~lock~
218 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
219 dnl Put some data in the database.
220 AT_CHECK(
221   [[for number in 0 1 2 3 4 5; do
222       ovsdb-tool transact db '
223         ["ordinals",
224          {"op": "insert",
225           "table": "ordinals",
226           "row": {"number": '$number'}},
227          {"op": "comment",
228           "comment": "add row for '"$number"'"}]'
229     done]],
230   [0], [stdout], [ignore])
231 dnl Dump out and check the actual database contents.
232 AT_CHECK([[ovsdb-server --unixctl=$PWD/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
233   [0], [stdout], [ignore])
234 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0],
235   [_uuid                                number
236 ------------------------------------ ------
237 <0> 0     @&t@
238 <1> 1     @&t@
239 <2> 2     @&t@
240 <3> 3     @&t@
241 <4> 4     @&t@
242 <5> 5     @&t@
243 ])
244 dnl Now convert the database in-place.
245 touch .db.tmp.~lock~
246 AT_CHECK([[ovsdb-tool convert db new-schema]], [0], [], [ignore])
247 dnl We can't fully re-check the contents of the database log, because the
248 dnl order of the records is not predictable, but there should only be 4 lines
249 dnl in it now.
250 AT_CAPTURE_FILE([db])
251 AT_CHECK([wc -l < db], [0], [4
252 ])
253 dnl And check that the dumped data is the same except for the added column:
254 AT_CHECK([[ovsdb-server --unixctl=$PWD/unixctl --remote=punix:socket --run "ovsdb-client dump unix:socket ordinals" db]],
255   [0], [stdout], [ignore])
256 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0],
257   [_uuid                                name number
258 ------------------------------------ ---- ------
259 <0> ""   0     @&t@
260 <1> ""   1     @&t@
261 <2> ""   2     @&t@
262 <3> ""   3     @&t@
263 <4> ""   4     @&t@
264 <5> ""   5     @&t@
265 ])
266 AT_CLEANUP