mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #50709 from mattLLVW/service_unmask
service.running unmask option
This commit is contained in:
commit
b1e5f3f887
2 changed files with 25 additions and 3 deletions
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -57,7 +57,10 @@ class ServiceTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'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)
|
||||
|
@ -91,6 +94,13 @@ class ServiceTestCase(TestCase, LoaderModuleMockMixin):
|
|||
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])
|
||||
|
|
Loading…
Add table
Reference in a new issue