Skip to content

Interfaces

ANTA catalog for interfaces tests

Test functions related to the device interfaces

verify_illegal_lacp(device, result) async

Verifies there is no illegal LACP packets received.

Parameters:

Name Type Description Default
device InventoryDevice

InventoryDevice instance containing all devices information.

required

Returns:

Type Description
TestResult

TestResult instance with

TestResult
  • result = “unset” if the test has not been executed
TestResult
  • result = “success” if there is no illegal LACP packets received. in particular “success” if there is no port-channel
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/interfaces.py
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
@anta_test
async def verify_illegal_lacp(device: InventoryDevice, result: TestResult) -> TestResult:

    """
    Verifies there is no illegal LACP packets received.

    Args:
        device (InventoryDevice): InventoryDevice instance containing all devices information.

    Returns:
        TestResult instance with
        * result = "unset" if the test has not been executed
        * result = "success" if there is no illegal LACP packets received.
                             in particular "success" if there is no port-channel
        * result = "failure" otherwise.
        * result = "error" if any exception is caught

    """
    response = await device.session.cli(command="show lacp counters all-ports", ofmt="json")

    po_with_illegal_lacp: List[Dict[str, Dict[str, int]]] = []
    for portchannel, portchannel_dict in response["portChannels"].items():
        po_with_illegal_lacp.extend(
            {portchannel: interface}
            for interface, interface_dict in portchannel_dict["interfaces"].items()
            if interface_dict["illegalRxCount"] != 0
        )

    if not po_with_illegal_lacp:
        result.is_success()
    else:
        result.is_failure(
            "The following port-channels have recieved illegal lacp packets on the "
            f"following ports: {po_with_illegal_lacp}"
        )

    return result

verify_interface_discards(device, result) async

Verifies interfaces packet discard counters are equal to zero.

Parameters:

Name Type Description Default
device InventoryDevice

InventoryDevice instance containing all devices information.

required

Returns:

Type Description
TestResult

TestResult instance with

TestResult
  • result = “unset” if the test has not been executed
TestResult
  • result = “success” if interfaces discard counters are equal to zero.
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/interfaces.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
@anta_test
async def verify_interface_discards(
    device: InventoryDevice, result: TestResult
) -> TestResult:

    """
    Verifies interfaces packet discard counters are equal to zero.

    Args:
        device (InventoryDevice): InventoryDevice instance containing all devices information.

    Returns:
        TestResult instance with
        * result = "unset" if the test has not been executed
        * result = "success" if interfaces discard counters are equal to zero.
        * result = "failure" otherwise.
        * result = "error" if any exception is caught

    """
    response = await device.session.cli(command="show interfaces counters discards", ofmt="json")

    wrong_interfaces: List[Dict[str, Dict[str, int]]] = []
    for interface, outer_v in response["interfaces"].items():
        wrong_interfaces.extend(
            {interface: outer_v}
            for counter, value in outer_v.items()
            if value > 0
        )
    if not wrong_interfaces:
        result.is_success()
    else:
        result.is_failure(
            f"The following interfaces have non 0 discard counter(s): {wrong_interfaces}"
        )

    return result

verify_interface_errdisabled(device, result) async

Verifies there is no interface in error disable state.

Parameters:

Name Type Description Default
device InventoryDevice

InventoryDevice instance containing all devices information.

required

Returns:

Type Description
TestResult

TestResult instance with

TestResult
  • result = “unset” if the test has not been executed
TestResult
  • result = “success” if no interface is in error disable state.
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/interfaces.py
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
@anta_test
async def verify_interface_errdisabled(
    device: InventoryDevice, result: TestResult
) -> TestResult:

    """
    Verifies there is no interface in error disable state.

    Args:
        device (InventoryDevice): InventoryDevice instance containing all devices information.

    Returns:
        TestResult instance with
        * result = "unset" if the test has not been executed
        * result = "success" if no interface is in error disable state.
        * result = "failure" otherwise.
        * result = "error" if any exception is caught

    """
    response = await device.session.cli(command="show interfaces status", ofmt="json")

    errdisabled_interfaces = [
        interface
        for interface, value in response["interfaceStatuses"].items()
        if value["linkStatus"] == "errdisabled"
    ]

    if not errdisabled_interfaces:
        result.is_success()
    else:
        result.is_failure(
            f"The following interfaces are in error disabled state: {errdisabled_interfaces}"
        )

    return result

verify_interface_errors(device, result) async

Verifies interfaces error counters are equal to zero.

