Skip to content

Commit a2dfe29

Browse files
committed
tests:integration: Avoid race condition with veth MAC addresses.
When a new veth device is created via iproute2 ("ip link add ..."), the kernel assigns a MAC address. Once udev picks up the interface, it will apply systemd "MACAddressPolicy=permanent" default policy. But as veths cannot (by nature) have a permanent MAC, systemd-udev will create a random (but persistent) MAC, changing the kernel MAC. Previously we waited for 0.1 sec to (hopefully) pick up the later system-udev MAC, but sometimes that wasn't enough, and we still got the earlier kernel MAC, failing certain tests cases, such as: __main__.TestNetworkManager.test_eth_permanent_mac __main__.TestNetworkManager.test_rename_interfaces __main__.TestNetworkd.test_eth_permanent_mac __main__.TestNetworkd.test_rename_interfaces This patch drops the "time.sleep(0.1)" and instead triggers our test interfaces and waits for settlement of those uevents via 'udevadm', to avoid race conditions.
1 parent 7351655 commit a2dfe29

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

tests/integration/base.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,18 @@ def create_devices(klass):
164164
subprocess.check_call(['ip', 'link', 'add', 'name', 'eth43', 'type',
165165
'veth', 'peer', 'name', 'veth43'])
166166

167-
# Creation of the veths introduces a race with newer versions of
168-
# systemd, as it will change the initial MAC address after the device
169-
# was created and networkd took control. Give it some time, so we read
170-
# the correct MAC address
171-
time.sleep(0.1)
167+
# systemd-udevd uses "MACAddressPolicy=permanent" by default in
168+
# /usr/lib/systemd/network/99-default.link
169+
# When a new veth device is created via iproute2 ("ip link add ..."),
170+
# the kernel assigns a MAC address. Once udev picks up the interface, it
171+
# will apply this default policy. But as veths cannot (by nature) have
172+
# a permanent MAC, udev will create a random (but persistent) MAC,
173+
# changing the kernel MAC.
174+
# Let's trigger out test interfaces and wait for settlement of those
175+
# uevents to avoid race conditions between the MAC assigned by the
176+
# kernel on veth creation and the pseudo "permanent" MAC from udev.
177+
subprocess.check_call(['udevadm', 'trigger', '--settle', '/sys/class/net/eth42'])
178+
subprocess.check_call(['udevadm', 'trigger', '--settle', '/sys/class/net/eth43'])
172179
out = subprocess.check_output(['ip', '-br', 'link', 'show', 'dev', 'eth42'],
173180
text=True)
174181
klass.dev_e_client_mac = out.split()[2]

0 commit comments

Comments
 (0)