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

« back to all changes in this revision

Viewing changes to neutron/tests/tempest/api/network/test_routers.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 2013 OpenStack Foundation
 
2
# All Rights Reserved.
 
3
#
 
4
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
5
#    not use this file except in compliance with the License. You may obtain
 
6
#    a copy of the License at
 
7
#
 
8
#         http://www.apache.org/licenses/LICENSE-2.0
 
9
#
 
10
#    Unless required by applicable law or agreed to in writing, software
 
11
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
12
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
13
#    License for the specific language governing permissions and limitations
 
14
#    under the License.
 
15
 
 
16
import netaddr
 
17
from tempest_lib.common.utils import data_utils
 
18
 
 
19
from neutron.tests.tempest.api.network import base_routers as base
 
20
from neutron.tests.api.contrib import clients
 
21
from neutron.tests.tempest import config
 
22
from neutron.tests.tempest import test
 
23
 
 
24
CONF = config.CONF
 
25
 
 
26
 
 
27
class RoutersTest(base.BaseRouterTest):
 
28
 
 
29
    @classmethod
 
30
    def resource_setup(cls):
 
31
        super(RoutersTest, cls).resource_setup()
 
32
        if not test.is_extension_enabled('router', 'network'):
 
33
            msg = "router extension not enabled."
 
34
            raise cls.skipException(msg)
 
35
        admin_manager = clients.AdminManager()
 
36
        cls.identity_admin_client = admin_manager.identity_client
 
37
        cls.tenant_cidr = (CONF.network.tenant_network_cidr
 
38
                           if cls._ip_version == 4 else
 
39
                           CONF.network.tenant_network_v6_cidr)
 
40
 
 
41
    def _cleanup_router(self, router):
 
42
        self.delete_router(router)
 
43
        self.routers.remove(router)
 
44
 
 
45
    def _create_router(self, name, admin_state_up=False,
 
46
                       external_network_id=None, enable_snat=None):
 
47
        # associate a cleanup with created routers to avoid quota limits
 
48
        router = self.create_router(name, admin_state_up,
 
49
                                    external_network_id, enable_snat)
 
50
        self.addCleanup(self._cleanup_router, router)
 
51
        return router
 
52
 
 
53
    @test.attr(type='smoke')
 
54
    @test.idempotent_id('f64403e2-8483-4b34-8ccd-b09a87bcc68c')
 
55
    def test_create_show_list_update_delete_router(self):
 
56
        # Create a router
 
57
        # NOTE(salv-orlando): Do not invoke self.create_router
 
58
        # as we need to check the response code
 
59
        name = data_utils.rand_name('router-')
 
60
        create_body = self.client.create_router(
 
61
            name, external_gateway_info={
 
62
                "network_id": CONF.network.public_network_id},
 
63
            admin_state_up=False)
 
64
        self.addCleanup(self._delete_router, create_body['router']['id'])
 
65
        self.assertEqual(create_body['router']['name'], name)
 
66
        self.assertEqual(
 
67
            create_body['router']['external_gateway_info']['network_id'],
 
68
            CONF.network.public_network_id)
 
69
        self.assertEqual(create_body['router']['admin_state_up'], False)
 
70
        # Show details of the created router
 
71
        show_body = self.client.show_router(create_body['router']['id'])
 
72
        self.assertEqual(show_body['router']['name'], name)
 
73
        self.assertEqual(
 
74
            show_body['router']['external_gateway_info']['network_id'],
 
75
            CONF.network.public_network_id)
 
76
        self.assertEqual(show_body['router']['admin_state_up'], False)
 
77
        # List routers and verify if created router is there in response
 
78
        list_body = self.client.list_routers()
 
79
        routers_list = list()
 
80
        for router in list_body['routers']:
 
81
            routers_list.append(router['id'])
 
82
        self.assertIn(create_body['router']['id'], routers_list)
 
83
        # Update the name of router and verify if it is updated
 
84
        updated_name = 'updated ' + name
 
85
        update_body = self.client.update_router(create_body['router']['id'],
 
86
                                                name=updated_name)
 
87
        self.assertEqual(update_body['router']['name'], updated_name)
 
88
        show_body = self.client.show_router(
 
89
            create_body['router']['id'])
 
90
        self.assertEqual(show_body['router']['name'], updated_name)
 
91
 
 
92
    @test.attr(type='smoke')
 
93
    @test.idempotent_id('e54dd3a3-4352-4921-b09d-44369ae17397')
 
94
    def test_create_router_setting_tenant_id(self):
 
95
        # Test creating router from admin user setting tenant_id.
 
96
        test_tenant = data_utils.rand_name('test_tenant_')
 
97
        test_description = data_utils.rand_name('desc_')
 
