From 20b752e6451b1f4bee97d18c55afb0cfe35058a8 Mon Sep 17 00:00:00 2001 From: VitthalMagadum Date: Tue, 8 Oct 2024 07:53:57 -0400 Subject: [PATCH 1/2] Added TC fot Syslog logging enabled --- anta/tests/logging.py | 31 +++++++++++++++++++ examples/tests.yaml | 1 + tests/units/anta_tests/test_logging.py | 42 ++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/anta/tests/logging.py b/anta/tests/logging.py index 2972b4ec8..262ae6dd1 100644 --- a/anta/tests/logging.py +++ b/anta/tests/logging.py @@ -43,6 +43,37 @@ def _get_logging_states(logger: logging.Logger, command_output: str) -> str: return log_states +class VerifySyslogLogging(AntaTest): + """Verifies if syslog logging is enabled. + + Expected Results + ---------------- + * Success: The test will pass if syslog logging is enabled. + * Failure: The test will fail if syslog logging is disabled. + + Examples + -------- + ```yaml + anta.tests.logging: + - VerifySyslogLogging: + ``` + """ + + name = "VerifySyslogLogging" + description = "Verifies if syslog logging is enabled." + categories: ClassVar[list[str]] = ["logging"] + commands: ClassVar[list[AntaCommand | AntaTemplate]] = [AntaCommand(command="show logging", ofmt="text")] + + @AntaTest.anta_test + def test(self) -> None: + """Main test function for VerifySyslogLogging.""" + self.result.is_success() + log_output = self.instance_commands[0].text_output + + if "Syslog logging: enabled" not in _get_logging_states(self.logger, log_output): + self.result.is_failure("Syslog logging is disabled.") + + class VerifyLoggingPersistent(AntaTest): """Verifies if logging persistent is enabled and logs are saved in flash. diff --git a/examples/tests.yaml b/examples/tests.yaml index ade4e7640..ddf908ed0 100644 --- a/examples/tests.yaml +++ b/examples/tests.yaml @@ -232,6 +232,7 @@ anta.tests.lanz: - VerifyLANZ: anta.tests.logging: + - VerifySyslogLogging: - VerifyLoggingPersistent: - VerifyLoggingSourceIntf: interface: Management1 diff --git a/tests/units/anta_tests/test_logging.py b/tests/units/anta_tests/test_logging.py index b4294367e..fc888ca9a 100644 --- a/tests/units/anta_tests/test_logging.py +++ b/tests/units/anta_tests/test_logging.py @@ -16,6 +16,7 @@ VerifyLoggingPersistent, VerifyLoggingSourceIntf, VerifyLoggingTimestamp, + VerifySyslogLogging, ) from tests.units.anta_tests import test @@ -277,4 +278,45 @@ "inputs": None, "expected": {"result": "failure", "messages": ["Device has reported syslog messages with a severity of ERRORS or higher"]}, }, + { + "name": "success", + "test": VerifySyslogLogging, + "eos_data": [ + """Syslog logging: enabled + Buffer logging: level debugging + + External configuration: + active: + inactive: + + Facility Severity Effective Severity + -------------------- ------------- ------------------ + aaa debugging debugging + accounting debugging debugging""", + ], + "inputs": None, + "expected": {"result": "success"}, + }, + { + "name": "failure", + "test": VerifySyslogLogging, + "eos_data": [ + """Syslog logging: disabled + Buffer logging: level debugging + Console logging: level errors + Persistent logging: disabled + Monitor logging: level errors + + External configuration: + active: + inactive: + + Facility Severity Effective Severity + -------------------- ------------- ------------------ + aaa debugging debugging + accounting debugging debugging""", + ], + "inputs": None, + "expected": {"result": "failure", "messages": ["Syslog logging is disabled."]}, + }, ] From 86a1047a8e01e3e8f4ab75715bb88dc98f6079e6 Mon Sep 17 00:00:00 2001 From: vitthalmagadum Date: Wed, 8 Jan 2025 04:52:52 -0500 Subject: [PATCH 2/2] Rebased and removed name & description --- anta/tests/logging.py | 2 -- examples/tests.yaml | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/anta/tests/logging.py b/anta/tests/logging.py index 90f6ea0e9..4a1c594e8 100644 --- a/anta/tests/logging.py +++ b/anta/tests/logging.py @@ -59,8 +59,6 @@ class VerifySyslogLogging(AntaTest): ``` """ - name = "VerifySyslogLogging" - description = "Verifies if syslog logging is enabled." categories: ClassVar[list[str]] = ["logging"] commands: ClassVar[list[AntaCommand | AntaTemplate]] = [AntaCommand(command="show logging", ofmt="text")] diff --git a/examples/tests.yaml b/examples/tests.yaml index a4bc1fabf..db7932d5d 100644 --- a/examples/tests.yaml +++ b/examples/tests.yaml @@ -306,6 +306,8 @@ anta.tests.logging: vrf: default - VerifyLoggingTimestamp: # Verifies if logs are generated with the appropriate timestamp. + - VerifySyslogLogging: + # Verifies if syslog logging is enabled. anta.tests.mlag: - VerifyMlagConfigSanity: # Verifies there are no MLAG config-sanity inconsistencies.