8000 doc: Update system tests docstrings by carl-baillargeon · Pull Request #291 · aristanetworks/anta · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

doc: Update system tests docstrings #291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 65 additions & 31 deletions anta/tests/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@

class VerifyUptime(AntaTest):
"""
Verifies the device uptime is higher than a value.
This test verifies if the device uptime is higher than the provided minimum uptime value.

Expected Results:
* success: The test will pass if the device uptime is higher than the provided value.
* failure: The test will fail if the device uptime is lower than the provided value.
* skipped: The test will be skipped if the provided uptime value is invalid or negative.
"""

name = "VerifyUptime"
description = "Verifies the device uptime is higher than a value."
description = "This test verifies if the device uptime is higher than the provided minimum uptime value."
categories = ["system"]
commands = [AntaCommand(command="show uptime")]

Expand All @@ -31,26 +36,27 @@ def test(self, minimum: Optional[int] = None) -> None:
command_output = self.instance_commands[0].json_output

if not (isinstance(minimum, (int, float))) or minimum < 0:
self.result.is_skipped("VerifyUptime was not run as incorrect minimum uptime was given")
self.result.is_skipped(f"{self.__class__.name} was not run since the provided uptime value is invalid or negative")
return

if command_output["upTime"] > minimum:
self.result.is_success()
else:
self.result.is_failure(f"Uptime is {command_output['upTime']}")
self.result.is_failure(f"Device uptime is {command_output['upTime']} seconds")


class VerifyReloadCause(AntaTest):
"""
Verifies the last reload of the device was requested by a user.
This test verifies the last reload cause of the device.

Test considers the following messages as normal and will return success. Failure is for other messages
* Reload requested by the user.
* Reload requested after FPGA upgrade
Expected Results:
* success: The test will pass if there are NO reload causes or if the last reload was caused by the user or after an FPGA upgrade.
* failure: The test will fail if the last reload was NOT caused by the user or after an FPGA upgrade.
* error: The test will report an error if the reload cause is NOT available.
"""

name = "VerifyReloadCause"
description = "Verifies the device uptime is higher than a value."
description = "This test verifies the last reload cause of the device."
categories = ["system"]
commands = [AntaCommand(command="show reload cause")]

Expand All @@ -63,7 +69,7 @@ def test(self) -> None:
command_output = self.instance_commands[0].json_output

if "resetCauses" not in command_output.keys():
self.result.is_error("no reload cause available")
self.result.is_error("No reload causes available")
return

if len(command_output["resetCauses"]) == 0:
Expand All @@ -79,16 +85,20 @@ def test(self) -> None:
]:
self.result.is_success()
else:
self.result.is_failure(f"Reload cause is {command_output_data}")
self.result.is_failure(f"Reload cause is: '{command_output_data}'")


class VerifyCoredump(AntaTest):
"""
Verifies there is no core file.
This test verifies if there are core files saved in the /var/core directory.

Expected Results:
* success: The test will pass if there are NO core files saved in the directory.
* failure: The test will fail if there are core files saved in the directory.
"""

name = "VerifyCoredump"
description = "Verifies there is no core file."
description = "This test verifies if there are core files saved in the /var/core directory."
categories = ["system"]
commands = [AntaCommand(command="bash timeout 10 ls /var/core", ofmt="text")]

Expand All @@ -107,11 +117,15 @@ def test(self) -> None:

class VerifyAgentLogs(AntaTest):
"""
Verifies there is no agent crash reported on the device.
This test verifies that no agent crash reports are present on the device.

Expected Results:
* success: The test will pass if there is NO agent crash reported.
* failure: The test will fail if any agent crashes are reported.
"""

name = "VerifyAgentLogs"
description = "Verifies there is no agent crash reported on the device."
description = "This test verifies that no agent crash reports are present on the device."
categories = ["system"]
commands = [AntaCommand(command="show agent logs crash", ofmt="text")]