98
        tenant = self.identity_admin_client.create_tenant(
 
99
            name=test_tenant, description=test_description)
 
100
        tenant_id = tenant['id']
 
101
        self.addCleanup(self.identity_admin_client.delete_tenant, tenant_id)
 
102
 
 
103
        name = data_utils.rand_name('router-')
 
104
        create_body = self.admin_client.create_router(name,
 
105
                                                      tenant_id=tenant_id)
 
106
        self.addCleanup(self.admin_client.delete_router,
 
107
                        create_body['router']['id'])
 
108
        self.assertEqual(tenant_id, create_body['router']['tenant_id'])
 
109
 
 
110
    @test.idempotent_id('847257cc-6afd-4154-b8fb-af49f5670ce8')
 
111
    @test.requires_ext(extension='ext-gw-mode', service='network')
 
112
    @test.attr(type='smoke')
 
113
    def test_create_router_with_default_snat_value(self):
 
114
        # Create a router with default snat rule
 
115
        name = data_utils.rand_name('router')
 
116
        router = self._create_router(
 
117
            name, external_network_id=CONF.network.public_network_id)
 
118
        self._verify_router_gateway(
 
119
            router['id'], {'network_id': CONF.network.public_network_id,
 
120
                           'enable_snat': True})
 
121
 
 
122
    @test.idempotent_id('ea74068d-09e9-4fd7-8995-9b6a1ace920f')
 
123
    @test.requires_ext(extension='ext-gw-mode', service='network')
 
124
    @test.attr(type='smoke')
 
125
    def test_create_router_with_snat_explicit(self):
 
126
        name = data_utils.rand_name('snat-router')
 
127
        # Create a router enabling snat attributes
 
128
        enable_snat_states = [False, True]
 
129
        for enable_snat in enable_snat_states:
 
130
            external_gateway_info = {
 
131
                'network_id': CONF.network.public_network_id,
 
132
                'enable_snat': enable_snat}
 
133
            create_body = self.admin_client.create_router(
 
134
                name, external_gateway_info=external_gateway_info)
 
135
            self.addCleanup(self.admin_client.delete_router,
 
136
                            create_body['router']['id'])
 
137
            # Verify snat attributes after router creation
 
138
            self._verify_router_gateway(create_body['router']['id'],
 
139
                                        exp_ext_gw_info=external_gateway_info)
 
140
 
 
141
    @test.attr(type='smoke')
 
142
    @test.idempotent_id('b42e6e39-2e37-49cc-a6f4-8467e940900a')
 
143
    def test_add_remove_router_interface_with_subnet_id(self):
 
144
        network = self.create_network()
 
145
        subnet = self.create_subnet(network)
 
146
        router = self._create_router(data_utils.rand_name('router-'))
 
147
        # Add router interface with subnet id
 
148
        interface = self.client.add_router_interface_with_subnet_id(
 
149
            router['id'], subnet['id'])
 
150
        self.addCleanup(self._remove_router_interface_with_subnet_id,
 
151
                        router['id'], subnet['id'])
 
152
        self.assertIn('subnet_id', interface.keys())
 
153
        self.assertIn('port_id', interface.keys())
 
154
        # Verify router id is equal to device id in port details
 
155
        show_port_body = self.client.show_port(
 
156
            interface['port_id'])
 
157
        self.assertEqual(show_port_body['port']['device_id'],
 
158
                         router['id'])
 
159
 
 
160
    @test.attr(type='smoke')
 
161
    @test.idempotent_id('2b7d2f37-6748-4d78-92e5-1d590234f0d5')
 
162
    def test_add_remove_router_interface_with_port_id(self):
 
163
        network = self.create_network()
 
164
        self.create_subnet(network)
 
165
        router = self._create_router(data_utils.rand_name('router-'))
 
166
        port_body = self.client.create_port(
 
167
            network_id=network['id'])
 
168
        # add router interface to port created above
 
169
        interface = self.client.add_router_interface_with_port_id(
 
170
            router['id'], port_body['port']['id'])
 
171
        self.addCleanup(self._remove_router_interface_with_port_id,
 
172
                        router['id'], port_body['port']['id'])
 
173
        self.assertIn('subnet_id', interface.keys())
 
174
        self.assertIn('port_id', interface.keys())
 
175
        # Verify router id is equal to device id in port details
 
176
        show_port_body = self.client.show_port(
 
177
            interface['port_id'])
 
178
        self.assertEqual(show_port_body['port']['device_id'],
 
179
                         router['id'])
 
180
 
 
181
    def _verify_router_gateway(self, router_id, exp_ext_gw_info=None):
 
182
        show_body = self.admin_client.show_router(router_id)
 
183
        actual_ext_gw_info = show_body['router']['external_gateway_info']
 
