Skip to content

Commit

Permalink
Merge pull request #50709 from mattLLVW/service_unmask
Browse files Browse the repository at this point in the history
service.running unmask option
  • Loading branch information
Mike Place committed Dec 10, 2018
2 parents e4e9563 + b199255 commit b1e5f3f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
16 changes: 14 additions & 2 deletions salt/states/service.py
Expand Up @@ -419,9 +419,16 @@ def running(name,
else:
before_toggle_enable_status = True

unmask_ret = {'comment': ''}
if unmask:
unmask_ret = unmasked(name, unmask_runtime)

# See if the service is already running
if before_toggle_status:
ret['comment'] = 'The service {0} is already running'.format(name)
ret['comment'] = '\n'.join(
[_f for _f in ['The service {0} is already running'.format(name),
unmask_ret['comment']] if _f]
)
if enable is True and not before_toggle_enable_status:
ret.update(_enable(name, None, **kwargs))
elif enable is False and before_toggle_enable_status:
Expand All @@ -431,7 +438,9 @@ def running(name,
# Run the tests
if __opts__['test']:
ret['result'] = None
ret['comment'] = 'Service {0} is set to start'.format(name)
ret['comment'] = '\n'.join(
[_f for _f in ['Service {0} is set to start'.format(name),
unmask_ret['comment']] if _f])
return ret

# Conditionally add systemd-specific args to call to service.start
Expand Down Expand Up @@ -491,6 +500,9 @@ def running(name,
.format(ret['comment'], init_delay)
)

if unmask:
ret['comment'] = '\n'.join([ret['comment'], unmask_ret['comment']])

return ret


Expand Down
12 changes: 11 additions & 1 deletion tests/unit/states/test_service.py
Expand Up @@ -57,7 +57,10 @@ def test_running(self):
'name': 'salt', 'result': True},
{'changes': 'saltstack',
'comment': 'Service salt failed to start', 'name': 'salt',
'result': False}]
'result': False},
{'changes': 'saltstack',
'comment': 'Started Service salt\nService masking not available on this minion',
'name': 'salt', 'result': True, 'warnings': ["The 'unmask' argument is not supported by this platform/action"]}]

tmock = MagicMock(return_value=True)
fmock = MagicMock(return_value=False)
Expand Down Expand Up @@ -91,6 +94,13 @@ def test_running(self):
with patch.object(service, '_enable', MagicMock(return_value={'changes': 'saltstack'})):
self.assertDictEqual(service.running("salt", True), ret[4])

with patch.dict(service.__salt__, {'service.status': MagicMock(side_effect=[False, True]),
'service.enabled': MagicMock(side_effect=[False, True]),
'service.unmask': MagicMock(side_effect=[False, True]),
'service.start': MagicMock(return_value="stack")}):
with patch.object(service, '_enable', MagicMock(return_value={'changes': 'saltstack'})):
self.assertDictEqual(service.running("salt", True, unmask=True), ret[7])

with patch.dict(service.__opts__, {'test': True}):
with patch.dict(service.__salt__, {'service.status': tmock}):
self.assertDictEqual(service.running("salt"), ret[5])
Expand Down

0 comments on commit b1e5f3f

Please sign in to comment.