blob: d6beb77900d3b96a406284e1681f6c41f99a9a6e [file] [log] [blame]
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001# 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
16import netaddr
17import six
18from tempest.lib.common.utils import data_utils
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000019from tempest.lib import decorators
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000020from tempest import test
21
Kevin Bentonc66aa802016-07-23 22:36:37 -070022from neutron.common import utils
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +020023from neutron.tests.tempest.api import base
24from neutron.tests.tempest.api import base_routers
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000025from neutron.tests.tempest import config
26
27CONF = config.CONF
28
29
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +020030class RoutersTest(base_routers.BaseRouterTest):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000031
32 @classmethod
33 @test.requires_ext(extension="router", service="network")
34 def skip_checks(cls):
35 super(RoutersTest, cls).skip_checks()
36
37 @classmethod
38 def resource_setup(cls):
39 super(RoutersTest, cls).resource_setup()
40 cls.tenant_cidr = (
41 config.safe_get_config_value('network', 'project_network_cidr')
42 if cls._ip_version == 4 else
43 config.safe_get_config_value('network', 'project_network_v6_cidr'))
44
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000045 @decorators.idempotent_id('c72c1c0c-2193-4aca-eeee-b1442640eeee')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000046 @test.requires_ext(extension="standard-attr-description",
47 service="network")
48 def test_create_update_router_description(self):
49 body = self.create_router(description='d1', router_name='test')
50 self.assertEqual('d1', body['description'])
51 body = self.client.show_router(body['id'])['router']
52 self.assertEqual('d1', body['description'])
53 body = self.client.update_router(body['id'], description='d2')
54 self.assertEqual('d2', body['router']['description'])
55 body = self.client.show_router(body['router']['id'])['router']
56 self.assertEqual('d2', body['description'])
57
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000058 @decorators.idempotent_id('847257cc-6afd-4154-b8fb-af49f5670ce8')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000059 @test.requires_ext(extension='ext-gw-mode', service='network')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000060 def test_create_router_with_default_snat_value(self):
61 # Create a router with default snat rule
62 name = data_utils.rand_name('router')
63 router = self._create_router(
64 name, external_network_id=CONF.network.public_network_id)
65 self._verify_router_gateway(
66 router['id'], {'network_id': CONF.network.public_network_id,
67 'enable_snat': True})
68
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000069 @decorators.idempotent_id('ea74068d-09e9-4fd7-8995-9b6a1ace920f')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000070 @test.requires_ext(extension='ext-gw-mode', service='network')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000071 def test_create_router_with_snat_explicit(self):
72 name = data_utils.rand_name('snat-router')
73 # Create a router enabling snat attributes
74 enable_snat_states = [False, True]
75 for enable_snat in enable_snat_states:
76 external_gateway_info = {
77 'network_id': CONF.network.public_network_id,
78 'enable_snat': enable_snat}
79 create_body = self.admin_client.create_router(
80 name, external_gateway_info=external_gateway_info)
81 self.addCleanup(self.admin_client.delete_router,
82 create_body['router']['id'])
83 # Verify snat attributes after router creation
84 self._verify_router_gateway(create_body['router']['id'],
85 exp_ext_gw_info=external_gateway_info)
86
87 def _verify_router_gateway(self, router_id, exp_ext_gw_info=None):
88 show_body = self.admin_client.show_router(router_id)
89 actual_ext_gw_info = show_body['router']['external_gateway_info']
90 if exp_ext_gw_info is None:
91 self.assertIsNone(actual_ext_gw_info)
92 return
93 # Verify only keys passed in exp_ext_gw_info
94 for k, v in six.iteritems(exp_ext_gw_info):
95 self.assertEqual(v, actual_ext_gw_info[k])
96
97 def _verify_gateway_port(self, router_id):
98 list_body = self.admin_client.list_ports(
99 network_id=CONF.network.public_network_id,
100 device_id=router_id)
101 self.assertEqual(len(list_body['ports']), 1)
102 gw_port = list_body['ports'][0]
103 fixed_ips = gw_port['fixed_ips']
104 self.assertGreaterEqual(len(fixed_ips), 1)
105 public_net_body = self.admin_client.show_network(
106 CONF.network.public_network_id)
107 public_subnet_id = public_net_body['network']['subnets'][0]
108 self.assertIn(public_subnet_id,
109 [x['subnet_id'] for x in fixed_ips])
110
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000111 @decorators.idempotent_id('b386c111-3b21-466d-880c-5e72b01e1a33')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000112 @test.requires_ext(extension='ext-gw-mode', service='network')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000113 def test_update_router_set_gateway_with_snat_explicit(self):
114 router = self._create_router(data_utils.rand_name('router-'))
115 self.admin_client.update_router_with_snat_gw_info(
116 router['id'],
117 external_gateway_info={
118 'network_id': CONF.network.public_network_id,
119 'enable_snat': True})
120 self._verify_router_gateway(
121 router['id'],
122 {'network_id': CONF.network.public_network_id,
123 'enable_snat': True})
124 self._verify_gateway_port(router['id'])
125
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000126 @decorators.idempotent_id('96536bc7-8262-4fb2-9967-5c46940fa279')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000127 @test.requires_ext(extension='ext-gw-mode', service='network')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000128 def test_update_router_set_gateway_without_snat(self):
129 router = self._create_router(data_utils.rand_name('router-'))
130 self.admin_client.update_router_with_snat_gw_info(
131 router['id'],
132 external_gateway_info={
133 'network_id': CONF.network.public_network_id,
134 'enable_snat': False})
135 self._verify_router_gateway(
136 router['id'],
137 {'network_id': CONF.network.public_network_id,
138 'enable_snat': False})
139 self._verify_gateway_port(router['id'])
140
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000141 @decorators.idempotent_id('f2faf994-97f4-410b-a831-9bc977b64374')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000142 @test.requires_ext(extension='ext-gw-mode', service='network')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000143 def test_update_router_reset_gateway_without_snat(self):
144 router = self._create_router(
145 data_utils.rand_name('router-'),
146 external_network_id=CONF.network.public_network_id)
147 self.admin_client.update_router_with_snat_gw_info(
148 router['id'],
149 external_gateway_info={
150 'network_id': CONF.network.public_network_id,
151 'enable_snat': False})
152 self._verify_router_gateway(
153 router['id'],
154 {'network_id': CONF.network.public_network_id,
155 'enable_snat': False})
156 self._verify_gateway_port(router['id'])
157
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000158 @decorators.idempotent_id('db3093b1-93b6-4893-be83-c4716c251b3e')
Kevin Bentonc66aa802016-07-23 22:36:37 -0700159 def test_router_interface_status(self):
160 network = self.create_network()
161 subnet = self.create_subnet(network)
162 # Add router interface with subnet id
163 router = self._create_router(data_utils.rand_name('router-'), True)
164 intf = self.create_router_interface(router['id'], subnet['id'])
165 status_active = lambda: self.client.show_port(
166 intf['port_id'])['port']['status'] == 'ACTIVE'
Wim De Clercqf09b6e52017-01-05 16:01:27 +0100167 utils.wait_until_true(status_active, exception=AssertionError)
Kevin Bentonc66aa802016-07-23 22:36:37 -0700168
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000169 @decorators.idempotent_id('c86ac3a8-50bd-4b00-a6b8-62af84a0765c')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000170 @test.requires_ext(extension='extraroute', service='network')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000171 def test_update_extra_route(self):
172 self.network = self.create_network()
173 self.name = self.network['name']
174 self.subnet = self.create_subnet(self.network)
175 # Add router interface with subnet id
176 self.router = self._create_router(
177 data_utils.rand_name('router-'), True)
178 self.create_router_interface(self.router['id'], self.subnet['id'])
179 self.addCleanup(
180 self._delete_extra_routes,
181 self.router['id'])
182 # Update router extra route, second ip of the range is
183 # used as next hop
184 cidr = netaddr.IPNetwork(self.subnet['cidr'])
185 next_hop = str(cidr[2])
186 destination = str(self.subnet['cidr'])
187 extra_route = self.client.update_extra_routes(self.router['id'],
188 next_hop, destination)
189 self.assertEqual(1, len(extra_route['router']['routes']))
190 self.assertEqual(destination,
191 extra_route['router']['routes'][0]['destination'])
192 self.assertEqual(next_hop,
193 extra_route['router']['routes'][0]['nexthop'])
194 show_body = self.client.show_router(self.router['id'])
195 self.assertEqual(destination,
196 show_body['router']['routes'][0]['destination'])
197 self.assertEqual(next_hop,
198 show_body['router']['routes'][0]['nexthop'])
199
200 def _delete_extra_routes(self, router_id):
201 self.client.delete_extra_routes(router_id)
202
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000203 @decorators.idempotent_id('01f185d1-d1a6-4cf9-abf7-e0e1384c169c')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000204 def test_network_attached_with_two_routers(self):
205 network = self.create_network(data_utils.rand_name('network1'))
206 self.create_subnet(network)
207 port1 = self.create_port(network)
208 port2 = self.create_port(network)
209 router1 = self._create_router(data_utils.rand_name('router1'))
210 router2 = self._create_router(data_utils.rand_name('router2'))
211 self.client.add_router_interface_with_port_id(
212 router1['id'], port1['id'])
213 self.client.add_router_interface_with_port_id(
214 router2['id'], port2['id'])
215 self.addCleanup(self.client.remove_router_interface_with_port_id,
216 router1['id'], port1['id'])
217 self.addCleanup(self.client.remove_router_interface_with_port_id,
218 router2['id'], port2['id'])
219 body = self.client.show_port(port1['id'])
220 port_show1 = body['port']
221 body = self.client.show_port(port2['id'])
222 port_show2 = body['port']
223 self.assertEqual(port_show1['network_id'], network['id'])
224 self.assertEqual(port_show2['network_id'], network['id'])
225 self.assertEqual(port_show1['device_id'], router1['id'])
226 self.assertEqual(port_show2['device_id'], router2['id'])
227
228
229class RoutersIpV6Test(RoutersTest):
230 _ip_version = 6
231
232
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200233class DvrRoutersTest(base_routers.BaseRouterTest):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000234
235 @classmethod
236 @test.requires_ext(extension="dvr", service="network")
237 def skip_checks(cls):
238 super(DvrRoutersTest, cls).skip_checks()
239
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000240 @decorators.idempotent_id('141297aa-3424-455d-aa8d-f2d95731e00a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000241 def test_create_distributed_router(self):
242 name = data_utils.rand_name('router')
243 create_body = self.admin_client.create_router(
244 name, distributed=True)
245 self.addCleanup(self._delete_router,
246 create_body['router']['id'],
247 self.admin_client)
248 self.assertTrue(create_body['router']['distributed'])
249
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000250 @decorators.idempotent_id('644d7a4a-01a1-4b68-bb8d-0c0042cb1729')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000251 def test_convert_centralized_router(self):
252 router = self._create_router(data_utils.rand_name('router'))
253 self.assertNotIn('distributed', router)
254 update_body = self.admin_client.update_router(router['id'],
255 distributed=True)
256 self.assertTrue(update_body['router']['distributed'])
257 show_body = self.admin_client.show_router(router['id'])
258 self.assertTrue(show_body['router']['distributed'])
259 show_body = self.client.show_router(router['id'])
260 self.assertNotIn('distributed', show_body['router'])
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200261
262
263class RoutersSearchCriteriaTest(base.BaseSearchCriteriaTest):
264
265 resource = 'router'
266
267 @classmethod
268 @test.requires_ext(extension="router", service="network")
269 def skip_checks(cls):
270 super(RoutersSearchCriteriaTest, cls).skip_checks()
271
272 @classmethod
273 def resource_setup(cls):
274 super(RoutersSearchCriteriaTest, cls).resource_setup()
275 for name in cls.resource_names:
276 cls.create_router(router_name=name)
277
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000278 @decorators.idempotent_id('03a69efb-90a7-435b-bb5c-3add3612085a')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200279 def test_list_sorts_asc(self):
280 self._test_list_sorts_asc()
281
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000282 @decorators.idempotent_id('95913d30-ff41-4b17-9f44-5258c651e78c')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200283 def test_list_sorts_desc(self):
284 self._test_list_sorts_desc()
285
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000286 @decorators.idempotent_id('7f7d40b1-e165-4817-8dc5-02f8e2f0dff3')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200287 def test_list_pagination(self):
288 self._test_list_pagination()
289
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000290 @decorators.idempotent_id('a5b83e83-3d98-45bb-a2c7-0ee179ffd42c')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200291 def test_list_pagination_with_marker(self):
292 self._test_list_pagination_with_marker()
293
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000294 @decorators.idempotent_id('40804af8-c25d-45f8-b8a8-b4c70345215d')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200295 def test_list_pagination_with_href_links(self):
296 self._test_list_pagination_with_href_links()
297
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000298 @decorators.idempotent_id('77b9676c-d3cb-43af-a0e8-a5b8c6099e70')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200299 def test_list_pagination_page_reverse_asc(self):
300 self._test_list_pagination_page_reverse_asc()
301
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000302 @decorators.idempotent_id('3133a2c5-1bb9-4fc7-833e-cf9a1d160255')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200303 def test_list_pagination_page_reverse_desc(self):
304 self._test_list_pagination_page_reverse_desc()
305
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000306 @decorators.idempotent_id('8252e2f0-b3da-4738-8e25-f6f8d878a2da')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200307 def test_list_pagination_page_reverse_with_href_links(self):
308 self._test_list_pagination_page_reverse_with_href_links()
309
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000310 @decorators.idempotent_id('fb102124-20f8-4cb3-8c81-f16f5e41d192')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200311 def test_list_no_pagination_limit_0(self):
312 self._test_list_no_pagination_limit_0()