184
        if exp_ext_gw_info is None:
 
185
            self.assertIsNone(actual_ext_gw_info)
 
186
            return
 
187
        # Verify only keys passed in exp_ext_gw_info
 
188
        for k, v in exp_ext_gw_info.iteritems():
 
189
            self.assertEqual(v, actual_ext_gw_info[k])
 
190
 
 
191
    def _verify_gateway_port(self, router_id):
 
192
        list_body = self.admin_client.list_ports(
 
193
            network_id=CONF.network.public_network_id,
 
194
            device_id=router_id)
 
195
        self.assertEqual(len(list_body['ports']), 1)
 
196
        gw_port = list_body['ports'][0]
 
197
        fixed_ips = gw_port['fixed_ips']
 
198
        self.assertGreaterEqual(len(fixed_ips), 1)
 
199
        public_net_body = self.admin_client.show_network(
 
200
            CONF.network.public_network_id)
 
201
        public_subnet_id = public_net_body['network']['subnets'][0]
 
202
        self.assertIn(public_subnet_id,
 
203
                      map(lambda x: x['subnet_id'], fixed_ips))
 
204
 
 
205
    @test.attr(type='smoke')
 
206
    @test.idempotent_id('6cc285d8-46bf-4f36-9b1a-783e3008ba79')
 
207
    def test_update_router_set_gateway(self):
 
208
        router = self._create_router(data_utils.rand_name('router-'))
 
209
        self.client.update_router(
 
210
            router['id'],
 
211
            external_gateway_info={
 
212
                'network_id': CONF.network.public_network_id})
 
213
        # Verify operation - router
 
214
        self._verify_router_gateway(
 
215
            router['id'],
 
216
            {'network_id': CONF.network.public_network_id})
 
217
        self._verify_gateway_port(router['id'])
 
218
 
 
219
    @test.idempotent_id('b386c111-3b21-466d-880c-5e72b01e1a33')
 
220
    @test.requires_ext(extension='ext-gw-mode', service='network')
 
221
    @test.attr(type='smoke')
 
222
    def test_update_router_set_gateway_with_snat_explicit(self):
 
223
        router = self._create_router(data_utils.rand_name('router-'))
 
224
        self.admin_client.update_router_with_snat_gw_info(
 
225
            router['id'],
 
226
            external_gateway_info={
 
227
                'network_id': CONF.network.public_network_id,
 
228
                'enable_snat': True})
 
229
        self._verify_router_gateway(
 
230
            router['id'],
 
231
            {'network_id': CONF.network.public_network_id,
 
232
             'enable_snat': True})
 
233
        self._verify_gateway_port(router['id'])
 
234
 
 
235
    @test.idempotent_id('96536bc7-8262-4fb2-9967-5c46940fa279')
 
236
    @test.requires_ext(extension='ext-gw-mode', service='network')
 
237
    @test.attr(type='smoke')
 
238
    def test_update_router_set_gateway_without_snat(self):
 
239
        router = self._create_router(data_utils.rand_name('router-'))
 
240
        self.admin_client.update_router_with_snat_gw_info(
 
241
            router['id'],
 
242
            external_gateway_info={
 
243
                'network_id': CONF.network.public_network_id,
 
244
                'enable_snat': False})
 
245
        self._verify_router_gateway(
 
246
            router['id'],
 
247
            {'network_id': CONF.network.public_network_id,
 
248
             'enable_snat': False})
 
249
        self._verify_gateway_port(router['id'])
 
250
 
 
251
    @test.attr(type='smoke')
 
252
    @test.idempotent_id('ad81b7ee-4f81-407b-a19c-17e623f763e8')
 
253
    def test_update_router_unset_gateway(self):
 
254
        router = self._create_router(
 
255
            data_utils.rand_name('router-'),
 
256
            external_network_id=CONF.network.public_network_id)
 
257
        self.client.update_router(router['id'], external_gateway_info={})
 
258
        self._verify_router_gateway(router['id'])
 
259
        # No gateway port expected
 
260
        list_body = self.admin_client.list_ports(
 
261
            network_id=CONF.network.public_network_id,
 
262
            device_id=router['id'])
 
263
        self.assertFalse(list_body['ports'])
 
264
 
 
265
    @test.idempotent_id('f2faf994-97f4-410b-a831-9bc977b64374')
 
266
    @test.requires_ext(extension='ext-gw-mode', service='network')
 
267
    @test.attr(type='smoke')
 
268
    def test_update_router_reset_gateway_without_snat(self):
 
269
        router = self._create_router(
 
270
            data_utils.rand_name('router-'),
 
271
            external_network_id=CONF.network.public_network_id)
 
