Commit 9c25f15
committed
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
1 file changed
+1
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
176 | | - | |
| 176 | + | |
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
| |||
0 commit comments