]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
tests: avoid race condition when linking two namespaces
authorVincent Bernat <vincent@bernat.im>
Sun, 1 Jan 2017 12:26:08 +0000 (13:26 +0100)
committerVincent Bernat <vincent@bernat.im>
Sun, 1 Jan 2017 12:26:08 +0000 (13:26 +0100)
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
tests/integration/test_interfaces.py
tests/integration/test_lldpcli.py

index 34fef840d53799c0b47461fa27b1b37178a2eaee..42ff48e1798a54f8cf9766dbfba043fc5d656c21 100644 (file)
@@ -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')
index 571495e08ba5ac901b5eaa40d378a1753e847298..c09fc8dbde67db8a693227f3a68406d36ce5ef55 100644 (file)
@@ -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'
index 2c7fe1e6f80972c76fb20a8357445d59e74cd436..7a969d1d0b47e7a54ff778353ba9ab39cb779d93 100644 (file)
@@ -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'