~ubuntu-branches/ubuntu/vivid/neutron/vivid-updates

« back to all changes in this revision

Viewing changes to neutron/tests/unit/agent/linux/test_bridge_lib.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-03-30 11:17:19 UTC
  • mfrom: (1.1.21)
  • Revision ID: package-import@ubuntu.com-20150330111719-h0gx7233p4jkkgfh
Tags: 1:2015.1~b3-0ubuntu1
* New upstream milestone release:
  - d/control: Align version requirements with upstream.
  - d/control: Add new dependency on oslo-log.
  - d/p/*: Rebase.
  - d/control,d/neutron-plugin-hyperv*: Dropped, decomposed into
    separate project upstream.
  - d/control,d/neutron-plugin-openflow*: Dropped, decomposed into
    separate project upstream.
  - d/neutron-common.install: Add neutron-rootwrap-daemon and 
    neutron-keepalived-state-change binaries.
  - d/rules: Ignore neutron-hyperv-agent when installing; only for Windows.
  - d/neutron-plugin-cisco.install: Drop neutron-cisco-cfg-agent as
    decomposed into separate project upstream.
  - d/neutron-plugin-vmware.install: Drop neutron-check-nsx-config and
    neutron-nsx-manage as decomposed into separate project upstream.
  - d/control: Add dependency on python-neutron-fwaas to neutron-l3-agent.
* d/pydist-overrides: Add overrides for oslo packages.
* d/control: Fixup type in package description (LP: #1263539).
* d/p/fixup-driver-test-execution.patch: Cherry pick fix from upstream VCS
  to support unit test exection in out-of-tree vendor drivers.
* d/neutron-common.postinst: Allow general access to /etc/neutron but limit
  access to root/neutron to /etc/neutron/neutron.conf to support execution
  of unit tests in decomposed vendor drivers.
* d/control: Add dependency on python-neutron-fwaas to neutron-l3-agent
  package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2015 Intel Corporation.
 
2
# Copyright 2015 Isaku Yamahata <isaku.yamahata at intel com>
 
3
#                               <isaku.yamahata at gmail com>
 
4
# All Rights Reserved.
 
5
#
 
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
 
9
#
 
10
#         http://www.apache.org/licenses/LICENSE-2.0
 
11
#
 
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
 
16
#    under the License.
 
17
 
 
18
import mock
 
19
 
 
20
from neutron.agent.linux import bridge_lib
 
21
from neutron.agent.linux import utils
 
22
from neutron.tests import base
 
23
 
 
24
 
 
25
class BridgeLibTest(base.BaseTestCase):
 
26
    """A test suite to exercise the bridge libraries """
 
27
    _NAMESPACE = 'test-namespace'
 
28
    _BR_NAME = 'test-br'
 
29
    _IF_NAME = 'test-if'
 
30
 
 
31
    def setUp(self):
 
32
        super(BridgeLibTest, self).setUp()
 
33
        self.execute = mock.patch.object(
 
34
            utils, "execute", spec=utils.execute).start()
 
35
 
 
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()
 
42
 
 
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)
 
46
 
 
47
        br.addif(self._IF_NAME)
 
48
        self._verify_bridge_mock(
 
49
            ['brctl', 'addif', self._BR_NAME, self._IF_NAME], namespace)
 
50
 
 
51
        br.delif(self._IF_NAME)
 
52
        self._verify_bridge_mock(
 
53
            ['brctl', 'delif', self._BR_NAME, self._IF_NAME], namespace)
 
54
 
 
55
        br.delbr()
 
56
        self._verify_bridge_mock(['brctl', 'delbr', self._BR_NAME], namespace)
 
57
 
 
58
    def test_addbr_with_namespace(self):
 
59
        self._test_br(self._NAMESPACE)
 
60
 
 
61
    def test_addbr_without_namespace(self):
 
62
        self._test_br()