Browse Source

remove test_multiprocess_api

This test suite should be removed for the following reasons.

1) it's not a unit test

2) it's failing randomly, a lot, and depends on timing of the host for
process start and signal handling which are provably not predicable on
slower machines

3) it's triggering testr bugs in the ways that it fails which means we
don't actually get any subunit in the fail scenario, which makes it
actually impossible to move forward on fixes.

Change-Id: Ieb7c02115c12cd9f6c9fa67691a643aed7632784
Closes-Bug: #1357578
tags/2014.2.rc1
Sean Dague 5 years ago
parent
commit
f3c99ba1ef
1 changed files with 0 additions and 254 deletions
  1. 0
    254
      nova/tests/integrated/test_multiprocess_api.py

+ 0
- 254
nova/tests/integrated/test_multiprocess_api.py View File

@@ -1,254 +0,0 @@
1
-# Copyright (c) 2012 Intel, LLC
2
-# Copyright (c) 2012 OpenStack Foundation
3
-#
4
-#    Licensed under the Apache License, Version 2.0 (the "License"); you may
5
-#    not use this file except in compliance with the License. You may obtain
6
-#    a copy of the License at
7
-#
8
-#         http://www.apache.org/licenses/LICENSE-2.0
9
-#
10
-#    Unless required by applicable law or agreed to in writing, software
11
-#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
-#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
-#    License for the specific language governing permissions and limitations
14
-#    under the License.
15
-
16
-"""
17
-Test multiprocess enabled API service.
18
-"""
19
-import errno
20
-import os
21
-import signal
22
-import sys
23
-import time
24
-import traceback
25
-
26
-import fixtures
27
-
28
-from nova.openstack.common import log as logging
29
-from nova import service
30
-from nova.tests.integrated.api import client
31
-from nova.tests.integrated import integrated_helpers
32
-
33
-LOG = logging.getLogger(__name__)
34
-
35
-
36
-class MultiprocessWSGITest(integrated_helpers._IntegratedTestBase):
37
-    _api_version = 'v2'
38
-
39
-    def _start_api_service(self):
40
-        # Process will be started in _spawn()
41
-        self.osapi = service.WSGIService("osapi_compute")
42
-        self.auth_url = 'http://%(host)s:%(port)s/%(api_version)s' % ({
43
-            'host': self.osapi.host, 'port': self.osapi.port,
44
-            'api_version': self._api_version})
45
-        LOG.info('auth_url = %s' % self.auth_url)
46
-
47
-    def _get_flags(self):
48
-        self.workers = 2
49
-        f = super(MultiprocessWSGITest, self)._get_flags()
50
-        f['osapi_compute_workers'] = self.workers
51
-        return f
52
-
53
-    def _spawn(self):
54
-        pid = os.fork()
55
-        if pid == 0:
56
-            # NOTE(johannes): We can't let the child processes exit back
57
-            # into the unit test framework since then we'll have multiple
58
-            # processes running the same tests (and possibly forking more
59
-            # processes that end up in the same situation). So we need
60
-            # to catch all exceptions and make sure nothing leaks out, in
61
-            # particular SystemExit, which is raised by sys.exit(). We use
62
-            # os._exit() which doesn't have this problem.
63
-            sys.stdin.close()
64
-            sys.stdout.close()
65
-            sys.stderr.close()
66
-            status = 0
67
-            try:
68
-                launcher = service.process_launcher()
69
-                launcher.launch_service(self.osapi, workers=self.osapi.workers)
70
-                launcher.wait()
71
-            except SystemExit as exc:
72
-                status = exc.code
73
-            except BaseException:
74
-                # We need to be defensive here too
75
-                try:
76
-                    traceback.print_exc()
77
-                except BaseException:
78
-                    LOG.error("Couldn't print traceback")
79
-                status = 2
80
-
81
-            # Really exit
82
-            os._exit(status)
83
-
84
-        LOG.info("Launched OSAPI WSGI service in process %d", pid)
85
-        self.pid = pid
86
-
87
-        # Wait at most 10 seconds to spawn workers
88
-        cond = lambda: self.workers == len(self._get_workers())
89
-        timeout = 10
90
-        self._wait(cond, timeout)
91
-
92
-        workers = self._get_workers()
93
-        self.assertEqual(len(workers), self.workers)
94
-        return workers
95
-
96
-    def _wait(self, cond, timeout):
97
-        start = time.time()
98
-        while True:
99
-            if cond():
100
-                break
101
-            if time.time() - start > timeout:
102
-                break
103
-            time.sleep(.1)
104
-
105
-    def tearDown(self):
106
-        if self.pid:
107
-            # Make sure all processes are stopped
108
-            LOG.info("in tearDown(), stopping launcher pid %d with SIGTERM",
109
-                     self.pid)
110
-            os.kill(self.pid, signal.SIGTERM)
111
-
112
-            try:
113
-                # Make sure we reap our test process
114
-                self._wait_for_all_workers_to_end()
115
-                self._reap_test()
116
-            except fixtures.TimeoutException:
117
-                # If the child gets stuck or is too slow in exiting
118
-                # after receiving the SIGTERM, gracefully handle the
119
-                # timeout exception and try harder to kill it. We need
120
-                # to do this otherwise the child process can hold up
121
-                # the test run
122
-                LOG.warn("got fixtures.TimeoutException during tearDown(). "
123
-                         "going nuclear with SIGKILL.")
124
-                for worker_pid in self._get_workers():
125
-                    LOG.warn("worker pid %d" % worker_pid)
126
-                    os.kill(worker_pid, signal.SIGKILL)
127
-
128
-                LOG.warn("parent pid %d" % self.pid)
129
-                os.kill(self.pid, signal.SIGKILL)
130
-                raise
131
-
132
-        super(MultiprocessWSGITest, self).tearDown()
133
-
134
-    def _reap_test(self):
135
-        pid, status = os.waitpid(self.pid, 0)
136
-        self.pid = None
137
-        return status
138
-
139
-    def _get_workers(self):
140
-        # NOTE(hartsocks): use of ps checks the process table for child pid
141
-        # entries these processes may be ended but not reaped so ps may
142
-        # show processes that are still being cleaned out of the table.
143
-        f = os.popen('ps ax -o pid,ppid,command')
144
-        # Skip ps header
145
-        f.readline()
146
-
147
-        processes = [tuple(int(p) for p in l.strip().split()[:2])
148
-                     for l in f.readlines()]
149
-        workers = [p for p, pp in processes if pp == self.pid]
150
-        LOG.info('in _get_workers(), workers: %r for PPID %d',
151
-                 workers, self.pid)
152
-        return workers
153
-
154
-    def wait_on_process_until_end(self, worker_pid):
155
-        # NOTE: the testing framework itself has a
156
-        # built in test timeout function so a test
157
-        # stuck in an infinite loop will eventually
158
-        # be killed by the test framework.
159
-        LOG.info('waiting on process %r to exit' % worker_pid)
160
-
161
-        while True:
162
-            # poll the process until it isn't there to poll
163
-            try:
164
-                os.kill(worker_pid, 0)
165
-                time.sleep(0.1)
166
-                LOG.info("Worker: %s still around, trying again" % worker_pid)
167
-            except OSError as err:
168
-                # by watching specifically for errno.ESRCH
169
-                # we guarantee this loop continues until
170
-                # the process table has cleared the pid.
171
-                # Child process table entries hang around
172
-                # for several cycles in case a parent process
173
-                # needs to check their exit state.
174
-                if err.errno == errno.ESRCH:
175
-                    LOG.info("Worker: %s successfully shut down" % worker_pid)
176
-                    break
177
-                LOG.warning("got non-ESRCH errno %d when attempting "
178
-                            "status of worker PID %d",
179
-                            err.errno, worker_pid)
180
-        LOG.info('process %r has exited' % worker_pid)
181
-
182
-    def test_killed_worker_recover(self):
183
-        start_workers = self._spawn()
184
-
185
-        worker_pid = start_workers[0]
186
-        # kill one worker and check if new worker can come up
187
-        LOG.info('pid of first child is %s' % worker_pid)
188
-
189
-        # signal child
190
-        os.kill(worker_pid, signal.SIGTERM)
191
-
192
-        self.wait_on_process_until_end(worker_pid)
193
-
194
-        # Make sure worker pids don't match
195
-        end_workers = self._get_workers()
196
-        self.assertNotEqual(start_workers, end_workers)
197
-
198
-        # check if api service still works
199
-        flavors = self.api.get_flavors()
200
-        self.assertTrue(len(flavors) > 0, 'Num of flavors > 0.')
201
-
202
-    def _terminate_with_signal(self, sig):
203
-        self._spawn()
204
-
205
-        # check if api service is working
206
-        flavors = self.api.get_flavors()
207
-        self.assertTrue(len(flavors) > 0, 'Num of flavors > 0.')
208
-
209
-        LOG.info("sent launcher_process pid: %r signal: %r" % (self.pid, sig))
210
-        os.kill(self.pid, sig)
211
-
212
-        self._wait_for_all_workers_to_end()
213
-
214
-    def _wait_for_all_workers_to_end(self):
215
-        worker_pids = self._get_workers()
216
-
217
-        # did you know the test framework has a timeout of its own?
218
-        # if a test takes too long, the test will be killed.
219
-        for pid in worker_pids:
220
-            self.wait_on_process_until_end(pid)
221
-
222
-        workers = self._get_workers()
223
-        self.assertFalse(workers, 'OS processes left %r' % workers)
224
-
225
-    def test_terminate_sigkill(self):
226
-        self._terminate_with_signal(signal.SIGKILL)
227
-        status = self._reap_test()
228
-        self.assertTrue(os.WIFSIGNALED(status))
229
-        self.assertEqual(os.WTERMSIG(status), signal.SIGKILL)
230
-
231
-    def test_terminate_sigterm(self):
232
-        self._terminate_with_signal(signal.SIGTERM)
233
-        status = self._reap_test()
234
-        self.assertTrue(os.WIFEXITED(status))
235
-        self.assertEqual(os.WEXITSTATUS(status), 0)
236
-
237
-    def test_restart_sighup(self):
238
-        start_workers = self._spawn()
239
-
240
-        os.kill(self.pid, signal.SIGHUP)
241
-
242
-        # Wait at most 5 seconds to restart a worker
243
-        cond = lambda: start_workers == self._get_workers()
244
-        timeout = 5
245
-        self._wait(cond, timeout)
246
-
247
-        # Make sure worker pids match
248
-        end_workers = self._get_workers()
249
-        self.assertEqual(start_workers, end_workers)
250
-
251
-
252
-class MultiprocessWSGITestV3(client.TestOpenStackClientV3Mixin,
253
-                             MultiprocessWSGITest):
254
-    _api_version = 'v3'

Loading…
Cancel
Save