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

« back to all changes in this revision

Viewing changes to neutron/tests/unit/agent/l3/test_router_info.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
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
2
#    not use this file except in compliance with the License. You may obtain
 
3
#    a copy of the License at
 
4
#
 
5
#         http://www.apache.org/licenses/LICENSE-2.0
 
6
#
 
7
#    Unless required by applicable law or agreed to in writing, software
 
8
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
9
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
10
#    License for the specific language governing permissions and limitations
 
11
#    under the License.
 
12
 
 
13
import mock
 
14
 
 
15
from neutron.agent.common import config as agent_config
 
16
from neutron.agent.l3 import router_info
 
17
from neutron.openstack.common import uuidutils
 
18
from neutron.tests import base
 
19
 
 
20
 
 
21
_uuid = uuidutils.generate_uuid
 
22
 
 
23
 
 
24
class TestRouterInfo(base.BaseTestCase):
 
25
    def setUp(self):
 
26
        super(TestRouterInfo, self).setUp()
 
27
 
 
28
        conf = agent_config.setup_conf()
 
29
        conf.use_namespaces = True
 
30
 
 
31
        self.ip_cls_p = mock.patch('neutron.agent.linux.ip_lib.IPWrapper')
 
32
        ip_cls = self.ip_cls_p.start()
 
33
        self.mock_ip = mock.MagicMock()
 
34
        ip_cls.return_value = self.mock_ip
 
35
        self.ri_kwargs = {'agent_conf': conf,
 
36
                          'interface_driver': mock.sentinel.interface_driver}
 
37
 
 
38
    def _check_agent_method_called(self, calls):
 
39
        self.mock_ip.netns.execute.assert_has_calls(
 
40
            [mock.call(call, check_exit_code=False) for call in calls],
 
41
            any_order=True)
 
42
 
 
43
    def test_routing_table_update(self):
 
44
        ri = router_info.RouterInfo(_uuid(), {}, **self.ri_kwargs)
 
45
        ri.router = {}
 
46
 
 
47
        fake_route1 = {'destination': '135.207.0.0/16',
 
48
                       'nexthop': '1.2.3.4'}
 
49
        fake_route2 = {'destination': '135.207.111.111/32',
 
50
                       'nexthop': '1.2.3.4'}
 
51
 
 
52
        ri._update_routing_table('replace', fake_route1)
 
53
        expected = [['ip', 'route', 'replace', 'to', '135.207.0.0/16',
 
54
                     'via', '1.2.3.4']]
 
55
        self._check_agent_method_called(expected)
 
56
 
 
57
        ri._update_routing_table('delete', fake_route1)
 
58
        expected = [['ip', 'route', 'delete', 'to', '135.207.0.0/16',
 
59
                     'via', '1.2.3.4']]
 
60
        self._check_agent_method_called(expected)
 
61
 
 
62
        ri._update_routing_table('replace', fake_route2)
 
63
        expected = [['ip', 'route', 'replace', 'to', '135.207.111.111/32',
 
64
                     'via', '1.2.3.4']]
 
65
        self._check_agent_method_called(expected)
 
66
 
 
67
        ri._update_routing_table('delete', fake_route2)
 
68
        expected = [['ip', 'route', 'delete', 'to', '135.207.111.111/32',
 
69
                     'via', '1.2.3.4']]
 
70
        self._check_agent_method_called(expected)
 
71
 
 
72
    def test_routes_updated(self):
 
73
        ri = router_info.RouterInfo(_uuid(), {}, **self.ri_kwargs)
 
74
        ri.router = {}
 
75
 
 
76
        fake_old_routes = []
 
77
        fake_new_routes = [{'destination': "110.100.31.0/24",
 
78
                            'nexthop': "10.100.10.30"},
 
79
                           {'destination': "110.100.30.0/24",
 
80
                            'nexthop': "10.100.10.30"}]
 
81
        ri.routes = fake_old_routes
 
82
        ri.router['routes'] = fake_new_routes
 
83
        ri.routes_updated()
 
84
 
 
85
        expected = [['ip', 'route', 'replace', 'to', '110.100.30.0/24',
 
86
                    'via', '10.100.10.30'],
 
87
                    ['ip', 'route', 'replace', 'to', '110.100.31.0/24',
 
88
                     'via', '10.100.10.30']]
 
89
 
 
90
        self._check_agent_method_called(expected)
 
91
 
 
92
        fake_new_routes = [{'destination': "110.100.30.0/24",
 
93
                            'nexthop': "10.100.10.30"}]
 
94
        ri.router['routes'] = fake_new_routes
 
95
        ri.routes_updated()
 
96
        expected = [['ip', 'route', 'delete', 'to', '110.100.31.0/24',
 
97
                    'via', '10.100.10.30']]
 
98
 
 
99
        self._check_agent_method_called(expected)
 
100
        fake_new_routes = []
 
101
        ri.router['routes'] = fake_new_routes
 
102
        ri.routes_updated()
 
103
 
 
104
        expected = [['ip', 'route', 'delete', 'to', '110.100.30.0/24',
 
105
                    'via', '10.100.10.30']]
 
106
        self._check_agent_method_called(expected)