]> git.proxmox.com Git - ovs.git/blob - tests/daemon.at
System tests: Enable ALGs for userspace.
[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 --remote=punix:socket db 2>/dev/null & echo $! > expected], [0])
20 on_exit 'kill `cat expected`'
21 OVS_WAIT_UNTIL([test -s ovsdb-server.pid])
22 AT_CHECK([pid=`cat ovsdb-server.pid` && expected=`cat expected` && test "$pid" = "$expected"])
23 AT_CHECK([kill -0 `cat ovsdb-server.pid`])
24 # Kill the daemon and make sure that the pidfile gets deleted.
25 kill `cat expected`
26 OVS_WAIT_WHILE([kill -0 `cat expected`])
27 AT_CHECK([test ! -e ovsdb-server.pid])
28 AT_CLEANUP
29
30 AT_SETUP([daemon --monitor])
31 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
32 OVSDB_INIT([db])
33 AT_CAPTURE_FILE([pid])
34 AT_CAPTURE_FILE([parent])
35 AT_CAPTURE_FILE([parentpid])
36 AT_CAPTURE_FILE([newpid])
37 # Start the daemon and wait for the pidfile to get created.
38 AT_CHECK([ovsdb-server --monitor --pidfile --remote=punix:socket db 2>/dev/null & echo $! > parent], [0])
39 OVS_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.
42 AT_CHECK([kill -0 `cat ovsdb-server.pid`], [0], [], [], [kill `cat parent`])
43 AT_CHECK([parent_pid `cat ovsdb-server.pid` > parentpid],
44 [0], [], [], [kill `cat parent`])
45 AT_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).
52 OVS_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.
57 AT_CHECK([cp ovsdb-server.pid oldpid], [0], [], [], [kill `cat parent`])
58 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`], [0], [], [ignore], [kill `cat parent`])
59 OVS_WAIT_WHILE([kill -0 `cat oldpid`], [kill `cat parent`])
60 OVS_WAIT_UNTIL([test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat oldpid`],
61 [kill `cat parent`])
62 AT_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.
65 AT_CHECK([parent_pid `cat ovsdb-server.pid` > parentpid],
66 [0], [], [], [kill `cat parent`])
67 AT_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.
74 AT_CHECK([kill `cat ovsdb-server.pid`], [0], [], [ignore], [kill `cat parent`])
75 OVS_WAIT_WHILE([kill -0 `cat parent` || kill -0 `cat newpid` || test -e ovsdb-server.pid],
76 [kill `cat parent`])
77 AT_CLEANUP
78
79 AT_SETUP([daemon --detach])
80 AT_CAPTURE_FILE([pid])
81 OVSDB_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.
85 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket db], [0])
86 AT_CHECK([test -s ovsdb-server.pid])
87 AT_CHECK([kill -0 `cat ovsdb-server.pid`])
88 # Kill the daemon and make sure that the pidfile gets deleted.
89 cp ovsdb-server.pid saved-pid
90 if 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])
95 else
96 kill `cat ovsdb-server.pid`
97 fi
98 OVS_WAIT_WHILE([kill -0 `cat saved-pid`])
99 AT_CHECK([test ! -e ovsdb-server.pid])
100 AT_CLEANUP
101
102 AT_SETUP([daemon --detach --monitor])
103 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
104 OVSDB_INIT([db])
105 AT_CAPTURE_FILE([daemon])
106 AT_CAPTURE_FILE([olddaemon])
107 AT_CAPTURE_FILE([newdaemon])
108 AT_CAPTURE_FILE([monitor])
109 AT_CAPTURE_FILE([newmonitor])
110 AT_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.
114 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --monitor --remote=punix:socket db], [0])
115 on_exit 'kill `cat ovsdb-server.pid olddaemon newdaemon monitor newmonitor`'
116 AT_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.
120 AT_CHECK([kill -0 `cat ovsdb-server.pid`])
121 AT_CHECK([parent_pid `cat ovsdb-server.pid` > monitor])
122 AT_CHECK([kill -0 `cat monitor`])
123 AT_CHECK([parent_pid `cat monitor` > init])
124 AT_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.
127 AT_CHECK([cp ovsdb-server.pid olddaemon])
128 AT_CHECK([kill -SEGV `cat ovsdb-server.pid`], [0])
129 OVS_WAIT_WHILE([kill -0 `cat olddaemon`])
130 OVS_WAIT_UNTIL([test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat olddaemon`])
131 AT_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.
134 AT_CHECK([kill -0 `cat ovsdb-server.pid`])
135 AT_CHECK([diff olddaemon newdaemon], [1], [ignore])
136 AT_CHECK([parent_pid `cat ovsdb-server.pid` > newmonitor])
137 AT_CHECK([diff monitor newmonitor])
138 AT_CHECK([kill -0 `cat newmonitor`])
139 AT_CHECK([parent_pid `cat newmonitor` > init])
140 AT_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.
143 AT_CHECK([kill `cat ovsdb-server.pid`], [0], [], [ignore])
144 OVS_WAIT_WHILE(
145 [kill -0 `cat monitor` || kill -0 `cat newdaemon` || test -e ovsdb-server.pid])
146 AT_CLEANUP
147
148 AT_SETUP([daemon --detach startup errors])
149 AT_CAPTURE_FILE([pid])
150 OVSDB_INIT([db])
151 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --unixctl=nonexistent/unixctl db], [1], [], [stderr])
152 AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr],
153 [0], [ignore])
154 AT_CHECK([test ! -s pid])
155 AT_CLEANUP
156
157 AT_SETUP([daemon --detach --monitor startup errors])
158 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
159 AT_CAPTURE_FILE([pid])
160 OVSDB_INIT([db])
161 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --monitor --unixctl=nonexistent/unixctl db], [1], [], [stderr])
162 AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr],
163 [0], [ignore])
164 AT_CHECK([test ! -s pid])
165 AT_CLEANUP
166
167 AT_SETUP([daemon --service])
168 AT_KEYWORDS([windows-service])
169 AT_SKIP_IF([test "$IS_WIN32" != "yes"])
170 OVS_SKIP_NON_ADMIN_WIN
171 AT_SKIP_IF([sc qc ovsdb-server])
172
173 OVSDB_INIT([db])
174 AT_CAPTURE_FILE([pid])
175 # To create a Windows service, we need the absolute path for the executable.
176 abs_path="$(cd $(dirname `which ovsdb-server`); pwd -W; cd $OLDPWD)"
177
178 AT_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
182 AT_CHECK([sc start ovsdb-server], [0], [ignore], [ignore], [sc delete ovsdb-server])
183 OVS_WAIT_UNTIL([test -s ovsdb-server.pid])
184 OVS_WAIT_UNTIL([sc query ovsdb-server | grep STATE | grep RUNNING > /dev/null 2>&1])
185 AT_CHECK([kill -0 `cat ovsdb-server.pid`], [0], [ignore])
186 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs], [0],
187 [Open_vSwitch
188 ])
189 AT_CHECK([sc stop ovsdb-server], [0], [ignore])
190 OVS_WAIT_UNTIL([test ! -s ovsdb-server.pid])
191 AT_CHECK([sc query ovsdb-server | grep STATE | grep STOPPED], [0], [ignore])
192 AT_CHECK([sc delete ovsdb-server], [0], [[[SC]] DeleteService SUCCESS
193 ])
194 AT_CLEANUP