]>
Commit | Line | Data |
---|---|---|
99155935 | 1 | AT_BANNER([daemon unit tests - C]) |
ff8decf1 BP |
2 | |
3 | AT_SETUP([daemon]) | |
fc28ea52 | 4 | AT_SKIP_IF([test "$IS_WIN32" = "yes"]) |
ab7fc30e PB |
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 | ||
ff8decf1 BP |
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. | |
434380a6 | 19 | AT_CHECK([ovsdb-server --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db 2>/dev/null & echo $! > expected], [0]) |
ff8decf1 BP |
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]) | |
fc28ea52 | 32 | AT_SKIP_IF([test "$IS_WIN32" = "yes"]) |
ff8decf1 BP |
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. | |
434380a6 | 39 | AT_CHECK([ovsdb-server --monitor --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db 2>/dev/null & echo $! > parent], [0]) |
ff8decf1 BP |
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`]) | |
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). | |
53 | OVS_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. | |
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. | |
77a922c7 | 86 | AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0]) |
ff8decf1 BP |
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 | |
fc28ea52 GS |
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 | |
8a16ab90 | 95 | OVS_APP_EXIT_AND_WAIT_BY_TARGET([`pwd`/unixctl], [`pwd`/pid]) |
fc28ea52 GS |
96 | else |
97 | kill `cat pid` | |
98 | fi | |
ff8decf1 BP |
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]) | |
fc28ea52 | 104 | AT_SKIP_IF([test "$IS_WIN32" = "yes"]) |
ff8decf1 BP |
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. | |
77a922c7 | 117 | AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/daemon --monitor --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0]) |
ff8decf1 BP |
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]) | |
c8dc7b46 | 126 | CHECK([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. | |
129 | CHECK([cp daemon olddaemon]) | |
bc9dcfb3 | 130 | CHECK([kill -SEGV `cat daemon`], [0]) |
ff8decf1 BP |
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]) | |
c8dc7b46 | 143 | CHECK([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. | |
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]) | |
77a922c7 | 156 | AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/nonexistent/unixctl db], [1], [], [stderr]) |
ff8decf1 BP |
157 | AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr], |
158 | [0], [ignore], []) | |
159 | AT_CHECK([test ! -s pid]) | |
160 | AT_CLEANUP | |
161 | ||
162 | AT_SETUP([daemon --detach --monitor startup errors]) | |
fc28ea52 | 163 | AT_SKIP_IF([test "$IS_WIN32" = "yes"]) |
ff8decf1 BP |
164 | AT_CAPTURE_FILE([pid]) |
165 | OVSDB_INIT([db]) | |
77a922c7 | 166 | AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --monitor --unixctl="`pwd`"/nonexistent/unixctl db], [1], [], [stderr]) |
ff8decf1 BP |
167 | AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr], |
168 | [0], [ignore], []) | |
169 | AT_CHECK([test ! -s pid]) | |
170 | AT_CLEANUP | |
02a514ef GS |
171 | |
172 | AT_SETUP([daemon --service]) | |
05082734 | 173 | AT_KEYWORDS([windows-service]) |
02a514ef | 174 | AT_SKIP_IF([test "$IS_WIN32" != "yes"]) |
ab7fc30e PB |
175 | OVS_SKIP_NON_ADMIN_WIN |
176 | ||
02a514ef GS |
177 | OVSDB_INIT([db]) |
178 | AT_CAPTURE_FILE([pid]) | |
179 | # To create a Windows service, we need the absolute path for the executable. | |
180 | abs_path="$(cd $(dirname `which ovsdb-server`); pwd -W; cd $OLDPWD)" | |
181 | ||
182 | 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"], | |
183 | [0], [[[SC]] CreateService SUCCESS | |
184 | ]) | |
185 | ||
8164a704 | 186 | AT_CHECK([sc start ovsdb-server], [0], [ignore], [ignore], [sc delete ovsdb-server]) |
02a514ef | 187 | OVS_WAIT_UNTIL([test -s pid]) |
05082734 | 188 | OVS_WAIT_UNTIL([sc query ovsdb-server | grep STATE | grep RUNNING > /dev/null 2>&1]) |
02a514ef GS |
189 | AT_CHECK([kill -0 `cat pid`], [0], [ignore]) |
190 | AT_CHECK([ovs-appctl -t `pwd`/unixctl ovsdb-server/list-dbs], [0], | |
191 | [Open_vSwitch | |
192 | ]) | |
193 | AT_CHECK([sc stop ovsdb-server], [0], [ignore]) | |
194 | OVS_WAIT_UNTIL([test ! -s pid]) | |
195 | AT_CHECK([sc query ovsdb-server | grep STATE | grep STOPPED], [0], [ignore]) | |
196 | AT_CHECK([sc delete ovsdb-server], [0], [[[SC]] DeleteService SUCCESS | |
197 | ]) | |
198 | AT_CLEANUP |