blob: 9c915aa75763b3ad93b402c08d9bb2e488aa7fd1 [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
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000017from tempest.lib.common.utils import data_utils
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000018from tempest.lib import decorators
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000019from tempest import test
20
Chandan Kumar5e619872017-09-07 22:23:55 +053021from neutron.tests.tempest.common import utils
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +020022from neutron.tests.tempest.api import base
23from neutron.tests.tempest.api import base_routers
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000024from neutron.tests.tempest import config
25
26CONF = config.CONF
27
28
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +020029class RoutersTest(base_routers.BaseRouterTest):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000030
Jakub Libosvar1982aa12017-05-30 11:15:33 +000031 required_extensions = ['router']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000032
33 @classmethod
34 def resource_setup(cls):
35 super(RoutersTest, cls).resource_setup()
36 cls.tenant_cidr = (
37 config.safe_get_config_value('network', 'project_network_cidr')
38 if cls._ip_version == 4 else
39 config.safe_get_config_value('network', 'project_network_v6_cidr'))
40
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000041 @decorators.idempotent_id('c72c1c0c-2193-4aca-eeee-b1442640eeee')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000042 @test.requires_ext(extension="standard-attr-description",
43 service="network")
44 def test_create_update_router_description(self):
45 body = self.create_router(description='d1', router_name='test')
46 self.assertEqual('d1', body['description'])
47 body = self.client.show_router(body['id'])['router']
48 self.assertEqual('d1', body['description'])
49 body = self.client.update_router(body['id'], description='d2')
50 self.assertEqual('d2', body['router']['description'])
51 body = self.client.show_router(body['router']['id'])['router']
52 self.assertEqual('d2', body['description'])
53
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000054 @decorators.idempotent_id('847257cc-6afd-4154-b8fb-af49f5670ce8')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000055 @test.requires_ext(extension='ext-gw-mode', service='network')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000056 def test_create_router_with_default_snat_value(self):
57 # Create a router with default snat rule
58 name = data_utils.rand_name('router')
59 router = self._create_router(
60 name, external_network_id=CONF.network.public_network_id)
61 self._verify_router_gateway(
62 router['id'], {'network_id': CONF.network.public_network_id,
63 'enable_snat': True})
64
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000065 @decorators.idempotent_id('ea74068d-09e9-4fd7-8995-9b6a1ace920f')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000066 @test.requires_ext(extension='ext-gw-mode', service='network')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000067 def test_create_router_with_snat_explicit(self):
68 name = data_utils.rand_name('snat-router')
69 # Create a router enabling snat attributes
70 enable_snat_states = [False, True]
71 for enable_snat in enable_snat_states:
72 external_gateway_info = {
73 'network_id': CONF.network.public_network_id,
74 'enable_snat': enable_snat}
75 create_body = self.admin_client.create_router(
76 name, external_gateway_info=external_gateway_info)
77 self.addCleanup(self.admin_client.delete_router,
78 create_body['router']['id'])
79 # Verify snat attributes after router creation
80 self._verify_router_gateway(create_body['router']['id'],
81 exp_ext_gw_info=external_gateway_info)
82
83 def _verify_router_gateway(self, router_id, exp_ext_gw_info=None):
84 show_body = self.admin_client.show_router(router_id)
85 actual_ext_gw_info = show_body['router']['external_gateway_info']
86 if exp_ext_gw_info is None:
87 self.assertIsNone(actual_ext_gw_info)
88 return
89 # Verify only keys passed in exp_ext_gw_info
fpxieaa3bace2017-04-07 17:12:15 +080090 for k, v in exp_ext_gw_info.items():
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000091 self.assertEqual(v, actual_ext_gw_info[k])
92
93 def _verify_gateway_port(self, router_id):
94 list_body = self.admin_client.list_ports(
95 network_id=CONF.network.public_network_id,
96 device_id=router_id)
97 self.assertEqual(len(list_body['ports']), 1)
98 gw_port = list_body['ports'][0]
99 fixed_ips = gw_port['fixed_ips']
100 self.assertGreaterEqual(len(fixed_ips), 1)
101 public_net_body = self.admin_client.show_network(
102 CONF.network.public_network_id)
103 public_subnet_id = public_net_body['network']['subnets'][0]
104 self.assertIn(public_subnet_id,
105 [x['subnet_id'] for x in fixed_ips])
106
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000107 @decorators.idempotent_id('b386c111-3b21-466d-880c-5e72b01e1a33')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000108 @test.requires_ext(extension='ext-gw-mode', service='network')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000109 def test_update_router_set_gateway_with_snat_explicit(self):
110 router = self._create_router(data_utils.rand_name('router-'))
111 self.admin_client.update_router_with_snat_gw_info(
112 router['id'],
113 external_gateway_info={
114 'network_id': CONF.network.public_network_id,
115 'enable_snat': True})
116 self._verify_router_gateway(
117 router['id'],
118 {'network_id': CONF.network.public_network_id,
119 'enable_snat': True})
120 self._verify_gateway_port(router['id'])
121
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000122 @decorators.idempotent_id('96536bc7-8262-4fb2-9967-5c46940fa279')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000123 @test.requires_ext(extension='ext-gw-mode', service='network')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000124 def test_update_router_set_gateway_without_snat(self):
125 router = self._create_router(data_utils.rand_name('router-'))
126 self.admin_client.update_router_with_snat_gw_info(
127 router['id'],
128 external_gateway_info={
129 'network_id': CONF.network.public_network_id,
130 'enable_snat': False})
131 self._verify_router_gateway(
132 router['id'],
133 {'network_id': CONF.network.public_network_id,
134 'enable_snat': False})
135 self._verify_gateway_port(router['id'])
136
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000137 @decorators.idempotent_id('f2faf994-97f4-410b-a831-9bc977b64374')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000138 @test.requires_ext(extension='ext-gw-mode', service='network')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000139 def test_update_router_reset_gateway_without_snat(self):
140 router = self._create_router(
141 data_utils.rand_name('router-'),
142 external_network_id=CONF.network.public_network_id)
143 self.admin_client.update_router_with_snat_gw_info(
144 router['id'],
145 external_gateway_info={
146 'network_id': CONF.network.public_network_id,
147 'enable_snat': False})
148 self._verify_router_gateway(
149 router['id'],
150 {'network_id': CONF.network.public_network_id,
151 'enable_snat': False})
152 self._verify_gateway_port(router['id'])
153
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000154 @decorators.idempotent_id('db3093b1-93b6-4893-be83-c4716c251b3e')
Kevin Bentonc66aa802016-07-23 22:36:37 -0700155 def test_router_interface_status(self):
156 network = self.create_network()
157 subnet = self.create_subnet(network)
158 # Add router interface with subnet id
159 router = self._create_router(data_utils.rand_name('router-'), True)
160 intf = self.create_router_interface(router['id'], subnet['id'])
161 status_active = lambda: self.client.show_port(
162 intf['port_id'])['port']['status'] == 'ACTIVE'
Wim De Clercqf09b6e52017-01-05 16:01:27 +0100163 utils.wait_until_true(status_active, exception=AssertionError)
Kevin Bentonc66aa802016-07-23 22:36:37 -0700164
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000165 @decorators.idempotent_id('c86ac3a8-50bd-4b00-a6b8-62af84a0765c')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000166 @test.requires_ext(extension='extraroute', service='network')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000167 def test_update_extra_route(self):
168 self.network = self.create_network()
169 self.name = self.network['name']
170 self.subnet = self.create_subnet(self.network)
171 # Add router interface with subnet id
172 self.router = self._create_router(
173 data_utils.rand_name('router-'), True)
174 self.create_router_interface(self.router['id'], self.subnet['id'])
175 self.addCleanup(
176 self._delete_extra_routes,
177 self.router['id'])
178 # Update router extra route, second ip of the range is
179 # used as next hop
180 cidr = netaddr.IPNetwork(self.subnet['cidr'])
181 next_hop = str(cidr[2])
182 destination = str(self.subnet['cidr'])
183 extra_route = self.client.update_extra_routes(self.router['id'],
184 next_hop, destination)
185 self.assertEqual(1, len(extra_route['router']['routes']))
186 self.assertEqual(destination,
187 extra_route['router']['routes'][0]['destination'])
188 self.assertEqual(next_hop,
189 extra_route['router']['routes'][0]['nexthop'])
190 show_body = self.client.show_router(self.router['id'])
191 self.assertEqual(destination,
192 show_body['router']['routes'][0]['destination'])
193 self.assertEqual(next_hop,
194 show_body['router']['routes'][0]['nexthop'])
195
196 def _delete_extra_routes(self, router_id):
197 self.client.delete_extra_routes(router_id)
198
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000199 @decorators.idempotent_id('01f185d1-d1a6-4cf9-abf7-e0e1384c169c')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000200 def test_network_attached_with_two_routers(self):
201 network = self.create_network(data_utils.rand_name('network1'))
202 self.create_subnet(network)
203 port1 = self.create_port(network)
204 port2 = self.create_port(network)
205 router1 = self._create_router(data_utils.rand_name('router1'))
206 router2 = self._create_router(data_utils.rand_name('router2'))
207 self.client.add_router_interface_with_port_id(
208 router1['id'], port1['id'])
209 self.client.add_router_interface_with_port_id(
210 router2['id'], port2['id'])
211 self.addCleanup(self.client.remove_router_interface_with_port_id,
212 router1['id'], port1['id'])
213 self.addCleanup(self.client.remove_router_interface_with_port_id,
214 router2['id'], port2['id'])
215 body = self.client.show_port(port1['id'])
216 port_show1 = body['port']
217 body = self.client.show_port(port2['id'])
218 port_show2 = body['port']
219 self.assertEqual(port_show1['network_id'], network['id'])
220 self.assertEqual(port_show2['network_id'], network['id'])
221 self.assertEqual(port_show1['device_id'], router1['id'])
222 self.assertEqual(port_show2['device_id'], router2['id'])
223
224
225class RoutersIpV6Test(RoutersTest):
226 _ip_version = 6
227
228
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200229class DvrRoutersTest(base_routers.BaseRouterTest):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000230
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000231 required_extensions = ['dvr']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000232
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000233 @decorators.idempotent_id('141297aa-3424-455d-aa8d-f2d95731e00a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000234 def test_create_distributed_router(self):
235 name = data_utils.rand_name('router')
236 create_body = self.admin_client.create_router(
237 name, distributed=True)
238 self.addCleanup(self._delete_router,
239 create_body['router']['id'],
240 self.admin_client)
241 self.assertTrue(create_body['router']['distributed'])
242
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000243 @decorators.idempotent_id('644d7a4a-01a1-4b68-bb8d-0c0042cb1729')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000244 def test_convert_centralized_router(self):
Brian Haley198a2d92017-06-16 16:23:44 -0400245 router_args = {'tenant_id': self.client.tenant_id,
246 'distributed': False, 'ha': False}
247 router = self.admin_client.create_router(
248 data_utils.rand_name('router'), admin_state_up=False,
249 **router_args)['router']
250 self.addCleanup(self.admin_client.delete_router,
251 router['id'])
252 self.assertFalse(router['distributed'])
253 self.assertFalse(router['ha'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000254 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'])
Brian Haley198a2d92017-06-16 16:23:44 -0400261 self.assertNotIn('ha', show_body['router'])
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200262
263
Dongcan Ye6d8ec4a2017-05-03 15:07:36 +0800264class HaRoutersTest(base_routers.BaseRouterTest):
265
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000266 required_extensions = ['l3-ha']
Dongcan Ye6d8ec4a2017-05-03 15:07:36 +0800267
268 @decorators.idempotent_id('77db8eae-3aa3-4e61-bf2a-e739ce042e53')
269 def test_convert_legacy_router(self):
270 router = self._create_router(data_utils.rand_name('router'))
271 self.assertNotIn('ha', router)
272 update_body = self.admin_client.update_router(router['id'],
273 ha=True)
274 self.assertTrue(update_body['router']['ha'])
275 show_body = self.admin_client.show_router(router['id'])
276 self.assertTrue(show_body['router']['ha'])
277 show_body = self.client.show_router(router['id'])
278 self.assertNotIn('ha', show_body['router'])
279
280
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200281class RoutersSearchCriteriaTest(base.BaseSearchCriteriaTest):
282
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000283 required_extensions = ['router']
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200284 resource = 'router'
285
286 @classmethod
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200287 def resource_setup(cls):
288 super(RoutersSearchCriteriaTest, cls).resource_setup()
289 for name in cls.resource_names:
290 cls.create_router(router_name=name)
291
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000292 @decorators.idempotent_id('03a69efb-90a7-435b-bb5c-3add3612085a')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200293 def test_list_sorts_asc(self):
294 self._test_list_sorts_asc()
295
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000296 @decorators.idempotent_id('95913d30-ff41-4b17-9f44-5258c651e78c')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200297 def test_list_sorts_desc(self):
298 self._test_list_sorts_desc()
299
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000300 @decorators.idempotent_id('7f7d40b1-e165-4817-8dc5-02f8e2f0dff3')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200301 def test_list_pagination(self):
302 self._test_list_pagination()
303
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000304 @decorators.idempotent_id('a5b83e83-3d98-45bb-a2c7-0ee179ffd42c')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200305 def test_list_pagination_with_marker(self):
306 self._test_list_pagination_with_marker()
307
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000308 @decorators.idempotent_id('40804af8-c25d-45f8-b8a8-b4c70345215d')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200309 def test_list_pagination_with_href_links(self):
310 self._test_list_pagination_with_href_links()
311
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000312 @decorators.idempotent_id('77b9676c-d3cb-43af-a0e8-a5b8c6099e70')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200313 def test_list_pagination_page_reverse_asc(self):
314 self._test_list_pagination_page_reverse_asc()
315
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000316 @decorators.idempotent_id('3133a2c5-1bb9-4fc7-833e-cf9a1d160255')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200317 def test_list_pagination_page_reverse_desc(self):
318 self._test_list_pagination_page_reverse_desc()
319
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000320 @decorators.idempotent_id('8252e2f0-b3da-4738-8e25-f6f8d878a2da')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200321 def test_list_pagination_page_reverse_with_href_links(self):
322 self._test_list_pagination_page_reverse_with_href_links()
323
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000324 @decorators.idempotent_id('fb102124-20f8-4cb3-8c81-f16f5e41d192')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200325 def test_list_no_pagination_limit_0(self):
326 self._test_list_no_pagination_limit_0()