class LinuxBridgeManager(object):
def __init__(self, interface_mappings):
self.interface_mappings = interface_mappings
+ self.validate_interface_mappings()
self.ip = ip_lib.IPWrapper()
# VXLAN related parameters:
self.local_ip = cfg.CONF.VXLAN.local_ip
# Store network mapping to segments
self.network_map = {}
+ def validate_interface_mappings(self):
+ for physnet, interface in self.interface_mappings.items():
+ if not ip_lib.device_exists(interface):
+ LOG.error(_LE("Interface %(intf)s for physical network %(net)s"
+ " does not exist. Agent terminated!"),
+ {'intf': interface, 'net': physnet})
+ sys.exit(1)
+
def interface_exists_on_bridge(self, bridge, interface):
directory = '/sys/class/net/%s/brif' % bridge
for filename in os.listdir(directory):
:return: A tuntap ip_lib.IPDevice
"""
ip = ip_lib.IPWrapper(namespace=attr.namespace)
- ip.netns.add(attr.namespace)
- self.addCleanup(ip.netns.delete, attr.namespace)
+ if attr.namespace:
+ ip.netns.add(attr.namespace)
+ self.addCleanup(ip.netns.delete, attr.namespace)
tap_device = ip.add_tuntap(attr.name)
self.addCleanup(self._safe_delete_device, tap_device)
tap_device.link.set_address(attr.mac_address)
--- /dev/null
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import mock
+from oslo_log import log as logging
+import testtools
+
+from neutron.plugins.ml2.drivers.linuxbridge.agent import \
+ linuxbridge_neutron_agent
+from neutron.tests.functional.agent.linux import test_ip_lib
+
+LOG = logging.getLogger(__name__)
+lba = linuxbridge_neutron_agent
+
+
+class LinuxBridgeAgentTests(test_ip_lib.IpLibTestFramework):
+
+ def setUp(self):
+ super(LinuxBridgeAgentTests, self).setUp()
+ agent_rpc = ('neutron.agent.rpc.PluginApi')
+ mock.patch(agent_rpc).start()
+ mock.patch('neutron.agent.rpc.PluginReportStateAPI').start()
+
+ def test_validate_interface_mappings(self):
+ mappings = {'physnet1': 'int1', 'physnet2': 'int2'}
+ with testtools.ExpectedException(SystemExit):
+ lba.LinuxBridgeManager(mappings)
+ self.manage_device(
+ self.generate_device_details()._replace(namespace=None,
+ name='int1'))
+ with testtools.ExpectedException(SystemExit):
+ lba.LinuxBridgeManager(mappings)
+ self.manage_device(
+ self.generate_device_details()._replace(namespace=None,
+ name='int2'))
+ lba.LinuxBridgeManager(mappings)
interface_mappings = {'physnet1': 'eth1'}
with mock.patch.object(ip_lib.IPWrapper,
- 'get_device_by_ip', return_value=None):
+ 'get_device_by_ip', return_value=None),\
+ mock.patch.object(ip_lib, 'device_exists',
+ return_value=True):
self.linux_bridge = linuxbridge_neutron_agent.LinuxBridgeManager(
interface_mappings)
self.interface_mappings = {'physnet1': 'eth1'}
with mock.patch.object(ip_lib.IPWrapper,
- 'get_device_by_ip', return_value=None):
+ 'get_device_by_ip', return_value=None),\
+ mock.patch.object(ip_lib, 'device_exists',
+ return_value=True):
self.lbm = linuxbridge_neutron_agent.LinuxBridgeManager(
self.interface_mappings)
self.agent_id = 1
with mock.patch.object(
ip_lib.IPWrapper,
- 'get_device_by_ip', return_value=None):
+ 'get_device_by_ip', return_value=None),\
+ mock.patch.object(ip_lib, 'device_exists',
+ return_value=True):
self.br_mgr = (linuxbridge_neutron_agent.
LinuxBridgeManager({'physnet1': 'eth1'}))