]> git.proxmox.com Git - mirror_ovs.git/blob - tests/daemon-py.at
odp-util: Fix netlink message overflow with userdata.
[mirror_ovs.git] / tests / daemon-py.at
1 AT_BANNER([daemon unit tests - Python3])
2
3 AT_SETUP([daemon - Python3])
4 # Skip this test for Windows, echo $! gives shell pid instead of parent process
5 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
6 AT_KEYWORDS([python daemon])
7
8 on_exit 'kill $(cat *.pid)'
9 pidfile=test-daemon.py.pid
10
11 # Start the daemon and wait for the pidfile to get created
12 # and that its contents are the correct pid.
13 AT_CHECK([$PYTHON3 $srcdir/test-daemon.py --pidfile & echo $!], [0], [stdout])
14 pid=$(cat stdout)
15
16 OVS_WAIT_UNTIL([test -s $pidfile], [kill $pid])
17 AT_CHECK([test $pid = $(cat $pidfile)])
18 AT_CHECK([kill -0 $pid])
19
20 # Kill the daemon and make sure that the pidfile gets deleted.
21 kill $pid
22 OVS_WAIT_WHILE([kill -0 $pid])
23 AT_CHECK([test ! -e $pidfile])
24 AT_CLEANUP
25
26 AT_SETUP([daemon --monitor - Python3])
27 # Skip this test for Windows, echo $! gives shell pid instead of parent process
28 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
29
30 on_exit 'kill $(cat *.pid)'
31 pidfile=test-daemon.py.pid
32
33 # Start the daemon and wait for the pidfile to get created.
34 AT_CHECK([$PYTHON3 $srcdir/test-daemon.py --pidfile --monitor & echo $!], [0], [stdout])
35 monitor=$(cat stdout)
36 OVS_WAIT_UNTIL([test -s $pidfile])
37 child=$(cat $pidfile)
38
39 # Check that the pidfile names a running process,
40 # and that the parent process of that process is our child process.
41 check_ancestors $child $monitor
42
43 # Kill the daemon process, making it look like a segfault,
44 # and wait for a new child process to get spawned.
45 AT_CHECK([kill -SEGV $child])
46 OVS_WAIT_WHILE([kill -0 $child])
47 OVS_WAIT_UNTIL([test -s $pidfile && test $(cat $pidfile) != $child])
48 child2=$(cat $pidfile)
49
50 # Check that the pidfile names a running process,
51 # and that the parent process of that process is our child process.
52 check_ancestors $child2 $monitor
53
54 # Kill the daemon process with SIGTERM, and wait for the daemon
55 # and the monitor processes to go away and the pidfile to get deleted.
56 AT_CHECK([kill $child2])
57 OVS_WAIT_WHILE([kill -0 $monitor || kill -0 $child2 || test -e $pidfile])
58 AT_CLEANUP
59
60 AT_SETUP([daemon --monitor restart exit code - Python3])
61 # Skip this test for Windows, echo $! gives shell pid instead of parent process
62 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
63
64 on_exit 'kill $(cat *.pid)'
65 pidfile=test-daemon.py.pid
66
67 # Start the daemon and wait for the pidfile to get created.
68 AT_CHECK([$PYTHON3 $srcdir/test-daemon.py --pidfile --monitor & echo $!], [0], [stdout])
69 monitor=$(cat stdout)
70 OVS_WAIT_UNTIL([test -s $pidfile])
71 child=$(cat $pidfile)
72
73 # Check that the pidfile names a running process,
74 # and that the parent process of that process is our child process.
75 check_ancestors $child $monitor
76
77 # HUP the daemon process causing it to throw an exception,
78 # and wait for a new child process to get spawned.
79 AT_CHECK([kill -HUP $child])
80 OVS_WAIT_WHILE([kill -0 $child])
81 OVS_WAIT_UNTIL([test -s $pidfile && test $child != $(cat $pidfile)])
82 child2=$(cat $pidfile)
83
84 # Check that the pidfile names a running process,
85 # and that the parent process of that process is our child process.
86 check_ancestors $child2 $monitor
87
88 # Kill the daemon process with SIGTERM, and wait for the daemon
89 # and the monitor processes to go away and the pidfile to get deleted.
90 AT_CHECK([kill $child2])
91 OVS_WAIT_WHILE([kill -0 $monitor || kill -0 $child2 || test -e $pidfile])
92 AT_CLEANUP
93
94 AT_SETUP([daemon --detach - Python3])
95
96 # Skip this test for Windows, the pid file not removed if the daemon is killed
97 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
98
99 on_exit 'kill $(cat *.pid)'
100 pidfile=test-daemon.py.pid
101
102 # Start the daemon and make sure that the pidfile exists immediately.
103 # We don't wait for the pidfile to get created because the daemon is
104 # supposed to do so before the parent exits.
105 AT_CHECK([$PYTHON3 $srcdir/test-daemon.py --pidfile --detach --no-chdir], [0])
106 AT_CHECK([test -s $pidfile])
107 pid=$(cat $pidfile)
108 check_ancestors $pid 1
109
110 # Kill the daemon and make sure that the pidfile gets deleted.
111 AT_CHECK([kill $pid])
112 OVS_WAIT_WHILE([kill -0 $pid])
113 AT_CHECK([test ! -e $pidfile])
114 AT_CLEANUP
115
116 AT_SETUP([daemon --detach --monitor - Python3])
117
118 # Skip this test for Windows, uses Linux specific kill signal
119 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
120
121 on_exit 'kill $(cat *.pid)'
122 pidfile=test-daemon.py.pid
123
124 # Start the daemon and make sure that the pidfile exists immediately.
125 # We don't wait for the pidfile to get created because the daemon is
126 # supposed to do so before the parent exits.
127 AT_CHECK([$PYTHON3 $srcdir/test-daemon.py --pidfile --detach --no-chdir --monitor], [0])
128 AT_CHECK([test -s $pidfile])
129 child=$(cat $pidfile)
130 AT_CHECK([parent_pid $child], [0], [stdout])
131 monitor=$(cat stdout)
132
133 # Check that the pidfile names a running process,
134 # and that the parent process of that process is a running process,
135 # and that the parent process of that process is init.
136 check_ancestors $child $monitor 1
137
138 # Kill the daemon process, making it look like a segfault,
139 # and wait for a new daemon process to get spawned.
140 AT_CHECK([kill -SEGV $child])
141 OVS_WAIT_WHILE([kill -0 $child])
142 OVS_WAIT_UNTIL([test -s $pidfile && test $(cat $pidfile) != $child])
143 child2=$(cat $pidfile)
144
145 # Check that the pidfile names a running process,
146 # and that the parent process of that process is our child process.
147 check_ancestors $child2 $monitor 1
148
149 # Kill the daemon process with SIGTERM, and wait for the daemon
150 # and the monitor processes to go away and the pidfile to get deleted.
151 AT_CHECK([kill $child2])
152 OVS_WAIT_WHILE([kill -0 $child2 || kill -0 $monitor || test -e $pidfile])
153 AT_CLEANUP
154
155 AT_SETUP([daemon --detach startup errors - Python3])
156 AT_CHECK([$PYTHON3 $srcdir/test-daemon.py --pidfile --detach --no-chdir --bail], [1], [], [stderr])
157 AT_CHECK([grep 'test-daemon.py: exiting after daemonize_start() as requested' stderr],
158 [0], [ignore])
159 AT_CHECK([test ! -s test-daemon.py.pid])
160 AT_CLEANUP
161
162 AT_SETUP([daemon --detach --monitor startup errors - Python3])
163 AT_CAPTURE_FILE([pid])
164 AT_CHECK([$PYTHON3 $srcdir/test-daemon.py --pidfile --detach --no-chdir --monitor --bail], [1], [], [stderr])
165 AT_CHECK([grep 'test-daemon.py: exiting after daemonize_start() as requested' stderr],
166 [0], [ignore])
167 AT_CHECK([test ! -s test-daemon.py.pid])
168 AT_CLEANUP
169
170 AT_SETUP([daemon --detach closes standard fds - Python3])
171 # Skip this test for Windows, uses Linux specific kill signal
172 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
173
174 AT_CHECK([(yes 2>stderr; echo $? > status) | $PYTHON3 $srcdir/test-daemon.py --pidfile --detach --no-chdir])
175 AT_CHECK([kill $(cat test-daemon.py.pid)])
176 AT_CHECK([test -s status])
177 if grep '[[bB]]roken pipe' stderr >/dev/null 2>&1; then
178 # Something in the environment caused SIGPIPE to be ignored, but
179 # 'yes' at least told us that it got EPIPE. Good enough; we know
180 # that stdout was closed.
181 :
182 else
183 # Otherwise make sure that 'yes' died from SIGPIPE.
184 AT_CHECK([kill -l `cat status`], [0], [PIPE
185 ])
186 fi
187 AT_CLEANUP
188
189 AT_SETUP([daemon --detach --monitor closes standard fds - Python3])
190 # Skip this test for Windows, uses Linux specific kill signal
191 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
192 AT_CHECK([(yes 2>stderr; echo $? > status) | $PYTHON3 $srcdir/test-daemon.py --pidfile --detach --no-chdir], [0], [], [])
193 AT_CHECK([kill $(cat test-daemon.py.pid)])
194 AT_CHECK([test -s status])
195 if grep '[[bB]]roken pipe' stderr >/dev/null 2>&1; then
196 # Something in the environment caused SIGPIPE to be ignored, but
197 # 'yes' at least told us that it got EPIPE. Good enough; we know
198 # that stdout was closed.
199 :
200 else
201 # Otherwise make sure that 'yes' died from SIGPIPE.
202 AT_CHECK([kill -l `cat status`], [0], [PIPE
203 ])
204 fi
205 AT_CLEANUP