| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
"""Tests for anta.tests.mlag.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.mlag import VerifyMlagConfigSanity, VerifyMlagDualPrimary, VerifyMlagInterfaces, VerifyMlagPrimaryPriority, VerifyMlagReloadDelay, VerifyMlagStatus |
| 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 |
(VerifyMlagStatus, "success"): { |
| 21 |
"eos_data": [{"state": "active", "negStatus": "connected", "peerLinkStatus": "up", "localIntfStatus": "up"}], |
| 22 |
"expected": {"result": AntaTestStatus.SUCCESS}, |
| 23 |
}, |
| 24 |
(VerifyMlagStatus, "skipped"): { |
| 25 |
"eos_data": [{"state": "disabled"}], |
| 26 |
"expected": {"result": AntaTestStatus.SKIPPED, "messages": ["MLAG is disabled"]}, |
| 27 |
}, |
| 28 |
(VerifyMlagStatus, "failure-negotiation-status"): { |
| 29 |
"eos_data": [{"state": "active", "negStatus": "connecting", "peerLinkStatus": "up", "localIntfStatus": "up"}], |
| 30 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["MLAG negotiation status mismatch - Expected: connected Actual: connecting"]}, |
| 31 |
}, |
| 32 |
(VerifyMlagStatus, "failure-local-interface"): { |
| 33 |
"eos_data": [{"state": "active", "negStatus": "connected", "peerLinkStatus": "up", "localIntfStatus": "down"}], |
| 34 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["Operational state of the MLAG local interface is not correct - Expected: up Actual: down"]}, |
| 35 |
}, |
| 36 |
(VerifyMlagStatus, "failure-peer-link"): { |
| 37 |
"eos_data": [{"state": "active", "negStatus": "connected", "peerLinkStatus": "down", "localIntfStatus": "up"}], |
| 38 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["Operational state of the MLAG peer link is not correct - Expected: up Actual: down"]}, |
| 39 |
}, |
| 40 |
(VerifyMlagInterfaces, "success"): { |
| 41 |
"eos_data": [{"state": "active", "mlagPorts": {"Disabled": 0, "Configured": 0, "Inactive": 0, "Active-partial": 0, "Active-full": 1}}], |
| 42 |
"expected": {"result": AntaTestStatus.SUCCESS}, |
| 43 |
}, |
| 44 |
(VerifyMlagInterfaces, "skipped"): { |
| 45 |
"eos_data": [{"state": "disabled"}], |
| 46 |
"expected": {"result": AntaTestStatus.SKIPPED, "messages": ["MLAG is disabled"]}, |
| 47 |
}, |
| 48 |
(VerifyMlagInterfaces, "failure-active-partial"): { |
| 49 |
"eos_data": [{"state": "active", "mlagPorts": {"Disabled": 0, "Configured": 0, "Inactive": 0, "Active-partial": 1, "Active-full": 1}}], |
| 50 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["MLAG status is not ok - Inactive Ports: 0 Partial Active Ports: 1"]}, |
| 51 |
}, |
| 52 |
(VerifyMlagInterfaces, "failure-inactive"): { |
| 53 |
"eos_data": [{"state": "active", "mlagPorts": {"Disabled": 0, "Configured": 0, "Inactive": 1, "Active-partial": 1, "Active-full": 1}}], |
| 54 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["MLAG status is not ok - Inactive Ports: 1 Partial Active Ports: 1"]}, |
| 55 |
}, |
| 56 |
(VerifyMlagConfigSanity, "success"): { |
| 57 |
"eos_data": [{"globalConfiguration": {}, "interfaceConfiguration": {}, "mlagActive": True, "mlagConnected": True}], |
| 58 |
"expected": {"result": AntaTestStatus.SUCCESS}, |
| 59 |
}, |
| 60 |
(VerifyMlagConfigSanity, "skipped"): { |
| 61 |
"eos_data": [{"mlagActive": False}], |
| 62 |
"expected": {"result": AntaTestStatus.SKIPPED, "messages": ["MLAG is disabled"]}, |
| 63 |
}, |
| 64 |
(VerifyMlagConfigSanity, "failure-global"): { |
| 65 |
"eos_data": [ |
| 66 |
{ |
| 67 |
"globalConfiguration": {"mlag": {"globalParameters": {"dual-primary-detection-delay": {"localValue": "0", "peerValue": "200"}}}}, |
| 68 |
"interfaceConfiguration": {}, |
| 69 |
"mlagActive": True, |
| 70 |
"mlagConnected": True, |
| 71 |
} |
| 72 |
], |
| 73 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["MLAG config-sanity found in global configuration"]}, |
| 74 |
}, |
| 75 |
(VerifyMlagConfigSanity, "failure-interface"): { |
| 76 |
"eos_data": [ |
| 77 |
{ |
| 78 |
"globalConfiguration": {}, |
| 79 |
"interfaceConfiguration": {"trunk-native-vlan mlag30": {"interface": {"Port-Channel30": {"localValue": "123", "peerValue": "3700"}}}}, |
| 80 |
"mlagActive": True, |
| 81 |
"mlagConnected": True, |
| 82 |
} |
| 83 |
], |
| 84 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["MLAG config-sanity found in interface configuration"]}, |
| 85 |
}, |
| 86 |
(VerifyMlagReloadDelay, "success"): { |
| 87 |
"eos_data": [{"state": "active", "reloadDelay": 300, "reloadDelayNonMlag": 330}], |
| 88 |
"inputs": {"reload_delay": 300, "reload_delay_non_mlag": 330}, |
| 89 |
"expected": {"result": AntaTestStatus.SUCCESS}, |
| 90 |
}, |
| 91 |
(VerifyMlagReloadDelay, "skipped-disabled"): { |
| 92 |
"eos_data": [{"state": "disabled"}], |
| 93 |
"inputs": {"reload_delay": 300, "reload_delay_non_mlag": 330}, |
| 94 |
"expected": {"result": AntaTestStatus.SKIPPED, "messages": ["MLAG is disabled"]}, |
| 95 |
}, |
| 96 |
(VerifyMlagReloadDelay, "failure"): { |
| 97 |
"eos_data": [{"state": "active", "reloadDelay": 400, "reloadDelayNonMlag": 430}], |
| 98 |
"inputs": {"reload_delay": 300, "reload_delay_non_mlag": 330}, |
| 99 |
"expected": { |
| 100 |
"result": AntaTestStatus.FAILURE, |
| 101 |
"messages": ["MLAG reload-delay mismatch - Expected: 300s Actual: 400s", "Delay for non-MLAG ports mismatch - Expected: 330s Actual: 430s"], |
| 102 |
}, |
| 103 |
}, |
| 104 |
(VerifyMlagDualPrimary, "success"): { |
| 105 |
"eos_data": [ |
| 106 |
{ |
| 107 |
"state": "active", |
| 108 |
"dualPrimaryDetectionState": "configured", |
| 109 |
"dualPrimaryPortsErrdisabled": False, |
| 110 |
"dualPrimaryMlagRecoveryDelay": 60, |
| 111 |
"dualPrimaryNonMlagRecoveryDelay": 0, |
| 112 |
"detail": {"dualPrimaryDetectionDelay": 200, "dualPrimaryAction": "none"}, |
| 113 |
} |
| 114 |
], |
| 115 |
"inputs": {"detection_delay": 200, "errdisabled": False, "recovery_delay": 60, "recovery_delay_non_mlag": 0}, |
| 116 |
"expected": {"result": AntaTestStatus.SUCCESS}, |
| 117 |
}, |
| 118 |
(VerifyMlagDualPrimary, "skipped-disabled"): { |
| 119 |
"eos_data": [{"state": "disabled"}], |
| 120 |
"inputs": {"detection_delay": 200, "errdisabled": False, "recovery_delay": 60, "recovery_delay_non_mlag": 0}, |
| 121 |
"expected": {"result": AntaTestStatus.SKIPPED, "messages": ["MLAG is disabled"]}, |
| 122 |
}, |
| 123 |
(VerifyMlagDualPrimary, "failure-disabled"): { |
| 124 |
"eos_data": [{"state": "active", "dualPrimaryDetectionState": "disabled", "dualPrimaryPortsErrdisabled": False}], |
| 125 |
"inputs": {"detection_delay": 200, "errdisabled": False, "recovery_delay": 60, "recovery_delay_non_mlag": 0}, |
| 126 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["Dual-primary detection is disabled"]}, |
| 127 |
}, |
| 128 |
(VerifyMlagDualPrimary, "failure-wrong-timers"): { |
| 129 |
"eos_data": [ |
| 130 |
{ |
| 131 |
"state": "active", |
| 132 |
"dualPrimaryDetectionState": "configured", |
| 133 |
"dualPrimaryPortsErrdisabled": False, |
| 134 |
"dualPrimaryMlagRecoveryDelay": 160, |
| 135 |
"dualPrimaryNonMlagRecoveryDelay": 0, |
| 136 |
"detail": {"dualPrimaryDetectionDelay": 300, "dualPrimaryAction": "none"}, |
| 137 |
} |
| 138 |
], |
| 139 |
"inputs": {"detection_delay": 200, "errdisabled": False, "recovery_delay": 60, "recovery_delay_non_mlag": 0}, |
| 140 |
"expected": { |
| 141 |
"result": AntaTestStatus.FAILURE, |
| 142 |
"messages": [ |
| 143 |
"Dual-primary detection delay mismatch - Expected: 200 Actual: 300", |
| 144 |
"Dual-primary MLAG recovery delay mismatch - Expected: 60 Actual: 160", |
| 145 |
], |
| 146 |
}, |
| 147 |
}, |
| 148 |
(VerifyMlagDualPrimary, "failure-wrong-action"): { |
| 149 |
"eos_data": [ |
| 150 |
{ |
| 151 |
"state": "active", |
| 152 |
"dualPrimaryDetectionState": "configured", |
| 153 |
"dualPrimaryPortsErrdisabled": False, |
| 154 |
"dualPrimaryMlagRecoveryDelay": 60, |
| 155 |
"dualPrimaryNonMlagRecoveryDelay": 0, |
| 156 |
"detail": {"dualPrimaryDetectionDelay": 200, "dualPrimaryAction": "none"}, |
| 157 |
} |
| 158 |
], |
| 159 |
"inputs": {"detection_delay": 200, "errdisabled": True, "recovery_delay": 60, "recovery_delay_non_mlag": 0}, |
| 160 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["Dual-primary action mismatch - Expected: errdisableAllInterfaces Actual: none"]}, |
| 161 |
}, |
| 162 |
(VerifyMlagDualPrimary, "failure-wrong-non-mlag-delay"): { |
| 163 |
"eos_data": [ |
| 164 |
{ |
| 165 |
"state": "active", |
| 166 |
"dualPrimaryDetectionState": "configured", |
| 167 |
"dualPrimaryPortsErrdisabled": False, |
| 168 |
"dualPrimaryMlagRecoveryDelay": 60, |
| 169 |
"dualPrimaryNonMlagRecoveryDelay": 120, |
| 170 |
"detail": {"dualPrimaryDetectionDelay": 200, "dualPrimaryAction": "errdisableAllInterfaces"}, |
| 171 |
} |
| 172 |
], |
| 173 |
"inputs": {"detection_delay": 200, "errdisabled": True, "recovery_delay": 60, "recovery_delay_non_mlag": 60}, |
| 174 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["Dual-primary non MLAG recovery delay mismatch - Expected: 60 Actual: 120"]}, |
| 175 |
}, |
| 176 |
(VerifyMlagPrimaryPriority, "success"): { |
| 177 |
"eos_data": [{"state": "active", "detail": {"mlagState": "primary", "primaryPriority": 32767}}], |
| 178 |
"inputs": {"primary_priority": 32767}, |
| 179 |
"expected": {"result": AntaTestStatus.SUCCESS}, |
| 180 |
}, |
| 181 |
(VerifyMlagPrimaryPriority, "skipped-disabled"): { |
| 182 |
"eos_data": [{"state": "disabled"}], |
| 183 |
"inputs": {"primary_priority": 32767}, |
| 184 |
"expected": {"result": AntaTestStatus.SKIPPED, "messages": ["MLAG is disabled"]}, |
| 185 |
}, |
| 186 |
(VerifyMlagPrimaryPriority, "failure-not-primary"): { |
| 187 |
"eos_data": [{"state": "active", "detail": {"mlagState": "secondary", "primaryPriority": 32767}}], |
| 188 |
"inputs": {"primary_priority": 32767}, |
| 189 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["The device is not set as MLAG primary"]}, |
| 190 |
}, |
| 191 |
(VerifyMlagPrimaryPriority, "failure-incorrect-priority"): { |
| 192 |
"eos_data": [{"state": "active", "detail": {"mlagState": "secondary", "primaryPriority": 32767}}], |
| 193 |
"inputs": {"primary_priority": 1}, |
| 194 |
"expected": { |
| 195 |
"result": AntaTestStatus.FAILURE, |
| 196 |
"messages": ["The device is not set as MLAG primary", "MLAG primary priority mismatch - Expected: 1 Actual: 32767"], |
| 197 |
}, |
| 198 |
}, |
| 199 |
} |