Skip to content

Commit

Permalink
Updated docstrings and test failure message
Browse files Browse the repository at this point in the history
  • Loading branch information
geetanjalimanegslab committed Feb 13, 2025
1 parent b578dc2 commit fa2d6d5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 26 deletions.
18 changes: 8 additions & 10 deletions anta/tests/ptp.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


class VerifyPtpModeStatus(AntaTest):
"""Verifies that the device is configured as a Precision Time Protocol (PTP) Boundary Clock (BC).
"""Verifies that the device is configured as a PTP Boundary Clock.
Expected Results
----------------
Expand Down Expand Up @@ -47,13 +47,13 @@ def test(self) -> None:
return

if ptp_mode != "ptpBoundaryClock":
self.result.is_failure(f"The device is not configured as a PTP Boundary Clock - Actual: {ptp_mode}")
self.result.is_failure(f"Not configured as a PTP Boundary Clock - Actual: {ptp_mode}")
else:
self.result.is_success()


class VerifyPtpGMStatus(AntaTest):
"""Verifies that the device is locked to a valid Precision Time Protocol (PTP) Grandmaster (GM).
"""Verifies that the device is locked to a valid PTP Grandmaster.
To test PTP failover, re-run the test with a secondary GMID configured.
Expand Down Expand Up @@ -100,7 +100,7 @@ def test(self) -> None:


class VerifyPtpLockStatus(AntaTest):
"""Verifies that the device was locked to the upstream Precision Time Protocol (PTP) Grandmaster (GM) in the last minute.
"""Verifies that the device was locked to the upstream PTP GM in the last minute.
Expected Results
----------------
Expand Down Expand Up @@ -133,13 +133,13 @@ def test(self) -> None:
time_difference = ptp_clock_summary["currentPtpSystemTime"] - ptp_clock_summary["lastSyncTime"]

if time_difference >= threshold:
self.result.is_failure(f"The device lock is more than {threshold}s old - Actual: {time_difference}s")
self.result.is_failure(f"Lock is more than {threshold}s old - Actual: {time_difference}s")
else:
self.result.is_success()


class VerifyPtpOffset(AntaTest):
"""Verifies that the Precision Time Protocol (PTP) timing offset is within +/- 1000ns from the master clock.
"""Verifies that the PTP timing offset is within +/- 1000ns from the master clock.
Expected Results
----------------
Expand Down Expand Up @@ -175,13 +175,11 @@ def test(self) -> None:
offset_interfaces.setdefault(interface["intf"], []).append(interface["offsetFromMaster"])

for interface, data in offset_interfaces.items():
self.result.is_failure(
f"Interface: {interface} - The device timing offset from master is greater than +/- {threshold}ns: Actual: {', '.join(map(str, data))}"
)
self.result.is_failure(f"Interface: {interface} - Timing offset from master is greater than +/- {threshold}ns: Actual: {', '.join(map(str, data))}")


class VerifyPtpPortModeStatus(AntaTest):
"""Verifies that all interfaces are in a valid Precision Time Protocol (PTP) state.
"""Verifies the PTP interfaces state.
The interfaces can be in one of the following state: Master, Slave, Passive, or Disabled.
Expand Down
8 changes: 4 additions & 4 deletions anta/tests/software.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


class VerifyEOSVersion(AntaTest):
"""Verifies that the device is running one of the allowed EOS version.
"""Verifies the EOS version of the device.
Expected Results
----------------
Expand Down Expand Up @@ -49,11 +49,11 @@ def test(self) -> None:
command_output = self.instance_commands[0].json_output
self.result.is_success()
if command_output["version"] not in self.inputs.versions:
self.result.is_failure(f"Device version mismatch - Actual: {command_output['version']} not in Expected: {', '.join(self.inputs.versions)}")
self.result.is_failure(f"EOS version mismatch - Actual: {command_output['version']} not in Expected: {', '.join(self.inputs.versions)}")


class VerifyTerminAttrVersion(AntaTest):
"""Verifies that he device is running one of the allowed TerminAttr version.
"""Verifies the TerminAttr version of the device.
Expected Results
----------------
Expand Down Expand Up @@ -87,7 +87,7 @@ def test(self) -> None:
self.result.is_success()
command_output_data = command_output["details"]["packages"]["TerminAttr-core"]["version"]
if command_output_data not in self.inputs.versions:
self.result.is_failure(f"Device TerminAttr version mismatch - Actual: {command_output_data} not in Expected: {', '.join(self.inputs.versions)}")
self.result.is_failure(f"TerminAttr version mismatch - Actual: {command_output_data} not in Expected: {', '.join(self.inputs.versions)}")


