diff options
| author | Christian Breunig <christian@breunig.cc> | 2025-12-19 21:13:06 +0100 |
|---|---|---|
| committer | Christian Breunig <christian@breunig.cc> | 2025-12-19 21:51:28 +0100 |
| commit | e7b65794f82026bb8f02e3ac364c1b5589c00a22 (patch) | |
| tree | 5435cd8df1678edac625a464dc062b34f8fcd878 | |
| parent | a7af7360e3f2d4635d7bf0340d183f01e3846aa9 (diff) | |
| download | vyos-1x-e7b65794f82026bb8f02e3ac364c1b5589c00a22.tar.gz vyos-1x-e7b65794f82026bb8f02e3ac364c1b5589c00a22.zip | |
bond: T8084: refactor verify() to remove duplication
Consolidate repeated helper function calls used for both bonded and non-bonded
Ethernet interfaces, resulting in cleaner and more maintainable code.
| -rwxr-xr-x | src/conf_mode/interfaces_ethernet.py | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/src/conf_mode/interfaces_ethernet.py b/src/conf_mode/interfaces_ethernet.py index edcc6563c..8e490884f 100755 --- a/src/conf_mode/interfaces_ethernet.py +++ b/src/conf_mode/interfaces_ethernet.py @@ -371,51 +371,44 @@ def verify(ethernet): if 'deleted' in ethernet: return None + + ethtool = Ethtool(ethernet['ifname']) + verify_interface_exists(ethernet, ethernet['ifname']) + verify_eapol(ethernet) + verify_mirror_redirect(ethernet) + # No need to check speed and duplex keys as both have default values + verify_speed_duplex(ethernet, ethtool) + verify_flow_control(ethernet, ethtool) + verify_ring_buffer(ethernet, ethtool) + verify_offload(ethernet, ethtool) + if 'is_bond_member' in ethernet: - verify_bond_member(ethernet) + verify_bond_member(ethernet, ethtool) else: - verify_ethernet(ethernet) + verify_ethernet(ethernet, ethtool) -def verify_bond_member(ethernet): +def verify_bond_member(ethernet: dict, ethtool: Ethtool) -> None: """ Verification function for ethernet interface which is in bonding :param ethernet: dictionary which is received from get_interface_dict :type ethernet: dict """ - ifname = ethernet['ifname'] - verify_interface_exists(ethernet, ifname) - verify_eapol(ethernet) - verify_mirror_redirect(ethernet) - ethtool = Ethtool(ifname) - verify_speed_duplex(ethernet, ethtool) - verify_flow_control(ethernet, ethtool) - verify_ring_buffer(ethernet, ethtool) - verify_offload(ethernet, ethtool) verify_allowedbond_changes(ethernet) + return None -def verify_ethernet(ethernet): +def verify_ethernet(ethernet: dict, ethtool: Ethtool) -> None: """ Verification function for simple ethernet interface :param ethernet: dictionary which is received from get_interface_dict :type ethernet: dict """ - ifname = ethernet['ifname'] - verify_interface_exists(ethernet, ifname) verify_mtu(ethernet) verify_mtu_ipv6(ethernet) verify_dhcpv6(ethernet) verify_address(ethernet) verify_vrf(ethernet) verify_bond_bridge_member(ethernet) - verify_eapol(ethernet) - verify_mirror_redirect(ethernet) - ethtool = Ethtool(ifname) - # No need to check speed and duplex keys as both have default values. - verify_speed_duplex(ethernet, ethtool) - verify_flow_control(ethernet, ethtool) - verify_ring_buffer(ethernet, ethtool) - verify_offload(ethernet, ethtool) # use common function to verify VLAN configuration verify_vlan_config(ethernet) return None |
