'Test that _setup_tunnel_port doesn\'t fail if new vlan mapping is
added in a different coroutine while iterating over existing mappings.
See bug 1449944 for more info.'

def test__setup_tunnel_port_while_new_mapping_is_added(self):

    def add_new_vlan_mapping(*args, **kwargs):
        self.agent.vlan_manager.add('bar', 1, 2, 3, 4)
    bridge = mock.Mock()
    tunnel_type = 'vxlan'
    self.agent.tun_br_ofports = {tunnel_type: dict()}
    self.agent.l2_pop = False
    self.agent.vlan_manager.add('foo', 4, tunnel_type, 2, 1)
    self.agent.local_ip = '2.3.4.5'
    bridge.install_flood_to_tun.side_effect = add_new_vlan_mapping
    self.agent._setup_tunnel_port(bridge, 1, '1.2.3.4', tunnel_type=tunnel_type)
    self.agent._setup_tunnel_flood_flow(bridge, tunnel_type)
    self.assertIn('bar', self.agent.vlan_manager)
