Merge "Add workers' type check before launching the services"

This commit is contained in:
Zuul 2019-05-15 21:25:51 +00:00 committed by Gerrit Code Review
commit eeb28d93b0
2 changed files with 8 additions and 1 deletions

View File

@ -807,13 +807,17 @@ def launch(conf, service, workers=1, restart_method='reload'):
:param conf: an instance of ConfigOpts
:param service: a service to launch, must be an instance of
:class:`oslo_service.service.ServiceBase`
:param workers: a number of processes in which a service will be running
:param workers: a number of processes in which a service will be running,
type should be int.
:param restart_method: Passed to the constructed launcher. If 'reload', the
launcher will call reload_config_files on SIGHUP. If 'mutate', it will
call mutate_config_files on SIGHUP. Other values produce a ValueError.
:returns: instance of a launcher that was used to launch the service
"""
if workers is not None and not isinstance(workers, six.integer_types):
raise TypeError(_("Type of workers should be int!"))
if workers is not None and workers <= 0:
raise ValueError(_("Number of workers should be positive!"))

View File

@ -385,6 +385,9 @@ class LauncherTest(base.ServiceBaseTestCase):
for num_workers in [0, -1]:
self.assertRaises(ValueError, service.launch, self.conf,
svc, num_workers)
for num_workers in ["0", "a", "1"]:
self.assertRaises(TypeError, service.launch, self.conf,
svc, num_workers)
@mock.patch('signal.alarm')
@mock.patch('oslo_service.service.ProcessLauncher.launch_service')