From 1fd6a618b60d7168fd8f37585d5d39d22d775afd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 28 Mar 2024 07:11:39 +0100 Subject: Adding upstream version 0.13.0. Signed-off-by: Daniel Baumann --- tests/units/anta_tests/test_snmp.py | 128 ++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 tests/units/anta_tests/test_snmp.py (limited to 'tests/units/anta_tests/test_snmp.py') diff --git a/tests/units/anta_tests/test_snmp.py b/tests/units/anta_tests/test_snmp.py new file mode 100644 index 0000000..7009689 --- /dev/null +++ b/tests/units/anta_tests/test_snmp.py @@ -0,0 +1,128 @@ +# 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.snmp.py +""" +from __future__ import annotations + +from typing import Any + +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]] = [ + { + "name": "success", + "test": VerifySnmpStatus, + "eos_data": [{"vrfs": {"snmpVrfs": ["MGMT", "default"]}, "enabled": True}], + "inputs": {"vrf": "MGMT"}, + "expected": {"result": "success"}, + }, + { + "name": "failure-wrong-vrf", + "test": VerifySnmpStatus, + "eos_data": [{"vrfs": {"snmpVrfs": ["default"]}, "enabled": True}], + "inputs": {"vrf": "MGMT"}, + "expected": {"result": "failure", "messages": ["SNMP agent disabled in vrf MGMT"]}, + }, + { + "name": "failure-disabled", + "test": VerifySnmpStatus, + "eos_data": [{"vrfs": {"snmpVrfs": ["default"]}, "enabled": False}], + "inputs": {"vrf": "default"}, + "expected": {"result": "failure", "messages": ["SNMP agent disabled in vrf default"]}, + }, + { + "name": "success", + "test": VerifySnmpIPv4Acl, + "eos_data": [{"ipAclList": {"aclList": [{"type": "Ip4Acl", "name": "ACL_IPV4_SNMP", "configuredVrfs": ["MGMT"], "activeVrfs": ["MGMT"]}]}}], + "inputs": {"number": 1, "vrf": "MGMT"}, + "expected": {"result": "success"}, + }, + { + "name": "failure-wrong-number", + "test": VerifySnmpIPv4Acl, + "eos_data": [{"ipAclList": {"aclList": []}}], + "inputs": {"number": 1, "vrf": "MGMT"}, + "expected": {"result": "failure", "messages": ["Expected 1 SNMP IPv4 ACL(s) in vrf MGMT but got 0"]}, + }, + { + "name": "failure-wrong-vrf", + "test": VerifySnmpIPv4Acl, + "eos_data": [{"ipAclList": {"aclList": [{"type": "Ip4Acl", "name": "ACL_IPV4_SNMP", "configuredVrfs": ["default"], "activeVrfs": ["default"]}]}}], + "inputs": {"number": 1, "vrf": "MGMT"}, + "expected": {"result": "failure", "messages": ["SNMP IPv4 ACL(s) not configured or active in vrf MGMT: ['ACL_IPV4_SNMP']"]}, + }, + { + "name": "success", + "test": VerifySnmpIPv6Acl, + "eos_data": [{"ipv6AclList": {"aclList": [{"type": "Ip6Acl", "name": "ACL_IPV6_SNMP", "configuredVrfs": ["MGMT"], "activeVrfs": ["MGMT"]}]}}], + "inputs": {"number": 1, "vrf": "MGMT"}, + "expected": {"result": "success"}, + }, + { + "name": "failure-wrong-number", + "test": VerifySnmpIPv6Acl, + "eos_data": [{"ipv6AclList": {"aclList": []}}], + "inputs": {"number": 1, "vrf": "MGMT"}, + "expected": {"result": "failure", "messages": ["Expected 1 SNMP IPv6 ACL(s) in vrf MGMT but got 0"]}, + }, + { + "name": "failure-wrong-vrf", + "test": VerifySnmpIPv6Acl, + "eos_data": [{"ipv6AclList": {"aclList": [{"type": "Ip6Acl", "name": "ACL_IPV6_SNMP", "configuredVrfs": ["default"], "activeVrfs": ["default"]}]}}], + "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": "Jon@example.com"}, + } + ], + "inputs": {"contact": "Jon@example.com"}, + "expected": {"result": "success"}, + }, + { + "name": "failure-incorrect-contact", + "test": VerifySnmpContact, + "eos_data": [ + { + "contact": {"contact": "Jon@example.com"}, + } + ], + "inputs": {"contact": "Bob@example.com"}, + "expected": { + "result": "failure", + "messages": ["Expected `Bob@example.com` as the contact, but found `Jon@example.com` instead."], + }, + }, +] -- cgit v1.2.3