fix: Sort the list of links before fetching the corresponding link infos in sysfs #760
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.
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 documenthttps://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):