-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(anta.tests): Added the testcase to verify hostname, location and…
… contact (#523) * issue-521: Added the testcase to verify hostname, location and contact details * issue-521: updated snmp testcases * issue-521: updated categories * issue-521: updated doc string * issue-521: updated doc string for testcase
- Loading branch information
1 parent
ec8c171
commit 6e26ba4
Showing
8 changed files
with
206 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright (c) 2023-2024 Arista Networks, Inc. | ||
# Use of this source code is governed by the Apache License 2.0 | ||
# that can be found in the LICENSE file. | ||
""" | ||
Test functions related to the EOS various services settings | ||
""" | ||
from __future__ import annotations | ||
|
||
# Mypy does not understand AntaTest.Input typing | ||
# mypy: disable-error-code=attr-defined | ||
from anta.models import AntaCommand, AntaTest | ||
|
||
|
||
class VerifyHostname(AntaTest): | ||
""" | ||
This class verifies the hostname of a device. | ||
Expected results: | ||
* success: The test will pass if the hostname matches the provided input. | ||
* failure: The test will fail if the hostname does not match the provided input. | ||
""" | ||
|
||
name = "VerifyHostname" | ||
description = "Verifies the hostname of a device." | ||
categories = ["services"] | ||
commands = [AntaCommand(command="show hostname")] | ||
|
||
class Input(AntaTest.Input): | ||
"""Defines the input parameters for this test case.""" | ||
|
||
hostname: str | ||
"""Expected hostname of the device.""" | ||
|
||
@AntaTest.anta_test | ||
def test(self) -> None: | ||
hostname = self.instance_commands[0].json_output["hostname"] | ||
|
||
if hostname != self.inputs.hostname: | ||
self.result.is_failure(f"Expected `{self.inputs.hostname}` as the hostname, but found `{hostname}` instead.") | ||
else: | ||
self.result.is_success() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- | ||
~ Copyright (c) 2023-2024 Arista Networks, Inc. | ||
~ Use of this source code is governed by the Apache License 2.0 | ||
~ that can be found in the LICENSE file. | ||
--> | ||
|
||
# ANTA catalog for services tests | ||
|
||
::: anta.tests.services | ||
options: | ||
show_root_heading: false | ||
show_root_toc_entry: false | ||
merge_init_into_class: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -227,6 +227,8 @@ anta.tests.security: | |
common_name: Arista Networks Internal IT Root Cert Authority | ||
encryption_algorithm: RSA | ||
key_size: 4096 | ||
|
||
anta.tests.services: | ||
- VerifyBannerLogin: | ||
login_banner: | | ||
# Copyright (c) 2023-2024 Arista Networks, Inc. | ||
|
@@ -237,6 +239,8 @@ anta.tests.security: | |
# Copyright (c) 2023-2024 Arista Networks, Inc. | ||
# Use of this source code is governed by the Apache License 2.0 | ||
# that can be found in the LICENSE file. | ||
- VerifyHostname: | ||
hostname: s1-spine1 | ||
|
||
anta.tests.snmp: | ||
- VerifySnmpStatus: | ||
|
@@ -247,6 +251,10 @@ anta.tests.snmp: | |
- VerifySnmpIPv6Acl: | ||
number: 3 | ||
vrf: default | ||
- VerifySnmpLocation: | ||
location: New York | ||
- VerifySnmpContact: | ||
contact: [email protected] | ||
|
||
anta.tests.software: | ||
- VerifyEOSVersion: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright (c) 2023-2024 Arista Networks, Inc. | ||
# Use of this source code is governed by the Apache License 2.0 | ||
# that can be found in the LICENSE file. | ||
""" | ||
Tests for anta.tests.services.py | ||
""" | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
from anta.tests.services import VerifyHostname | ||
from tests.lib.anta import test # noqa: F401; pylint: disable=W0611 | ||
|
||
DATA: list[dict[str, Any]] = [ | ||
{ | ||
"name": "success", | ||
"test": VerifyHostname, | ||
"eos_data": [{"hostname": "s1-spine1", "fqdn": "s1-spine1.fun.aristanetworks.com"}], | ||
"inputs": {"hostname": "s1-spine1"}, | ||
"expected": {"result": "success"}, | ||
}, | ||
{ | ||
"name": "failure-incorrect-hostname", | ||
"test": VerifyHostname, | ||
"eos_data": [{"hostname": "s1-spine2", "fqdn": "s1-spine1.fun.aristanetworks.com"}], | ||
"inputs": {"hostname": "s1-spine1"}, | ||
"expected": { | ||
"result": "failure", | ||
"messages": ["Expected `s1-spine1` as the hostname, but found `s1-spine2` instead."], | ||
}, | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
|
||
from typing import Any | ||
|
||
from anta.tests.snmp import VerifySnmpIPv4Acl, VerifySnmpIPv6Acl, VerifySnmpStatus | ||
from anta.tests.snmp import VerifySnmpContact, VerifySnmpIPv4Acl, VerifySnmpIPv6Acl, VerifySnmpLocation, VerifySnmpStatus | ||
from tests.lib.anta import test # noqa: F401; pylint: disable=W0611 | ||
|
||
DATA: list[dict[str, Any]] = [ | ||
|
@@ -75,4 +75,54 @@ | |
"inputs": {"number": 1, "vrf": "MGMT"}, | ||
"expected": {"result": "failure", "messages": ["SNMP IPv6 ACL(s) not configured or active in vrf MGMT: ['ACL_IPV6_SNMP']"]}, | ||
}, | ||
{ | ||
"name": "success", | ||
"test": VerifySnmpLocation, | ||
"eos_data": [ | ||
{ | ||
"location": {"location": "New York"}, | ||
} | ||
], | ||
"inputs": {"location": "New York"}, | ||
"expected": {"result": "success"}, | ||
}, | ||
{ | ||
"name": "failure-incorrect-location", | ||
"test": VerifySnmpLocation, | ||
"eos_data": [ | ||
{ | ||
"location": {"location": "Europe"}, | ||
} | ||
], | ||
"inputs": {"location": "New York"}, | ||
"expected": { | ||
"result": "failure", | ||
"messages": ["Expected `New York` as the location, but found `Europe` instead."], | ||
}, | ||
}, | ||
{ | ||
"name": "success", | ||
"test": VerifySnmpContact, | ||
"eos_data": [ | ||
{ | ||
"contact": {"contact": "[email protected]"}, | ||
} | ||
], | ||
"inputs": {"contact": "[email protected]"}, | ||
"expected": {"result": "success"}, | ||
}, | ||
{ | ||
"name": "failure-incorrect-contact", | ||
"test": VerifySnmpContact, | ||
"eos_data": [ | ||
{ | ||
"contact": {"contact": "[email protected]"}, | ||
} | ||
], | ||
"inputs": {"contact": "[email protected]"}, | ||
"expected": { | ||
"result": "failure", | ||
"messages": ["Expected `[email protected]` as the contact, but found `[email protected]` instead."], | ||
}, | ||
}, | ||
] |