Skip to content

Commit

Permalink
tests: Prioritize find link info by permanent MAC address, with fallb…
Browse files Browse the repository at this point in the history
…ack 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]>
  • Loading branch information
liangwen12year committed Feb 4, 2025
1 parent 64b31cd commit 1871ed1
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 0 deletions.
65 changes: 65 additions & 0 deletions tests/playbooks/tests_mac_address_match.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions tests/tasks/assert_network_connections_succeeded.yml
Original file line number Diff line number Diff line change
@@ -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 }}"
23 changes: 23 additions & 0 deletions tests/tasks/cleanup_vlan_and_parent_profile+device.yml
Original file line number Diff line number Diff line change
@@ -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
...
37 changes: 37 additions & 0 deletions tests/tasks/create_mac_address_match.yml
Original file line number Diff line number Diff line change
@@ -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
...

0 comments on commit 1871ed1

Please sign in to comment.