From 4e137295f1fa6346866035fc7f64e5f113fb5112 Mon Sep 17 00:00:00 2001 From: Guillaume Mulocher Date: Tue, 24 Dec 2024 04:37:27 +0100 Subject: [PATCH] fix(anta.tests): Fix wrong type used for inputs for VerifyInterfaceIPv4 (#977) --- anta/tests/interfaces.py | 10 +++++----- examples/tests.yaml | 4 ++-- tests/units/anta_tests/test_interfaces.py | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/anta/tests/interfaces.py b/anta/tests/interfaces.py index b87c394f3..bc1acbb82 100644 --- a/anta/tests/interfaces.py +++ b/anta/tests/interfaces.py @@ -8,7 +8,7 @@ from __future__ import annotations import re -from ipaddress import IPv4Network +from ipaddress import IPv4Interface from typing import Any, ClassVar from pydantic import BaseModel, Field @@ -629,9 +629,9 @@ class VerifyInterfaceIPv4(AntaTest): - VerifyInterfaceIPv4: interfaces: - name: Ethernet2 - primary_ip: 172.30.11.0/31 + primary_ip: 172.30.11.1/31 secondary_ips: - - 10.10.10.0/31 + - 10.10.10.1/31 - 10.10.10.10/31 ``` """ @@ -651,9 +651,9 @@ class InterfaceDetail(BaseModel): name: Interface """Name of the interface.""" - primary_ip: IPv4Network + primary_ip: IPv4Interface """Primary IPv4 address in CIDR notation.""" - secondary_ips: list[IPv4Network] | None = None + secondary_ips: list[IPv4Interface] | None = None """Optional list of secondary IPv4 addresses in CIDR notation.""" def render(self, template: AntaTemplate) -> list[AntaCommand]: diff --git a/examples/tests.yaml b/examples/tests.yaml index 58d34c42a..9f1aea993 100644 --- a/examples/tests.yaml +++ b/examples/tests.yaml @@ -217,9 +217,9 @@ anta.tests.interfaces: # Verifies the interface IPv4 addresses. interfaces: - name: Ethernet2 - primary_ip: 172.30.11.0/31 + primary_ip: 172.30.11.1/31 secondary_ips: - - 10.10.10.0/31 + - 10.10.10.1/31 - 10.10.10.10/31 - VerifyInterfaceUtilization: # Verifies that the utilization of interfaces is below a certain threshold. diff --git a/tests/units/anta_tests/test_interfaces.py b/tests/units/anta_tests/test_interfaces.py index 271683b0c..f3b4ee0c2 100644 --- a/tests/units/anta_tests/test_interfaces.py +++ b/tests/units/anta_tests/test_interfaces.py @@ -1969,8 +1969,8 @@ "interfaces": { "Ethernet2": { "interfaceAddress": { - "primaryIp": {"address": "172.30.11.0", "maskLen": 31}, - "secondaryIpsOrderedList": [{"address": "10.10.10.0", "maskLen": 31}, {"address": "10.10.10.10", "maskLen": 31}], + "primaryIp": {"address": "172.30.11.1", "maskLen": 31}, + "secondaryIpsOrderedList": [{"address": "10.10.10.1", "maskLen": 31}, {"address": "10.10.10.10", "maskLen": 31}], } } } @@ -1988,7 +1988,7 @@ ], "inputs": { "interfaces": [ - {"name": "Ethernet2", "primary_ip": "172.30.11.0/31", "secondary_ips": ["10.10.10.0/31", "10.10.10.10/31"]}, + {"name": "Ethernet2", "primary_ip": "172.30.11.1/31", "secondary_ips": ["10.10.10.1/31", "10.10.10.10/31"]}, {"name": "Ethernet12", "primary_ip": "172.30.11.10/31", "secondary_ips": ["10.10.10.10/31", "10.10.10.20/31"]}, ] },