| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
"""Tests for anta.tests.services.py.""" |
| 5 |
|
| 6 |
from __future__ import annotations |
| 7 |
|
| 8 |
import sys |
| 9 |
from typing import TYPE_CHECKING, Any |
| 10 |
|
| 11 |
from anta.models import AntaTest |
| 12 |
from anta.result_manager.models import AntaTestStatus |
| 13 |
from anta.tests.services import VerifyDNSLookup, VerifyDNSServers, VerifyErrdisableRecovery, VerifyHostname |
| 14 |
from tests.units.anta_tests import test |
| 15 |
|
| 16 |
if TYPE_CHECKING: |
| 17 |
from tests.units.anta_tests import AntaUnitTestData |
| 18 |
|
| 19 |
DATA: AntaUnitTestData = { |
| 20 |
(VerifyHostname, "success"): { |
| 21 |
"eos_data": [{"hostname": "s1-spine1", "fqdn": "s1-spine1.fun.aristanetworks.com"}], |
| 22 |
"inputs": {"hostname": "s1-spine1"}, |
| 23 |
"expected": {"result": AntaTestStatus.SUCCESS}, |
| 24 |
}, |
| 25 |
(VerifyHostname, "failure-incorrect-hostname"): { |
| 26 |
"eos_data": [{"hostname": "s1-spine2", "fqdn": "s1-spine1.fun.aristanetworks.com"}], |
| 27 |
"inputs": {"hostname": "s1-spine1"}, |
| 28 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["Incorrect Hostname - Expected: s1-spine1 Actual: s1-spine2"]}, |
| 29 |
}, |
| 30 |
(VerifyDNSLookup, "success"): { |
| 31 |
"eos_data": [ |
| 32 |
{ |
| 33 |
"messages": [ |
| 34 |
"Server:\t\t127.0.0.1\nAddress:\t127.0.0.1#53\n\nNon-authoritative answer:\nName:\tarista.com\nAddress: 151.101.130.132\n" |
| 35 |
"Name:\tarista.com\nAddress: 151.101.2.132\nName:\tarista.com\nAddress: 151.101.194.132\nName:\tarista.com\nAddress: 151.101.66.132\n\n" |
| 36 |
] |
| 37 |
}, |
| 38 |
{"messages": ["Server:\t\t127.0.0.1\nAddress:\t127.0.0.1#53\n\nNon-authoritative answer:\nName:\twww.google.com\nAddress: 172.217.12.100\n\n"]}, |
| 39 |
], |
| 40 |
"inputs": {"domain_names": ["arista.com", "www.google.com"]}, |
| 41 |
"expected": {"result": AntaTestStatus.SUCCESS}, |
| 42 |
}, |
| 43 |
(VerifyDNSLookup, "failure"): { |
| 44 |
"eos_data": [ |
| 45 |
{"messages": ["Server:\t\t127.0.0.1\nAddress:\t127.0.0.1#53\n\nNon-authoritative answer:\n*** Can't find arista.ca: No answer\n\n"]}, |
| 46 |
{"messages": ["Server:\t\t127.0.0.1\nAddress:\t127.0.0.1#53\n\nNon-authoritative answer:\nName:\twww.google.com\nAddress: 172.217.12.100\n\n"]}, |
| 47 |
{"messages": ["Server:\t\t127.0.0.1\nAddress:\t127.0.0.1#53\n\nNon-authoritative answer:\n*** Can't find google.ca: No answer\n\n"]}, |
| 48 |
], |
| 49 |
"inputs": {"domain_names": ["arista.ca", "www.google.com", "google.ca"]}, |
| 50 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["The following domain(s) are not resolved to an IP address: arista.ca, google.ca"]}, |
| 51 |
}, |
| 52 |
(VerifyDNSServers, "success"): { |
| 53 |
"eos_data": [ |
| 54 |
{ |
| 55 |
"nameServerConfigs": [ |
| 56 |
{"ipAddr": "10.14.0.1", "vrf": "default", "priority": 0}, |
| 57 |
{"ipAddr": "10.14.0.11", "vrf": "MGMT", "priority": 1}, |
| 58 |
{"ipAddr": "fd12:3456:789a::1", "vrf": "default", "priority": 0}, |
| 59 |
] |
| 60 |
} |
| 61 |
], |
| 62 |
"inputs": { |
| 63 |
"dns_servers": [ |
| 64 |
{"server_address": "10.14.0.1", "vrf": "default", "priority": 0}, |
| 65 |
{"server_address": "10.14.0.11", "vrf": "MGMT", "priority": 1}, |
| 66 |
{"server_address": "fd12:3456:789a::1", "vrf": "default", "priority": 0}, |
| 67 |
] |
| 68 |
}, |
| 69 |
"expected": {"result": AntaTestStatus.SUCCESS}, |
| 70 |
}, |
| 71 |
(VerifyDNSServers, "failure-no-dns-found"): { |
| 72 |
"eos_data": [{"nameServerConfigs": []}], |
| 73 |
"inputs": { |
| 74 |
"dns_servers": [{"server_address": "10.14.0.10", "vrf": "default", "priority": 0}, {"server_address": "10.14.0.21", "vrf": "MGMT", "priority": 1}] |
| 75 |
}, |
| 76 |
"expected": { |
| 77 |
"result": AntaTestStatus.FAILURE, |
| 78 |
"messages": ["Server 10.14.0.10 VRF: default Priority: 0 - Not configured", "Server 10.14.0.21 VRF: MGMT Priority: 1 - Not configured"], |
| 79 |
}, |
| 80 |
}, |
| 81 |
(VerifyDNSServers, "failure-incorrect-dns-details"): { |
| 82 |
"eos_data": [{"nameServerConfigs": [{"ipAddr": "10.14.0.1", "vrf": "CS", "priority": 1}, {"ipAddr": "10.14.0.11", "vrf": "MGMT", "priority": 1}]}], |
| 83 |
"inputs": { |
| 84 |
"dns_servers": [ |
| 85 |
{"server_address": "10.14.0.1", "vrf": "CS", "priority": 0}, |
| 86 |
{"server_address": "10.14.0.11", "vrf": "default", "priority": 0}, |
| 87 |
{"server_address": "10.14.0.110", "vrf": "MGMT", "priority": 0}, |
| 88 |
] |
| 89 |
}, |
| 90 |
"expected": { |
| 91 |
"result": AntaTestStatus.FAILURE, |
| 92 |
"messages": [ |
| 93 |
"Server 10.14.0.1 VRF: CS Priority: 0 - Incorrect priority - Priority: 1", |
| 94 |
"Server 10.14.0.11 VRF: default Priority: 0 - Not configured", |
| 95 |
"Server 10.14.0.110 VRF: MGMT Priority: 0 - Not configured", |
| 96 |
], |
| 97 |
}, |
| 98 |
}, |
| 99 |
(VerifyErrdisableRecovery, "success"): { |
| 100 |
"eos_data": [ |
| 101 |
"\n Errdisable Reason Timer Status Timer Interval\n ------------------------------" |
| 102 |
" ----------------- --------------\n acl Enabled 300\n\n " |
| 103 |
" bpduguard Enabled 300\n arp-inspection " |
| 104 |
" Enabled 30\n " |
| 105 |
], |
| 106 |
"inputs": {"reasons": [{"reason": "acl", "interval": 300}, {"reason": "bpduguard", "interval": 300}]}, |
| 107 |
"expected": {"result": AntaTestStatus.SUCCESS}, |
| 108 |
}, |
| 109 |
(VerifyErrdisableRecovery, "failure-reason-missing"): { |
| 110 |
"eos_data": [ |
| 111 |
"\n Errdisable Reason Timer Status Timer Interval\n ------------------------------" |
| 112 |
" ----------------- --------------\n acl Enabled 300\n " |
| 113 |
" bpduguard Enabled 300\n arp-inspection Enabled" |
| 114 |
" 30\n " |
| 115 |
], |
| 116 |
"inputs": {"reasons": [{"reason": "acl", "interval": 300}, {"reason": "arp-inspection", "interval": 30}, {"reason": "tapagg", "interval": 30}]}, |
| 117 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["Reason: tapagg Status: Enabled Interval: 30 - Not found"]}, |
| 118 |
}, |
| 119 |
(VerifyErrdisableRecovery, "failure-reason-disabled"): { |
| 120 |
"eos_data": [ |
| 121 |
"\n Errdisable Reason Timer Status Timer Interval\n ------------------------------ " |
| 122 |
"----------------- --------------\n acl Disabled 300\n " |
| 123 |
"bpduguard Enabled 300\n arp-inspection Enabled" |
| 124 |
" 30\n " |
| 125 |
], |
| 126 |
"inputs": {"reasons": [{"reason": "acl", "interval": 300}, {"reason": "arp-inspection", "interval": 30}]}, |
| 127 |
"expected": { |
| 128 |
"result": AntaTestStatus.FAILURE, |
| 129 |
"messages": ["Reason: acl - Invalid status - Expected: Enabled Actual: Disabled"], |
| 130 |
}, |
| 131 |
}, |
| 132 |
(VerifyErrdisableRecovery, "failure-interval-not-ok"): { |
| 133 |
"eos_data": [ |
| 134 |
"\n Errdisable Reason Timer Status Timer Interval\n ------------------------------ " |
| 135 |
"----------------- --------------\n acl Enabled 300\n " |
| 136 |
"bpduguard Enabled 300\n arp-inspection Enabled " |
| 137 |
" 30\n " |
| 138 |
], |
| 139 |
"inputs": {"reasons": [{"reason": "acl", "interval": 30}, {"reason": "arp-inspection", "interval": 30}]}, |
| 140 |
"expected": { |
| 141 |
"result": AntaTestStatus.FAILURE, |
| 142 |
"messages": ["Reason: acl - Incorrect interval - Expected: 30 second(s) Actual: 300 second(s)"], |
| 143 |
}, |
| 144 |
}, |
| 145 |
(VerifyErrdisableRecovery, "failure-interval-not-configurable"): { |
| 146 |
"eos_data": [ |
| 147 |
"\n Errdisable Reason Timer Status Timer Interval\n ------------------------------ " |
| 148 |
"----------------- --------------\n acl Enabled 300\n " |
| 149 |
"bpduguard Disabled N/A\n arp-inspection Enabled " |
| 150 |
" 30\n " |
| 151 |
], |
| 152 |
"inputs": {"reasons": [{"reason": "bpduguard", "interval": 30, "status": "Disabled"}]}, |
| 153 |
"expected": { |
| 154 |
"result": AntaTestStatus.FAILURE, |
| 155 |
"messages": ["Reason: bpduguard Status: Disabled Interval: 30 - Interval is not configurable"], |
| 156 |
}, |
| 157 |
}, |
| 158 |
(VerifyErrdisableRecovery, "failure-all-type"): { |
| 159 |
"eos_data": [ |
| 160 |
"\n Errdisable Reason Timer Status Timer Interval\n ------------------------------ " |
| 161 |
"----------------- --------------\n acl Disabled 300\n " |
| 162 |
"bpduguard Enabled 300\n arp-inspection Enabled " |
| 163 |
" 30\n " |
| 164 |
], |
| 165 |
"inputs": {"reasons": [{"reason": "acl", "interval": 30}, {"reason": "arp-inspection", "interval": 300}, {"reason": "tapagg", "interval": 30}]}, |
| 166 |
"expected": { |
| 167 |
"result": AntaTestStatus.FAILURE, |
| 168 |
"messages": [ |
| 169 |
"Reason: acl - Invalid status - Expected: Enabled Actual: Disabled", |
| 170 |
"Reason: acl - Incorrect interval - Expected: 30 second(s) Actual: 300 second(s)", |
| 171 |
"Reason: arp-inspection - Incorrect interval - Expected: 300 second(s) Actual: 30 second(s)", |
| 172 |
"Reason: tapagg Status: Enabled Interval: 30 - Not found", |
| 173 |
], |
| 174 |
}, |
| 175 |
}, |
| 176 |
} |