self.local_ip = cfg.CONF.VXLAN.local_ip
self.vxlan_mode = lconst.VXLAN_NONE
if cfg.CONF.VXLAN.enable_vxlan:
- 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'))
+ device = self.get_local_ip_device(self.local_ip)
+ self.local_int = device.name
+ self.check_vxlan_support()
# Store network mapping to segments
self.network_map = {}
{'brq': bridge, 'net': physnet})
sys.exit(1)
+ def get_local_ip_device(self, local_ip):
+ """Return the device with local_ip on the host."""
+ device = self.ip.get_device_by_ip(local_ip)
+ if not device:
+ LOG.error(_LE("Tunneling cannot be enabled without the local_ip "
+ "bound to an interface on the host. Please "
+ "configure local_ip %s on the host interface to "
+ "be used for tunneling and restart the agent."),
+ local_ip)
+ sys.exit(1)
+ return device
+
def interface_exists_on_bridge(self, bridge, interface):
directory = '/sys/class/net/%s/brif' % bridge
for filename in os.listdir(directory):
# under the License.
import os
+import sys
import mock
from oslo_config import cfg
DEVICE_1 = 'tapabcdef01-12'
BRIDGE_MAPPINGS = {'physnet0': 'br-eth2'}
INTERFACE_MAPPINGS = {'physnet1': 'eth1'}
+FAKE_DEFAULT_DEV = mock.Mock()
+FAKE_DEFAULT_DEV.name = 'eth1'
class FakeIpLinkCommand(object):
bridge_mappings = BRIDGE_MAPPINGS
with mock.patch.object(ip_lib.IPWrapper,
- 'get_device_by_ip', return_value=None),\
+ 'get_device_by_ip', return_value=FAKE_DEFAULT_DEV),\
mock.patch.object(ip_lib, 'device_exists',
- return_value=True):
+ return_value=True),\
+ mock.patch.object(
+ linuxbridge_neutron_agent.LinuxBridgeManager,
+ 'check_vxlan_support'):
self.linux_bridge = linuxbridge_neutron_agent.LinuxBridgeManager(
bridge_mappings, interface_mappings)
self.get_mac = self.get_mac_p.start()
self.get_mac.return_value = '00:00:00:00:00:01'
with mock.patch.object(ip_lib.IPWrapper,
- 'get_device_by_ip', return_value=None):
+ 'get_device_by_ip',
+ return_value=FAKE_DEFAULT_DEV):
self.agent = linuxbridge_neutron_agent.LinuxBridgeNeutronAgentRPC(
{}, {}, 0, cfg.CONF.AGENT.quitting_rpc_timeout)
- with mock.patch.object(self.agent, "daemon_loop"):
+ with mock.patch.object(self.agent, "daemon_loop"),\
+ mock.patch.object(
+ linuxbridge_neutron_agent.LinuxBridgeManager,
+ 'check_vxlan_support'):
self.agent.start()
def test_treat_devices_removed_with_existed_device(self):
self.bridge_mappings = BRIDGE_MAPPINGS
with mock.patch.object(ip_lib.IPWrapper,
- 'get_device_by_ip', return_value=None),\
+ 'get_device_by_ip',
+ return_value=FAKE_DEFAULT_DEV),\
mock.patch.object(ip_lib, 'device_exists',
- return_value=True):
+ return_value=True),\
+ mock.patch.object(
+ linuxbridge_neutron_agent.LinuxBridgeManager,
+ 'check_vxlan_support'):
self.lbm = linuxbridge_neutron_agent.LinuxBridgeManager(
self.bridge_mappings, self.interface_mappings)
+ def test_local_ip_validation_with_valid_ip(self):
+ with mock.patch.object(ip_lib.IPWrapper,
+ 'get_device_by_ip',
+ return_value=FAKE_DEFAULT_DEV):
+ result = self.lbm.get_local_ip_device(LOCAL_IP)
+ self.assertEqual(FAKE_DEFAULT_DEV, result)
+
+ def test_local_ip_validation_with_invalid_ip(self):
+ with mock.patch.object(ip_lib.IPWrapper,
+ 'get_device_by_ip',
+ return_value=None),\
+ mock.patch.object(sys, 'exit') as exit,\
+ mock.patch.object(linuxbridge_neutron_agent.LOG,
+ 'error') as log:
+ self.lbm.get_local_ip_device(LOCAL_IP)
+ self.assertEqual(1, log.call_count)
+ exit.assert_called_once_with(1)
+
def test_interface_exists_on_bridge(self):
with mock.patch.object(os, 'listdir') as listdir_fn:
listdir_fn.return_value = ["abc"]
bridge_mappings = {}
interface_mappings = {}
with mock.patch.object(ip_lib.IPWrapper,
- 'get_device_by_ip', return_value=None):
+ 'get_device_by_ip',
+ return_value=FAKE_DEFAULT_DEV),\
+ mock.patch.object(
+ linuxbridge_neutron_agent.LinuxBridgeManager,
+ 'check_vxlan_support'):
lbm = linuxbridge_neutron_agent.LinuxBridgeManager(
bridge_mappings, interface_mappings)
self.agent_id = 1
with mock.patch.object(
ip_lib.IPWrapper,
- 'get_device_by_ip', return_value=None),\
- mock.patch.object(ip_lib, 'device_exists',
- return_value=True):
+ 'get_device_by_ip', return_value=FAKE_DEFAULT_DEV),\
+ mock.patch.object(ip_lib, 'device_exists',
+ return_value=True),\
+ mock.patch.object(
+ linuxbridge_neutron_agent.LinuxBridgeManager,
+ 'check_vxlan_support'):
self.br_mgr = (
linuxbridge_neutron_agent.LinuxBridgeManager(
BRIDGE_MAPPINGS,