Skip to content

Commit

Permalink
fix: Make VerifyAgentLogs less verbose (#260)
Browse files Browse the repository at this point in the history
Fix: Make VerifyAgentLogs less verbose
  • Loading branch information
gmuloc authored Jul 11, 2023
1 parent 0e9b74e commit 46dc361
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 4 additions & 1 deletion anta/tests/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
from __future__ import annotations

import re
from typing import Optional

from anta.models import AntaCommand, AntaTest
Expand Down Expand Up @@ -124,7 +125,9 @@ def test(self) -> None:
if len(command_output) == 0:
self.result.is_success()
else:
self.result.is_failure(f"device reported some agent crashes: {command_output}")
pattern = re.compile(r"^===> (.*?) <===$", re.MULTILINE)
agents = "\n * ".join(pattern.findall(command_output))
self.result.is_failure(f"device reported some agent logs:\n * {agents}")


class VerifySyslog(AntaTest):
Expand Down
14 changes: 11 additions & 3 deletions tests/units/anta_tests/system/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,22 @@
"""===> /var/log/agents/Test-666 Thu May 4 09:57:02 2023 <===
CLI Exception: Exception
CLI Exception: Backtrace
===> /var/log/agents/Aaa-855 Fri Jul 7 15:07:00 2023 <===
===== Output from /usr/bin/Aaa [] (PID=855) started Jul 7 15:06:11.606414 ===
EntityManager::doBackoff waiting for remote sysdb version ....ok
===> /var/log/agents/Acl-830 Fri Jul 7 15:07:00 2023 <===
===== Output from /usr/bin/Acl [] (PID=830) started Jul 7 15:06:10.871700 ===
EntityManager::doBackoff waiting for remote sysdb version ...................ok
"""
],
"side_effect": [],
"expected_result": "failure",
"expected_messages": [
"device reported some agent crashes: ===> /var/log/agents/Test-666 Thu May 4 09:57:02 2023 <===\n"
"CLI Exception: Exception\n"
"CLI Exception: Backtrace\n",
'device reported some agent logs:\n'
' * /var/log/agents/Test-666 Thu May 4 09:57:02 2023\n'
' * /var/log/agents/Aaa-855 Fri Jul 7 15:07:00 2023\n'
' * /var/log/agents/Acl-830 Fri Jul 7 15:07:00 2023',
],
},
]
Expand Down

0 comments on commit 46dc361

Please sign in to comment.