mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Merge pull request #26400 from rallytime/bp-26318
Back-port #26318 to 2015.8
This commit is contained in:
commit
b3335d627f
@ -407,6 +407,24 @@ def mask(name):
|
||||
return not __salt__['cmd.retcode'](_systemctl_cmd('mask', name))
|
||||
|
||||
|
||||
def masked(name):
|
||||
'''
|
||||
Return if the named service is masked.
|
||||
|
||||
.. versionadded:: 2015.8.0
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' service.masked <service name>
|
||||
'''
|
||||
if _untracked_custom_unit_found(name) or _unit_file_changed(name):
|
||||
systemctl_reload()
|
||||
out = __salt__['cmd.run_all'](_systemctl_cmd('is-enabled', name), ignore_retcode=True)
|
||||
return out['retcode'] == 1 and 'masked' in out['stdout']
|
||||
|
||||
|
||||
def start(name):
|
||||
'''
|
||||
Start the specified service with systemd
|
||||
@ -513,6 +531,8 @@ def enable(name, **kwargs):
|
||||
'''
|
||||
if _untracked_custom_unit_found(name) or _unit_file_changed(name):
|
||||
systemctl_reload()
|
||||
if masked(name):
|
||||
unmask(name)
|
||||
if _service_is_sysv(name):
|
||||
executable = _get_service_exec()
|
||||
cmd = '{0} -f {1} defaults 99'.format(executable, name)
|
||||
|
@ -196,15 +196,22 @@ class SystemdTestCase(TestCase):
|
||||
exe = MagicMock(return_value='foo')
|
||||
tmock = MagicMock(return_value=True)
|
||||
mock = MagicMock(return_value=False)
|
||||
disabled_mock = MagicMock(return_value={'retcode': 1, 'stdout': 'disabled', 'stderr': ''})
|
||||
masked_mock = MagicMock(return_value={'retcode': 1, 'stdout': 'masked', 'stderr': ''})
|
||||
with patch.object(systemd, '_untracked_custom_unit_found', mock):
|
||||
with patch.object(systemd, '_unit_file_changed', mock):
|
||||
with patch.dict(systemd.__salt__, {'cmd.retcode': mock}):
|
||||
with patch.dict(systemd.__salt__, {'cmd.run_all': disabled_mock}):
|
||||
with patch.object(systemd, "_service_is_sysv", mock):
|
||||
self.assertTrue(systemd.enable("sshd"))
|
||||
with patch.object(systemd, "_get_service_exec", exe):
|
||||
with patch.object(systemd, "_service_is_sysv", tmock):
|
||||
self.assertTrue(systemd.enable("sshd"))
|
||||
|
||||
with patch.dict(systemd.__salt__, {'cmd.run_all': masked_mock}):
|
||||
with patch.object(systemd, "_service_is_sysv", mock):
|
||||
self.assertTrue(systemd.enable("sshd"))
|
||||
|
||||
def test_disable(self):
|
||||
'''
|
||||
Test to disable the named service to not
|
||||
|
Loading…
Reference in New Issue
Block a user