Parameters:

Name Type Description Default
device InventoryDevice

InventoryDevice instance containing all devices information.

required

Returns:

Type Description
TestResult

TestResult instance with

TestResult
  • result = “unset” if the test has not been executed
TestResult
  • result = “success” if interfaces error counters are equal to zero.
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/interfaces.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
@anta_test
async def verify_interface_errors(device: InventoryDevice, result: TestResult) -> TestResult:

    """
    Verifies interfaces error counters are equal to zero.

    Args:
        device (InventoryDevice): InventoryDevice instance containing all devices information.

    Returns:
        TestResult instance with
        * result = "unset" if the test has not been executed
        * result = "success" if interfaces error counters are equal to zero.
        * result = "failure" otherwise.
        * result = "error" if any exception is caught

    """
    response = await device.session.cli(command="show interfaces counters errors", ofmt="json")

    wrong_interfaces: List[Dict[str, Dict[str, int]]] = []
    for interface, outer_v in response["interfaceErrorCounters"].items():
        wrong_interfaces.extend(
            {interface: outer_v}
            for counter, value in outer_v.items()
            if value > 0
        )
    if not wrong_interfaces:
        result.is_success()
    else:
        result.is_failure(
            f"The following interfaces have non 0 error counter(s): {wrong_interfaces}"
        )

    return result

verify_interface_utilization(device, result) async

Verifies interfaces utilization is below 75%.

Parameters:

Name Type Description Default
device InventoryDevice

InventoryDevice instance containing all devices information.

required

Returns:

Type Description
TestResult

TestResult instance with

TestResult
  • result = “unset” if the test has not been executed
TestResult
  • result = “success” if interfaces utilization is below 75%
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/interfaces.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
@anta_test
async def verify_interface_utilization(
    device: InventoryDevice, result: TestResult
) -> TestResult:

    """
    Verifies interfaces utilization is below 75%.

    Args:
        device (InventoryDevice): InventoryDevice instance containing all devices information.

    Returns:
        TestResult instance with
        * result = "unset" if the test has not been executed
        * result = "success" if interfaces utilization is below 75%
        * result = "failure" otherwise.
        * result = "error" if any exception is caught

    """
    # TODO make it JSON - bad news it seems percentages are not in the json payload
    response = await device.session.cli(command="show interfaces counters rates", ofmt="text")

    wrong_interfaces = {}
    for line in response.split("\n")[1:]:
        if len(line) > 0:
            if line.split()[-5] == "-" or line.split()[-2] == "-":
                pass
            elif float(line.split()[-5].replace("%", "")) > 75.0:
                wrong_interfaces[line.split()[0]] = line.split()[-5]
            elif float(line.split()[-2].replace("%", "")) > 75.0:
                wrong_interfaces[line.split()[0]] = line.split()[-2]

    if not wrong_interfaces:
        result.is_success()
    else:
        result.is_failure(
            f"The following interfaces have a usage > 75%: {wrong_interfaces}"
        )

    return result

verify_interfaces_status(device, result, minimum=None) async

Verifies the number of Ethernet interfaces up/up on the device is higher or equal than a value.

Parameters:

Name Type Description Default
device InventoryDevice

InventoryDevice instance containing all devices information.

required
minimum int

Expected minimum number of Ethernet interfaces up/up

None

Returns:

Type Description
TestResult

TestResult instance with

TestResult
  • result = “unset” if the test has not been executed
TestResult
  • result = “skipped” if the minimum parameter is missing
TestResult
  • result = “success” if the number of Ethernet interface up/up is >= minimum
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/interfaces.py
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
@anta_test
async def verify_interfaces_status(
    device: InventoryDevice, result: TestResult, minimum: Optional[int] = None
) -> TestResult:
    """
    Verifies the number of Ethernet interfaces up/up on the device is higher or equal than a value.

    Args:
        device (InventoryDevice): InventoryDevice instance containing all devices information.
        minimum (int): Expected minimum number of Ethernet interfaces up/up

    Returns:
        TestResult instance with
        * result = "unset" if the test has not been executed
        * result = "skipped" if the `minimum` parameter is missing
        * result = "success" if the number of Ethernet interface up/up is >= minimum
        * result = "failure" otherwise.
        * result = "error" if any exception is caught

    """
    if not minimum:
        result.result = "skipped"
        result.messages.append(
            "verify_interfaces_status was not run as no minimum value was given."
        )
        return result

    response = await device.session.cli(command="show interfaces description", ofmt="json")

    count_up_up = 0
    other_ethernet_interfaces = []

    for interface in response["interfaceDescriptions"]:
        interface_dict = response["interfaceDescriptions"][interface]
        if "Ethernet" in interface:
            if (
                re.match(r"connected|up", interface_dict["lineProtocolStatus"])
                and re.match(r"connected|up", interface_dict["interfaceStatus"])
            ):
                count_up_up += 1
            else:
                other_ethernet_interfaces.append(interface)

    if count_up_up >= minimum:
        result.is_success()
    else:
        result.is_failure(
            f"Only {count_up_up}, less than {minimum} Ethernet interfaces are UP/UP"
        )
        result.messages.append(
            f"The following Ethernet interfaces are not UP/UP: {other_ethernet_interfaces}"
        )

    return result

