2016-11-30 17:22:05 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
2016-11-30 17:27:37 +00:00
|
|
|
Tests for the service state
|
2016-11-30 17:22:05 +00:00
|
|
|
'''
|
|
|
|
# Import python libs
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
# Import Salt Testing libs
|
2017-04-03 16:04:09 +00:00
|
|
|
from tests.support.case import ModuleCase
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import skipIf
|
2017-02-27 15:59:04 +00:00
|
|
|
from tests.support.helpers import destructiveTest
|
2017-04-02 16:09:47 +00:00
|
|
|
from tests.support.mixins import SaltReturnAssertsMixin
|
2016-11-30 17:22:05 +00:00
|
|
|
|
|
|
|
# Import salt libs
|
|
|
|
import salt.utils
|
|
|
|
|
|
|
|
INIT_DELAY = 5
|
|
|
|
SERVICE_NAME = 'crond'
|
|
|
|
|
2016-11-30 20:22:53 +00:00
|
|
|
|
2016-11-30 17:22:05 +00:00
|
|
|
@destructiveTest
|
|
|
|
@skipIf(salt.utils.which('crond') is None, 'crond not installed')
|
2017-04-03 16:04:09 +00:00
|
|
|
class ServiceTest(ModuleCase, SaltReturnAssertsMixin):
|
2016-11-30 17:22:05 +00:00
|
|
|
'''
|
|
|
|
Validate the service state
|
|
|
|
'''
|
|
|
|
def check_service_status(self, exp_return):
|
|
|
|
'''
|
|
|
|
helper method to check status of service
|
|
|
|
'''
|
|
|
|
check_status = self.run_function('service.status', name=SERVICE_NAME)
|
|
|
|
if check_status is not exp_return:
|
2017-02-28 01:06:24 +00:00
|
|
|
self.fail('status of service is not returning correctly')
|
2016-11-30 17:22:05 +00:00
|
|
|
|
|
|
|
def test_service_dead(self):
|
|
|
|
'''
|
|
|
|
test service.dead state module
|
|
|
|
'''
|
|
|
|
start_service = self.run_state('service.running', name=SERVICE_NAME)
|
|
|
|
self.assertSaltTrueReturn(start_service)
|
|
|
|
self.check_service_status(True)
|
|
|
|
|
|
|
|
ret = self.run_state('service.dead', name=SERVICE_NAME)
|
|
|
|
self.assertSaltTrueReturn(ret)
|
|
|
|
self.check_service_status(False)
|
|
|
|
|
|
|
|
def test_service_dead_init_delay(self):
|
|
|
|
'''
|
|
|
|
test service.dead state module with init_delay arg
|
|
|
|
'''
|
|
|
|
start_service = self.run_state('service.running', name=SERVICE_NAME)
|
|
|
|
self.assertSaltTrueReturn(start_service)
|
|
|
|
self.check_service_status(True)
|
|
|
|
|
|
|
|
ret = self.run_state('service.dead', name=SERVICE_NAME,
|
|
|
|
init_delay=INIT_DELAY)
|
|
|
|
self.assertSaltTrueReturn(ret)
|
|
|
|
self.check_service_status(False)
|