Debian Codegraph @

tests/units/anta_tests/test_path_selection.py

raw symbols SCIP
1 # Copyright (c) 2023-2026 Arista Networks, Inc.
2 # Use of this source code is governed by the Apache License 2.0
3 # that can be found in the LICENSE file.
4 """Tests for anta.tests.path_selection.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.path_selection import VerifyPathsHealth, VerifySpecificPath
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 (VerifyPathsHealth, "success"): {
21 "eos_data": [
22 {
23 "dpsPeers": {
24 "10.255.0.1": {
25 "dpsGroups": {
26 "internet": {"dpsPaths": {"path3": {"state": "routeResolved", "dpsSessions": {"0": {"active": True}}}}},
27 "mpls": {"dpsPaths": {"path4": {"state": "ipsecEstablished", "dpsSessions": {"0": {"active": True}}}}},
28 }
29 },
30 "10.255.0.2": {
31 "dpsGroups": {
32 "internet": {"dpsPaths": {"path1": {"state": "ipsecEstablished", "dpsSessions": {"0": {"active": True}}}}},
33 "mpls": {"dpsPaths": {"path2": {"state": "routeResolved", "dpsSessions": {"0": {"active": True}}}}},
34 }
35 },
36 }
37 }
38 ],
39 "inputs": {},
40 "expected": {"result": AntaTestStatus.SUCCESS},
41 },
42 (VerifyPathsHealth, "failure-no-peer"): {
43 "eos_data": [{"dpsPeers": {}}],
44 "inputs": {},
45 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["No path configured for router path-selection"]},
46 },
47 (VerifyPathsHealth, "failure-not-established"): {
48 "eos_data": [
49 {
50 "dpsPeers": {
51 "10.255.0.1": {
52 "dpsGroups": {
53 "internet": {"dpsPaths": {"path3": {"state": "ipsecPending", "dpsSessions": {"0": {"active": False}}}}},
54 "mpls": {"dpsPaths": {"path4": {"state": "ipsecPending", "dpsSessions": {"0": {"active": False}}}}},
55 }
56 },
57 "10.255.0.2": {
58 "dpsGroups": {
59 "internet": {"dpsPaths": {"path1": {"state": "ipsecEstablished", "dpsSessions": {"0": {"active": True}}}}},
60 "mpls": {"dpsPaths": {"path2": {"state": "ipsecPending", "dpsSessions": {"0": {"active": False}}}}},
61 }
62 },
63 }
64 }
65 ],
66 "inputs": {},
67 "expected": {
68 "result": AntaTestStatus.FAILURE,
69 "messages": [
70 "Peer: 10.255.0.1 Path Group: internet - Invalid path state - Expected: ipsecEstablished, routeResolved Actual: ipsecPending",
71 "Peer: 10.255.0.1 Path Group: mpls - Invalid path state - Expected: ipsecEstablished, routeResolved Actual: ipsecPending",
72 "Peer: 10.255.0.2 Path Group: mpls - Invalid path state - Expected: ipsecEstablished, routeResolved Actual: ipsecPending",
73 ],
74 },
75 },
76 (VerifyPathsHealth, "failure-inactive"): {
77 "eos_data": [
78 {
79 "dpsPeers": {
80 "10.255.0.1": {
81 "dpsGroups": {
82 "internet": {"dpsPaths": {"path3": {"state": "routeResolved", "dpsSessions": {"0": {"active": False}}}}},
83 "mpls": {"dpsPaths": {"path4": {"state": "routeResolved", "dpsSessions": {"0": {"active": False}}}}},
84 }
85 },
86 "10.255.0.2": {
87 "dpsGroups": {
88 "internet": {"dpsPaths": {"path1": {"state": "routeResolved", "dpsSessions": {"0": {"active": True}}}}},
89 "mpls": {"dpsPaths": {"path2": {"state": "routeResolved", "dpsSessions": {"0": {"active": False}}}}},
90 }
91 },
92 }
93 }
94 ],
95 "inputs": {},
96 "expected": {
97 "result": AntaTestStatus.FAILURE,
98 "messages": [
99 "Peer: 10.255.0.1 Path Group internet - Telemetry state inactive",
100 "Peer: 10.255.0.1 Path Group mpls - Telemetry state inactive",
101 "Peer: 10.255.0.2 Path Group mpls - Telemetry state inactive",
102 ],
103 },
104 },
105 (VerifySpecificPath, "success"): {
106 "eos_data": [
107 {
108 "dpsPeers": {
109 "10.255.0.2": {
110 "dpsGroups": {
111 "mpls": {
112 "dpsPaths": {
113 "path7": {},
114 "path8": {
115 "source": "172.18.13.2",
116 "destination": "172.18.15.2",
117 "state": "ipsecEstablished",
118 "dpsSessions": {"0": {"active": True}},
119 },
120 }
121 },
122 "internet": {},
123 }
124 },
125 "10.255.0.1": {
126 "dpsGroups": {
127 "internet": {
128 "dpsPaths": {
129 "path6": {
130 "source": "100.64.3.2",
131 "destination": "100.64.1.2",
132 "state": "ipsecEstablished",
133 "dpsSessions": {"0": {"active": True}},
134 }
135 }
136 },
137 "mpls": {},
138 }
139 },
140 }
141 }
142 ],
143 "inputs": {
144 "paths": [
145 {"peer": "10.255.0.1", "path_group": "internet", "source_address": "100.64.3.2", "destination_address": "100.64.1.2"},
146 {"peer": "10.255.0.2", "path_group": "mpls", "source_address": "172.18.13.2", "destination_address": "172.18.15.2"},
147 ]
148 },
149 "expected": {
150 "result": AntaTestStatus.SUCCESS,
151 "atomic_results": [
152 {
153 "description": "Peer: 10.255.0.1 Path Group: internet Source: 100.64.3.2 Destination: 100.64.1.2",
154 "result": AntaTestStatus.SUCCESS,
155 },
156 {
157 "description": "Peer: 10.255.0.2 Path Group: mpls Source: 172.18.13.2 Destination: 172.18.15.2",
158 "result": AntaTestStatus.SUCCESS,
159 },
160 ],
161 },
162 },
163 (VerifySpecificPath, "success-with-description"): {
164 "eos_data": [
165 {
166 "dpsPeers": {
167 "10.255.0.2": {
168 "dpsGroups": {
169 "mpls": {
170 "dpsPaths": {
171 "path7": {},
172 "path8": {
173 "source": "172.18.13.2",
174 "destination": "172.18.15.2",
175 "state": "ipsecEstablished",
176 "dpsSessions": {"0": {"active": True}},
177 },
178 }
179 },
180 "internet": {},
181 }
182 },
183 }
184 }
185 ],
186 "inputs": {
187 "paths": [
188 {
189 "peer": "10.255.0.2",
190 "description": "Branch Pune peer",
191 "path_group": "mpls",
192 "source_address": "172.18.13.2",
193 "destination_address": "172.18.15.2",
194 },
195 ]
196 },
197 "expected": {
198 "result": AntaTestStatus.SUCCESS,
199 "atomic_results": [
200 {
201 "description": "Peer: 10.255.0.2 (Branch Pune peer) Path Group: mpls Source: 172.18.13.2 Destination: 172.18.15.2",
202 "result": AntaTestStatus.SUCCESS,
203 }
204 ],
205 },
206 },
207 (VerifySpecificPath, "failure-expected-path-group-not-found"): {
208 "eos_data": [{"dpsPeers": {"10.255.0.2": {"dpsGroups": {"internet": {}}}, "10.255.0.1": {"peerName": "", "dpsGroups": {"mpls": {}}}}}],
209 "inputs": {
210 "paths": [
211 {"peer": "10.255.0.1", "path_group": "internet", "source_address": "100.64.3.2", "destination_address": "100.64.1.2"},
212 {"peer": "10.255.0.2", "path_group": "mpls", "source_address": "172.18.13.2", "destination_address": "172.18.15.2"},
213 ]
214 },
215 "expected": {
216 "result": AntaTestStatus.FAILURE,
217 "messages": [
218 "Peer: 10.255.0.1 Path Group: internet Source: 100.64.3.2 Destination: 100.64.1.2 - No DPS path found for this peer and path group",
219 "Peer: 10.255.0.2 Path Group: mpls Source: 172.18.13.2 Destination: 172.18.15.2 - No DPS path found for this peer and path group",
220 ],
221 "atomic_results": [
222 {
223 "description": "Peer: 10.255.0.1 Path Group: internet Source: 100.64.3.2 Destination: 100.64.1.2",
224 "result": AntaTestStatus.FAILURE,
225 "messages": ["No DPS path found for this peer and path group"],
226 },
227 {
228 "description": "Peer: 10.255.0.2 Path Group: mpls Source: 172.18.13.2 Destination: 172.18.15.2",
229 "result": AntaTestStatus.FAILURE,
230 "messages": ["No DPS path found for this peer and path group"],
231 },
232 ],
233 },
234 },
235 (VerifySpecificPath, "failure-no-router-path-configured"): {
236 "eos_data": [{"dpsPeers": {}}],
237 "inputs": {"paths": [{"peer": "10.255.0.1", "path_group": "internet", "source_address": "100.64.3.2", "destination_address": "100.64.1.2"}]},
238 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["Router path-selection not configured"]},
239 },
240 (VerifySpecificPath, "failure-no-specific-peer-configured"): {
241 "eos_data": [{"dpsPeers": {"10.255.0.2": {}}}],
242 "inputs": {"paths": [{"peer": "10.255.0.1", "path_group": "internet", "source_address": "172.18.3.2", "destination_address": "172.18.5.2"}]},
243 "expected": {
244 "result": AntaTestStatus.FAILURE,
245 "messages": ["Peer: 10.255.0.1 Path Group: internet Source: 172.18.3.2 Destination: 172.18.5.2 - Peer not found"],
246 "atomic_results": [
247 {
248 "description": "Peer: 10.255.0.1 Path Group: internet Source: 172.18.3.2 Destination: 172.18.5.2",
249 "result": AntaTestStatus.FAILURE,
250 "messages": ["Peer not found"],
251 },
252 ],
253 },
254 },
255 (VerifySpecificPath, "failure-not-established"): {
256 "eos_data": [
257 {
258 "dpsPeers": {
259 "10.255.0.2": {
260 "dpsGroups": {
261 "mpls": {
262 "dpsPaths": {
263 "path7": {},
264 "path8": {
265 "source": "172.18.13.2",
266 "destination": "172.18.15.2",
267 "state": "ipsecPending",
268 "dpsSessions": {"0": {"active": True}},
269 },
270 }
271 },
272 "internet": {"dpsPaths": {}},
273 }
274 },
275 "10.255.0.1": {
276 "dpsGroups": {
277 "internet": {
278 "dpsPaths": {
279 "path6": {"source": "172.18.3.2", "destination": "172.18.5.2", "state": "ipsecPending", "dpsSessions": {"0": {"active": True}}}
280 }
281 },
282 "mpls": {"dpsPaths": {}},
283 }
284 },
285 }
286 }
287 ],
288 "inputs": {
289 "paths": [
290 {"peer": "10.255.0.1", "path_group": "internet", "source_address": "172.18.3.2", "destination_address": "172.18.5.2"},
291 {"peer": "10.255.0.2", "path_group": "mpls", "source_address": "172.18.13.2", "destination_address": "172.18.15.2"},
292 ]
293 },
294 "expected": {
295 "result": AntaTestStatus.FAILURE,
296 "messages": [
297 "Peer: 10.255.0.1 Path Group: internet Source: 172.18.3.2 Destination: 172.18.5.2 - Invalid state path - "
298 "Expected: ipsecEstablished, routeResolved Actual: ipsecPending",
299 "Peer: 10.255.0.2 Path Group: mpls Source: 172.18.13.2 Destination: 172.18.15.2 - Invalid state path - "
300 "Expected: ipsecEstablished, routeResolved Actual: ipsecPending",
301 ],
302 "atomic_results": [
303 {
304 "description": "Peer: 10.255.0.1 Path Group: internet Source: 172.18.3.2 Destination: 172.18.5.2",
305 "result": AntaTestStatus.FAILURE,
306 "messages": ["Invalid state path - Expected: ipsecEstablished, routeResolved Actual: ipsecPending"],
307 },
308 {
309 "description": "Peer: 10.255.0.2 Path Group: mpls Source: 172.18.13.2 Destination: 172.18.15.2",
310 "result": AntaTestStatus.FAILURE,
311 "messages": ["Invalid state path - Expected: ipsecEstablished, routeResolved Actual: ipsecPending"],
312 },
313 ],
314 },
315 },
316 (VerifySpecificPath, "failure-inactive"): {
317 "eos_data": [
318 {
319 "dpsPeers": {
320 "10.255.0.2": {
321 "dpsGroups": {
322 "mpls": {
323 "dpsPaths": {
324 "path8": {
325 "source": "172.18.13.2",
326 "destination": "172.18.15.2",
327 "state": "routeResolved",
328 "dpsSessions": {"0": {"active": False}},
329 }
330 }
331 }
332 }
333 },
334 "10.255.0.1": {
335 "dpsGroups": {
336 "internet": {
337 "dpsPaths": {
338 "path6": {"source": "172.18.3.2", "destination": "172.18.5.2", "state": "routeResolved", "dpsSessions": {"0": {"active": False}}}
339 }
340 }
341 }
342 },
343 }
344 }
345 ],
346 "inputs": {
347 "paths": [
348 {"peer": "10.255.0.1", "path_group": "internet", "source_address": "172.18.3.2", "destination_address": "172.18.5.2"},
349 {"peer": "10.255.0.2", "path_group": "mpls", "source_address": "172.18.13.2", "destination_address": "172.18.15.2"},
350 ]
351 },
352 "expected": {
353 "result": AntaTestStatus.FAILURE,
354 "messages": [
355 "Peer: 10.255.0.1 Path Group: internet Source: 172.18.3.2 Destination: 172.18.5.2 - Telemetry state inactive for this path",
356 "Peer: 10.255.0.2 Path Group: mpls Source: 172.18.13.2 Destination: 172.18.15.2 - Telemetry state inactive for this path",
357 ],
358 "atomic_results": [
359 {
360 "description": "Peer: 10.255.0.1 Path Group: internet Source: 172.18.3.2 Destination: 172.18.5.2",
361 "result": AntaTestStatus.FAILURE,
362 "messages": ["Telemetry state inactive for this path"],
363 },
364 {
365 "description": "Peer: 10.255.0.2 Path Group: mpls Source: 172.18.13.2 Destination: 172.18.15.2",
366 "result": AntaTestStatus.FAILURE,
367 "messages": ["Telemetry state inactive for this path"],
368 },
369 ],
370 },
371 },
372 (VerifySpecificPath, "failure-source-destination-not-configured"): {
373 "eos_data": [
374 {
375 "dpsPeers": {
376 "10.255.0.2": {
377 "dpsGroups": {
378 "mpls": {
379 "dpsPaths": {
380 "path8": {"source": "172.18.3.2", "destination": "172.8.15.2", "state": "routeResolved", "dpsSessions": {"0": {"active": False}}}
381 }
382 }
383 }
384 },
385 "10.255.0.1": {
386 "dpsGroups": {
387 "internet": {
388 "dpsPaths": {
389 "path6": {"source": "172.8.3.2", "destination": "172.8.5.2", "state": "routeResolved", "dpsSessions": {"0": {"active": False}}}
390 }
391 }
392 }
393 },
394 }
395 }
396 ],
397 "inputs": {
398 "paths": [
399 {"peer": "10.255.0.1", "path_group": "internet", "source_address": "172.18.3.2", "destination_address": "172.18.5.2"},
400 {"peer": "10.255.0.2", "path_group": "mpls", "source_address": "172.18.13.2", "destination_address": "172.18.15.2"},
401 ]
402 },
403 "expected": {
404 "result": AntaTestStatus.FAILURE,
405 "messages": [
406 "Peer: 10.255.0.1 Path Group: internet Source: 172.18.3.2 Destination: 172.18.5.2 - No path matching the source and destination found",
407 "Peer: 10.255.0.2 Path Group: mpls Source: 172.18.13.2 Destination: 172.18.15.2 - No path matching the source and destination found",
408 ],
409 "atomic_results": [
410 {
411 "description": "Peer: 10.255.0.1 Path Group: internet Source: 172.18.3.2 Destination: 172.18.5.2",
412 "result": AntaTestStatus.FAILURE,
413 "messages": ["No path matching the source and destination found"],
414 },
415 {
416 "description": "Peer: 10.255.0.2 Path Group: mpls Source: 172.18.13.2 Destination: 172.18.15.2",
417 "result": AntaTestStatus.FAILURE,
418 "messages": ["No path matching the source and destination found"],
419 },
420 ],
421 },
422 },
423 }