From 36d0c286ecb38a8168cd1bf65bcc214dd19206da Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sun, 1 Jan 2017 13:26:08 +0100 Subject: [PATCH] tests: avoid race condition when linking two namespaces When creating a link between two namespaces, one lldpd will see the link and send a LLDPDU before the other one. There is a slight delay for lldpd to wait before sending the LLDPDU, but when the load is heavy, it can be expected that the other side didn't configure the interface when the LLDPDU is received. To solve this, just wait a bit before putting up the second interface. --- tests/integration/fixtures/network.py | 4 +++- tests/integration/test_interfaces.py | 4 ++-- tests/integration/test_lldpcli.py | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/integration/fixtures/network.py b/tests/integration/fixtures/network.py index 34fef840..42ff48e1 100644 --- a/tests/integration/fixtures/network.py +++ b/tests/integration/fixtures/network.py @@ -1,6 +1,7 @@ import pytest import pyroute2 import struct +import time from .namespaces import Namespace @@ -27,7 +28,7 @@ class LinksFactory(object): def __call__(self, *args): return self.veth(*args) - def veth(self, ns1, ns2): + def veth(self, ns1, ns2, sleep=0): """Create a veth pair between two namespaces.""" with self.ns: # First, create a link @@ -54,6 +55,7 @@ class LinksFactory(object): with ns1: ipr = pyroute2.IPRoute() ipr.link('set', index=idx[0], state='up') + time.sleep(sleep) with ns2: ipr = pyroute2.IPRoute() ipr.link('set', index=idx[1], state='up') diff --git a/tests/integration/test_interfaces.py b/tests/integration/test_interfaces.py index 571495e0..c09fc8db 100644 --- a/tests/integration/test_interfaces.py +++ b/tests/integration/test_interfaces.py @@ -207,8 +207,8 @@ def test_down_then_up_with_vlan(lldpd1, lldpd, lldpcli, namespaces, links): def test_new_interface(lldpd1, lldpd, lldpcli, namespaces, links): with namespaces(2): lldpd() - links(namespaces(1), namespaces(2)) - time.sleep(10) + links(namespaces(1), namespaces(2), 4) + time.sleep(6) with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") assert out['lldp.eth0.port.descr'] == 'eth1' diff --git a/tests/integration/test_lldpcli.py b/tests/integration/test_lldpcli.py index 2c7fe1e6..7a969d1d 100644 --- a/tests/integration/test_lldpcli.py +++ b/tests/integration/test_lldpcli.py @@ -202,8 +202,8 @@ def test_new_port_take_default(lldpd1, lldpd, lldpcli, namespaces, links): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") assert out['lldp.eth0.port.descr'] == 'eth1' assert out['lldp.eth0.port.power.device-type'] == 'PSE' - links(namespaces(1), namespaces(2)) - time.sleep(10) + links(namespaces(1), namespaces(2), 4) + time.sleep(6) with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") assert out['lldp.eth2.port.descr'] == 'eth3' -- 2.39.5