]> git.proxmox.com Git - ovs.git/blame - tests/daemon.at
system-kmod-macros: Load TFTP module.
[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"])
ab7fc30e
PB
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
ff8decf1
BP
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.
56120500
BP
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`])
ff8decf1
BP
24# Kill the daemon and make sure that the pidfile gets deleted.
25kill `cat expected`
26OVS_WAIT_WHILE([kill -0 `cat expected`])
56120500 27AT_CHECK([test ! -e ovsdb-server.pid])
ff8decf1
BP
28AT_CLEANUP
29
30AT_SETUP([daemon --monitor])
fc28ea52 31AT_SKIP_IF([test "$IS_WIN32" = "yes"])
ff8decf1
BP
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.
56120500
BP
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`])
ff8decf1
BP
40# Check that the pidfile names a running process,
41# and that the parent process of that process is our child process.
56120500
BP
42AT_CHECK([kill -0 `cat ovsdb-server.pid`], [0], [], [], [kill `cat parent`])
43AT_CHECK([parent_pid `cat ovsdb-server.pid` > parentpid],
ff8decf1
BP
44 [0], [], [], [kill `cat parent`])
45AT_CHECK(
46 [parentpid=`cat parentpid` &&
47 parent=`cat parent` &&
48 test $parentpid = $parent],
49 [0], [], [], [kill `cat parent`])
34a57104
BP
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(
56120500
BP
53 [ovs-appctl --timeout=10 -t ovsdb-server version],
54 [kill `cat ovsdb-server.pid`])
ff8decf1
BP
55# Kill the daemon process, making it look like a segfault,
56# and wait for a new child process to get spawned.
56120500
BP
57AT_CHECK([cp ovsdb-server.pid oldpid], [0], [], [], [kill `cat parent`])
58AT_CHECK([kill -SEGV `cat ovsdb-server.pid`], [0], [], [ignore], [kill `cat parent`])
ff8decf1 59OVS_WAIT_WHILE([kill -0 `cat oldpid`], [kill `cat parent`])
56120500 60OVS_WAIT_UNTIL([test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat oldpid`],
ff8decf1 61 [kill `cat parent`])
56120500 62AT_CHECK([cp ovsdb-server.pid newpid], [0], [], [], [kill `cat parent`])
ff8decf1
BP
63# Check that the pidfile names a running process,
64# and that the parent process of that process is our child process.
56120500 65AT_CHECK([parent_pid `cat ovsdb-server.pid` > parentpid],
ff8decf1
BP
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.
56120500
BP
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],
ff8decf1
BP
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.
56120500
BP
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`])
ff8decf1 88# Kill the daemon and make sure that the pidfile gets deleted.
56120500 89cp ovsdb-server.pid saved-pid
fc28ea52
GS
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
56120500 94 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
fc28ea52 95else
56120500 96 kill `cat ovsdb-server.pid`
fc28ea52 97fi
ff8decf1 98OVS_WAIT_WHILE([kill -0 `cat saved-pid`])
56120500 99AT_CHECK([test ! -e ovsdb-server.pid])
ff8decf1
BP
100AT_CLEANUP
101
102AT_SETUP([daemon --detach --monitor])
fc28ea52 103AT_SKIP_IF([test "$IS_WIN32" = "yes"])
ff8decf1
BP
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.
56120500
BP
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])
ff8decf1
BP
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.
56120500
BP
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` != $$])
ff8decf1
BP
125# Kill the daemon process, making it look like a segfault,
126# and wait for a new daemon process to get spawned.
56120500
BP
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])
ff8decf1
BP
132# Check that the pidfile names a running process,
133# and that the parent process of that process is our child process.
56120500
BP
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` != $$])
ff8decf1
BP
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.
56120500 143AT_CHECK([kill `cat ovsdb-server.pid`], [0], [], [ignore])
ff8decf1 144OVS_WAIT_WHILE(
56120500 145 [kill -0 `cat monitor` || kill -0 `cat newdaemon` || test -e ovsdb-server.pid])
ff8decf1
BP
146AT_CLEANUP
147
148AT_SETUP([daemon --detach startup errors])
149AT_CAPTURE_FILE([pid])
150OVSDB_INIT([db])
56120500 151AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --unixctl=nonexistent/unixctl db], [1], [], [stderr])
ff8decf1 152AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr],
56120500 153 [0], [ignore])
ff8decf1
BP
154AT_CHECK([test ! -s pid])
155AT_CLEANUP
156
157AT_SETUP([daemon --detach --monitor startup errors])
fc28ea52 158AT_SKIP_IF([test "$IS_WIN32" = "yes"])
ff8decf1
BP
159AT_CAPTURE_FILE([pid])
160OVSDB_INIT([db])
56120500 161AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --monitor --unixctl=nonexistent/unixctl db], [1], [], [stderr])
ff8decf1 162AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr],
56120500 163 [0], [ignore])
ff8decf1
BP
164AT_CHECK([test ! -s pid])
165AT_CLEANUP
02a514ef
GS
166
167AT_SETUP([daemon --service])
05082734 168AT_KEYWORDS([windows-service])
02a514ef 169AT_SKIP_IF([test "$IS_WIN32" != "yes"])
ab7fc30e 170OVS_SKIP_NON_ADMIN_WIN
13574ee6 171AT_SKIP_IF([sc qc ovsdb-server])
ab7fc30e 172
02a514ef
GS
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
13574ee6 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"],
02a514ef
GS
179[0], [[[SC]] CreateService SUCCESS
180])
181
8164a704 182AT_CHECK([sc start ovsdb-server], [0], [ignore], [ignore], [sc delete ovsdb-server])
56120500 183OVS_WAIT_UNTIL([test -s ovsdb-server.pid])
05082734 184OVS_WAIT_UNTIL([sc query ovsdb-server | grep STATE | grep RUNNING > /dev/null 2>&1])
56120500
BP
185AT_CHECK([kill -0 `cat ovsdb-server.pid`], [0], [ignore])
186AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs], [0],
02a514ef
GS
187[Open_vSwitch
188])
189AT_CHECK([sc stop ovsdb-server], [0], [ignore])
56120500 190OVS_WAIT_UNTIL([test ! -s ovsdb-server.pid])
02a514ef
GS
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