Remove argument ServiceLauncher.wait() method

Signature of method wait in ServiceLauncher and ProcessLauncher must
be the same because if user uses service.launch() function and
workers number is taken from config file user couldn't know what
kind of launcher will be instantiated.

Change-Id: Ie25a3349e15eb2c10b5b054c005b32f471dbafa1
This commit is contained in:
Marian Horban 2015-12-08 10:18:08 -05:00
parent 26384b3772
commit 7bfa2ea96c
2 changed files with 16 additions and 9 deletions

View File

@ -248,7 +248,7 @@ class ServiceLauncher(Launcher):
('SIGTERM', 'SIGHUP', 'SIGINT'),
self._handle_signal)
def _wait_for_exit_or_signal(self, ready_callback=None):
def _wait_for_exit_or_signal(self):
status = None
signo = 0
@ -257,8 +257,6 @@ class ServiceLauncher(Launcher):
self.conf.log_opt_values(LOG, logging.DEBUG)
try:
if ready_callback:
ready_callback()
super(ServiceLauncher, self).wait()
except SignalExit as exc:
signame = SignalHandler().signals_to_name[exc.signo]
@ -269,10 +267,9 @@ class ServiceLauncher(Launcher):
status = exc.code
finally:
self.stop()
return status, signo
def wait(self, ready_callback=None):
def wait(self):
"""Wait for a service to terminate and restart it on SIGHUP.
:returns: termination status
@ -281,7 +278,7 @@ class ServiceLauncher(Launcher):
SignalHandler().clear()
while True:
self.handle_signal()
status, signo = self._wait_for_exit_or_signal(ready_callback)
status, signo = self._wait_for_exit_or_signal()
if not _is_sighup_and_daemon(signo):
return status
self.restart()

View File

@ -55,11 +55,20 @@ class ServiceManagerTestCase(test_base.BaseTestCase):
class ServiceWithTimer(service.Service):
def __init__(self, ready_event=None):
super(ServiceWithTimer, self).__init__()
self.ready_event = ready_event
def start(self):
super(ServiceWithTimer, self).start()
self.timer_fired = 0
self.tg.add_timer(1, self.timer_expired)
def wait(self):
if self.ready_event:
self.ready_event.set()
super(ServiceWithTimer, self).wait()
def timer_expired(self):
self.timer_fired = self.timer_fired + 1
@ -81,9 +90,9 @@ class ServiceTestBase(base.ServiceBaseTestCase):
# os._exit() which doesn't have this problem.
status = 0
try:
serv = ServiceWithTimer()
serv = ServiceWithTimer(*args, **kwargs)
launcher = service.launch(self.conf, serv, workers=workers)
launcher.wait(*args, **kwargs)
launcher.wait()
except SystemExit as exc:
status = exc.code
except BaseException:
@ -111,6 +120,7 @@ class ServiceTestBase(base.ServiceBaseTestCase):
self.addCleanup(self.conf.reset)
self.addCleanup(self.conf.reset)
self.addCleanup(self._reap_pid)
self.pid = 0
def _reap_pid(self):
if self.pid:
@ -228,7 +238,7 @@ class ServiceRestartTest(ServiceTestBase):
def _spawn(self):
ready_event = multiprocessing.Event()
self.pid = self._spawn_service(workers=1,
ready_callback=ready_event.set)
ready_event=ready_event)
return ready_event
def test_service_restart(self):