verify_loopback_count(device, result, number=None) async

Verifies the number of loopback interfaces on the device is the one we expect. And if none of the loopback is down.

Parameters:

Name Type Description Default
device InventoryDevice

InventoryDevice instance containing all devices information.

required
number int

Expected number of loopback interfaces.

None

Returns:

Type Description
TestResult

TestResult instance with

TestResult
  • result = “unset” if the test has not been executed
TestResult
  • result = “success” if the number of loopback is equal to number and if none of the loopback is down
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/interfaces.py
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
@anta_test
async def verify_loopback_count(
    device: InventoryDevice, result: TestResult, number: Optional[int] = None
) -> TestResult:
    """
    Verifies the number of loopback interfaces on the device is the one we expect.
    And if none of the loopback is down.

    Args:
        device (InventoryDevice): InventoryDevice instance containing all devices information.
        number (int): Expected number of loopback interfaces.

    Returns:
        TestResult instance with
        * result = "unset" if the test has not been executed
        * result = "success" if the number of loopback is equal to `number` and if
                             none of the loopback is down
        * result = "failure" otherwise.
        * result = "error" if any exception is caught

    """
    if not number:
        result.is_skipped(
            "verify_loopback_count was not run as no number value was given."
        )
        return result

    response = await device.session.cli(command="show ip interface brief ", ofmt="json")

    loopback_count = 0
    down_loopback_interfaces = []

    for interface in response["interfaces"]:
        interface_dict = response["interfaces"][interface]
        if "Loopback" in interface:
            loopback_count += 1
            if not (
                interface_dict["lineProtocolStatus"] == "up"
                and interface_dict["interfaceStatus"] == "connected"
            ):
                down_loopback_interfaces.append(interface)

    if loopback_count == number and len(down_loopback_interfaces) == 0:
        result.is_success()
    else:
        result.is_failure()
        if loopback_count != number:
            result.is_failure(
                f"Found {loopback_count} Loopbacks when expecting {number}"
            )
        elif len(down_loopback_interfaces) != 0:
            result.is_failure(
                f"The following Loopbacks are not up: {down_loopback_interfaces}"
            )

    return result

verify_portchannels(device, result) async

Verifies there is no inactive port in port channels.

Parameters:

Name Type Description Default
device InventoryDevice

InventoryDevice instance containing all devices information.

required

Returns:

Type Description
TestResult

TestResult instance with

TestResult
  • result = “unset” if the test has not been executed
TestResult
  • result = “success” if there is no inactive ports in port-channels in particular “success” if there is no port-channel
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/interfaces.py
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
@anta_test
async def verify_portchannels(device: InventoryDevice, result: TestResult) -> TestResult:

    """
    Verifies there is no inactive port in port channels.

    Args:
        device (InventoryDevice): InventoryDevice instance containing all devices information.

    Returns:
        TestResult instance with
        * result = "unset" if the test has not been executed
        * result = "success" if there is no inactive ports in port-channels
                             in particular "success" if there is no port-channel
        * result = "failure" otherwise.
        * result = "error" if any exception is caught

    """
    response = await device.session.cli(command="show port-channel", ofmt="json")

    po_with_invactive_ports: List[Dict[str, str]] = []
    for portchannel, portchannel_dict in response["portChannels"].items():
        if len(portchannel_dict["inactivePorts"]) != 0:
            po_with_invactive_ports.extend(
                {portchannel: portchannel_dict["inactivePorts"]}
            )

    if not po_with_invactive_ports:
        result.is_success()
    else:
        result.is_failure(
            f"The following port-channels have inactive port(s): {po_with_invactive_ports}"
        )

    return result

verify_spanning_tree_blocked_ports(device, result) async

Verifies there is no spanning-tree blocked ports.

