mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Update linux_sysctl tests to reflect changes to mock_open
This commit is contained in:
parent
05c68fd5d9
commit
75307a47c5
1 changed files with 17 additions and 12 deletions
|
@ -101,6 +101,7 @@ class LinuxSysctlTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'''
|
||||
Tests successful add of config file when previously not one
|
||||
'''
|
||||
config = '/etc/sysctl.conf'
|
||||
with patch('os.path.isfile', MagicMock(return_value=False)), \
|
||||
patch('os.path.exists', MagicMock(return_value=True)):
|
||||
asn_cmd = {'pid': 1337, 'retcode': 0, 'stderr': '',
|
||||
|
@ -110,18 +111,22 @@ class LinuxSysctlTestCase(TestCase, LoaderModuleMockMixin):
|
|||
sys_cmd = 'systemd 208\n+PAM +LIBWRAP'
|
||||
mock_sys_cmd = MagicMock(return_value=sys_cmd)
|
||||
|
||||
with patch('salt.utils.files.fopen', mock_open()) as m_open:
|
||||
with patch.dict(linux_sysctl.__context__, {'salt.utils.systemd.version': 232}):
|
||||
with patch.dict(linux_sysctl.__salt__,
|
||||
{'cmd.run_stdout': mock_sys_cmd,
|
||||
'cmd.run_all': mock_asn_cmd}):
|
||||
with patch.dict(systemd.__context__,
|
||||
{'salt.utils.systemd.booted': True,
|
||||
'salt.utils.systemd.version': 232}):
|
||||
linux_sysctl.persist('net.ipv4.ip_forward', 1)
|
||||
helper_open = m_open()
|
||||
helper_open.write.assert_called_once_with(
|
||||
'#\n# Kernel sysctl configuration\n#\n')
|
||||
with patch('salt.utils.files.fopen', mock_open()) as m_open, \
|
||||
patch.dict(linux_sysctl.__context__,
|
||||
{'salt.utils.systemd.version': 232}), \
|
||||
patch.dict(linux_sysctl.__salt__,
|
||||
{'cmd.run_stdout': mock_sys_cmd,
|
||||
'cmd.run_all': mock_asn_cmd}), \
|
||||
patch.dict(systemd.__context__,
|
||||
{'salt.utils.systemd.booted': True,
|
||||
'salt.utils.systemd.version': 232}):
|
||||
linux_sysctl.persist('net.ipv4.ip_forward', 1, config=config)
|
||||
writes = []
|
||||
for fh_ in m_open.handles[config]:
|
||||
writes.extend(fh_.write_calls)
|
||||
assert writes == [
|
||||
'#\n# Kernel sysctl configuration\n#\n'
|
||||
], writes
|
||||
|
||||
def test_persist_read_conf_success(self):
|
||||
'''
|
||||
|
|
Loading…
Add table
Reference in a new issue