Expand All @@ -127,16 +141,20 @@ def test(self) -> None:
else:
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}")
self.result.is_failure(f"Device has reported agent crashes:\n * {agents}")


class VerifySyslog(AntaTest):
"""
Verifies the device had no syslog message with a severity of warning (or a more severe message) during the last 7 days.
This test verifies there are no syslog messages with a severity of WARNING or higher in the last 7 days.

Expected Results:
* success: The test will pass if there are NO syslog messages with a severity of WARNING or higher in the last 7 days.
* failure: The test will fail if WARNING or higher syslog messages are present in the last 7 days.
"""

name = "VerifySyslog"
description = "Verifies the device had no syslog message with a severity of warning (or a more severe message) during the last 7 days."
description = "This test verifies there are no syslog messages with a severity of WARNING or higher in the last 7 days."
categories = ["system"]
commands = [AntaCommand(command="show logging last 7 days threshold warnings", ofmt="text")]

Expand All @@ -150,16 +168,20 @@ def test(self) -> None:
if len(command_output) == 0:
self.result.is_success()
else:
self.result.is_failure("Device has some log messages with a severity WARNING or higher")
self.result.is_failure("Device has reported some log messages with WARNING or higher severity")


class VerifyCPUUtilization(AntaTest):
"""
Verifies the CPU utilization is less than 75%.
This test verifies whether the CPU utilization is below 75%.

Expected Results:
* success: The test will pass if the CPU utilization is below 75%.
* failure: The test will fail if the CPU utilization is over 75%.
"""

name = "VerifyCPUUtilization"
description = "Verifies the CPU utilization is less than 75%."
description = "This test verifies whether the CPU utilization is below 75%."
categories = ["system"]
commands = [AntaCommand(command="show processes top once")]

Expand All @@ -174,16 +196,20 @@ def test(self) -> None:
if command_output_data > 25:
self.result.is_success()
else:
self.result.is_failure(f"device reported a high CPU utilization ({100 - command_output_data}%)")
self.result.is_failure(f"Device has reported a high CPU utilization: {100 - command_output_data}%")


class VerifyMemoryUtilization(AntaTest):
"""
Verifies the Memory utilization is less than 75%.
This test verifies whether the memory utilization is below 75%.

Expected Results:
* success: The test will pass if the memory utilization is below 75%.
* failure: The test will fail if the memory utilization is over 75%.
"""

name = "VerifyMemoryUtilization"
description = "Verifies the Memory utilization is less than 75%."
description = "This test verifies whether the memory utilization is below 75%."
categories = ["system"]
commands = [AntaCommand(command="show version")]

Expand All @@ -198,16 +224,20 @@ def test(self) -> None:
if memory_usage > 0.25:
self.result.is_success()
else:
self.result.is_failure(f"device report a high memory usage: {(1 - memory_usage)*100:.2f}%")
self.result.is_failure(f"Device has reported a high memory usage: {(1 - memory_usage)*100:.2f}%")


class VerifyFileSystemUtilization(AntaTest):
"""
Verifies each partition on the disk is used less than 75%.
This test verifies that no partition is utilizing more than 75% of its disk space.

Expected Results:
* success: The test will pass if all partitions are using less than 75% of its disk space.
* failure: The test will fail if any partitions are using more than 75% of its disk space.
"""

name = "VerifyFileSystemUtilization"
description = "Verifies each partition on the disk is used less than 75%."
description = "This test verifies that no partition is utilizing more than 75% of its disk space."
categories = ["system"]
commands = [AntaCommand(command="bash timeout 10 df -h", ofmt="text")]

Expand All @@ -222,16 +252,20 @@ def test(self) -> None:

for line in command_output.split("\n")[1:]:
if "loop" not in line and len(line) > 0 and (percentage := int(line.split()[4].replace("%", ""))) > 75:
self.result.is_failure(f"mount point {line} is higher than 75% (reported {percentage})")
self.result.is_failure(f"Mount point {line} is higher than 75%: reported {percentage}%")


