salt/tests/integration/modules/test_mac_service.py

222 lines
6.7 KiB
Python
Raw Normal View History

2016-03-22 23:29:32 +00:00
# -*- coding: utf-8 -*-
'''
integration tests for mac_service
'''
# Import python libs
from __future__ import absolute_import, print_function
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest, skip_if_not_root
2016-03-22 23:29:32 +00:00
# Import salt libs
import salt.utils
2016-09-09 14:47:51 +00:00
@skipIf(not salt.utils.is_darwin(), 'Test only available on macOS')
2016-09-08 22:30:35 +00:00
@skipIf(not salt.utils.which('launchctl'), 'Test requires launchctl binary')
@skipIf(not salt.utils.which('plutil'), 'Test requires plutil binary')
@skip_if_not_root
class MacServiceModuleTest(ModuleCase):
2016-03-22 23:29:32 +00:00
'''
Validate the mac_service module
'''
SERVICE_NAME = 'com.apple.apsd'
SERVICE_ENABLED = False
2016-03-22 23:29:32 +00:00
def setUp(self):
'''
2016-09-08 22:30:35 +00:00
Get current state of the test service
2016-03-22 23:29:32 +00:00
'''
self.SERVICE_ENABLED = self.run_function('service.enabled',
[self.SERVICE_NAME])
2016-03-23 17:13:55 +00:00
2016-03-22 23:29:32 +00:00
def tearDown(self):
'''
2016-09-08 22:30:35 +00:00
Reset the test service to the original state
2016-03-22 23:29:32 +00:00
'''
if self.SERVICE_ENABLED:
self.run_function('service.start', [self.SERVICE_NAME])
2016-03-23 17:13:55 +00:00
else:
self.run_function('service.stop', [self.SERVICE_NAME])
2016-03-22 23:29:32 +00:00
2016-03-23 15:50:56 +00:00
def test_show(self):
'''
Test service.show
'''
# Existing Service
service_info = self.run_function('service.show', [self.SERVICE_NAME])
2016-03-23 15:50:56 +00:00
self.assertIsInstance(service_info, dict)
self.assertEqual(service_info['plist']['Label'], self.SERVICE_NAME)
2016-03-23 15:50:56 +00:00
# Missing Service
self.assertIn(
'Service not found',
self.run_function('service.show', ['spongebob']))
def test_launchctl(self):
'''
Test service.launchctl
'''
# Expected Functionality
self.assertTrue(
2016-09-08 23:07:28 +00:00
self.run_function('service.launchctl',
['error', 'bootstrap', 64]))
2016-03-23 15:50:56 +00:00
self.assertEqual(
self.run_function('service.launchctl',
['error', 'bootstrap', 64],
2016-03-23 17:56:49 +00:00
return_stdout=True),
2016-03-23 15:50:56 +00:00
'64: unknown error code')
# Raise an error
self.assertIn(
2016-09-08 22:30:35 +00:00
'Failed to error service',
self.run_function('service.launchctl', ['error', 'bootstrap']))
2016-03-23 15:50:56 +00:00
2016-03-23 17:13:55 +00:00
def test_list(self):
'''
Test service.list
'''
# Expected Functionality
self.assertIn('PID', self.run_function('service.list'))
self.assertIn(
'{',
self.run_function('service.list', ['com.apple.coreservicesd']))
# Service not found
self.assertIn(
'Service not found',
self.run_function('service.list', ['spongebob']))
[develop] Merge forward from 2016.3 to develop (#32636) * Ensure rh_service not used on CloudLinux 7 Add CloudLinux to RHEL-derived distros excluded from rh_service use in osrelease >= 7 * Fix binary search and replace (#32542) * Don't return None from eval_master (#32555) Raise an exception instead. Because eval master if returns should return a tuple. * redact passwords and hashes from user.present updates Fixes #32381 * Better log message on minion restart if master couldn't be reached. (#32576) * Revert PR #32480 and apply #32314 with fixes / documentation (#32558) * Revert "Fix loop in maint.flo" This reverts commit 5196cd6a6e5db3c7b1a47b1740881bbd3e87ea3d. * Revert "Clear VCS fsbackend and git_pillar locks on master start" This reverts commit 7e3caa9bae1ac4de62db9924374e35a8b826937e. * Revert "Add functions to remove VCS fsbackend update locks and git_pillar update/checkout locks" This reverts commit 4c2db32419022501eae2a695ec488693e043d189. * prevent eternal gitfs lock due to process crash * Use salt.utils.fopen() instead of open() * Make pid locking work for more than just gitfs Also, make logging more descriptive, to aid in troubleshooting. * Add git_pillar_global_lock config option default value * Document proper usage of {gitfs,git_pillar}_global_lock * Fix comments value in salt.states.pkgrepo example (#32604) 'comments' option adds '#' automatically. Example contains `#http://mirror.centos.org/centos/$releasever/os/$basearch/` string which becomes prefixed with '##' in generated file. * alphabetize directories for dynamic modules (#32599) Also add engines and proxy minions to the list. * Expand on the open-source vs open-core FAQ * Language clarification. * Fix some mistakes in the salt-ssh thin shell script (#32583) * [[ is bash, not compatible with /bin/sh * check if python command exists before calling it * Deprecate 'user' and 'group' in state cmd (#32613) * Remove unused 'group' argument * Fix unit testing of cmd.mod_run_check without group arg * Deprecate 'user/group' in cmd.run * Deprecate 'user'/'group' in cmd.script * Deprecate 'user' in cmd.wait * Deprecate 'user'/'group' in cmd.wait_script * Fix mod_run_check without 'group' * Push deprecation back one release * Fix mac_service and mac_system modules (#32587) * Fix mac_service module * Add integration tests for new functions * Start will not enable the service beforehand * Remove unused variables
2016-04-18 14:40:20 +00:00
@destructiveTest
def test_enable(self):
'''
Test service.enable
'''
self.assertTrue(
self.run_function('service.enable', [self.SERVICE_NAME]))
self.assertIn(
'Service not found',
self.run_function('service.enable', ['spongebob']))
@destructiveTest
def test_disable(self):
'''
Test service.disable
'''
self.assertTrue(
self.run_function('service.disable', [self.SERVICE_NAME]))
self.assertIn(
'Service not found',
self.run_function('service.disable', ['spongebob']))
2016-03-23 17:13:55 +00:00
@destructiveTest
def test_start(self):
'''
Test service.start
Test service.stop
Test service.status
'''
self.assertTrue(self.run_function('service.start', [self.SERVICE_NAME]))
2016-03-23 17:13:55 +00:00
self.assertIn(
'Service not found',
self.run_function('service.start', ['spongebob']))
@destructiveTest
def test_stop(self):
'''
Test service.stop
'''
self.assertTrue(self.run_function('service.stop', [self.SERVICE_NAME]))
2016-03-23 17:13:55 +00:00
self.assertIn(
'Service not found',
self.run_function('service.stop', ['spongebob']))
@destructiveTest
def test_status(self):
'''
Test service.status
'''
# A running service
self.assertTrue(self.run_function('service.start', [self.SERVICE_NAME]))
2016-03-23 17:13:55 +00:00
self.assertTrue(
self.run_function('service.status', [self.SERVICE_NAME]).isdigit())
2016-03-23 17:13:55 +00:00
# A stopped service
self.assertTrue(self.run_function('service.stop', [self.SERVICE_NAME]))
2016-03-23 17:13:55 +00:00
self.assertEqual(
'',
self.run_function('service.status', [self.SERVICE_NAME]))
2016-03-23 17:13:55 +00:00
# Service not found
self.assertEqual('', self.run_function('service.status', ['spongebob']))
def test_available(self):
'''
Test service.available
'''
self.assertTrue(
self.run_function('service.available', [self.SERVICE_NAME]))
2016-03-23 17:13:55 +00:00
self.assertFalse(self.run_function('service.available', ['spongebob']))
def test_missing(self):
'''
Test service.missing
'''
self.assertFalse(self.run_function('service.missing', [self.SERVICE_NAME]))
2016-03-23 17:13:55 +00:00
self.assertTrue(self.run_function('service.missing', ['spongebob']))
@destructiveTest
def test_enabled(self):
'''
Test service.enabled
'''
self.assertTrue(self.run_function('service.start', [self.SERVICE_NAME]))
self.assertTrue(
self.run_function('service.enabled', [self.SERVICE_NAME]))
2016-03-23 17:13:55 +00:00
self.assertTrue(self.run_function('service.stop', [self.SERVICE_NAME]))
self.assertFalse(
self.run_function('service.enabled', [self.SERVICE_NAME]))
2016-03-23 17:13:55 +00:00
self.assertFalse(self.run_function('service.enabled', ['spongebob']))
@destructiveTest
def test_disabled(self):
'''
Test service.disabled
'''
2016-11-15 16:33:01 +00:00
SERVICE_NAME = 'com.apple.nfsd'
self.assertTrue(self.run_function('service.start', [SERVICE_NAME]))
self.assertFalse(
self.run_function('service.disabled', [SERVICE_NAME]))
2016-03-23 17:13:55 +00:00
2018-07-19 18:15:58 +00:00
self.assertTrue(self.run_function('service.disable', [SERVICE_NAME]))
self.assertTrue(
self.run_function('service.disabled', [SERVICE_NAME]))
2018-07-19 18:15:58 +00:00
self.assertTrue(self.run_function('service.enable', [SERVICE_NAME]))
2016-03-23 17:13:55 +00:00
2018-07-19 18:15:58 +00:00
self.assertFalse(self.run_function('service.disabled', ['spongebob']))
2016-03-23 17:13:55 +00:00
def test_get_all(self):
'''
Test service.get_all
'''
services = self.run_function('service.get_all')
self.assertIsInstance(services, list)
self.assertIn(self.SERVICE_NAME, services)
2016-03-23 17:13:55 +00:00
def test_get_enabled(self):
'''
Test service.get_enabled
'''
services = self.run_function('service.get_enabled')
self.assertIsInstance(services, list)
self.assertIn('com.apple.coreservicesd', services)