From 98863bc3780168c082a167a1b22330301ef6a490 Mon Sep 17 00:00:00 2001 From: Dhiraj Lulla Date: Wed, 13 May 2026 13:49:55 -0700 Subject: [PATCH] feat: Allow filtering interface using mac_address Specifying a mac_address in topology also requires the interface getting filtered in the call to mfd-network-adapter. Signed-off-by: Dhiraj Lulla --- mfd_host/base.py | 4 ++++ tests/unit/test_mfd_host/test_base.py | 31 ++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/mfd_host/base.py b/mfd_host/base.py index 5f9ba32..5f9f9aa 100644 --- a/mfd_host/base.py +++ b/mfd_host/base.py @@ -10,6 +10,7 @@ from mfd_common_libs import add_logging_level, log_levels from mfd_typing import OSName, PCIAddress, PCIDevice from mfd_typing.network_interface import InterfaceType, InterfaceInfo +from mfd_typing.mac_address import MACAddress from .exceptions import HostConnectedOSNotSupported, NetworkInterfaceRefreshException, HostConnectionTypeNotSupported from .feature.stats import BaseFeatureStats, StatsFeatureType @@ -367,6 +368,9 @@ def _get_filtered_interface_info_by_topology( random_interface=None if interface_model.random_interface is None else interface_model.random_interface, + mac_address=None + if interface_model.mac_address is None + else MACAddress(addr=interface_model.mac_address), all_interfaces=None if interface_model.all_interfaces is None else interface_model.all_interfaces, ) if info: diff --git a/tests/unit/test_mfd_host/test_base.py b/tests/unit/test_mfd_host/test_base.py index 6ebc6bd..fa1967d 100644 --- a/tests/unit/test_mfd_host/test_base.py +++ b/tests/unit/test_mfd_host/test_base.py @@ -8,7 +8,7 @@ from mfd_common_libs.exceptions import UnexpectedOSException from mfd_connect import RPyCConnection from mfd_network_adapter import NetworkInterface -from mfd_typing import OSName, PCIAddress +from mfd_typing import MACAddress, OSName, PCIAddress from mfd_typing.network_interface import LinuxInterfaceInfo, InterfaceType from mfd_model.config import HostModel, NetworkInterfaceModelBase as NetworkInterfaceModel @@ -253,6 +253,35 @@ def test__get_filtered_interface_info_by_topology(self, host): == filtered_info ) + def test__get_filtered_interface_info_by_topology_with_mac_address(self, host): + mac_str = "aa:bb:cc:dd:ee:ff" + model = NetworkInterfaceModel(mac_address=mac_str, instantiate=True) + host.topology.network_interfaces = [model] + interfaces_info = [ + LinuxInterfaceInfo(mac_address=MACAddress(mac_str)), + LinuxInterfaceInfo(mac_address=MACAddress("11:22:33:44:55:66")), + LinuxInterfaceInfo(mac_address=MACAddress("aa:bb:cc:dd:ee:00")), + ] + filtered_info = [(LinuxInterfaceInfo(mac_address=MACAddress(mac_str)), model)] + assert ( + host._get_filtered_interface_info_by_topology(interfaces_info=interfaces_info, ignore_instantiate=False) + == filtered_info + ) + + def test__get_filtered_interface_info_by_topology_with_mac_address_none(self, host): + model = NetworkInterfaceModel(mac_address=None, instantiate=True) + host.topology.network_interfaces = [model] + interfaces_info = [ + LinuxInterfaceInfo(mac_address=MACAddress("aa:bb:cc:dd:ee:ff")), + LinuxInterfaceInfo(mac_address=MACAddress("11:22:33:44:55:66")), + LinuxInterfaceInfo(mac_address=MACAddress("aa:bb:cc:dd:ee:00")), + ] + filtered_info = [(info, model) for info in interfaces_info] + assert ( + host._get_filtered_interface_info_by_topology(interfaces_info=interfaces_info, ignore_instantiate=False) + == filtered_info + ) + def test__update_interfaces(self, host): interface_info = LinuxInterfaceInfo(name="eth0", namespace="foo") updated_namespace = "bar"