class VerifyNTP(AntaTest):
"""
Verifies NTP is synchronised.
This test verifies that the Network Time Protocol (NTP) is synchronized.

Expected Results:
* success: The test will pass if the NTP is synchronised.
* failure: The test will fail if the NTP is NOT synchronised.
"""

name = "VerifyNTP"
description = "Verifies NTP is synchronised."
description = "This test verifies if NTP is synchronised."
categories = ["system"]
commands = [AntaCommand(command="show ntp status", ofmt="text")]

Expand All @@ -246,4 +280,4 @@ def test(self) -> None:
self.result.is_success()
else:
data = command_output.split("\n")[0]
self.result.is_failure(f"not sync with NTP server ({data})")
self.result.is_failure(f"NTP server is not synchronized: '{data}'")
29 changes: 19 additions & 10 deletions tests/units/anta_tests/system/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
"eos_data": [{"upTime": 665.15, "loadAvg": [0.13, 0.12, 0.09], "users": 1, "currentTime": 1683186659.139859}],
"side_effect": 666,
"expected_result": "failure",
"expected_messages": ["Uptime is 665.15"],
"expected_messages": ["Device uptime is 665.15 seconds"],
},
{
"name": "skipped-no-minimum",
"eos_data": [{"upTime": 665.15, "loadAvg": [0.13, 0.12, 0.09], "users": 1, "currentTime": 1683186659.139859}],
"side_effect": None,
"expected_result": "skipped",
"expected_messages": ["VerifyUptime was not run as incorrect minimum uptime was given"],
"expected_messages": ["VerifyUptime was not run since the provided uptime value is invalid or negative"],
},
]

Expand Down Expand Up @@ -61,7 +61,16 @@
],
"side_effect": [],
"expected_result": "failure",
"expected_messages": ["Reload cause is Reload after crash."],
"expected_messages": ["Reload cause is: 'Reload after crash.'"],
},
{
"name": "error",
"eos_data": [
{}
],
"side_effect": [],
"expected_result": "error",
"expected_messages": ["No reload causes available"],
},
]

Expand Down Expand Up @@ -108,7 +117,7 @@
"side_effect": [],
"expected_result": "failure",
"expected_messages": [
'device reported some agent logs:\n'
'Device has reported agent crashes:\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 All @@ -133,7 +142,7 @@
],
"side_effect": [],
"expected_result": "failure",
"expected_messages": ["Device has some log messages with a severity WARNING or higher"],
"expected_messages": ["Device has reported some log messages with WARNING or higher severity"],
},
]

Expand Down Expand Up @@ -190,7 +199,7 @@
],
"side_effect": [],
"expected_result": "failure",
"expected_messages": ["device reported a high CPU utilization (75.2%)"],
"expected_messages": ["Device has reported a high CPU utilization: 75.2%"],
},
]

Expand Down Expand Up @@ -225,7 +234,7 @@
],
"side_effect": [],
"expected_result": "failure",
"expected_messages": ["device report a high memory usage: 95.56%"],
"expected_messages": ["Device has reported a high memory usage: 95.56%"],
},
]

Expand Down Expand Up @@ -257,8 +266,8 @@
"side_effect": [],
"expected_result": "failure",
"expected_messages": [
"mount point /dev/sda2 3.9G 988M 2.9G 84% /mnt/flash is higher than 75% (reported 84)",
"mount point none 294M 78M 217M 84% /.overlay is higher than 75% (reported 84)",
"Mount point /dev/sda2 3.9G 988M 2.9G 84% /mnt/flash is higher than 75%: reported 84%",
"Mount point none 294M 78M 217M 84% /.overlay is higher than 75%: reported 84%",
],
},
]
Expand All @@ -285,6 +294,6 @@
],
"side_effect": [],
"expected_result": "failure",
"expected_messages": ["not sync with NTP server (unsynchronised)"],
"expected_messages": ["NTP server is not synchronized: 'unsynchronised'"],
},
]
0