| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
"""Data for testing anta.tests.cvx.""" |
| 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.cvx import VerifyActiveCVXConnections, VerifyCVXClusterStatus, VerifyManagementCVX, VerifyMcsClientMounts, VerifyMcsServerMounts |
| 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 |
(VerifyMcsClientMounts, "success"): { |
| 21 |
"eos_data": [{"mountStates": [{"path": "mcs/v1/toSwitch/28-99-3a-8f-93-7b", "type": "Mcs::DeviceConfigV1", "state": "mountStateMountComplete"}]}], |
| 22 |
"expected": {"result": AntaTestStatus.SUCCESS}, |
| 23 |
}, |
| 24 |
(VerifyMcsClientMounts, "success-haclient"): { |
| 25 |
"eos_data": [ |
| 26 |
{ |
| 27 |
"mountStates": [ |
| 28 |
{"path": "mcs/v1/apiCfgRedState", "type": "Mcs::ApiConfigRedundancyState", "state": "mountStateMountComplete"}, |
| 29 |
{"path": "mcs/v1/toSwitch/00-1c-73-74-c0-8b", "type": "Mcs::DeviceConfigV1", "state": "mountStateMountComplete"}, |
| 30 |
] |
| 31 |
} |
| 32 |
], |
| 33 |
"expected": {"result": AntaTestStatus.SUCCESS}, |
| 34 |
}, |
| 35 |
(VerifyMcsClientMounts, "success-partial-non-mcs"): { |
| 36 |
"eos_data": [ |
| 37 |
{ |
| 38 |
"mountStates": [ |
| 39 |
{"path": "blah/blah/blah", "type": "blah::blah", "state": "mountStatePreservedUnmounted"}, |
| 40 |
{"path": "mcs/v1/toSwitch/00-1c-73-74-c0-8b", "type": "Mcs::DeviceConfigV1", "state": "mountStateMountComplete"}, |
| 41 |
] |
| 42 |
} |
| 43 |
], |
| 44 |
"expected": {"result": AntaTestStatus.SUCCESS}, |
| 45 |
}, |
| 46 |
(VerifyMcsClientMounts, "failure-nomounts"): { |
| 47 |
"eos_data": [{"mountStates": []}], |
| 48 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["MCS Client mount states are not present"]}, |
| 49 |
}, |
| 50 |
(VerifyMcsClientMounts, "failure-mountStatePreservedUnmounted"): { |
| 51 |
"eos_data": [{"mountStates": [{"path": "mcs/v1/toSwitch/28-99-3a-8f-93-7b", "type": "Mcs::DeviceConfigV1", "state": "mountStatePreservedUnmounted"}]}], |
| 52 |
"expected": { |
| 53 |
"result": AntaTestStatus.FAILURE, |
| 54 |
"messages": ["MCS Client mount states are not valid - Expected: mountStateMountComplete Actual: mountStatePreservedUnmounted"], |
| 55 |
}, |
| 56 |
}, |
| 57 |
(VerifyMcsClientMounts, "failure-partial-haclient"): { |
| 58 |
"eos_data": [ |
| 59 |
{ |
| 60 |
"mountStates": [ |
| 61 |
{"path": "mcs/v1/apiCfgRedState", "type": "Mcs::ApiConfigRedundancyState", "state": "mountStateMountComplete"}, |
| 62 |
{"path": "mcs/v1/toSwitch/00-1c-73-74-c0-8b", "type": "Mcs::DeviceConfigV1", "state": "mountStatePreservedUnmounted"}, |
| 63 |
] |
| 64 |
} |
| 65 |
], |
| 66 |
"expected": { |
| 67 |
"result": AntaTestStatus.FAILURE, |
| 68 |
"messages": ["MCS Client mount states are not valid - Expected: mountStateMountComplete Actual: mountStatePreservedUnmounted"], |
| 69 |
}, |
| 70 |
}, |
| 71 |
(VerifyMcsClientMounts, "failure-full-haclient"): { |
| 72 |
"eos_data": [ |
| 73 |
{ |
| 74 |
"mountStates": [ |
| 75 |
{"path": "blah/blah/blah", "type": "blah::blahState", "state": "mountStatePreservedUnmounted"}, |
| 76 |
{"path": "mcs/v1/toSwitch/00-1c-73-74-c0-8b", "type": "Mcs::DeviceConfigV1", "state": "mountStatePreservedUnmounted"}, |
| 77 |
] |
| 78 |
} |
| 79 |
], |
| 80 |
"expected": { |
| 81 |
"result": AntaTestStatus.FAILURE, |
| 82 |
"messages": ["MCS Client mount states are not valid - Expected: mountStateMountComplete Actual: mountStatePreservedUnmounted"], |
| 83 |
}, |
| 84 |
}, |
| 85 |
(VerifyMcsClientMounts, "failure-non-mcs-client"): { |
| 86 |
"eos_data": [{"mountStates": [{"path": "blah/blah/blah", "type": "blah::blahState", "state": "mountStatePreservedUnmounted"}]}], |
| 87 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["MCS Client mount states are not present"]}, |
| 88 |
}, |
| 89 |
(VerifyMcsClientMounts, "failure-partial-mcs-client"): { |
| 90 |
"eos_data": [ |
| 91 |
{ |
| 92 |
"mountStates": [ |
| 93 |
{"path": "blah/blah/blah", "type": "blah::blahState", "state": "mountStatePreservedUnmounted"}, |
| 94 |
{"path": "blah/blah/blah", "type": "Mcs::DeviceConfigV1", "state": "mountStatePreservedUnmounted"}, |
| 95 |
] |
| 96 |
} |
| 97 |
], |
| 98 |
"expected": { |
| 99 |
"result": AntaTestStatus.FAILURE, |
| 100 |
"messages": ["MCS Client mount states are not valid - Expected: mountStateMountComplete Actual: mountStatePreservedUnmounted"], |
| 101 |
}, |
| 102 |
}, |
| 103 |
(VerifyManagementCVX, "success-enabled"): { |
| 104 |
"eos_data": [{"clusterStatus": {"enabled": True}}], |
| 105 |
"inputs": {"enabled": True}, |
| 106 |
"expected": {"result": AntaTestStatus.SUCCESS}, |
| 107 |
}, |
| 108 |
(VerifyManagementCVX, "success-disabled"): { |
| 109 |
"eos_data": [{"clusterStatus": {"enabled": False}}], |
| 110 |
"inputs": {"enabled": False}, |
| 111 |
"expected": {"result": AntaTestStatus.SUCCESS}, |
| 112 |
}, |
| 113 |
(VerifyManagementCVX, "failure-invalid-state"): { |
| 114 |
"eos_data": [{"clusterStatus": {"enabled": False}}], |
| 115 |
"inputs": {"enabled": True}, |
| 116 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["Management CVX status is not valid: Expected: enabled Actual: disabled"]}, |
| 117 |
}, |
| 118 |
(VerifyManagementCVX, "failure-no-enabled state"): { |
| 119 |
"eos_data": [{"clusterStatus": {}}], |
| 120 |
"inputs": {"enabled": False}, |
| 121 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["Management CVX status - Not configured"]}, |
| 122 |
}, |
| 123 |
(VerifyManagementCVX, "failure - no clusterStatus"): { |
| 124 |
"eos_data": [{}], |
| 125 |
"inputs": {"enabled": False}, |
| 126 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["Management CVX status - Not configured"]}, |
| 127 |
}, |
| 128 |
(VerifyMcsServerMounts, "success"): { |
| 129 |
"eos_data": [ |
| 130 |
{ |
| 131 |
"connections": [ |
| 132 |
{ |
| 133 |
"hostname": "media-leaf-1", |
| 134 |
"mounts": [ |
| 135 |
{ |
| 136 |
"service": "Mcs", |
| 137 |
"mountStates": [ |
| 138 |
{ |
| 139 |
"pathStates": [ |
| 140 |
{"path": "mcs/v1/apiCfgRedStatus", "type": "Mcs::ApiConfigRedundancyStatus", "state": "mountStateMountComplete"}, |
| 141 |
{"path": "mcs/v1/activeflows", "type": "Mcs::ActiveFlows", "state": "mountStateMountComplete"}, |
| 142 |
{"path": "mcs/switch/status", "type": "Mcs::Client::Status", "state": "mountStateMountComplete"}, |
| 143 |
] |
| 144 |
} |
| 145 |
], |
| 146 |
} |
| 147 |
], |
| 148 |
} |
| 149 |
] |
| 150 |
} |
| 151 |
], |
| 152 |
"inputs": {"connections_count": 1}, |
| 153 |
"expected": {"result": AntaTestStatus.SUCCESS}, |
| 154 |
}, |
| 155 |
(VerifyMcsServerMounts, "failure-no-mounts"): { |
| 156 |
"eos_data": [{"connections": [{"hostname": "media-leaf-1", "mounts": []}]}], |
| 157 |
"inputs": {"connections_count": 1}, |
| 158 |
"expected": { |
| 159 |
"result": AntaTestStatus.FAILURE, |
| 160 |
"messages": ["Host: media-leaf-1 - No mount status found", "Incorrect CVX successful connections count - Expected: 1 Actual: 0"], |
| 161 |
}, |
| 162 |
}, |
| 163 |
(VerifyMcsServerMounts, "failure-unexpected-number-paths"): { |
| 164 |
"eos_data": [ |
| 165 |
{ |
| 166 |
"connections": [ |
| 167 |
{ |
| 168 |
"hostname": "media-leaf-1", |
| 169 |
"mounts": [ |
| 170 |
{ |
| 171 |
"service": "Mcs", |
| 172 |
"mountStates": [ |
| 173 |
{ |
| 174 |
"pathStates": [ |
| 175 |
{"path": "mcs/v1/apiCfgRedStatus", "type": "Mcs::ApiStatus", "state": "mountStateMountComplete"}, |
| 176 |
{"path": "mcs/v1/activeflows", "type": "Mcs::ActiveFlows", "state": "mountStateMountComplete"}, |
| 177 |
] |
| 178 |
} |
| 179 |
], |
| 180 |
} |
| 181 |
], |
| 182 |
} |
| 183 |
] |
| 184 |
} |
| 185 |
], |
| 186 |
"inputs": {"connections_count": 1}, |
| 187 |
"expected": { |
| 188 |
"result": AntaTestStatus.FAILURE, |
| 189 |
"messages": [ |
| 190 |
"Host: media-leaf-1 - Incorrect number of mount path states - Expected: 3 Actual: 2", |
| 191 |
"Host: media-leaf-1 - Unexpected MCS path type - Expected: Mcs::ApiConfigRedundancyStatus, " |
| 192 |
"Mcs::ActiveFlows, Mcs::Client::Status Actual: Mcs::ApiStatus", |
| 193 |
], |
| 194 |
}, |
| 195 |
}, |
| 196 |
(VerifyMcsServerMounts, "failure-unexpected-path-type"): { |
| 197 |
"eos_data": [ |
| 198 |
{ |
| 199 |
"connections": [ |
| 200 |
{ |
| 201 |
"hostname": "media-leaf-1", |
| 202 |
"mounts": [ |
| 203 |
{ |
| 204 |
"service": "Mcs", |
| 205 |
"mountStates": [ |
| 206 |
{ |
| 207 |
"pathStates": [ |
| 208 |
{"path": "mcs/v1/apiCfgRedStatus", "type": "Mcs::ApiStatus", "state": "mountStateMountComplete"}, |
| 209 |
{"path": "mcs/v1/activeflows", "type": "Mcs::ActiveFlows", "state": "mountStateMountComplete"}, |
| 210 |
{"path": "mcs/switch/status", "type": "Mcs::Client::Status", "state": "mountStateMountComplete"}, |
| 211 |
] |
| 212 |
} |
| 213 |
], |
| 214 |
} |
| 215 |
], |
| 216 |
} |
| 217 |
] |
| 218 |
} |
| 219 |
], |
| 220 |
"inputs": {"connections_count": 1}, |
| 221 |
"expected": { |
| 222 |
"result": AntaTestStatus.FAILURE, |
| 223 |
"messages": [ |
| 224 |
"Host: media-leaf-1 - Unexpected MCS path type - Expected: Mcs::ApiConfigRedundancyStatus, Mcs::ActiveFlows, " |
| 225 |
"Mcs::Client::Status Actual: Mcs::ApiStatus" |
| 226 |
], |
| 227 |
}, |
| 228 |
}, |
| 229 |
(VerifyMcsServerMounts, "failure-invalid-mount-state"): { |
| 230 |
"eos_data": [ |
| 231 |
{ |
| 232 |
"connections": [ |
| 233 |
{ |
| 234 |
"hostname": "media-leaf-1", |
| 235 |
"mounts": [ |
| 236 |
{ |
| 237 |
"service": "Mcs", |
| 238 |
"mountStates": [ |
| 239 |
{ |
| 240 |
"pathStates": [ |
| 241 |
{"path": "mcs/v1/apiCfgRedStatus", "type": "Mcs::ApiConfigRedundancyStatus", "state": "mountStateMountFailed"}, |
| 242 |
{"path": "mcs/v1/activeflows", "type": "Mcs::ActiveFlows", "state": "mountStateMountComplete"}, |
| 243 |
{"path": "mcs/switch/status", "type": "Mcs::Client::Status", "state": "mountStateMountComplete"}, |
| 244 |
] |
| 245 |
} |
| 246 |
], |
| 247 |
} |
| 248 |
], |
| 249 |
} |
| 250 |
] |
| 251 |
} |
| 252 |
], |
| 253 |
"inputs": {"connections_count": 1}, |
| 254 |
"expected": { |
| 255 |
"result": AntaTestStatus.FAILURE, |
| 256 |
"messages": [ |
| 257 |
"Host: media-leaf-1 Path Type: Mcs::ApiConfigRedundancyStatus - MCS server mount state is not valid - " |
| 258 |
"Expected: mountStateMountComplete Actual:mountStateMountFailed" |
| 259 |
], |
| 260 |
}, |
| 261 |
}, |
| 262 |
(VerifyMcsServerMounts, "failure-no-mcs-mount"): { |
| 263 |
"eos_data": [ |
| 264 |
{ |
| 265 |
"connections": [ |
| 266 |
{ |
| 267 |
"hostname": "media-leaf-1", |
| 268 |
"mounts": [ |
| 269 |
{ |
| 270 |
"service": "blah-blah", |
| 271 |
"mountStates": [{"pathStates": [{"path": "blah-blah-path", "type": "blah-blah-type", "state": "blah-blah-state"}]}], |
| 272 |
} |
| 273 |
], |
| 274 |
} |
| 275 |
] |
| 276 |
} |
| 277 |
], |
| 278 |
"inputs": {"connections_count": 1}, |
| 279 |
"expected": { |
| 280 |
"result": AntaTestStatus.FAILURE, |
| 281 |
"messages": ["MCS mount state not detected", "Incorrect CVX successful connections count - Expected: 1 Actual: 0"], |
| 282 |
}, |
| 283 |
}, |
| 284 |
(VerifyMcsServerMounts, "failure-connections"): { |
| 285 |
"eos_data": [{}], |
| 286 |
"inputs": {"connections_count": 1}, |
| 287 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["CVX connections are not available"]}, |
| 288 |
}, |
| 289 |
(VerifyActiveCVXConnections, "success"): { |
| 290 |
"eos_data": [ |
| 291 |
{ |
| 292 |
"connections": [ |
| 293 |
{"switchId": "fc:bd:67:c3:16:55", "hostname": "lyv563", "oobConnectionActive": True}, |
| 294 |
{"switchId": "00:1c:73:3c:e3:9e", "hostname": "tg264", "oobConnectionActive": True}, |
| 295 |
] |
| 296 |
} |
| 297 |
], |
| 298 |
"inputs": {"connections_count": 2}, |
| 299 |
"expected": {"result": AntaTestStatus.SUCCESS}, |
| 300 |
}, |
| 301 |
(VerifyActiveCVXConnections, "failure"): { |
| 302 |
"eos_data": [ |
| 303 |
{ |
| 304 |
"connections": [ |
| 305 |
{"switchId": "fc:bd:67:c3:16:55", "hostname": "lyv563", "oobConnectionActive": False}, |
| 306 |
{"switchId": "00:1c:73:3c:e3:9e", "hostname": "tg264", "oobConnectionActive": True}, |
| 307 |
] |
| 308 |
} |
| 309 |
], |
| 310 |
"inputs": {"connections_count": 2}, |
| 311 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["CVX active connections count - Expected: 2 Actual: 1"]}, |
| 312 |
}, |
| 313 |
(VerifyActiveCVXConnections, "failure-no-connections"): { |
| 314 |
"eos_data": [{}], |
| 315 |
"inputs": {"connections_count": 2}, |
| 316 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["CVX connections are not available"]}, |
| 317 |
}, |
| 318 |
(VerifyCVXClusterStatus, "success-all"): { |
| 319 |
"eos_data": [ |
| 320 |
{ |
| 321 |
"enabled": True, |
| 322 |
"clusterMode": True, |
| 323 |
"clusterStatus": { |
| 324 |
"role": "Master", |
| 325 |
"peerStatus": { |
| 326 |
"cvx-red-2": {"peerName": "cvx-red-2", "registrationState": "Registration complete"}, |
| 327 |
"cvx-red-3": {"peerName": "cvx-red-3", "registrationState": "Registration complete"}, |
| 328 |
}, |
| 329 |
}, |
| 330 |
} |
| 331 |
], |
| 332 |
"inputs": { |
| 333 |
"role": "Master", |
| 334 |
"peer_status": [ |
| 335 |
{"peer_name": "cvx-red-2", "registrationState": "Registration complete"}, |
| 336 |
{"peer_name": "cvx-red-3", "registrationState": "Registration complete"}, |
| 337 |
], |
| 338 |
}, |
| 339 |
"expected": {"result": AntaTestStatus.SUCCESS}, |
| 340 |
}, |
| 341 |
(VerifyCVXClusterStatus, "failure-invalid-role"): { |
| 342 |
"eos_data": [ |
| 343 |
{ |
| 344 |
"enabled": True, |
| 345 |
"clusterMode": True, |
| 346 |
"clusterStatus": { |
| 347 |
"role": "Standby", |
| 348 |
"peerStatus": { |
| 349 |
"cvx-red-2": {"peerName": "cvx-red-2", "registrationState": "Registration complete"}, |
| 350 |
"cvx-red-3": {"peerName": "cvx-red-3", "registrationState": "Registration complete"}, |
| 351 |
}, |
| 352 |
}, |
| 353 |
} |
| 354 |
], |
| 355 |
"inputs": { |
| 356 |
"role": "Master", |
| 357 |
"peer_status": [ |
| 358 |
{"peer_name": "cvx-red-2", "registrationState": "Registration complete"}, |
| 359 |
{"peer_name": "cvx-red-3", "registrationState": "Registration complete"}, |
| 360 |
], |
| 361 |
}, |
| 362 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["CVX Role is not valid: Expected: Master Actual: Standby"]}, |
| 363 |
}, |
| 364 |
(VerifyCVXClusterStatus, "failure-cvx-enabled"): { |
| 365 |
"eos_data": [{"enabled": False, "clusterMode": True, "clusterStatus": {"role": "Master", "peerStatus": {}}}], |
| 366 |
"inputs": {"role": "Master", "peer_status": []}, |
| 367 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["CVX Server status is not enabled"]}, |
| 368 |
}, |
| 369 |
(VerifyCVXClusterStatus, "failure-cluster-enabled"): { |
| 370 |
"eos_data": [{"enabled": True, "clusterMode": False, "clusterStatus": {}}], |
| 371 |
"inputs": {"role": "Master", "peer_status": []}, |
| 372 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["CVX Server is not a cluster"]}, |
| 373 |
}, |
| 374 |
(VerifyCVXClusterStatus, "failure-missing-peers"): { |
| 375 |
"eos_data": [ |
| 376 |
{ |
| 377 |
"enabled": True, |
| 378 |
"clusterMode": True, |
| 379 |
"clusterStatus": {"role": "Master", "peerStatus": {"cvx-red-2": {"peerName": "cvx-red-2", "registrationState": "Registration complete"}}}, |
| 380 |
} |
| 381 |
], |
| 382 |
"inputs": { |
| 383 |
"role": "Master", |
| 384 |
"peer_status": [ |
| 385 |
{"peer_name": "cvx-red-2", "registrationState": "Registration complete"}, |
| 386 |
{"peer_name": "cvx-red-3", "registrationState": "Registration complete"}, |
| 387 |
], |
| 388 |
}, |
| 389 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["Unexpected number of peers - Expected: 2 Actual: 1", "cvx-red-3 - Not present"]}, |
| 390 |
}, |
| 391 |
(VerifyCVXClusterStatus, "failure-invalid-peers"): { |
| 392 |
"eos_data": [{"enabled": True, "clusterMode": True, "clusterStatus": {"role": "Master", "peerStatus": {}}}], |
| 393 |
"inputs": { |
| 394 |
"role": "Master", |
| 395 |
"peer_status": [ |
| 396 |
{"peer_name": "cvx-red-2", "registrationState": "Registration complete"}, |
| 397 |
{"peer_name": "cvx-red-3", "registrationState": "Registration complete"}, |
| 398 |
], |
| 399 |
}, |
| 400 |
"expected": { |
| 401 |
"result": AntaTestStatus.FAILURE, |
| 402 |
"messages": ["Unexpected number of peers - Expected: 2 Actual: 0", "cvx-red-2 - Not present", "cvx-red-3 - Not present"], |
| 403 |
}, |
| 404 |
}, |
| 405 |
(VerifyCVXClusterStatus, "failure-registration-error"): { |
| 406 |
"eos_data": [ |
| 407 |
{ |
| 408 |
"enabled": True, |
| 409 |
"clusterMode": True, |
| 410 |
"clusterStatus": { |
| 411 |
"role": "Master", |
| 412 |
"peerStatus": { |
| 413 |
"cvx-red-2": {"peerName": "cvx-red-2", "registrationState": "Registration error"}, |
| 414 |
"cvx-red-3": {"peerName": "cvx-red-3", "registrationState": "Registration complete"}, |
| 415 |
}, |
| 416 |
}, |
| 417 |
} |
| 418 |
], |
| 419 |
"inputs": { |
| 420 |
"role": "Master", |
| 421 |
"peer_status": [ |
| 422 |
{"peer_name": "cvx-red-2", "registrationState": "Registration complete"}, |
| 423 |
{"peer_name": "cvx-red-3", "registrationState": "Registration complete"}, |
| 424 |
], |
| 425 |
}, |
| 426 |
"expected": { |
| 427 |
"result": AntaTestStatus.FAILURE, |
| 428 |
"messages": ["cvx-red-2 - Invalid registration state - Expected: Registration complete Actual: Registration error"], |
| 429 |
}, |
| 430 |
}, |
| 431 |
} |