Merge pull request #45297 from Ch3LL/mac_service_state

Allow macosx service state tests to check for pid return
This commit is contained in:
Nicole Thomas 2018-01-09 15:47:23 -05:00 committed by GitHub
commit fb87010461
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,6 +4,7 @@ Tests for the service state
'''
# Import python libs
from __future__ import absolute_import
import re
# Import Salt Testing libs
from tests.support.case import ModuleCase
@ -25,11 +26,17 @@ class ServiceTest(ModuleCase, SaltReturnAssertsMixin):
self.service_name = 'cron'
cmd_name = 'crontab'
os_family = self.run_function('grains.get', ['os_family'])
self.stopped = False
self.running = True
if os_family == 'RedHat':
self.service_name = 'crond'
elif os_family == 'Arch':
self.service_name = 'systemd-journald'
cmd_name = 'systemctl'
elif os_family == 'MacOS':
self.service_name = 'org.ntp.ntpd'
self.stopped = ''
self.running = '[0-9]'
if salt.utils.which(cmd_name) is None:
self.skipTest('{0} is not installed'.format(cmd_name))
@ -40,8 +47,13 @@ class ServiceTest(ModuleCase, SaltReturnAssertsMixin):
'''
check_status = self.run_function('service.status',
name=self.service_name)
if check_status is not exp_return:
self.fail('status of service is not returning correctly')
try:
if not re.match(exp_return, check_status):
self.fail('status of service is not returning correctly')
except TypeError:
if check_status is not exp_return:
self.fail('status of service is not returning correctly')
def test_service_running(self):
'''
@ -49,12 +61,12 @@ class ServiceTest(ModuleCase, SaltReturnAssertsMixin):
'''
stop_service = self.run_function('service.stop', self.service_name)
self.assertTrue(stop_service)
self.check_service_status(False)
self.check_service_status(self.stopped)
start_service = self.run_state('service.running',
name=self.service_name)
self.assertTrue(start_service)
self.check_service_status(True)
self.check_service_status(self.running)
def test_service_dead(self):
'''
@ -63,11 +75,11 @@ class ServiceTest(ModuleCase, SaltReturnAssertsMixin):
start_service = self.run_state('service.running',
name=self.service_name)
self.assertSaltTrueReturn(start_service)
self.check_service_status(True)
self.check_service_status(self.running)
ret = self.run_state('service.dead', name=self.service_name)
self.assertSaltTrueReturn(ret)
self.check_service_status(False)
self.check_service_status(self.stopped)
def test_service_dead_init_delay(self):
'''
@ -76,9 +88,9 @@ class ServiceTest(ModuleCase, SaltReturnAssertsMixin):
start_service = self.run_state('service.running',
name=self.service_name)
self.assertSaltTrueReturn(start_service)
self.check_service_status(True)
self.check_service_status(self.running)
ret = self.run_state('service.dead', name=self.service_name,
init_delay=INIT_DELAY)
self.assertSaltTrueReturn(ret)
self.check_service_status(False)
self.check_service_status(self.stopped)