mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 01:30:20 +00:00
sysctl.persist should check in-memory values event if config is correct
On FreeBSD, it ignored the in-memory value if the on-disk value is correct.
This commit is contained in:
parent
98d1cdb972
commit
52b9a29ea3
3 changed files with 47 additions and 1 deletions
1
changelog/62461.fixed
Normal file
1
changelog/62461.fixed
Normal file
|
@ -0,0 +1 @@
|
|||
sysctl.persist now updates the in-memory value on FreeBSD even if the on-disk value was already correct.
|
|
@ -167,7 +167,12 @@ def persist(name, value, config="/etc/sysctl.conf"):
|
|||
rest_v = rest.split()[0]
|
||||
rest = rest[len(rest_v) :]
|
||||
if rest_v == value:
|
||||
return "Already set"
|
||||
# If it is correct in the config file, check in memory
|
||||
if str(get(name)) != value:
|
||||
assign(name, value)
|
||||
return "Updated"
|
||||
else:
|
||||
return "Already set"
|
||||
new_line = _formatfor(key, value, config, rest)
|
||||
nlines.append(new_line)
|
||||
edited = True
|
||||
|
|
|
@ -88,6 +88,46 @@ def test_persist_no_conf_failure():
|
|||
)
|
||||
|
||||
|
||||
def test_persist_nochange():
|
||||
"""
|
||||
Tests success when no changes need to be made
|
||||
"""
|
||||
mock_get_cmd = MagicMock(return_value="1")
|
||||
content = "vfs.usermount=1\n"
|
||||
with patch("salt.utils.files.fopen", mock_open(read_data=content)):
|
||||
with patch.dict(
|
||||
freebsd_sysctl.__salt__,
|
||||
{"cmd.run": mock_get_cmd},
|
||||
):
|
||||
assert freebsd_sysctl.persist("vfs.usermount", 1) == "Already set"
|
||||
|
||||
|
||||
def test_persist_in_memory():
|
||||
"""
|
||||
Tests success when the on-disk value is correct but the in-memory value
|
||||
needs updating.
|
||||
"""
|
||||
mock_get_cmd = MagicMock(return_value="0")
|
||||
set_cmd = {
|
||||
"pid": 1337,
|
||||
"retcode": 0,
|
||||
"stderr": "",
|
||||
"stdout": "vfs.usermount: 0 -> 1",
|
||||
}
|
||||
mock_set_cmd = MagicMock(return_value=set_cmd)
|
||||
content = "vfs.usermount=1\n"
|
||||
with patch("salt.utils.files.fopen", mock_open(read_data=content)):
|
||||
with patch.dict(
|
||||
freebsd_sysctl.__salt__,
|
||||
{"cmd.run": mock_get_cmd},
|
||||
):
|
||||
with patch.dict(
|
||||
freebsd_sysctl.__salt__,
|
||||
{"cmd.run_all": mock_set_cmd},
|
||||
):
|
||||
assert freebsd_sysctl.persist("vfs.usermount", 1) == "Updated"
|
||||
|
||||
|
||||
def test_persist_updated():
|
||||
"""
|
||||
Tests sysctl.conf success
|
||||
|
|
Loading…
Add table
Reference in a new issue