Parameters:

Name Type Description Default
device InventoryDevice

InventoryDevice instance containing all devices information.

required

Returns:

Type Description
TestResult

TestResult instance with

TestResult
  • result = “unset” if the test has not been executed
TestResult
  • result = “success” if there is no spanning-tree blocked ports
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/interfaces.py
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
@anta_test
async def verify_spanning_tree_blocked_ports(
    device: InventoryDevice, result: TestResult
) -> TestResult:

    """
    Verifies there is no spanning-tree blocked ports.

    Args:
        device (InventoryDevice): InventoryDevice instance containing all devices information.

    Returns:
        TestResult instance with
        * result = "unset" if the test has not been executed
        * result = "success" if there is no spanning-tree blocked ports
        * result = "failure" otherwise.
        * result = "error" if any exception is caught

    """
    response = await device.session.cli(command="show spanning-tree blockedports", ofmt="json")

    if len(response["spanningTreeInstances"]) == 0:
        result.is_success()
    else:
        result.is_failure()
        # TODO: a bit lazy would need a real output for this
        result.messages.append(
            f"The following ports are spanning-tree blocked {response['spanningTreeInstances']}"
        )

    return result

verify_storm_control_drops(device, result) async

Verifies the device did not drop packets due its to storm-control configuration.

Parameters:

Name Type Description Default
device InventoryDevice

InventoryDevice instance containing all devices information.

required

Returns:

Type Description
TestResult

TestResult instance with

TestResult
  • result = “unset” if the test has not been executed
TestResult
  • result = “success” if the device did not drop packet due to its storm-control configuration.
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/interfaces.py
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
@skip_on_platforms(["cEOSLab", "VEOS-LAB"])
@anta_test
async def verify_storm_control_drops(
    device: InventoryDevice, result: TestResult
) -> TestResult:
    """
    Verifies the device did not drop packets due its to storm-control configuration.

    Args:
        device (InventoryDevice): InventoryDevice instance containing all devices information.

    Returns:
        TestResult instance with
        * result = "unset" if the test has not been executed
        * result = "success" if the device did not drop packet due to its storm-control configuration.
        * result = "failure" otherwise.
        * result = "error" if any exception is caught

    """
    response = await device.session.cli(command="show storm-control", ofmt="json")

    storm_controlled_interfaces: Dict[str, Dict[str, Any]] = {}
    for interface, interface_dict in response["interfaces"].items():
        for traffic_type, traffic_type_dict in interface_dict["trafficTypes"]:
            if "drop" in traffic_type_dict and traffic_type_dict["drop"] != 0:
                storm_controlled_interface_dict = (
                    storm_controlled_interfaces.setdefault(interface, {})
                )
                storm_controlled_interface_dict.update(
                    {traffic_type: traffic_type_dict["drop"]}
                )

    if len(storm_controlled_interfaces) == 0:
        result.is_success()
    else:
        result.is_failure(
            f"The following interfaces have none 0 storm-control drop counters {storm_controlled_interfaces}"
        )

    return result

verify_svi(device, result) async

Verifies there is no interface vlan down.

Parameters:

Name Type Description Default
device InventoryDevice

InventoryDevice instance containing all devices information.

required

Returns:

Type Description
TestResult

TestResult instance with

TestResult
  • result = “unset” if the test has not been executed
TestResult
  • result = “success” if no SVI is down
TestResult
  • result = “failure” otherwise.
TestResult
  • result = “error” if any exception is caught
Source code in anta/tests/interfaces.py
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
@anta_test
async def verify_svi(device: InventoryDevice, result: TestResult) -> TestResult:
    """
    Verifies there is no interface vlan down.

    Args:
        device (InventoryDevice): InventoryDevice instance containing all devices information.

    Returns:
        TestResult instance with
        * result = "unset" if the test has not been executed
        * result = "success" if no SVI is down
        * result = "failure" otherwise.
        * result = "error" if any exception is caught

    """
    response = await device.session.cli(command="show ip interface brief", ofmt="json")

    down_svis = []

    for interface in response["interfaces"]:
        interface_dict = response["interfaces"][interface]
        if "Vlan" in interface:
            if not (
                interface_dict["lineProtocolStatus"] == "up"
                and interface_dict["interfaceStatus"] == "connected"
            ):
                down_svis.append(interface)

    if len(down_svis) == 0:
        result.is_success()
    else:
        result.is_failure(f"The following SVIs are not up: {down_svis}")

    return result

Last update: September 5, 2022