1 AT_BANNER([OVSDB -- ovsdb-tool])
3 # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
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.
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
15 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
16 m4_define([OVSDB_CHECK_EXECUTION],
18 AT_KEYWORDS([ovsdb file positive $5])
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])
27 AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4])
32 AT_SETUP([transaction comments])
33 AT_KEYWORDS([ovsdb file positive])
34 AT_DATA([schema], [ORDINAL_SCHEMA
37 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
38 AT_CHECK([[ovsdb-tool transact db '
42 "row": {"name": "five", "number": 5}},
44 "comment": "add row for 5"}]']], [0], [stdout], [ignore])
45 AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0],
46 [[[{"uuid":["uuid","<0>"]},{}]
48 AT_CHECK([grep -q "add row for 5" db])
51 AT_SETUP([ovsdb-tool compact])
52 AT_KEYWORDS([ovsdb file positive])
53 AT_DATA([schema], [ORDINAL_SCHEMA
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.
59 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
61 ovsdb-tool transact db '
65 "row": {"name": "'$1'", "number": '$2'}},
67 "comment": "add row for '"$pair"'"}]'
68 ovsdb-tool transact db '
72 "where": [["number", "==", '$2']]},
74 "comment": "delete row for '"$2"'"}]'
75 ovsdb-tool transact db '
79 "row": {"name": "'$1'", "number": '$2'}},
81 "comment": "add back row for '"$pair"'"}]'
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}}}
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],
111 ------------------------------------ ----- ------
119 dnl Now compact the database in-place.
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
125 AT_CAPTURE_FILE([db])
126 AT_CHECK([wc -l < db], [0], [4
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],
133 ------------------------------------ ----- ------
143 AT_SETUP([ovsdb-tool convert -- removing a column])
144 AT_KEYWORDS([ovsdb file positive])
145 AT_DATA([schema], [ORDINAL_SCHEMA
147 AT_DATA([new-schema],
148 [[{"name": "ordinals",
152 "number": {"type": "integer"}}}}}
155 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
156 dnl Put some data in the database.
158 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
160 ovsdb-tool transact db '
164 "row": {"name": "'$1'", "number": '$2'}},
166 "comment": "add row for '"$pair"'"}]'
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],
174 ------------------------------------ ----- ------
182 dnl Now convert the database in-place.
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
188 AT_CAPTURE_FILE([db])
189 AT_CHECK([wc -l < db], [0], [4
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],
196 ------------------------------------ ------
206 AT_SETUP([ovsdb-tool convert -- adding a column])
207 AT_KEYWORDS([ovsdb file positive])
209 [[{"name": "ordinals",
213 "number": {"type": "integer"}}}}}
215 AT_DATA([new-schema], [ORDINAL_SCHEMA
218 AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
219 dnl Put some data in the database.
221 [[for number in 0 1 2 3 4 5; do
222 ovsdb-tool transact db '
226 "row": {"number": '$number'}},
228 "comment": "add row for '"$number"'"}]'
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],
236 ------------------------------------ ------
244 dnl Now convert the database in-place.
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
250 AT_CAPTURE_FILE([db])
251 AT_CHECK([wc -l < db], [0], [4
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],
258 ------------------------------------ ---- ------