mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 01:30:20 +00:00
Avoid warning noise in logrotate.get (#56105)
* Avoid warning noise in logrotate.get There is no guarantee that a lookup failure is necessarily a problem, so presenting a message to this effect as a warning has led to confusion for some (and annoyance for others). This resolves the issue by showing the message at the debug level. Fixes #53988 * Adding a test for changes to logrotate.get. * Fix pre-commit and add changelog Co-authored-by: Gareth J. Greenaway <gareth@saltstack.com> Co-authored-by: Megan Wilhite <mwilhite@vmware.com>
This commit is contained in:
parent
784777c110
commit
db5456609e
3 changed files with 27 additions and 1 deletions
1
changelog/53988.fixed
Normal file
1
changelog/53988.fixed
Normal file
|
@ -0,0 +1 @@
|
|||
Avoid warning noise in lograte.get
|
|
@ -159,7 +159,7 @@ def get(key, value=None, conf_file=_DEFAULT_CONF):
|
|||
if value:
|
||||
if stanza:
|
||||
return stanza.get(value, False)
|
||||
_LOG.warning("Block '%s' not present or empty.", key)
|
||||
_LOG.debug("Block '%s' not present or empty.", key)
|
||||
return stanza
|
||||
|
||||
|
||||
|
|
|
@ -76,3 +76,28 @@ class LogrotateTestCase(TestCase, LoaderModuleMockMixin):
|
|||
):
|
||||
kwargs = {"key": "rotate", "value": "/var/log/wtmp", "setting": "2"}
|
||||
self.assertRaises(SaltInvocationError, logrotate.set_, **kwargs)
|
||||
|
||||
def test_get(self):
|
||||
"""
|
||||
Test if get a value for a specific configuration line
|
||||
"""
|
||||
with patch(
|
||||
"salt.modules.logrotate._parse_conf", MagicMock(return_value=PARSE_CONF)
|
||||
):
|
||||
# A single key returns the right value
|
||||
self.assertEqual(logrotate.get("rotate"), 1)
|
||||
|
||||
# A single key returns the wrong value
|
||||
self.assertNotEqual(logrotate.get("rotate"), 2)
|
||||
|
||||
# A single key returns the right stanza value
|
||||
self.assertEqual(logrotate.get("/var/log/wtmp", "rotate"), 1)
|
||||
|
||||
# A single key returns the wrong stanza value
|
||||
self.assertNotEqual(logrotate.get("/var/log/wtmp", "rotate"), 2)
|
||||
|
||||
# Ensure we're logging the message as debug not warn
|
||||
with patch.object(logrotate, "_LOG") as log_mock:
|
||||
res = logrotate.get("/var/log/utmp", "rotate")
|
||||
self.assertTrue(log_mock.debug.called)
|
||||
self.assertFalse(log_mock.warn.called)
|
||||
|
|
Loading…
Add table
Reference in a new issue