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