mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Update systemd module unit tests
The _systemctl_status() function has changed its return data, this commit updates the affected tests to reflect this.
This commit is contained in:
parent
a2439acbc9
commit
b3364646ad
1 changed files with 43 additions and 9 deletions
|
@ -28,15 +28,35 @@ systemd.__salt__ = {}
|
|||
systemd.__context__ = {}
|
||||
|
||||
_SYSTEMCTL_STATUS = {
|
||||
'sshd.service': '''\
|
||||
'sshd.service': {
|
||||
'stdout': '''\
|
||||
* sshd.service - OpenSSH Daemon
|
||||
Loaded: loaded (/usr/lib/systemd/system/sshd.service; disabled; vendor preset: disabled)
|
||||
Active: inactive (dead)''',
|
||||
'stderr': '',
|
||||
'retcode': 3,
|
||||
'pid': 12345,
|
||||
},
|
||||
|
||||
'foo.service': '''\
|
||||
'foo.service': {
|
||||
'stdout': '''\
|
||||
* foo.service
|
||||
Loaded: not-found (Reason: No such file or directory)
|
||||
Active: inactive (dead)'''
|
||||
Active: inactive (dead)''',
|
||||
'stderr': '',
|
||||
'retcode': 3,
|
||||
'pid': 12345,
|
||||
},
|
||||
}
|
||||
|
||||
# This reflects systemd >= 231 behavior
|
||||
_SYSTEMCTL_STATUS_GTE_231 = {
|
||||
'bar.service': {
|
||||
'stdout': 'Unit bar.service could not be found.',
|
||||
'stderr': '',
|
||||
'retcode': 4,
|
||||
'pid': 12345,
|
||||
},
|
||||
}
|
||||
|
||||
_LIST_UNIT_FILES = '''\
|
||||
|
@ -169,18 +189,32 @@ class SystemdTestCase(TestCase):
|
|||
Test to check that the given service is available
|
||||
'''
|
||||
mock = MagicMock(side_effect=lambda x: _SYSTEMCTL_STATUS[x])
|
||||
with patch.object(systemd, '_systemctl_status', mock):
|
||||
self.assertTrue(systemd.available('sshd.service'))
|
||||
self.assertFalse(systemd.available('foo.service'))
|
||||
with patch.dict(systemd.__context__, {'salt.utils.systemd.version': 230}):
|
||||
with patch.object(systemd, '_systemctl_status', mock):
|
||||
self.assertTrue(systemd.available('sshd.service'))
|
||||
self.assertFalse(systemd.available('foo.service'))
|
||||
|
||||
with patch.dict(systemd.__context__, {'salt.utils.systemd.version': 231}):
|
||||
with patch.dict(_SYSTEMCTL_STATUS, _SYSTEMCTL_STATUS_GTE_231):
|
||||
with patch.object(systemd, '_systemctl_status', mock):
|
||||
self.assertTrue(systemd.available('sshd.service'))
|
||||
self.assertFalse(systemd.available('bar.service'))
|
||||
|
||||
def test_missing(self):
|
||||
'''
|
||||
Test to the inverse of service.available.
|
||||
'''
|
||||
mock = MagicMock(side_effect=lambda x: _SYSTEMCTL_STATUS[x])
|
||||
with patch.object(systemd, '_systemctl_status', mock):
|
||||
self.assertFalse(systemd.missing('sshd.service'))
|
||||
self.assertTrue(systemd.missing('foo.service'))
|
||||
with patch.dict(systemd.__context__, {'salt.utils.systemd.version': 230}):
|
||||
with patch.object(systemd, '_systemctl_status', mock):
|
||||
self.assertFalse(systemd.missing('sshd.service'))
|
||||
self.assertTrue(systemd.missing('foo.service'))
|
||||
|
||||
with patch.dict(systemd.__context__, {'salt.utils.systemd.version': 231}):
|
||||
with patch.dict(_SYSTEMCTL_STATUS, _SYSTEMCTL_STATUS_GTE_231):
|
||||
with patch.object(systemd, '_systemctl_status', mock):
|
||||
self.assertFalse(systemd.missing('sshd.service'))
|
||||
self.assertTrue(systemd.missing('bar.service'))
|
||||
|
||||
def test_show(self):
|
||||
'''
|
||||
|
|
Loading…
Add table
Reference in a new issue