]>
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. | |
56120500 BP |
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`]) | |
ff8decf1 BP |
24 | # Kill the daemon and make sure that the pidfile gets deleted. |
25 | kill `cat expected` | |
26 | OVS_WAIT_WHILE([kill -0 `cat expected`]) | |
56120500 | 27 | AT_CHECK([test ! -e ovsdb-server.pid]) |
ff8decf1 BP |
28 | AT_CLEANUP |
29 | ||
30 | AT_SETUP([daemon --monitor]) | |
fc28ea52 | 31 | AT_SKIP_IF([test "$IS_WIN32" = "yes"]) |
ff8decf1 BP |
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. | |
56120500 BP |
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`]) | |
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 |
42 | AT_CHECK([kill -0 `cat ovsdb-server.pid`], [0], [], [], [kill `cat parent`]) |
43 | AT_CHECK([parent_pid `cat ovsdb-server.pid` > parentpid], | |
ff8decf1 BP |
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`]) | |
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). | |
52 | OVS_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 |
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`]) | |
ff8decf1 | 59 | OVS_WAIT_WHILE([kill -0 `cat oldpid`], [kill `cat parent`]) |
56120500 | 60 | OVS_WAIT_UNTIL([test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != `cat oldpid`], |
ff8decf1 | 61 | [kill `cat parent`]) |
56120500 | 62 | AT_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 | 65 | AT_CHECK([parent_pid `cat ovsdb-server.pid` > parentpid], |
ff8decf1 BP |
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. | |
56120500 BP |
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], | |
ff8decf1 BP |
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. | |
56120500 BP |
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`]) | |
ff8decf1 | 88 | # Kill the daemon and make sure that the pidfile gets deleted. |
56120500 | 89 | cp ovsdb-server.pid saved-pid |
fc28ea52 GS |
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 | |
56120500 | 94 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) |
fc28ea52 | 95 | else |
56120500 | 96 | kill `cat ovsdb-server.pid` |
fc28ea52 | 97 | fi |
ff8decf1 | 98 | OVS_WAIT_WHILE([kill -0 `cat saved-pid`]) |
56120500 | 99 | AT_CHECK([test ! -e ovsdb-server.pid]) |
ff8decf1 BP |
100 | AT_CLEANUP |
101 | ||
102 | AT_SETUP([daemon --detach --monitor]) | |
fc28ea52 | 103 | AT_SKIP_IF([test "$IS_WIN32" = "yes"]) |
ff8decf1 BP |
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. | |
56120500 BP |
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]) | |
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 |
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` != $$]) | |
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 |
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]) | |
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 |
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` != $$]) | |
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 | 143 | AT_CHECK([kill `cat ovsdb-server.pid`], [0], [], [ignore]) |
ff8decf1 | 144 | OVS_WAIT_WHILE( |
56120500 | 145 | [kill -0 `cat monitor` || kill -0 `cat newdaemon` || test -e ovsdb-server.pid]) |
ff8decf1 BP |
146 | AT_CLEANUP |
147 | ||
148 | AT_SETUP([daemon --detach startup errors]) | |
149 | AT_CAPTURE_FILE([pid]) | |
150 | OVSDB_INIT([db]) | |
56120500 | 151 | AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --unixctl=nonexistent/unixctl db], [1], [], [stderr]) |
ff8decf1 | 152 | AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr], |
56120500 | 153 | [0], [ignore]) |
ff8decf1 BP |
154 | AT_CHECK([test ! -s pid]) |
155 | AT_CLEANUP | |
156 | ||
157 | AT_SETUP([daemon --detach --monitor startup errors]) | |
fc28ea52 | 158 | AT_SKIP_IF([test "$IS_WIN32" = "yes"]) |
ff8decf1 BP |
159 | AT_CAPTURE_FILE([pid]) |
160 | OVSDB_INIT([db]) | |
56120500 | 161 | AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --monitor --unixctl=nonexistent/unixctl db], [1], [], [stderr]) |
ff8decf1 | 162 | AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr], |
56120500 | 163 | [0], [ignore]) |
ff8decf1 BP |
164 | AT_CHECK([test ! -s pid]) |
165 | AT_CLEANUP | |
02a514ef GS |
166 | |
167 | AT_SETUP([daemon --service]) | |
05082734 | 168 | AT_KEYWORDS([windows-service]) |
02a514ef | 169 | AT_SKIP_IF([test "$IS_WIN32" != "yes"]) |
ab7fc30e | 170 | OVS_SKIP_NON_ADMIN_WIN |
13574ee6 | 171 | AT_SKIP_IF([sc qc ovsdb-server]) |
ab7fc30e | 172 | |
02a514ef GS |
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 | ||
13574ee6 | 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"], |
02a514ef GS |
179 | [0], [[[SC]] CreateService SUCCESS |
180 | ]) | |
181 | ||
8164a704 | 182 | AT_CHECK([sc start ovsdb-server], [0], [ignore], [ignore], [sc delete ovsdb-server]) |
56120500 | 183 | OVS_WAIT_UNTIL([test -s ovsdb-server.pid]) |
05082734 | 184 | OVS_WAIT_UNTIL([sc query ovsdb-server | grep STATE | grep RUNNING > /dev/null 2>&1]) |
56120500 BP |
185 | AT_CHECK([kill -0 `cat ovsdb-server.pid`], [0], [ignore]) |
186 | AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs], [0], | |
02a514ef GS |
187 | [Open_vSwitch |
188 | ]) | |
189 | AT_CHECK([sc stop ovsdb-server], [0], [ignore]) | |
56120500 | 190 | OVS_WAIT_UNTIL([test ! -s ovsdb-server.pid]) |
02a514ef GS |
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 |