Fix regression in service.dead state (#37562)

* Fix regression in service.dead state when service is not available

This was originally broken in c4f899b.

* Add unit test for issue 37511
This commit is contained in:
Erik Johnson 2016-11-08 15:58:33 -06:00 committed by Nicole Thomas
parent ac754dbac5
commit 2fc0b222bc
2 changed files with 22 additions and 0 deletions

View file

@ -431,6 +431,9 @@ def dead(name, enable=None, sig=None, **kwargs):
# Check if the service is available
try:
if not _available(name, ret):
# A non-available service is OK here, don't let the state fail
# because of it.
ret['result'] = True
return ret
except CommandExecutionError as exc:
ret['result'] = False

View file

@ -247,6 +247,25 @@ class ServiceTestCase(TestCase):
):
self.assertDictEqual(service.dead("salt", False), ret[4])
def test_dead_with_missing_service(self):
'''
Tests the case in which a service.dead state is executed on a state
which does not exist.
See https://github.com/saltstack/salt/issues/37511
'''
name = 'thisisnotarealservice'
with patch.dict(service.__salt__,
{'service.available': MagicMock(return_value=False)}):
ret = service.dead(name=name)
self.assertDictEqual(
ret,
{'changes': {},
'comment': 'The named service {0} is not available'.format(name),
'result': True,
'name': name}
)
def test_enabled(self):
'''
Test to verify that the service is enabled