272
        self.admin_client.update_router_with_snat_gw_info(
 
273
            router['id'],
 
274
            external_gateway_info={
 
275
                'network_id': CONF.network.public_network_id,
 
276
                'enable_snat': False})
 
277
        self._verify_router_gateway(
 
278
            router['id'],
 
279
            {'network_id': CONF.network.public_network_id,
 
280
             'enable_snat': False})
 
281
        self._verify_gateway_port(router['id'])
 
282
 
 
283
    @test.idempotent_id('c86ac3a8-50bd-4b00-a6b8-62af84a0765c')
 
284
    @test.requires_ext(extension='extraroute', service='network')
 
285
    @test.attr(type='smoke')
 
286
    def test_update_extra_route(self):
 
287
        self.network = self.create_network()
 
288
        self.name = self.network['name']
 
289
        self.subnet = self.create_subnet(self.network)
 
290
        # Add router interface with subnet id
 
291
        self.router = self._create_router(
 
292
            data_utils.rand_name('router-'), True)
 
293
        self.create_router_interface(self.router['id'], self.subnet['id'])
 
294
        self.addCleanup(
 
295
            self._delete_extra_routes,
 
296
            self.router['id'])
 
297
        # Update router extra route, second ip of the range is
 
298
        # used as next hop
 
299
        cidr = netaddr.IPNetwork(self.subnet['cidr'])
 
300
        next_hop = str(cidr[2])
 
301
        destination = str(self.subnet['cidr'])
 
302
        extra_route = self.client.update_extra_routes(self.router['id'],
 
303
                                                      next_hop, destination)
 
304
        self.assertEqual(1, len(extra_route['router']['routes']))
 
305
        self.assertEqual(destination,
 
306
                         extra_route['router']['routes'][0]['destination'])
 
307
        self.assertEqual(next_hop,
 
308
                         extra_route['router']['routes'][0]['nexthop'])
 
309
        show_body = self.client.show_router(self.router['id'])
 
310
        self.assertEqual(destination,
 
311
                         show_body['router']['routes'][0]['destination'])
 
312
        self.assertEqual(next_hop,
 
313
                         show_body['router']['routes'][0]['nexthop'])
 
314
 
 
315
    def _delete_extra_routes(self, router_id):
 
316
        self.client.delete_extra_routes(router_id)
 
317
 
 
318
    @test.attr(type='smoke')
 
319
    @test.idempotent_id('a8902683-c788-4246-95c7-ad9c6d63a4d9')
 
320
    def test_update_router_admin_state(self):
 
321
        self.router = self._create_router(data_utils.rand_name('router-'))
 
322
        self.assertFalse(self.router['admin_state_up'])
 
323
        # Update router admin state
 
324
        update_body = self.client.update_router(self.router['id'],
 
325
                                                admin_state_up=True)
 
326
        self.assertTrue(update_body['router']['admin_state_up'])
 
327
        show_body = self.client.show_router(self.router['id'])
 
328
        self.assertTrue(show_body['router']['admin_state_up'])
 
329
 
 
330
    @test.attr(type='smoke')
 
331
    @test.idempotent_id('802c73c9-c937-4cef-824b-2191e24a6aab')
 
332
    def test_add_multiple_router_interfaces(self):
 
333
        network01 = self.create_network(
 
334
            network_name=data_utils.rand_name('router-network01-'))
 
335
        network02 = self.create_network(
 
336
            network_name=data_utils.rand_name('router-network02-'))
 
337
        subnet01 = self.create_subnet(network01)
 
338
        sub02_cidr = netaddr.IPNetwork(self.tenant_cidr).next()
 
339
        subnet02 = self.create_subnet(network02, cidr=sub02_cidr)
 
340
        router = self._create_router(data_utils.rand_name('router-'))
 
341
        interface01 = self._add_router_interface_with_subnet_id(router['id'],
 
342
                                                                subnet01['id'])
 
343
        self._verify_router_interface(router['id'], subnet01['id'],
 
344
                                      interface01['port_id'])
 
345
        interface02 = self._add_router_interface_with_subnet_id(router['id'],
 
346
                                                                subnet02['id'])
 
347
        self._verify_router_interface(router['id'], subnet02['id'],
 
348
                                      interface02['port_id'])
 
349
 
 
350
    def _verify_router_interface(self, router_id, subnet_id, port_id):
 
351
        show_port_body = self.client.show_port(port_id)
 
352
        interface_port = show_port_body['port']
 
353
        self.assertEqual(router_id, interface_port['device_id'])
 
354
        self.assertEqual(subnet_id,
 
355
                         interface_port['fixed_ips'][0]['subnet_id'])
 
356
 
 
357
 
 
358
class RoutersIpV6Test(RoutersTest):
 
359
    _ip_version = 6