]> git.proxmox.com Git - mirror_ovs.git/blame - tests/daemon.at
tests/ovs_client: Remove broken debug code
[mirror_ovs.git] / tests / daemon.at
CommitLineData
99155935 1AT_BANNER([daemon unit tests - C])
ff8decf1
BP
2
3AT_SETUP([daemon])
fc28ea52 4AT_SKIP_IF([test "$IS_WIN32" = "yes"])
ff8decf1
BP
5OVSDB_INIT([db])
6AT_CAPTURE_FILE([pid])
7AT_CAPTURE_FILE([expected])
8# Start the daemon and wait for the pidfile to get created
9# and that its contents are the correct pid.
434380a6 10AT_CHECK([ovsdb-server --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db 2>/dev/null & echo $! > expected], [0])
ff8decf1
BP
11OVS_WAIT_UNTIL([test -s pid], [kill `cat expected`])
12AT_CHECK(
13 [pid=`cat pid` && expected=`cat expected` && test "$pid" = "$expected"],
14 [0], [], [], [kill `cat expected`])
15AT_CHECK([kill -0 `cat pid`], [0], [], [], [kill `cat expected`])
16# Kill the daemon and make sure that the pidfile gets deleted.
17kill `cat expected`
18OVS_WAIT_WHILE([kill -0 `cat expected`])
19AT_CHECK([test ! -e pid])
20AT_CLEANUP
21
22AT_SETUP([daemon --monitor])
fc28ea52 23AT_SKIP_IF([test "$IS_WIN32" = "yes"])
ff8decf1
BP
24OVSDB_INIT([db])
25AT_CAPTURE_FILE([pid])
26AT_CAPTURE_FILE([parent])
27AT_CAPTURE_FILE([parentpid])
28AT_CAPTURE_FILE([newpid])
29# Start the daemon and wait for the pidfile to get created.
434380a6 30AT_CHECK([ovsdb-server --monitor --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db 2>/dev/null & echo $! > parent], [0])
ff8decf1
BP
31OVS_WAIT_UNTIL([test -s pid], [kill `cat parent`])
32# Check that the pidfile names a running process,
33# and that the parent process of that process is our child process.
34AT_CHECK([kill -0 `cat pid`], [0], [], [], [kill `cat parent`])
35AT_CHECK([ps -o ppid= -p `cat pid` > parentpid],
36 [0], [], [], [kill `cat parent`])
37AT_CHECK(
38 [parentpid=`cat parentpid` &&
39 parent=`cat parent` &&
40 test $parentpid = $parent],
41 [0], [], [], [kill `cat parent`])
34a57104
BP
42# Avoid a race between pidfile creation and notifying the parent,
43# which can easily trigger if ovsdb-server is slow (e.g. due to valgrind).
44OVS_WAIT_UNTIL(
45 [ovs-appctl --timeout=10 -t "`pwd`/unixctl" version],
46 [kill `cat pid`])
ff8decf1
BP
47# Kill the daemon process, making it look like a segfault,
48# and wait for a new child process to get spawned.
49AT_CHECK([cp pid oldpid], [0], [], [], [kill `cat parent`])
50AT_CHECK([kill -SEGV `cat pid`], [0], [], [ignore], [kill `cat parent`])
51OVS_WAIT_WHILE([kill -0 `cat oldpid`], [kill `cat parent`])
52OVS_WAIT_UNTIL([test -s pid && test `cat pid` != `cat oldpid`],
53 [kill `cat parent`])
54AT_CHECK([cp pid newpid], [0], [], [], [kill `cat parent`])
55# Check that the pidfile names a running process,
56# and that the parent process of that process is our child process.
57AT_CHECK([ps -o ppid= -p `cat pid` > parentpid],
58 [0], [], [], [kill `cat parent`])
59AT_CHECK(
60 [parentpid=`cat parentpid` &&
61 parent=`cat parent` &&
62 test $parentpid = $parent],
63 [0], [], [], [kill `cat parent`])
64# Kill the daemon process with SIGTERM, and wait for the daemon
65# and the monitor processes to go away and the pidfile to get deleted.
66AT_CHECK([kill `cat pid`], [0], [], [ignore], [kill `cat parent`])
67OVS_WAIT_WHILE([kill -0 `cat parent` || kill -0 `cat newpid` || test -e pid],
68 [kill `cat parent`])
69AT_CLEANUP
70
71AT_SETUP([daemon --detach])
72AT_CAPTURE_FILE([pid])
73OVSDB_INIT([db])
74# Start the daemon and make sure that the pidfile exists immediately.
75# We don't wait for the pidfile to get created because the daemon is
76# supposed to do so before the parent exits.
77a922c7 77AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0])
ff8decf1
BP
78AT_CHECK([test -s pid])
79AT_CHECK([kill -0 `cat pid`])
80# Kill the daemon and make sure that the pidfile gets deleted.
81cp pid saved-pid
fc28ea52
GS
82if test "$IS_WIN32" = "yes"; then
83 # When a 'kill pid' is done on windows (through 'taskkill //F'),
84 # pidfiles are not deleted (because it is force kill), so use
85 # 'ovs-appctl exit' instead
86 ovs-appctl -t `pwd`/unixctl exit
87else
88 kill `cat pid`
89fi
ff8decf1
BP
90OVS_WAIT_WHILE([kill -0 `cat saved-pid`])
91AT_CHECK([test ! -e pid])
92AT_CLEANUP
93
94AT_SETUP([daemon --detach --monitor])
fc28ea52 95AT_SKIP_IF([test "$IS_WIN32" = "yes"])
ff8decf1
BP
96m4_define([CHECK],
97 [AT_CHECK([$1], [$2], [$3], [$4], [kill `cat daemon monitor`])])
98OVSDB_INIT([db])
99AT_CAPTURE_FILE([daemon])
100AT_CAPTURE_FILE([olddaemon])
101AT_CAPTURE_FILE([newdaemon])
102AT_CAPTURE_FILE([monitor])
103AT_CAPTURE_FILE([newmonitor])
104AT_CAPTURE_FILE([init])
105# Start the daemon and make sure that the pidfile exists immediately.
106# We don't wait for the pidfile to get created because the daemon is
107# supposed to do so before the parent exits.
77a922c7 108AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/daemon --monitor --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0])
ff8decf1
BP
109AT_CHECK([test -s daemon])
110# Check that the pidfile names a running process,
111# and that the parent process of that process is a running process,
112# and that the parent process of that process is init.
113CHECK([kill -0 `cat daemon`])
114CHECK([ps -o ppid= -p `cat daemon` > monitor])
115CHECK([kill -0 `cat monitor`])
116CHECK([ps -o ppid= -p `cat monitor` > init])
c8dc7b46 117CHECK([test `cat init` != $$])
ff8decf1
BP
118# Kill the daemon process, making it look like a segfault,
119# and wait for a new daemon process to get spawned.
120CHECK([cp daemon olddaemon])
bc9dcfb3 121CHECK([kill -SEGV `cat daemon`], [0])
ff8decf1
BP
122OVS_WAIT_WHILE([kill -0 `cat olddaemon`], [kill `cat olddaemon daemon`])
123OVS_WAIT_UNTIL([test -s daemon && test `cat daemon` != `cat olddaemon`],
124 [kill `cat olddaemon daemon`])
125CHECK([cp daemon newdaemon])
126# Check that the pidfile names a running process,
127# and that the parent process of that process is our child process.
128CHECK([kill -0 `cat daemon`])
129CHECK([diff olddaemon newdaemon], [1], [ignore])
130CHECK([ps -o ppid= -p `cat daemon` > newmonitor])
131CHECK([diff monitor newmonitor])
132CHECK([kill -0 `cat newmonitor`])
133CHECK([ps -o ppid= -p `cat newmonitor` > init])
c8dc7b46 134CHECK([test `cat init` != $$])
ff8decf1
BP
135# Kill the daemon process with SIGTERM, and wait for the daemon
136# and the monitor processes to go away and the pidfile to get deleted.
137CHECK([kill `cat daemon`], [0], [], [ignore])
138OVS_WAIT_WHILE(
139 [kill -0 `cat monitor` || kill -0 `cat newdaemon` || test -e daemon],
140 [kill `cat monitor newdaemon`])
141m4_undefine([CHECK])
142AT_CLEANUP
143
144AT_SETUP([daemon --detach startup errors])
145AT_CAPTURE_FILE([pid])
146OVSDB_INIT([db])
77a922c7 147AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/nonexistent/unixctl db], [1], [], [stderr])
ff8decf1
BP
148AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr],
149 [0], [ignore], [])
150AT_CHECK([test ! -s pid])
151AT_CLEANUP
152
153AT_SETUP([daemon --detach --monitor startup errors])
fc28ea52 154AT_SKIP_IF([test "$IS_WIN32" = "yes"])
ff8decf1
BP
155AT_CAPTURE_FILE([pid])
156OVSDB_INIT([db])
77a922c7 157AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --monitor --unixctl="`pwd`"/nonexistent/unixctl db], [1], [], [stderr])
ff8decf1
BP
158AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr],
159 [0], [ignore], [])
160AT_CHECK([test ! -s pid])
161AT_CLEANUP
02a514ef
GS
162
163AT_SETUP([daemon --service])
164AT_SKIP_IF([test "$IS_WIN32" != "yes"])
165OVSDB_INIT([db])
166AT_CAPTURE_FILE([pid])
167# To create a Windows service, we need the absolute path for the executable.
168abs_path="$(cd $(dirname `which ovsdb-server`); pwd -W; cd $OLDPWD)"
169
170AT_CHECK([sc create ovsdb-server binpath="$abs_path/ovsdb-server `pwd`/db --log-file=`pwd`/ovsdb-server.log --pidfile=`pwd`/pid --remote=punix:`pwd`/socket --unixctl=`pwd`/unixctl --service"],
171[0], [[[SC]] CreateService SUCCESS
172])
173
174AT_CHECK([sc start ovsdb-server], [0], [ignore])
175OVS_WAIT_UNTIL([test -s pid])
176AT_CHECK([sc query ovsdb-server | grep STATE | grep RUNNING], [0], [ignore])
177AT_CHECK([kill -0 `cat pid`], [0], [ignore])
178AT_CHECK([ovs-appctl -t `pwd`/unixctl ovsdb-server/list-dbs], [0],
179[Open_vSwitch
180])
181AT_CHECK([sc stop ovsdb-server], [0], [ignore])
182OVS_WAIT_UNTIL([test ! -s pid])
183AT_CHECK([sc query ovsdb-server | grep STATE | grep STOPPED], [0], [ignore])
184AT_CHECK([sc delete ovsdb-server], [0], [[[SC]] DeleteService SUCCESS
185])
186AT_CLEANUP