-
Notifications
You must be signed in to change notification settings - Fork 112
tests: Prefer permanent MAC for finding link info, fallback to current MAC #751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
liangwen12year
wants to merge
3
commits into
linux-system-roles:main
from
liangwen12year:link_info_find_fix
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
| --- | ||
| - name: Play for creating the connection to match the port device | ||
| based on the perm_hwaddr | ||
| hosts: all | ||
| vars: | ||
| controller_profile: bond0 | ||
| controller_device: nm-bond | ||
| port1_profile: bond0.0 | ||
| dhcp_interface1: test1 | ||
| port2_profile: bond0.1 | ||
| dhcp_interface2: test2 | ||
| profile: test2conn | ||
| interface: test2 | ||
| tasks: | ||
| - name: Test creating the connection to match the port device | ||
| based on the perm_hwaddr | ||
| tags: | ||
| - tests::bond:create | ||
| block: | ||
| - name: Include the task 'run_test.yml' | ||
| include_tasks: tasks/run_test.yml | ||
| vars: | ||
| lsr_description: Given two DHCP-enabled network interfaces, | ||
| when creating a bond profile with them, | ||
| then we can still create the connection to match the port device | ||
| based on the perm_hwaddr | ||
| lsr_setup: | ||
| - tasks/create_test_interfaces_with_dhcp.yml | ||
| - tasks/assert_dhcp_device_present.yml | ||
| lsr_test: | ||
| - tasks/create_bond_profile.yml | ||
| - tasks/create_bond_port_match_by_mac.yml | ||
| lsr_assert: | ||
| - tasks/assert_controller_device_present.yml | ||
| - tasks/assert_profile_present.yml | ||
| lsr_cleanup: | ||
| - tasks/cleanup_bond_profile+device.yml | ||
| - tasks/remove_test_interfaces_with_dhcp.yml | ||
| - tasks/check_network_dns.yml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
| --- | ||
| - name: Play for testing MAC address match on device | ||
| hosts: all | ||
| vars: | ||
| # This test requires an Ethernet interface whose permanent | ||
| # MAC address matches its current MAC address. Ensure that the | ||
| # specified interface meets this condition. | ||
| # | ||
| # Two VLAN profiles are defined to test deterministic behavior when fetching | ||
| # link information from sysfs. The issue being tested arises when `os.listdir(path)` | ||
| # returns interfaces in an arbitrary order, potentially listing a VLAN device | ||
| # before its parent interface. This can cause intermittent "no such interface | ||
| # exists" errors when applying configurations repeatedly. | ||
| # | ||
| # - `vlan_profile1` (e.g., `eth1.3732`) is named with the VLAN ID appended | ||
| # after the parent interface, following the standard `<parent>.<vlan_id>` format. | ||
| # - `vlan_profile2` (e.g., `120-vlan`) has a fixed name, designed to test a scenario | ||
| # where lexicographic sorting causes the VLAN to appear before its parent interface. | ||
| interface: "{{ lookup('env', 'MAC_ADDR_MATCH_INTERFACE') | default('eth1', true) }}" | ||
| profile: "{{ interface }}" | ||
| vlan_profile1: "{{ interface }}.3732" | ||
| vlan_profile2: "120-vlan" | ||
| lsr_fail_debug: | ||
| - __network_connections_result | ||
| tags: | ||
| - "tests::match" | ||
| 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::match: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/find+remove_profile.yml | ||
| - tasks/assert_profile_absent.yml | ||
| lsr_test: | ||
| - tasks/create_mac_address_match.yml | ||
liangwen12year marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # 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_profile1 }}" | ||
| persistent_state: absent | ||
| state: down | ||
| - name: "{{ vlan_profile2 }}" | ||
| persistent_state: absent | ||
| state: down | ||
| failed_when: false | ||
| - name: Delete the device '{{ interface }}' | ||
| command: ip link del {{ interface }} | ||
| failed_when: false | ||
| changed_when: false | ||
| ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
| --- | ||
| - name: Retrieve perm_hwaddr using ethtool | ||
| # wokeignore:rule=slave | ||
| command: cat /sys/class/net/{{ interface }}/bonding_slave/perm_hwaddr | ||
| 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 matching the port device based on the perm_hwaddr | ||
| import_role: | ||
| name: linux-system-roles.network | ||
| vars: | ||
| network_connections: | ||
| - name: "{{ profile }}" | ||
| state: up | ||
| type: ethernet | ||
| interface_name: "{{ interface }}" | ||
| mac: "{{ mac }}" | ||
| ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # 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_profile1 }}" | ||
| state: up | ||
| persistent_state: present | ||
| type: vlan | ||
| parent: "{{ interface }}" | ||
| vlan: | ||
| id: 3732 | ||
| autoconnect: true | ||
| ip: | ||
| auto_gateway: false | ||
| gateway4: 10.10.0.1 | ||
| address: 10.10.0.6/24 | ||
| dhcp4: false | ||
| auto6: false | ||
|
|
||
| - name: "{{ vlan_profile2 }}" | ||
| state: up | ||
| persistent_state: present | ||
| type: vlan | ||
| parent: "{{ interface }}" | ||
| vlan: | ||
| id: 120 | ||
| autoconnect: true | ||
| ip: | ||
| auto_gateway: false | ||
| gateway4: 10.10.120.1 | ||
| address: 10.10.120.120/24 | ||
| dhcp4: false | ||
| auto6: false | ||
| - name: Show result | ||
| debug: | ||
| var: __network_connections_result | ||
| ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
| --- | ||
| - name: Get connection profile for '{{ interface }}' | ||
| command: "nmcli -g GENERAL.CONNECTION device show {{ interface }}" | ||
| register: connection_name | ||
| changed_when: false | ||
|
|
||
| - name: Bring down and delete the connection profile for '{{ interface }}' | ||
| include_role: | ||
| name: linux-system-roles.network | ||
| vars: | ||
| network_connections: | ||
| - name: "{{ connection_name.stdout }}" | ||
| persistent_state: absent | ||
| state: down |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.