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