Merge pull request #26400 from rallytime/bp-26318

Back-port #26318 to 2015.8
This commit is contained in:
Mike Place 2015-08-17 15:17:50 -06:00
commit b3335d627f
2 changed files with 31 additions and 4 deletions

View File

@ -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)

View File

@ -196,13 +196,20 @@ 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.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):
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):