Skip to content
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

fix: Sort the list of links before fetching the corresponding link infos in sysfs #760

Closed

Conversation

liangwen12year
Copy link
Collaborator

@liangwen12year liangwen12year commented Feb 4, 2025

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 and the role compares the user-specified MAC address against either the "perm-address" (permanent MAC) or "address" (current MAC) from sysfs, treating a match with only the current MAC as valid even if the interface name differs from the user-specified one, then the error “no such interface exists” is raised. The error occurs on the second time the playbook runs where the VLAN device is created and the VLAN device's linkinfo can be extracted from sysfs, but the error is not guaranteed to be raised because The role uses os.listdir(path) when collecting the link infos from sysfs. According to the python document
https://docs.python.org/3/library/os.html#os.listdir, the function returns a list containing the names of the entries in the directory given by path and the list is in arbitrary order. The error will only be raised when the VLAN device appears earlier than its parent in the list (the VLAN device is assigned smaller index than its parent in the list). Since the VLAN's device name can be independent of the parent's device name and VLAN ID, to make the behavior deterministic (either guaranteed to raise the error or guaranteed to not raise the error), sort the list of links before fetching the corresponding link infos.

Enhancement:

Reason:

Result:

Issue Tracker Tickets (Jira or BZ if any):

…fos in sysfs

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 and the role compares the
user-specified MAC address against either the "perm-address" (permanent
MAC) or "address" (current MAC) from sysfs, treating a match with only
the current MAC as valid even if the interface name differs from the
user-specified one, then the error “no such interface exists” is raised.
The error occurs on the second time the playbook runs where the VLAN
device is created and the VLAN device's linkinfo can be extracted from
sysfs, but the error is not guaranteed to be raised because The role
uses `os.listdir(path)` when collecting the link infos from sysfs.
According to the python document
https://docs.python.org/3/library/os.html#os.listdir, the function
returns a list containing the names of the entries in the directory
given by path and the list is in arbitrary order. The error will only be
raised when the VLAN device appears earlier than its parent in the list
(the VLAN device is assigned smaller index than its parent in the list).
Since the VLAN's device name can be independent of the parent's device
name and VLAN ID, to make the behavior deterministic (either guaranteed
to raise the error or guaranteed to not raise the error), sort the list
of links before fetching the corresponding link infos.
Copy link

codecov bot commented Feb 4, 2025

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 43.11%. Comparing base (89d7148) to head (9c25f15).
Report is 28 commits behind head on main.

Files with missing lines Patch % Lines
library/network_connections.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #760       +/-   ##
===========================================
+ Coverage   20.40%   43.11%   +22.71%     
===========================================
  Files          10       12        +2     
  Lines        1485     3124     +1639     
  Branches      436        0      -436     
===========================================
+ Hits          303     1347     +1044     
- Misses       1181     1777      +596     
+ Partials        1        0        -1     
Flag Coverage Δ
sanity ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant