Skip to content

Commit c4ac501

Browse files
tests: Prioritize find link info by permanent MAC address, with fallback to current address
Given that a network connection specifies both an interface name and a MAC address for configuring a parent and VLAN connection, and the physical interface has the same permanent and current MAC address, when the configuration is applied multiple times, then 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. When running the integration test `tests_mac_address_match.yml`, it is essential to provide an Ethernet interface of which the permanent MAC address matches the current MAC address. Typically, the vritual interface like VLAN lacks a valid permanent MAC address and inherits the current MAC address of its parent interface instead of the permanent MAC. Thus, the test can verify that the commit "Prioritize find link info by permanent MAC address, with fallback to current address" (c341683) can properly resolve the scenarios where multiple network interfaces share the same current MAC address, leading to potential ambiguity in link matching. Notice that the test `tests_mac_address_match.yml` will be skipped in upstream testing in short term until the upstream testing machine is set up with two extra NICs. Resolves: https://issues.redhat.com/browse/RHEL-74211 Signed-off-by: Wen Liang <[email protected]>
1 parent 424ad35 commit c4ac501

File tree

4 files changed

+133
-0
lines changed

4 files changed

+133
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
---
3+
- name: Play for testing MAC address match on device
4+
hosts: all
5+
vars_prompt:
6+
- name: "interface"
7+
prompt: "The test requires matching an Ethernet interface to its
8+
permanent MAC address, ensuring that the permanent MAC address matches
9+
the current MAC address. Please provide the name of an interface where
10+
its permanent MAC address equals its current MAC address (e.g., eno2)"
11+
private: false
12+
vars:
13+
profile: "{{ interface }}"
14+
vlan_profile: "{{ interface }}.3732"
15+
lsr_fail_debug:
16+
- __network_connections_result
17+
tags:
18+
- "tests::mac"
19+
tasks:
20+
- name: Show playbook name
21+
debug:
22+
msg: "this is: playbooks/tests_mac_address_match.yml"
23+
tags:
24+
- always
25+
26+
- name: Install ethtool (test dependency)
27+
package:
28+
name: ethtool
29+
state: present
30+
use: "{{ (__network_is_ostree | d(false)) |
31+
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
32+
33+
- name: Retrieve MAC address using ethtool
34+
command: ethtool -P {{ interface }}
35+
register: mac_address_result
36+
changed_when: false
37+
failed_when: mac_address_result.rc != 0
38+
39+
- name: Set the MAC address variable
40+
set_fact:
41+
mac: "{{ mac_address_result.stdout_lines[-1].split(' ')[-1] }}"
42+
43+
- name: Display the retrieved MAC address
44+
debug:
45+
msg: "Retrieved MAC address for {{ interface }}: {{ mac }}"
46+
47+
- name: Test the MAC address match
48+
tags:
49+
- tests::mac:match
50+
block:
51+
- name: Include the task 'run_test.yml'
52+
include_tasks: tasks/run_test.yml
53+
vars:
54+
lsr_description: Test MAC address match on device
55+
lsr_setup:
56+
- tasks/assert_profile_absent.yml
57+
lsr_test:
58+
- tasks/create_mac_address_match.yml
59+
- tasks/create_mac_address_match.yml
60+
lsr_assert:
61+
- tasks/assert_profile_present.yml
62+
- tasks/assert_network_connections_succeeded.yml
63+
lsr_cleanup:
64+
- tasks/cleanup_vlan_and_parent_profile+device.yml
65+
- tasks/check_network_dns.yml
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
---
3+
- name: Assert that configuring network connections is succeeded
4+
assert:
5+
that:
6+
- __network_connections_result.failed == false
7+
msg: Configuring network connections is failed with the error
8+
"{{ __network_connections_result.stderr }}"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
---
3+
- name: Clean up the test devices and the connection profiles
4+
tags:
5+
- "tests::cleanup"
6+
block:
7+
- name: Import network role
8+
import_role:
9+
name: linux-system-roles.network
10+
vars:
11+
network_connections:
12+
- name: "{{ profile }}"
13+
persistent_state: absent
14+
state: down
15+
- name: "{{ vlan_profile }}"
16+
persistent_state: absent
17+
state: down
18+
failed_when: false
19+
- name: Delete the device '{{ interface }}'
20+
command: ip link del {{ interface }}
21+
failed_when: false
22+
changed_when: false
23+
...
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
---
3+
- name: Include network role
4+
include_role:
5+
name: linux-system-roles.network
6+
vars:
7+
network_connections:
8+
- name: "{{ interface }}"
9+
state: up
10+
persistent_state: present
11+
autoconnect: true
12+
type: ethernet
13+
interface_name: "{{ interface }}"
14+
mac: "{{ mac }}"
15+
ip:
16+
dhcp4: false
17+
auto6: false
18+
19+
- name: "{{ vlan_profile }}"
20+
state: up
21+
persistent_state: present
22+
type: vlan
23+
parent: "{{ interface }}"
24+
vlan:
25+
id: 3732
26+
autoconnect: true
27+
ip:
28+
auto_gateway: false
29+
ipv6_disabled: true
30+
gateway4: 10.10.0.1
31+
address: 10.10.0.6/24
32+
dhcp4: false
33+
auto6: false
34+
- name: Show result
35+
debug:
36+
var: __network_connections_result
37+
...

0 commit comments

Comments
 (0)