mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #47753 from Ch3LL/service_mac
Add stderr launchctl helper class and fix service mac tests
This commit is contained in:
commit
8f78e3aef6
3 changed files with 24 additions and 3 deletions
|
@ -119,6 +119,18 @@ def _run_all(cmd):
|
|||
return ret
|
||||
|
||||
|
||||
def _check_launchctl_stderr(ret):
|
||||
'''
|
||||
helper class to check the launchctl stderr.
|
||||
launchctl does not always return bad exit code
|
||||
if there is a failure
|
||||
'''
|
||||
err = ret['stderr'].lower()
|
||||
if 'service is disabled' in err:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def execute_return_success(cmd):
|
||||
'''
|
||||
Executes the passed command. Returns True if successful
|
||||
|
@ -274,9 +286,10 @@ def launchctl(sub_cmd, *args, **kwargs):
|
|||
kwargs['python_shell'] = False
|
||||
kwargs = salt.utils.args.clean_kwargs(**kwargs)
|
||||
ret = __salt__['cmd.run_all'](cmd, **kwargs)
|
||||
error = _check_launchctl_stderr(ret)
|
||||
|
||||
# Raise an error or return successful result
|
||||
if ret['retcode']:
|
||||
if ret['retcode'] or error:
|
||||
out = 'Failed to {0} service:\n'.format(sub_cmd)
|
||||
out += 'stdout: {0}\n'.format(ret['stdout'])
|
||||
out += 'stderr: {0}\n'.format(ret['stderr'])
|
||||
|
|
|
@ -40,8 +40,10 @@ class MacServiceModuleTest(ModuleCase):
|
|||
'''
|
||||
if self.SERVICE_ENABLED:
|
||||
self.run_function('service.start', [self.SERVICE_NAME])
|
||||
self.run_function('service.enable', [self.SERVICE_NAME])
|
||||
else:
|
||||
self.run_function('service.stop', [self.SERVICE_NAME])
|
||||
self.run_function('service.disable', [self.SERVICE_NAME])
|
||||
|
||||
def test_show(self):
|
||||
'''
|
||||
|
|
|
@ -13,6 +13,7 @@ from tests.support.mixins import SaltReturnAssertsMixin
|
|||
|
||||
# Import salt libs
|
||||
import salt.utils.path
|
||||
import salt.utils.platform
|
||||
|
||||
INIT_DELAY = 5
|
||||
|
||||
|
@ -62,10 +63,15 @@ class ServiceTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
'''
|
||||
test service.running state module
|
||||
'''
|
||||
stop_service = self.run_function('service.stop', self.service_name)
|
||||
self.assertTrue(stop_service)
|
||||
if self.run_function('service.status', name=self.service_name):
|
||||
stop_service = self.run_function('service.stop', name=self.service_name)
|
||||
self.assertTrue(stop_service)
|
||||
self.check_service_status(self.stopped)
|
||||
|
||||
if salt.utils.platform.is_darwin():
|
||||
# make sure the service is enabled on macosx
|
||||
enable = self.run_function('service.enable', name=self.service_name)
|
||||
|
||||
start_service = self.run_state('service.running',
|
||||
name=self.service_name)
|
||||
self.assertTrue(start_service)
|
||||
|
|
Loading…
Add table
Reference in a new issue