From 9cd64bba1feebcb91e729c974300e38e47762afd Mon Sep 17 00:00:00 2001 From: Wen Liang Date: Sat, 18 Jan 2025 14:27:45 -0500 Subject: [PATCH] tests: Prioritize find link info by permanent MAC address, with fallback to current address MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When providing the interface name and mac address at the same time in the network connections for configuring the parent and the vlan connection, and applying the same network connections multiple times, the network role will raise an error - “profile specifies interface_name 'eno2' and mac 'ec:f4:bb:d3:ec:92' but no such interface exists”. The reason for the issue is that `SysUtil._link_infos_fetch()` will create a dictionary containing all the available link infos in the `/sys/class/net/`, each dictionary element has the structure - {“ifname”: {“ifindex”, “ifname”, “address”, “perm-address”}}, later on, in the `SysUtil.link_info_find()` function, the code iterates through all the link info in the aforementioned dictionary, and tries to compare if the mac address that the user specified in the network connections appeared either as the “perm-address” or “address” (current address) in the link info, return such link info if appeared. However, if the mac address that the user specified matches only the “address” but not the “perm-address”, the function will still return. In this case, the returned link info will contain a different “ifname” than the interface name that the user specified in the network connections, as a result, the error is raised. Add the integration test `tests_mac_address_match.yml` to verify that the commit "Prioritize find link info by permanent MAC address, with fallback to current address" (c3416831) can properly resolve the scenarios where multiple network interfaces share the same current MAC address, leading to potential ambiguity in link matching (for example, Virtual interfaces or VLANs, which often lack a valid perm-address and rely on the parent interface's address). Notice that the test `tests_mac_address_match.yml` will be skipped in upstream testing and it will only be manually tested downstream since the test requires to know the permanent mac address to match when configuring vlan's parent. Resolves: https://issues.redhat.com/browse/RHEL-74211 Signed-off-by: Wen Liang --- tests/playbooks/tests_mac_address_match.yml | 65 +++++++++++++++++++ .../assert_network_connections_succeeded.yml | 8 +++ ...cleanup_vlan_and_parent_profile+device.yml | 23 +++++++ tests/tasks/create_mac_address_match.yml | 37 +++++++++++ 4 files changed, 133 insertions(+) create mode 100644 tests/playbooks/tests_mac_address_match.yml create mode 100644 tests/tasks/assert_network_connections_succeeded.yml create mode 100644 tests/tasks/cleanup_vlan_and_parent_profile+device.yml create mode 100644 tests/tasks/create_mac_address_match.yml diff --git a/tests/playbooks/tests_mac_address_match.yml b/tests/playbooks/tests_mac_address_match.yml new file mode 100644 index 00000000..74f82ce5 --- /dev/null +++ b/tests/playbooks/tests_mac_address_match.yml @@ -0,0 +1,65 @@ +# SPDX-License-Identifier: BSD-3-Clause +--- +- name: Play for testing MAC address match on device + hosts: all + vars_prompt: + - name: "interface" + prompt: "The test requires matching an Ethernet interface to its + permanent MAC address, ensuring that the permanent MAC address matches + the current MAC address. Please provide the name of an interface where + its permanent MAC address equals its current MAC address (e.g., eno2)" + private: false + vars: + profile: "{{ interface }}" + vlan_profile: "{{ interface }}.3732" + lsr_fail_debug: + - __network_connections_result + tags: + - "tests::mac" + tasks: + - name: Show playbook name + debug: + msg: "this is: playbooks/tests_mac_address_match.yml" + tags: + - always + + - name: Install ethtool (test dependency) + package: + name: ethtool + state: present + use: "{{ (__network_is_ostree | d(false)) | + ternary('ansible.posix.rhel_rpm_ostree', omit) }}" + + - name: Retrieve MAC address using ethtool + command: ethtool -P {{ interface }} + register: mac_address_result + changed_when: false + failed_when: mac_address_result.rc != 0 + + - name: Set the MAC address variable + set_fact: + mac: "{{ mac_address_result.stdout_lines[-1].split(' ')[-1] }}" + + - name: Display the retrieved MAC address + debug: + msg: "Retrieved MAC address for {{ interface }}: {{ mac }}" + + - name: Test the MAC address match + tags: + - tests::mac:match + block: + - name: Include the task 'run_test.yml' + include_tasks: tasks/run_test.yml + vars: + lsr_description: Test MAC address match on device + lsr_setup: + - tasks/assert_profile_absent.yml + lsr_test: + - tasks/create_mac_address_match.yml + - tasks/create_mac_address_match.yml + lsr_assert: + - tasks/assert_profile_present.yml + - tasks/assert_network_connections_succeeded.yml + lsr_cleanup: + - tasks/cleanup_vlan_and_parent_profile+device.yml + - tasks/check_network_dns.yml diff --git a/tests/tasks/assert_network_connections_succeeded.yml b/tests/tasks/assert_network_connections_succeeded.yml new file mode 100644 index 00000000..2bca1492 --- /dev/null +++ b/tests/tasks/assert_network_connections_succeeded.yml @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: BSD-3-Clause +--- +- name: Assert that configuring network connections is succeeded + assert: + that: + - __network_connections_result.failed == false + msg: Configuring network connections is failed with the error + "{{ __network_connections_result.stderr }}" diff --git a/tests/tasks/cleanup_vlan_and_parent_profile+device.yml b/tests/tasks/cleanup_vlan_and_parent_profile+device.yml new file mode 100644 index 00000000..13318a50 --- /dev/null +++ b/tests/tasks/cleanup_vlan_and_parent_profile+device.yml @@ -0,0 +1,23 @@ +# SPDX-License-Identifier: BSD-3-Clause +--- +- name: Clean up the test devices and the connection profiles + tags: + - "tests::cleanup" + block: + - name: Import network role + import_role: + name: linux-system-roles.network + vars: + network_connections: + - name: "{{ profile }}" + persistent_state: absent + state: down + - name: "{{ vlan_profile }}" + persistent_state: absent + state: down + failed_when: false + - name: Delete the device '{{ interface }}' + command: ip link del {{ interface }} + failed_when: false + changed_when: false +... diff --git a/tests/tasks/create_mac_address_match.yml b/tests/tasks/create_mac_address_match.yml new file mode 100644 index 00000000..9ab08f47 --- /dev/null +++ b/tests/tasks/create_mac_address_match.yml @@ -0,0 +1,37 @@ +# SPDX-License-Identifier: BSD-3-Clause +--- +- name: Include network role + include_role: + name: linux-system-roles.network + vars: + network_connections: + - name: "{{ interface }}" + state: up + persistent_state: present + autoconnect: true + type: ethernet + interface_name: "{{ interface }}" + mac: "{{ mac }}" + ip: + dhcp4: false + auto6: false + + - name: "{{ vlan_profile }}" + state: up + persistent_state: present + type: vlan + parent: "{{ interface }}" + vlan: + id: 3732 + autoconnect: true + ip: + auto_gateway: false + ipv6_disabled: true + gateway4: 10.10.0.1 + address: 10.10.0.6/24 + dhcp4: false + auto6: false +- name: Show result + debug: + var: __network_connections_result +...