Skip to content

Commit 9c25f15

Browse files
fix: Sort the list of links before fetching the corresponding link infos 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.
1 parent e890ab5 commit 9c25f15

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

library/network_connections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def _link_read_permaddress(ifname):
173173
@staticmethod
174174
def _link_infos_fetch():
175175
links = {}
176-
for ifname in os.listdir("/sys/class/net/"):
176+
for ifname in sorted(os.listdir("/sys/class/net/")):
177177
if not os.path.islink("/sys/class/net/" + ifname):
178178
# /sys/class/net may contain certain entries
179179
# that are not interface names, like

0 commit comments

Comments
 (0)