Skip to content

Commit

Permalink
issue_753 Handling review comments: updated docstring & failure message
Browse files Browse the repository at this point in the history
  • Loading branch information
VitthalMagadum committed Jul 24, 2024
1 parent 54fecac commit 0630da7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
13 changes: 8 additions & 5 deletions anta/tests/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,17 @@ class VerifyNTPAssociations(AntaTest):
Expected Results
----------------
* Success: The test will pass if the Primary NTP server should be preferred and will have condition 'sys.peer' and other servers will have condition "candidate".
* Failure: The test will fail if the Primary NTP server is NOT preferred.
* Success: The test will pass if the Primary NTP server (marked as preferred) has the condition 'sys.peer' and
all other NTP servers have the condition 'candidate'.
* Failure: The test will fail if the Primary NTP server (marked as preferred) does not have the condition 'sys.peer' or
if any other NTP server does not have the condition 'candidate'.
Examples
--------
```yaml
- VerifyNTPAssociations:
ntp_servers:
anta.tests.system:
- VerifyNTPAssociations:
ntp_servers:
- server_address: 1.1.1.1
preferred: True
- server_address: 2.2.2.2
Expand Down Expand Up @@ -350,7 +353,7 @@ def test(self) -> None:
failures: str = ""

if not (peer_details := get_value(self.instance_commands[0].json_output, "peers")):
self.result.is_failure("NTP peers are not configured.")
self.result.is_failure("None of NTP peers are not configured.")
return

# Iterate over each NTP server
Expand Down
8 changes: 4 additions & 4 deletions examples/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,10 @@ anta.tests.system:
- VerifyNTP:
- VerifyNTPAssociations:
ntp_servers:
- server_address: 1.1.1.1
preferred: True
- server_address: 2.2.2.2
- server_address: 3.3.3.3
- server_address: 1.1.1.1
preferred: True
- server_address: 2.2.2.2
- server_address: 3.3.3.3

anta.tests.vlan:
- VerifyVlanInternalPolicy:
Expand Down
22 changes: 22 additions & 0 deletions tests/units/anta_tests/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,26 @@
"messages": ["NTP peer 3.3.3.3 is not configured."],
},
},
{
"name": "failure-with-two-peers-not-found",
"test": VerifyNTPAssociations,
"eos_data": [
{
"peers": {
"1.1.1.1 (*.pool.ntp.org)": {
"condition": "candidate",
"peerIpAddr": "1.1.1.1",
}
}
}
],
"inputs": {"ntp_servers": [{"server_address": "1.1.1.1", "preferred": True}, {"server_address": "2.2.2.2"}, {"server_address": "3.3.3.3"}]},
"expected": {
"result": "failure",
"messages": [
"For NTP peer 1.1.1.1 expected condition as 'sys.peer' but found 'candidate' instead.\n"
"NTP peer 2.2.2.2 is not configured.\nNTP peer 3.3.3.3 is not configured.\n"
],
},
},
]

0 comments on commit 0630da7

Please sign in to comment.