salt/tests
Benjamin Drung 3325f7dd01
linux_sysctl: Fix replacing spaces by tabs and fix parsing of sysctl.conf files (#61452)
* test_linux_sysctl: Reduce indentation level

Reduce indentation level to improve readability.

Signed-off-by: Benjamin Drung <benjamin.drung@ionos.com>

* test_linux_sysctl: Fix test_persist_no_conf_failure

`test_persist_no_conf_failure` has different behaviour depending on the
operating system it is executed on. Mock all system calls and let it
fail in the first try to write the sysctl configuration file.

Signed-off-by: Benjamin Drung <benjamin.drung@ionos.com>

* linux_sysctl: Pass parameters as list to cmd.run

Signed-off-by: Benjamin Drung <benjamin.drung@ionos.com>

* linux_sysctl.show: Fix parsing of sysctl.conf files

The lines in sysctl.conf files can contain leading and trailing spaces.
The equal sign (that separates the key and value) might have zero to
multiple white spaces. Valid example:

```
kernel.core_pattern = |/usr/share/kdump-tools/dump-core %p %s %t %e
 # Stop low-level messages on console = less logging
 kernel.printk  = 3 4 1 3

net.ipv4.ip_forward=1
```

`sysctl.show` currently has two issues:
* all values contain a trailing newline
* Comments with leading spaces and equal sign in them are not skipped

Address both issues and simplify the code and cover them with unit tests.

Signed-off-by: Benjamin Drung <benjamin.drung@ionos.com>

* linux_sysctl.present: Fix replacing spaces by tabs

`salt/modules/linux_sysctl.py` tries to be smart in `persist()` and
replaces spaces by tabs, which will be correct for keys like
`net.ipv4.tcp_rmem` but not for `kernel.core_pattern`.

So only sanitize the values for comparison, but not for persisting them
in the configuration file.

Bug: https://github.com/saltstack/salt/issues/40054
Signed-off-by: Benjamin Drung <benjamin.drung@ionos.com>

* linux_sysctl: Drop unreachable code

The check `if "=" not in line` already ensures that the split by `=`
will return two elements.

Signed-off-by: Benjamin Drung <benjamin.drung@ionos.com>

* fixing failing tests

* need to mock which in test_assign_success

Signed-off-by: Benjamin Drung <benjamin.drung@ionos.com>
Co-authored-by: Benjamin Drung <benjamin.drung@ionos.com>
Co-authored-by: Gareth J. Greenaway <gareth@saltstack.com>
2022-09-22 21:31:59 -07:00
..
integration Add dir_mode to file.copy state 2022-09-21 13:01:09 -07:00
kitchen Pyupgrade and drop six 2021-07-06 09:04:28 -04:00
pkg/rpm Deprecating and removing salt-unity. 2021-12-07 16:15:56 -05:00
pytests linux_sysctl: Fix replacing spaces by tabs and fix parsing of sysctl.conf files (#61452) 2022-09-22 21:31:59 -07:00
support Merge branch 'master' into hotfix/payload 2022-09-15 14:40:48 -07:00
unit migrate fileserver unit tests to pytest 2022-09-22 16:06:11 -07:00
__init__.py Pyupgrade and drop six 2021-07-06 09:04:28 -04:00
buildpackage.py Fix strings 2021-08-06 13:09:47 -07:00
committer_parser.py Fix strings 2021-08-06 13:09:47 -07:00
conftest.py Test fixes when running with the onedir build 2022-08-29 13:24:21 -07:00
eventlisten.py Remove 'transport' kwarg fom 'salt.utils.event.get_event' 2022-02-25 09:10:06 -05:00
eventlisten.sh
filename_map.yml Merge pull request #62510 from s0undt3ch/hotfix/payload 2022-09-22 13:06:00 -06:00
minionswarm.py bring back the minionswarm script 2022-09-01 07:01:31 -06:00
modparser.py Pyupgrade and drop six 2021-07-06 09:04:28 -04:00
packdump.py Pyupgrade and drop six 2021-07-06 09:04:28 -04:00
runtests.py Fix strings 2021-08-06 13:09:47 -07:00
salt-tcpdump.py Remaining requested review changes missed in #60494 2021-08-11 08:40:09 -04:00
saltsh.py Update to isort 5.10.1 2022-08-01 12:49:16 -06:00
wheeltest.py Pyupgrade and drop six 2021-07-06 09:04:28 -04:00
zypp_plugin.py Pyupgrade and drop six 2021-07-06 09:04:28 -04:00