salt/tests/integration/modules/test_service.py

51 lines
1.5 KiB
Python
Raw Normal View History

2017-10-24 20:25:19 +00:00
# -*- coding: utf-8 -*-
2017-11-06 03:39:40 +00:00
# Import Python libs
2017-10-24 20:25:19 +00:00
from __future__ import absolute_import
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.helpers import destructiveTest
# Import Salt libs
2017-11-06 03:39:40 +00:00
import salt.utils.path
2017-10-24 20:25:19 +00:00
@destructiveTest
class ServiceModuleTest(ModuleCase):
'''
Module testing the service module
'''
2017-10-26 15:44:38 +00:00
def setUp(self):
self.service_name = 'cron'
cmd_name = 'crontab'
os_family = self.run_function('grains.get', ['os_family'])
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'
2017-10-26 15:44:38 +00:00
2017-11-06 03:39:40 +00:00
if salt.utils.path.which(cmd_name) is None:
2017-10-26 15:44:38 +00:00
self.skipTest('{0} is not installed'.format(cmd_name))
2017-10-24 20:25:19 +00:00
def test_service_status_running(self):
'''
test service.status execution module
when service is running
'''
2017-11-06 03:39:40 +00:00
self.run_function('service.start', [self.service_name])
2017-10-26 15:44:38 +00:00
check_service = self.run_function('service.status', [self.service_name])
2017-10-24 20:25:19 +00:00
self.assertTrue(check_service)
def test_service_status_dead(self):
'''
test service.status execution module
when service is dead
'''
2017-11-06 03:39:40 +00:00
self.run_function('service.stop', [self.service_name])
2017-10-26 15:44:38 +00:00
check_service = self.run_function('service.status', [self.service_name])
2017-10-24 20:25:19 +00:00
self.assertFalse(check_service)