]> git.proxmox.com Git - mirror_ovs.git/blob - tests/daemon.at
tests/ovs-monitor-ipsec: Remove --no-wait -vreconnect:emer from ovs-vsctl.
[mirror_ovs.git] / tests / daemon.at
1 AT_BANNER([daemon unit tests - C])
2
3 AT_SETUP([daemon])
4 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
5
6 dnl OVS_SKIP_NON_ADMIN_WIN()
7 dnl
8 dnl Checks if we have enough rights to create a service
9 m4_define([OVS_SKIP_NON_ADMIN_WIN],
10 [
11 AT_SKIP_IF([net session; test $? -ne 0])
12 ])
13
14 OVSDB_INIT([db])
15 AT_CAPTURE_FILE([pid])
16 AT_CAPTURE_FILE([expected])
17 # Start the daemon and wait for the pidfile to get created
18 # and that its contents are the correct pid.
19 AT_CHECK([ovsdb-server --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db 2>/dev/null & echo $! > expected], [0])
20 OVS_WAIT_UNTIL([test -s pid], [kill `cat expected`])
21 AT_CHECK(
22 [pid=`cat pid` && expected=`cat expected` && test "$pid" = "$expected"],
23 [0], [], [], [kill `cat expected`])
24 AT_CHECK([kill -0 `cat pid`], [0], [], [], [kill `cat expected`])
25 # Kill the daemon and make sure that the pidfile gets deleted.
26 kill `cat expected`
27 OVS_WAIT_WHILE([kill -0 `cat expected`])
28 AT_CHECK([test ! -e pid])
29 AT_CLEANUP
30
31 AT_SETUP([daemon --monitor])
32 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
33 OVSDB_INIT([db])
34 AT_CAPTURE_FILE([pid])
35 AT_CAPTURE_FILE([parent])
36 AT_CAPTURE_FILE([parentpid])
37 AT_CAPTURE_FILE([newpid])
38 # Start the daemon and wait for the pidfile to get created.
39 AT_CHECK([ovsdb-server --monitor --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db 2>/dev/null & echo $! > parent], [0])
40 OVS_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.
43 AT_CHECK([kill -0 `cat pid`], [0], [], [], [kill `cat parent`])
44 AT_CHECK([ps -o ppid= -p `cat pid` > parentpid],
45 [0], [], [], [kill `cat parent`])
46 AT_CHECK(
47 [parentpid=`cat parentpid` &&
48 parent=`cat parent` &&
49 test $parentpid = $parent],
50 [0], [], [], [kill `cat parent`])
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).
53 OVS_WAIT_UNTIL(
54 [ovs-appctl --timeout=10 -t "`pwd`/unixctl" version],
55 [kill `cat pid`])
56 # Kill the daemon process, making it look like a segfault,
57 # and wait for a new child process to get spawned.
58 AT_CHECK([cp pid oldpid], [0], [], [], [kill `cat parent`])
59 AT_CHECK([kill -SEGV `cat pid`], [0], [], [ignore], [kill `cat parent`])
60 OVS_WAIT_WHILE([kill -0 `cat oldpid`], [kill `cat parent`])
61 OVS_WAIT_UNTIL([test -s pid && test `cat pid` != `cat oldpid`],
62 [kill `cat parent`])
63 AT_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.
66 AT_CHECK([ps -o ppid= -p `cat pid` > parentpid],
67 [0], [], [], [kill `cat parent`])
68 AT_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.
75 AT_CHECK([kill `cat pid`], [0], [], [ignore], [kill `cat parent`])
76 OVS_WAIT_WHILE([kill -0 `cat parent` || kill -0 `cat newpid` || test -e pid],
77 [kill `cat parent`])
78 AT_CLEANUP
79
80 AT_SETUP([daemon --detach])
81 AT_CAPTURE_FILE([pid])
82 OVSDB_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.
86 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0])
87 AT_CHECK([test -s pid])
88 AT_CHECK([kill -0 `cat pid`])
89 # Kill the daemon and make sure that the pidfile gets deleted.
90 cp pid saved-pid
91 if 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
95 OVS_APP_EXIT_AND_WAIT_BY_TARGET([`pwd`/unixctl], [`pwd`/pid])
96 else
97 kill `cat pid`
98 fi
99 OVS_WAIT_WHILE([kill -0 `cat saved-pid`])
100 AT_CHECK([test ! -e pid])
101 AT_CLEANUP
102
103 AT_SETUP([daemon --detach --monitor])
104 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
105 m4_define([CHECK],
106 [AT_CHECK([$1], [$2], [$3], [$4], [kill `cat daemon monitor`])])
107 OVSDB_INIT([db])
108 AT_CAPTURE_FILE([daemon])
109 AT_CAPTURE_FILE([olddaemon])
110 AT_CAPTURE_FILE([newdaemon])
111 AT_CAPTURE_FILE([monitor])
112 AT_CAPTURE_FILE([newmonitor])
113 AT_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.
117 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/daemon --monitor --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0])
118 AT_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.
122 CHECK([kill -0 `cat daemon`])
123 CHECK([ps -o ppid= -p `cat daemon` > monitor])
124 CHECK([kill -0 `cat monitor`])
125 CHECK([ps -o ppid= -p `cat monitor` > init])
126 CHECK([test `cat init` != $$])
127 # Kill the daemon process, making it look like a segfault,
128 # and wait for a new daemon process to get spawned.
129 CHECK([cp daemon olddaemon])
130 CHECK([kill -SEGV `cat daemon`], [0])
131 OVS_WAIT_WHILE([kill -0 `cat olddaemon`], [kill `cat olddaemon daemon`])
132 OVS_WAIT_UNTIL([test -s daemon && test `cat daemon` != `cat olddaemon`],
133 [kill `cat olddaemon daemon`])
134 CHECK([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.
137 CHECK([kill -0 `cat daemon`])
138 CHECK([diff olddaemon newdaemon], [1], [ignore])
139 CHECK([ps -o ppid= -p `cat daemon` > newmonitor])
140 CHECK([diff monitor newmonitor])
141 CHECK([kill -0 `cat newmonitor`])
142 CHECK([ps -o ppid= -p `cat newmonitor` > init])
143 CHECK([test `cat init` != $$])
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.
146 CHECK([kill `cat daemon`], [0], [], [ignore])
147 OVS_WAIT_WHILE(
148 [kill -0 `cat monitor` || kill -0 `cat newdaemon` || test -e daemon],
149 [kill `cat monitor newdaemon`])
150 m4_undefine([CHECK])
151 AT_CLEANUP
152
153 AT_SETUP([daemon --detach startup errors])
154 AT_CAPTURE_FILE([pid])
155 OVSDB_INIT([db])
156 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/nonexistent/unixctl db], [1], [], [stderr],
157 [kill `cat pid`])
158 AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr],
159 [0], [ignore], [])
160 AT_CHECK([test ! -s pid])
161 AT_CLEANUP
162
163 AT_SETUP([daemon --detach --monitor startup errors])
164 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
165 AT_CAPTURE_FILE([pid])
166 OVSDB_INIT([db])
167 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --monitor --unixctl="`pwd`"/nonexistent/unixctl db], [1], [], [stderr])
168 AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr],
169 [0], [ignore], [])
170 AT_CHECK([test ! -s pid])
171 AT_CLEANUP
172
173 AT_SETUP([daemon --service])
174 AT_KEYWORDS([windows-service])
175 AT_SKIP_IF([test "$IS_WIN32" != "yes"])
176 OVS_SKIP_NON_ADMIN_WIN
177
178 OVSDB_INIT([db])
179 AT_CAPTURE_FILE([pid])
180 # To create a Windows service, we need the absolute path for the executable.
181 abs_path="$(cd $(dirname `which ovsdb-server`); pwd -W; cd $OLDPWD)"
182
183 AT_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"],
184 [0], [[[SC]] CreateService SUCCESS
185 ])
186
187 AT_CHECK([sc start ovsdb-server], [0], [ignore], [ignore], [sc delete ovsdb-server])
188 OVS_WAIT_UNTIL([test -s pid])
189 OVS_WAIT_UNTIL([sc query ovsdb-server | grep STATE | grep RUNNING > /dev/null 2>&1])
190 AT_CHECK([kill -0 `cat pid`], [0], [ignore])
191 AT_CHECK([ovs-appctl -t `pwd`/unixctl ovsdb-server/list-dbs], [0],
192 [Open_vSwitch
193 ])
194 AT_CHECK([sc stop ovsdb-server], [0], [ignore])
195 OVS_WAIT_UNTIL([test ! -s pid])
196 AT_CHECK([sc query ovsdb-server | grep STATE | grep STOPPED], [0], [ignore])
197 AT_CHECK([sc delete ovsdb-server], [0], [[[SC]] DeleteService SUCCESS
198 ])
199 AT_CLEANUP