]> git.proxmox.com Git - ovs.git/blame - tests/ovs-vswitchd.at
raft: Fix the problem of stuck in candidate role forever.
[ovs.git] / tests / ovs-vswitchd.at
CommitLineData
b7898031
BP
1AT_BANNER([ovs-vswitchd])
2
3dnl The OVS initscripts never make an empty database (one without even an
4dnl Open_vSwitch record) visible to ovs-vswitchd, but hand-rolled scripts
5dnl sometimes do. At one point, "ovs-vswitchd --detach" would never detach
6dnl and use 100% CPU if this happened, so this test checks for regression.
7AT_SETUP([ovs-vswitchd detaches correctly with empty db])
53eb8cb8 8on_exit 'kill `cat ovsdb-server.pid ovs-vswitchd.pid`'
b7898031
BP
9
10dnl Create database.
11touch .conf.db.~lock~
12AT_CHECK([ovsdb-tool create conf.db $abs_top_srcdir/vswitchd/vswitch.ovsschema])
13
14dnl Start ovsdb-server. *Don't* initialize database.
15AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --log-file --remote=punix:$OVS_RUNDIR/db.sock], [0], [ignore], [ignore])
16AT_CAPTURE_FILE([ovsdb-server.log])
17
18dnl Start ovs-vswitchd.
19AT_CHECK([ovs-vswitchd --detach --no-chdir --pidfile --enable-dummy --disable-system --log-file], [0], [], [stderr])
20AT_CAPTURE_FILE([ovs-vswitchd.log])
21
22dnl ovs-vswitchd detached OK or we wouldn't have made it this far. Success.
d9c8c57c
LR
23OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
24OVS_APP_EXIT_AND_WAIT([ovsdb-server])
b7898031 25AT_CLEANUP
12eb035b
AW
26
27
28dnl ----------------------------------------------------------------------
29m4_define([OVS_VSCTL_CHECK_RX_PKT], [
2bf0b4a3 30AT_CHECK([ovs-vsctl list int $1 | grep statistics | sed -n 's/^.*\(rx_packets=[[0-9]][[0-9]]*\).*$/\1/p'],[0],
12eb035b
AW
31[dnl
32rx_packets=$2
33])
34])
35
36AT_SETUP([ovs-vswitchd -- stats-update-interval])
37OVS_VSWITCHD_START([add-port br0 p1 -- set int p1 type=internal])
38ovs-appctl time/stop
39
76eb754a 40dnl at the beginning, the update of rx_packets should happen every 5 seconds.
bdba1947 41ovs-appctl time/warp 11000 1000
12eb035b
AW
42OVS_VSCTL_CHECK_RX_PKT([p1], [0])
43AT_CHECK([ovs-appctl netdev-dummy/receive p1 'eth(src=50:54:00:00:00:09,dst=50:54:00:00:00:0a),eth_type(0x0800),ipv4(src=10.0.0.2,dst=10.0.0.1,proto=1,tos=0,ttl=64,frag=no),icmp(type=8,code=0)'])
bdba1947 44ovs-appctl time/warp 11000 1000
12eb035b
AW
45OVS_VSCTL_CHECK_RX_PKT([p1], [1])
46
47dnl set the stats update interval to 100K ms, the following 'recv' should not be updated.
48AT_CHECK([ovs-vsctl set O . other_config:stats-update-interval=100000])
bdba1947 49ovs-appctl time/warp 51000 1000
12eb035b
AW
50for i in `seq 1 5`; do
51 AT_CHECK([ovs-appctl netdev-dummy/receive p1 'eth(src=50:54:00:00:00:09,dst=50:54:00:00:00:0a),eth_type(0x0800),ipv4(src=10.0.0.2,dst=10.0.0.1,proto=1,tos=0,ttl=64,frag=no),icmp(type=8,code=0)'])
52done
53
54OVS_VSCTL_CHECK_RX_PKT([p1], [1])
55dnl advance the clock by 100K ms, the previous 'recv' should be updated.
bdba1947 56ovs-appctl time/warp 100000 1000
12eb035b
AW
57OVS_VSCTL_CHECK_RX_PKT([p1], [6])
58
59dnl now remove the configuration. 'recv' one packet. there should be an update after 5000 ms.
60AT_CHECK([ovs-vsctl clear O . other_config])
61AT_CHECK([ovs-appctl netdev-dummy/receive p1 'eth(src=50:54:00:00:00:09,dst=50:54:00:00:00:0a),eth_type(0x0800),ipv4(src=10.0.0.2,dst=10.0.0.1,proto=1,tos=0,ttl=64,frag=no),icmp(type=8,code=0)'])
bdba1947 62ovs-appctl time/warp 11000 1000
12eb035b
AW
63OVS_VSCTL_CHECK_RX_PKT([p1], [7])
64
65OVS_VSWITCHD_STOP
76eb754a 66AT_CLEANUP
6bef3c7c
AW
67
68dnl ----------------------------------------------------------------------
69AT_SETUP([ovs-vswitchd -- start additional ovs-vswitchd process])
70OVS_VSWITCHD_START
71
72# start another ovs-vswitchd process.
56120500 73ovs-vswitchd --log-file=fakelog --unixctl=unixctl2 --pidfile=ovs-vswitchd-2.pid &
8a16ab90 74on_exit 'kill `cat ovs-vswitchd-2.pid`'
6bef3c7c
AW
75
76# sleep for a while
77sleep 5
78
79# stop the process.
56120500 80OVS_APP_EXIT_AND_WAIT_BY_TARGET(["`pwd`"/unixctl2], [`pwd`/ovs-vswitchd-2.pid])
6bef3c7c
AW
81
82# check the fakelog, should only see one ERR for reporting
1786535e 83# the existing ovs-vswitchd process.
a07e26bf 84AT_CHECK([test `grep ERR fakelog | wc -l` -eq 1])
6bef3c7c 85
1786535e 86AT_CHECK([tail -n1 fakelog | sed -e 's/^.*ERR|//; s/pid [[0-9]]*//'], [0], [dnl
6bef3c7c
AW
87another ovs-vswitchd process is running, disabling this process () until it goes away
88])
89
90OVS_VSWITCHD_STOP
91AT_CLEANUP
e15df145
AW
92
93dnl ----------------------------------------------------------------------
94AT_SETUP([ovs-vswitchd -- switch over to another ovs-vswitchd process])
95OVS_VSWITCHD_START
96
97# start a new ovs-vswitchd process.
56120500 98ovs-vswitchd --log-file=fakelog --enable-dummy --unixctl=unixctl2 --pidfile=ovs-vswitchd-2.pid &
8a16ab90 99on_exit 'kill `cat ovs-vswitchd-2.pid`'
e15df145
AW
100
101# sleep for a while.
102sleep 5
103
104# kill the current active ovs-vswitchd process.
105kill `cat ovs-vswitchd.pid`
106
107sleep 5
108
109# check the creation of br0 on the new ovs-vswitchd process.
110AT_CHECK([grep "bridge br0" fakelog | sed -e 's/port [[0-9]]*$/port/;
111s/datapath ID [[a-z0-9]]*$/datapath ID/;s/^.*INFO|//'], [0], [dnl
112bridge br0: added interface br0 on port
113bridge br0: using datapath ID
114])
115
116# stop the process.
56120500 117OVS_APP_EXIT_AND_WAIT_BY_TARGET(["`pwd`"/unixctl2], [ovs-vswitchd-2.pid])
e15df145
AW
118
119# check the fakelog, should not see WARN/ERR/EMER log other than the one
120# for reporting the existing ovs-vswitchd process and the one for killing
121# the process.
122AT_CHECK([sed -n "
123/|ERR|another ovs-vswitchd process is running/d
e15df145
AW
124/|WARN|/p
125/|ERR|/p
126/|EMER|/p" fakelog
127])
128
129# cleanup.
130kill `cat ovsdb-server.pid`
131AT_CLEANUP
5aca3322
AW
132
133dnl ----------------------------------------------------------------------
134AT_SETUP([ovs-vswitchd -- invalid database path])
135
136# start an ovs-vswitchd process with invalid db path.
56120500
BP
137ovs-vswitchd unix:invalid.db.sock --log-file --enable-dummy --pidfile &
138on_exit 'kill `cat ovs-vswitchd.pid`'
5aca3322
AW
139
140# sleep for a while.
141sleep 10
142
143# stop the process.
56120500 144OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
5aca3322
AW
145
146# should not see this log (which indicates high cpu utilization).
56120500 147AT_CHECK([grep "wakeup due to" ovs-vswitchd.log], [ignore])
5aca3322 148
56120500 149# check the log, should not see any WARN/ERR/EMER log.
5aca3322
AW
150AT_CHECK([sed -n "
151/|WARN|/p
152/|ERR|/p
56120500 153/|EMER|/p" ovs-vswitchd.log
5aca3322
AW
154])
155
156AT_CLEANUP
14dd55a3
AW
157
158dnl ----------------------------------------------------------------------
159AT_SETUP([ovs-vswitchd -- set service controller])
160AT_SKIP_IF([test "$IS_WIN32" = "yes"])
161OVS_VSWITCHD_START
162
163AT_CHECK([ovs-vsctl set-controller br0 punix:$(pwd)/br0.void])
164OVS_WAIT_UNTIL([test -e br0.void])
165
166AT_CHECK([ovs-vsctl set-controller br0 punix:$(pwd)/br0.void/../overwrite.file])
167OVS_WAIT_UNTIL([test -n "`grep ERR ovs-vswitchd.log | grep overwrite.file`"])
168
169OVS_VSWITCHD_STOP(["/Not adding Unix domain socket controller/d"])
170AT_CLEANUP
e47cb14c
AZ
171
172dnl ----------------------------------------------------------------------
c383f3bf 173dnl OVSDB server before release version 2.5 does not support the monitor_cond
e47cb14c
AZ
174dnl method. This test defeatures the OVSDB server to simulate an older
175dnl OVSDB server and make sure ovs-vswitchd can still work with it
c383f3bf 176AT_SETUP([ovs-vswitchd -- Compatible with OVSDB server - w/o monitor_cond])
e47cb14c
AZ
177OVS_VSWITCHD_START
178
c383f3bf
LS
179dnl defeature OVSDB server -- no monitor_cond
180AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/disable-monitor-cond])
e47cb14c
AZ
181
182sleep 1
183
184AT_CHECK([ovs-vsctl add-port br0 p0 -- set interface p0 type=internal])
185AT_CHECK([ovs-vsctl add-port br0 p1 -- set interface p1 type=internal])
186
187dnl ovs-vswitchd should still 'see' ovsdb change with the 'monitor' method
188AT_CHECK([ovs-appctl dpif/show | tail -n +3], [0], [dnl
7be29a47
BP
189 br0 65534/100: (dummy-internal)
190 p0 1/1: (dummy-internal)
191 p1 2/2: (dummy-internal)
e47cb14c
AZ
192])
193OVS_VSWITCHD_STOP
194AT_CLEANUP
e6448d2f
DDP
195
196dnl ----------------------------------------------------------------------
197AT_SETUP([ovs-vswitchd - do not create sockets with unsafe names])
198OVS_VSWITCHD_START
199
200# On Unix systems, test for sockets with "test -S".
201#
202# On Windows systems, we simulate a socket with a regular file that contains
203# a TCP port number, so use "test -f" there instead.
204if test $IS_WIN32 = yes; then
205 S=f
206else
207 S=S
208fi
209
210# Create a bridge with an ordinary name and make sure that the management
211# socket gets creatd.
212AT_CHECK([ovs-vsctl add-br a -- set bridge a datapath-type=dummy])
213AT_CHECK([test -$S a.mgmt])
214
215# Create a bridge with an unsafe name and make sure that the management
216# socket does not get created.
217mkdir b
feb38b6d
DDP
218
219cat >experr <<EOF
220ovs-vsctl: Error detected while setting up 'b/c'. See ovs-vswitchd log for details.
221ovs-vsctl: The default log directory is "$OVS_RUNDIR".
222EOF
223AT_CHECK([ovs-vsctl add-br b/c -- set bridge b/c datapath-type=dummy], [0], [], [experr])
e6448d2f
DDP
224AT_CHECK([test ! -e b/c.mgmt])
225
226OVS_VSWITCHD_STOP(['/ignoring bridge with invalid name/d'])
227AT_CLEANUP
62705b81
BP
228
229dnl ----------------------------------------------------------------------
230AT_SETUP([ovs-vswitchd - set datapath IDs])
231OVS_VSWITCHD_START([remove bridge br0 other-config datapath-id])
232
233# Get the default dpid and verify that it is of the expected form.
15394e0f 234AT_CHECK([ovs-vsctl wait-until bridge br0 datapath-id!='[[]]'])
62705b81
BP
235AT_CHECK([ovs-vsctl get bridge br0 datapath-id], [0], [stdout])
236orig_dpid=$(tr -d \" < stdout)
237AT_CHECK([sed 's/[[0-9a-f]]/x/g' stdout], [0], ["xxxxxxxxxxxxxxxx"
238])
239AT_CHECK_UNQUOTED([ovs-ofctl show br0 | strip_xids | head -1], [0], [dnl
240OFPT_FEATURES_REPLY: dpid:$orig_dpid
241])
242
243# Set a dpid with 16 hex digits.
244AT_CHECK([ovs-vsctl set bridge br0 other-config:datapath-id=0123456789abcdef])
15394e0f 245AT_CHECK([ovs-vsctl wait-until bridge br0 datapath-id=0123456789abcdef])
62705b81
BP
246AT_CHECK([ovs-ofctl show br0 | strip_xids | head -1], [0], [dnl
247OFPT_FEATURES_REPLY: dpid:0123456789abcdef
248])
249
250# Set a dpif with 0x prefix.
251AT_CHECK([ovs-vsctl set bridge br0 other-config:datapath-id=0x5ad515c0])
15394e0f 252AT_CHECK([ovs-vsctl wait-until bridge br0 datapath-id=000000005ad515c0])
62705b81
BP
253AT_CHECK([ovs-ofctl show br0 | strip_xids | head -1], [0], [dnl
254OFPT_FEATURES_REPLY: dpid:000000005ad515c0
255])
256
257# Set invalid all-zeros dpid and make sure that the default reappears.
258AT_CHECK([ovs-vsctl set bridge br0 other-config:datapath-id=0x00])
15394e0f 259AT_CHECK([ovs-vsctl wait-until bridge br0 datapath-id=$orig_dpid])
62705b81
BP
260AT_CHECK_UNQUOTED([ovs-ofctl show br0 | strip_xids | head -1], [0], [dnl
261OFPT_FEATURES_REPLY: dpid:$orig_dpid
262])
263
264OVS_VSWITCHD_STOP
265AT_CLEANUP