1
# Copyright 2015 Intel Corporation.
2
# Copyright 2015 Isaku Yamahata <isaku.yamahata at intel com>
3
# <isaku.yamahata at gmail com>
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may
7
# not use this file except in compliance with the License. You may obtain
8
# a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
# License for the specific language governing permissions and limitations
20
from neutron.agent.linux import bridge_lib
21
from neutron.agent.linux import utils
22
from neutron.tests import base
25
class BridgeLibTest(base.BaseTestCase):
26
"""A test suite to exercise the bridge libraries """
27
_NAMESPACE = 'test-namespace'
32
super(BridgeLibTest, self).setUp()
33
self.execute = mock.patch.object(
34
utils, "execute", spec=utils.execute).start()
36
def _verify_bridge_mock(self, cmd, namespace=None):
37
if namespace is not None:
38
cmd = ['ip', 'netns', 'exec', namespace] + cmd
39
self.execute.assert_called_once_with(cmd, run_as_root=True,
40
log_fail_as_error=True)
41
self.execute.reset_mock()
43
def _test_br(self, namespace=None):
44
br = bridge_lib.BridgeDevice.addbr(self._BR_NAME, namespace)
45
self._verify_bridge_mock(['brctl', 'addbr', self._BR_NAME], namespace)
47
br.addif(self._IF_NAME)
48
self._verify_bridge_mock(
49
['brctl', 'addif', self._BR_NAME, self._IF_NAME], namespace)
51
br.delif(self._IF_NAME)
52
self._verify_bridge_mock(
53
['brctl', 'delif', self._BR_NAME, self._IF_NAME], namespace)
56
self._verify_bridge_mock(['brctl', 'delbr', self._BR_NAME], namespace)
58
def test_addbr_with_namespace(self):
59
self._test_br(self._NAMESPACE)
61
def test_addbr_without_namespace(self):