diff --git a/changelog/53988.fixed b/changelog/53988.fixed new file mode 100644 index 000000000000..8220d4acddd6 --- /dev/null +++ b/changelog/53988.fixed @@ -0,0 +1 @@ +Avoid warning noise in lograte.get diff --git a/salt/modules/logrotate.py b/salt/modules/logrotate.py index d9801ab16241..314fc607cfca 100644 --- a/salt/modules/logrotate.py +++ b/salt/modules/logrotate.py @@ -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 diff --git a/tests/unit/modules/test_logrotate.py b/tests/unit/modules/test_logrotate.py index 5f589a61d911..4cc0fc49db3a 100644 --- a/tests/unit/modules/test_logrotate.py +++ b/tests/unit/modules/test_logrotate.py @@ -76,3 +76,28 @@ def test_set_setting_failed(self): ): 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)