16
16
17
17
from neutron_lib import constants
18
18
19
+ from neutron .agent .linux import ip_lib
20
+ from neutron .common import utils as common_utils
19
21
from neutron .plugins .ml2 .drivers .macvtap .agent import macvtap_neutron_agent
20
22
from neutron .tests .common import net_helpers
21
23
from neutron .tests .functional import base as functional_base
@@ -27,11 +29,30 @@ def setUp(self):
27
29
self .mgr = macvtap_neutron_agent .MacvtapManager ({})
28
30
29
31
def test_get_all_devices (self ):
32
+ # NOTE(ralonsoh): Clean-up before testing. This test is executed with
33
+ # concurrency=1. That means no other test is being executed at the same
34
+ # time. Because the macvtap interface must be created in the root
35
+ # namespace (``MacvtapManager`` cannot handle namespaces), the test
36
+ # deletes any previous existing interface.
37
+ for mac in self .mgr .get_all_devices ():
38
+ devices = ip_lib .IPWrapper ().get_devices ()
39
+ for device in (d for d in devices if d .address == mac ):
40
+ device .link .delete ()
41
+
30
42
# Veth is simulating the hosts eth device. In this test it is used as
31
43
# src_dev for the macvtap
32
44
veth1 , veth2 = self .useFixture (net_helpers .VethFixture ()).ports
33
45
macvtap = self .useFixture (net_helpers .MacvtapFixture (
34
46
src_dev = veth1 .name , mode = 'bridge' ,
35
47
prefix = constants .MACVTAP_DEVICE_PREFIX )).ip_dev
36
- self .assertEqual (set ([macvtap .link .address ]),
37
- self .mgr .get_all_devices ())
48
+ try :
49
+ common_utils .wait_until_true (
50
+ lambda : {macvtap .link .address } == self .mgr .get_all_devices (),
51
+ timeout = 5 )
52
+ except common_utils .WaitTimeout :
53
+ msg = 'MacVTap address: %s, read devices: %s\n ' % (
54
+ macvtap .link .address , self .mgr .get_all_devices ())
55
+ for device in ip_lib .IPWrapper ().get_devices ():
56
+ msg += ' Device %s, MAC: %s' % (device .name ,
57
+ device .link .address )
58
+ self .fail (msg )
0 commit comments