self.local_ip = cfg.CONF.VXLAN.local_ip
self.vxlan_mode = lconst.VXLAN_NONE
if cfg.CONF.VXLAN.enable_vxlan:
- self.local_int = self.get_interface_by_ip(self.local_ip)
- if self.local_int:
+ device = self.ip.get_device_by_ip(self.local_ip)
+ if device:
+ self.local_int = device.name
self.check_vxlan_support()
else:
+ self.local_int = None
LOG.warning(_LW('VXLAN is enabled, a valid local_ip '
'must be provided'))
# Store network mapping to segments
except OSError:
return 0
- def get_interface_by_ip(self, ip):
- for device in self.ip.get_devices():
- if device.addr.list(to=ip):
- return device.name
-
def get_bridge_for_tap_device(self, tap_device_name):
bridges = self.get_all_neutron_bridges()
for bridge in bridges:
Device = collections.namedtuple('Device',
'name ip_cidrs mac_address namespace')
+WRONG_IP = '0.0.0.0'
+TEST_IP = '240.0.0.1'
+
class IpLibTestFramework(functional_base.BaseSudoTestCase):
def setUp(self):
def generate_device_details(self, name=None, ip_cidrs=None,
mac_address=None, namespace=None):
return Device(name or base.get_rand_name(),
- ip_cidrs or ['240.0.0.1/24'],
+ ip_cidrs or ["%s/24" % TEST_IP],
mac_address or
utils.get_random_mac('fa:16:3e:00:00:00'.split(':')),
namespace or base.get_rand_name())
self.assertFalse(
ip_lib.device_exists(attr.name, namespace=attr.namespace))
+ def test_ipwrapper_get_device_by_ip(self):
+ attr = self.generate_device_details()
+ self.manage_device(attr)
+ ip_wrapper = ip_lib.IPWrapper(namespace=attr.namespace)
+ self.assertEqual(attr.name, ip_wrapper.get_device_by_ip(TEST_IP).name)
+ self.assertIsNone(ip_wrapper.get_device_by_ip(WRONG_IP))
+
def test_device_exists_with_ips_and_mac(self):
attr = self.generate_device_details()
device = self.manage_device(attr)
super(TestLinuxBridge, self).setUp()
interface_mappings = {'physnet1': 'eth1'}
- with mock.patch.object(linuxbridge_neutron_agent.LinuxBridgeManager,
- 'get_interface_by_ip', return_value=None):
+ with mock.patch.object(ip_lib.IPWrapper,
+ 'get_device_by_ip', return_value=None):
self.linux_bridge = linuxbridge_neutron_agent.LinuxBridgeManager(
interface_mappings)
'get_interface_mac')
self.get_mac = self.get_mac_p.start()
self.get_mac.return_value = '00:00:00:00:00:01'
- with mock.patch.object(linuxbridge_neutron_agent.LinuxBridgeManager,
- 'get_interface_by_ip', return_value=None):
+ with mock.patch.object(ip_lib.IPWrapper,
+ 'get_device_by_ip', return_value=None):
self.agent = linuxbridge_neutron_agent.LinuxBridgeNeutronAgentRPC(
{}, 0, cfg.CONF.AGENT.quitting_rpc_timeout)
with mock.patch.object(self.agent, "daemon_loop"):
super(TestLinuxBridgeManager, self).setUp()
self.interface_mappings = {'physnet1': 'eth1'}
- with mock.patch.object(linuxbridge_neutron_agent.LinuxBridgeManager,
- 'get_interface_by_ip', return_value=None):
+ with mock.patch.object(ip_lib.IPWrapper,
+ 'get_device_by_ip', return_value=None):
self.lbm = linuxbridge_neutron_agent.LinuxBridgeManager(
self.interface_mappings)
listdir_fn.side_effect = OSError()
self.assertEqual(self.lbm.get_tap_devices_count('br0'), 0)
- def test_get_interface_by_ip(self):
- with mock.patch.object(ip_lib.IPWrapper, 'get_devices') as get_dev_fn,\
- mock.patch.object(ip_lib.IpAddrCommand, 'list') as ip_list_fn:
- device = mock.Mock()
- device.name = 'dev_name'
- get_dev_fn.return_value = [device]
- ip_list_fn.returnvalue = mock.Mock()
- self.assertEqual(self.lbm.get_interface_by_ip(LOCAL_IP),
- 'dev_name')
-
def test_get_bridge_for_tap_device(self):
with mock.patch.object(self.lbm,
"get_all_neutron_bridges") as get_all_qbr_fn,\
def test_delete_vxlan_bridge_no_int_mappings(self):
interface_mappings = {}
- with mock.patch.object(linuxbridge_neutron_agent.LinuxBridgeManager,
- 'get_interface_by_ip', return_value=None):
+ with mock.patch.object(ip_lib.IPWrapper,
+ 'get_device_by_ip', return_value=None):
lbm = linuxbridge_neutron_agent.LinuxBridgeManager(
interface_mappings)
def __init__(self):
self.agent_id = 1
with mock.patch.object(
- linuxbridge_neutron_agent.LinuxBridgeManager,
- 'get_interface_by_ip', return_value=None):
+ ip_lib.IPWrapper,
+ 'get_device_by_ip', return_value=None):
self.br_mgr = (linuxbridge_neutron_agent.
LinuxBridgeManager({'physnet1': 'eth1'}))