]> git.proxmox.com Git - mirror_ovs.git/blame - tests/ovsdb-client.at
treewide: Convert leading tabs to spaces.
[mirror_ovs.git] / tests / ovsdb-client.at
CommitLineData
7ed92408
BP
1AT_BANNER([OVSDB -- ovsdb-client commands])
2
33785c07 3AT_SETUP([ovsdb-client get-schema-version and get-schema-cksum])
7ed92408
BP
4AT_KEYWORDS([ovsdb client positive])
5ordinal_schema > schema
6AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
7AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db], [0], [ignore], [ignore])
8AT_CHECK([ovsdb-client get-schema-version unix:socket ordinals], [0], [5.1.3
9])
33785c07
BP
10AT_CHECK([ovsdb-client get-schema-cksum unix:socket ordinals], [0], [12345678 9
11])
7ed92408
BP
12OVSDB_SERVER_SHUTDOWN
13AT_CLEANUP
4d0a31b6 14
fe0fb885 15AT_SETUP([ovsdb-client backup and restore])
4d0a31b6
BP
16AT_KEYWORDS([ovsdb client positive])
17
18on_exit 'kill `cat *.pid`'
19
20dnl Create a database.
21ordinal_schema > schema
22touch .db.~lock~
23AT_CHECK([ovsdb-tool create db schema])
24
25dnl Put some data in the database.
26AT_CHECK(
27 [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do
28 set -- $pair
29 ovsdb-tool transact db '
30 ["ordinals",
31 {"op": "insert",
32 "table": "ordinals",
33 "row": {"name": "'$1'", "number": '$2'}},
34 {"op": "comment",
35 "comment": "add row for '"$pair"'"}]'
36 done | uuidfilt]], [0],
37[[[{"uuid":["uuid","<0>"]},{}]
38[{"uuid":["uuid","<1>"]},{}]
39[{"uuid":["uuid","<2>"]},{}]
40[{"uuid":["uuid","<3>"]},{}]
41[{"uuid":["uuid","<4>"]},{}]
42[{"uuid":["uuid","<5>"]},{}]
43]], [ignore])
44
45dnl Start the database server.
46AT_CHECK([ovsdb-server -vfile -vvlog:off --detach --no-chdir --pidfile --log-file --remote=punix:db.sock db], [0])
47AT_CAPTURE_FILE([ovsdb-server.log])
48
49dnl Dump a copy of the data and a backup of it.
50AT_CHECK([ovsdb-client dump > dump1])
51AT_CHECK([ovsdb-client backup > backup])
52
fe0fb885
BP
53dnl Mess up the data a little, verify that it changed, then restore it
54dnl and verify restoration.
55AT_CHECK(
56 [[ovsdb-client transact '
57 ["ordinals",
58 {"op": "update",
59 "table": "ordinals",
5a0e4aec
BP
60 "where": [],
61 "row": {"name": ""}}]']],
fe0fb885
BP
62 [0],
63 [[[{"count":6}]
64]])
65AT_CHECK([ovsdb-client --no-headings dump ordinals | sort -k 3 | uuidfilt], [0], [dnl
66ordinals table
80f66ee0
BP
67<0> "" 0
68<1> "" 1
69<2> "" 2
70<3> "" 3
71<4> "" 4
72<5> "" 5
fe0fb885
BP
73])
74AT_CHECK([ovsdb-client restore < backup])
75AT_CHECK([ovsdb-client dump | tr -s ' ' | sort -k 3 | uuidfilt], [0], [dnl
76ordinals table
77------------------------------------ ----- ------
78<0> zero 0
79<1> one 1
80<2> two 2
81<3> three 3
82<4> four 4
83<5> five 5
84_uuid name number
85])
86# Combining the original dump and the backup dump should reveal that the
87# rows have different uuids:
88AT_CHECK([(ovsdb-client dump; cat dump1) | tr -s ' ' | sort -k 3 | uuidfilt], [0], [dnl
89ordinals table
90ordinals table
91------------------------------------ ----- ------
92------------------------------------ ----- ------
93<0> zero 0
94<1> zero 0
95<2> one 1
96<3> one 1
97<4> two 2
98<5> two 2
99<6> three 3
100<7> three 3
101<8> four 4
102<9> four 4
103<10> five 5
104<11> five 5
105_uuid name number
106_uuid name number
107])
108
4d0a31b6
BP
109dnl Stop the database server, then re-start it based on the backup.
110OVS_APP_EXIT_AND_WAIT([ovsdb-server])
111AT_CHECK([ovsdb-server -vfile -vvlog:off --detach --no-chdir --pidfile --log-file --remote=punix:db.sock backup], [0])
112
113dnl Dump a new copy of the data.
114AT_CHECK([ovsdb-client dump > dump2])
115sort dump2 > expout
116
117dnl Verify that the two dumps are the same.
118AT_CHECK([sort dump1], [0], [expout])
119
120AT_CLEANUP
838f9c31
BP
121
122AT_SETUP([ovsdb-client query])
123AT_KEYWORDS([ovsdb client positive])
124
125on_exit 'kill `cat *.pid`'
126
127dnl Create a database.
128ordinal_schema > schema
129touch .db.~lock~
130AT_CHECK([ovsdb-tool create db schema])
131
132dnl Start the database server.
133AT_CHECK([ovsdb-server -vfile -vvlog:off --detach --no-chdir --pidfile --log-file --remote=punix:db.sock db], [0])
134AT_CAPTURE_FILE([ovsdb-server.log])
135
136dnl Put some data in the database.
137dnl Use "query" for some of them, which won't have any effect.
138AT_CHECK(
139 [[for txn in 'transact zero 0' \
140 'query one 1' \
5a0e4aec
BP
141 'transact two 2' \
142 'query three 3' \
143 'transact four 4' \
144 'query five 5'
838f9c31
BP
145 do
146 set -- $txn
147 ovsdb-client $1 '
148 ["ordinals",
149 {"op": "insert",
150 "table": "ordinals",
151 "row": {"name": "'$2'", "number": '$3'}},
152 {"op": "comment",
153 "comment": "add row for '"$pair"'"}]'
154 done | uuidfilt]], [0],
155[[[{"uuid":["uuid","<0>"]},{}]
156[{"uuid":["uuid","<1>"]},{}]
157[{"uuid":["uuid","<2>"]},{}]
158[{"uuid":["uuid","<3>"]},{}]
159[{"uuid":["uuid","<4>"]},{}]
160[{"uuid":["uuid","<5>"]},{}]
161]], [ignore])
162
163AT_CHECK([ovsdb-client -f csv dump | sort -t, -k 3 | uuidfilt], [0], [dnl
164ordinals table
165<0>,zero,0
166<1>,two,2
167<2>,four,4
168_uuid,name,number
169])
170
171OVS_APP_EXIT_AND_WAIT([ovsdb-server])
172
173AT_CLEANUP