class VerifyEOSExtensions(AntaTest):
Expand Down
14 changes: 7 additions & 7 deletions examples/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -365,16 +365,16 @@ anta.tests.profiles:
mode: 3
anta.tests.ptp:
- VerifyPtpGMStatus:
# Verifies that the device is locked to a valid Precision Time Protocol (PTP) Grandmaster (GM).
# Verifies that the device is locked to a valid PTP Grandmaster.
gmid: 0xec:46:70:ff:fe:00:ff:a9
- VerifyPtpLockStatus:
# Verifies that the device was locked to the upstream Precision Time Protocol (PTP) Grandmaster (GM) in the last minute.
# Verifies that the device was locked to the upstream PTP GM in the last minute.
- VerifyPtpModeStatus:
# Verifies that the device is configured as a Precision Time Protocol (PTP) Boundary Clock (BC).
# Verifies that the device is configured as a PTP Boundary Clock.
- VerifyPtpOffset:
# Verifies that the Precision Time Protocol (PTP) timing offset is within +/- 1000ns from the master clock.
# Verifies that the PTP timing offset is within +/- 1000ns from the master clock.
- VerifyPtpPortModeStatus:
# Verifies that all interfaces are in a valid Precision Time Protocol (PTP) state.
# Verifies the PTP interfaces state.
anta.tests.routing.bgp:
- VerifyBGPAdvCommunities:
# Verifies that advertised communities are standard, extended and large for BGP IPv4 peer(s).
Expand Down Expand Up @@ -860,12 +860,12 @@ anta.tests.software:
- VerifyEOSExtensions:
# Verifies that all EOS extensions installed on the device are enabled for boot persistence.
- VerifyEOSVersion:
# Verifies that the device is running one of the allowed EOS version.
# Verifies the EOS version of the device.
versions:
- 4.25.4M
- 4.26.1F
- VerifyTerminAttrVersion:
# Verifies that he device is running one of the allowed TerminAttr version.
# Verifies the TerminAttr version of the device.
versions:
- v1.13.6
- v1.8.0
Expand Down
6 changes: 3 additions & 3 deletions tests/units/anta_tests/test_ptp.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"test": VerifyPtpModeStatus,
"eos_data": [{"ptpMode": "ptpDisabled", "ptpIntfSummaries": {}}],
"inputs": None,
"expected": {"result": "failure", "messages": ["The device is not configured as a PTP Boundary Clock - Actual: ptpDisabled"]},
"expected": {"result": "failure", "messages": ["Not configured as a PTP Boundary Clock - Actual: ptpDisabled"]},
},
{
"name": "skipped",
Expand Down Expand Up @@ -158,7 +158,7 @@
}
],
"inputs": None,
"expected": {"result": "failure", "messages": ["The device lock is more than 60s old - Actual: 157s"]},
"expected": {"result": "failure", "messages": ["Lock is more than 60s old - Actual: 157s"]},
},
{
"name": "skipped",
Expand Down Expand Up @@ -237,7 +237,7 @@
"expected": {
"result": "failure",
"messages": [
"Interface: Ethernet27/1 - The device timing offset from master is greater than +/- 1000ns: Actual: 1200, -1300",
"Interface: Ethernet27/1 - Timing offset from master is greater than +/- 1000ns: Actual: 1200, -1300",
],
},
},
Expand Down
4 changes: 2 additions & 2 deletions tests/units/anta_tests/test_software.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
],
"inputs": {"versions": ["4.27.1F"]},
"expected": {"result": "failure", "messages": ["Device version mismatch - Actual: 4.27.0F not in Expected: 4.27.1F"]},
"expected": {"result": "failure", "messages": ["EOS version mismatch - Actual: 4.27.0F not in Expected: 4.27.1F"]},
},
{
"name": "success",
Expand Down Expand Up @@ -77,7 +77,7 @@
},
],
"inputs": {"versions": ["v1.17.1", "v1.18.1"]},
"expected": {"result": "failure", "messages": ["Device TerminAttr version mismatch - Actual: v1.17.0 not in Expected: v1.17.1, v1.18.1"]},
"expected": {"result": "failure", "messages": ["TerminAttr version mismatch - Actual: v1.17.0 not in Expected: v1.17.1, v1.18.1"]},
},
# TODO: add a test with a real extension?
{
Expand Down

0 comments on commit fa2d6d5

Please sign in to comment.