blob: ff5d3916cbc09e0ee27687b5275ad9d93ede9666 [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
Dongcan Yea71b8342018-05-02 06:56:26 +000017
Arkady Shtemplerb667ac32020-11-17 20:23:41 +020018from neutron_lib import constants as const
19
Chandan Kumarc125fd12017-11-15 19:41:01 +053020from tempest.common import utils as tutils
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000021from tempest.lib.common.utils import data_utils
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000022from tempest.lib import decorators
Arkady Shtemplerb667ac32020-11-17 20:23:41 +020023from tempest.lib import exceptions as lib_exc
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000024
Chandan Kumar667d3d32017-09-22 12:24:06 +053025from neutron_tempest_plugin.api import base
26from neutron_tempest_plugin.api import base_routers
27from neutron_tempest_plugin.common import utils
28from neutron_tempest_plugin import config
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000029
30CONF = config.CONF
31
32
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +020033class RoutersTest(base_routers.BaseRouterTest):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000034
Jakub Libosvar1982aa12017-05-30 11:15:33 +000035 required_extensions = ['router']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000036
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')
Chandan Kumarc125fd12017-11-15 19:41:01 +053046 @tutils.requires_ext(extension="standard-attr-description",
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000047 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')
Chandan Kumarc125fd12017-11-15 19:41:01 +053059 @tutils.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')
Chandan Kumarc125fd12017-11-15 19:41:01 +053070 @tutils.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}
Brian Haleyee000852019-08-29 17:27:38 -040079 router = self._create_admin_router(
80 name, external_network_id=CONF.network.public_network_id,
81 enable_snat=enable_snat)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000082 # Verify snat attributes after router creation
Brian Haleyee000852019-08-29 17:27:38 -040083 self._verify_router_gateway(router['id'],
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000084 exp_ext_gw_info=external_gateway_info)
85
86 def _verify_router_gateway(self, router_id, exp_ext_gw_info=None):
87 show_body = self.admin_client.show_router(router_id)
88 actual_ext_gw_info = show_body['router']['external_gateway_info']
89 if exp_ext_gw_info is None:
90 self.assertIsNone(actual_ext_gw_info)
91 return
92 # Verify only keys passed in exp_ext_gw_info
fpxieaa3bace2017-04-07 17:12:15 +080093 for k, v in exp_ext_gw_info.items():
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000094 self.assertEqual(v, actual_ext_gw_info[k])
95
96 def _verify_gateway_port(self, router_id):
97 list_body = self.admin_client.list_ports(
98 network_id=CONF.network.public_network_id,
99 device_id=router_id)
100 self.assertEqual(len(list_body['ports']), 1)
101 gw_port = list_body['ports'][0]
102 fixed_ips = gw_port['fixed_ips']
103 self.assertGreaterEqual(len(fixed_ips), 1)
104 public_net_body = self.admin_client.show_network(
105 CONF.network.public_network_id)
Chandan Kumarc125fd12017-11-15 19:41:01 +0530106 public_subnet_ids = public_net_body['network']['subnets']
107 for fixed_ip in fixed_ips:
108 self.assertIn(fixed_ip['subnet_id'],
109 public_subnet_ids)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000110
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000111 @decorators.idempotent_id('b386c111-3b21-466d-880c-5e72b01e1a33')
Chandan Kumarc125fd12017-11-15 19:41:01 +0530112 @tutils.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):
Chandan Kumarc125fd12017-11-15 19:41:01 +0530114 router = self._create_router(data_utils.rand_name('router'))
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000115 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')
Chandan Kumarc125fd12017-11-15 19:41:01 +0530127 @tutils.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):
Chandan Kumarc125fd12017-11-15 19:41:01 +0530129 router = self._create_router(data_utils.rand_name('router'))
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000130 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')
Chandan Kumarc125fd12017-11-15 19:41:01 +0530142 @tutils.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(
Chandan Kumarc125fd12017-11-15 19:41:01 +0530145 data_utils.rand_name('router'),
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000146 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
Chandan Kumarc125fd12017-11-15 19:41:01 +0530163 router = self._create_router(data_utils.rand_name('router'), True)
Kevin Bentonc66aa802016-07-23 22:36:37 -0700164 intf = self.create_router_interface(router['id'], subnet['id'])
Brian Haley33ef4602018-04-26 14:37:49 -0400165
166 def _status_active():
167 return self.client.show_port(
168 intf['port_id'])['port']['status'] == 'ACTIVE'
169
170 utils.wait_until_true(_status_active, exception=AssertionError)
Kevin Bentonc66aa802016-07-23 22:36:37 -0700171
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000172 @decorators.idempotent_id('c86ac3a8-50bd-4b00-a6b8-62af84a0765c')
Chandan Kumarc125fd12017-11-15 19:41:01 +0530173 @tutils.requires_ext(extension='extraroute', service='network')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000174 def test_update_extra_route(self):
175 self.network = self.create_network()
176 self.name = self.network['name']
177 self.subnet = self.create_subnet(self.network)
178 # Add router interface with subnet id
179 self.router = self._create_router(
180 data_utils.rand_name('router-'), True)
181 self.create_router_interface(self.router['id'], self.subnet['id'])
182 self.addCleanup(
183 self._delete_extra_routes,
184 self.router['id'])
185 # Update router extra route, second ip of the range is
186 # used as next hop
187 cidr = netaddr.IPNetwork(self.subnet['cidr'])
188 next_hop = str(cidr[2])
189 destination = str(self.subnet['cidr'])
190 extra_route = self.client.update_extra_routes(self.router['id'],
191 next_hop, destination)
192 self.assertEqual(1, len(extra_route['router']['routes']))
193 self.assertEqual(destination,
194 extra_route['router']['routes'][0]['destination'])
195 self.assertEqual(next_hop,
196 extra_route['router']['routes'][0]['nexthop'])
197 show_body = self.client.show_router(self.router['id'])
198 self.assertEqual(destination,
199 show_body['router']['routes'][0]['destination'])
200 self.assertEqual(next_hop,
201 show_body['router']['routes'][0]['nexthop'])
202
203 def _delete_extra_routes(self, router_id):
204 self.client.delete_extra_routes(router_id)
205
Bence Romsics46bd3af2019-09-13 10:52:41 +0200206 @decorators.idempotent_id('b29d1698-d603-11e9-9c66-079cc4aec539')
207 @tutils.requires_ext(extension='extraroute-atomic', service='network')
208 def test_extra_routes_atomic(self):
209 self.network = self.create_network()
210 self.subnet = self.create_subnet(self.network)
211 self.router = self._create_router(
212 data_utils.rand_name('router-'), True)
213 self.create_router_interface(self.router['id'], self.subnet['id'])
214 self.addCleanup(
215 self._delete_extra_routes,
216 self.router['id'])
217
218 if self._ip_version == 6:
219 dst = '2001:db8:%s::/64'
220 else:
221 dst = '10.0.%s.0/24'
222
223 cidr = netaddr.IPNetwork(self.subnet['cidr'])
224
225 routes = [
226 {'destination': dst % 2, 'nexthop': cidr[2]},
227 ]
228 resp = self.client.add_extra_routes_atomic(
229 self.router['id'], routes)
230 self.assertEqual(1, len(resp['router']['routes']))
231
232 routes = [
233 {'destination': dst % 2, 'nexthop': cidr[2]},
234 {'destination': dst % 3, 'nexthop': cidr[3]},
235 ]
236 resp = self.client.add_extra_routes_atomic(
237 self.router['id'], routes)
238 self.assertEqual(2, len(resp['router']['routes']))
239
240 routes = [
241 {'destination': dst % 3, 'nexthop': cidr[3]},
242 {'destination': dst % 4, 'nexthop': cidr[4]},
243 ]
244 resp = self.client.remove_extra_routes_atomic(
245 self.router['id'], routes)
246 self.assertEqual(1, len(resp['router']['routes']))
247
248 routes = [
249 {'destination': dst % 2, 'nexthop': cidr[5]},
250 ]
251 resp = self.client.add_extra_routes_atomic(
252 self.router['id'], routes)
253 self.assertEqual(2, len(resp['router']['routes']))
254
255 routes = [
256 {'destination': dst % 2, 'nexthop': cidr[5]},
257 ]
258 resp = self.client.remove_extra_routes_atomic(
259 self.router['id'], routes)
260 self.assertEqual(1, len(resp['router']['routes']))
261
262 routes = [
263 {'destination': dst % 2, 'nexthop': cidr[2]},
264 {'destination': dst % 3, 'nexthop': cidr[3]},
265 {'destination': dst % 2, 'nexthop': cidr[5]},
266 ]
267 resp = self.client.remove_extra_routes_atomic(
268 self.router['id'], routes)
269 self.assertEqual(0, len(resp['router']['routes']))
270
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000271 @decorators.idempotent_id('01f185d1-d1a6-4cf9-abf7-e0e1384c169c')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000272 def test_network_attached_with_two_routers(self):
273 network = self.create_network(data_utils.rand_name('network1'))
274 self.create_subnet(network)
275 port1 = self.create_port(network)
276 port2 = self.create_port(network)
277 router1 = self._create_router(data_utils.rand_name('router1'))
278 router2 = self._create_router(data_utils.rand_name('router2'))
279 self.client.add_router_interface_with_port_id(
280 router1['id'], port1['id'])
281 self.client.add_router_interface_with_port_id(
282 router2['id'], port2['id'])
283 self.addCleanup(self.client.remove_router_interface_with_port_id,
284 router1['id'], port1['id'])
285 self.addCleanup(self.client.remove_router_interface_with_port_id,
286 router2['id'], port2['id'])
287 body = self.client.show_port(port1['id'])
288 port_show1 = body['port']
289 body = self.client.show_port(port2['id'])
290 port_show2 = body['port']
291 self.assertEqual(port_show1['network_id'], network['id'])
292 self.assertEqual(port_show2['network_id'], network['id'])
293 self.assertEqual(port_show1['device_id'], router1['id'])
294 self.assertEqual(port_show2['device_id'], router2['id'])
295
Rodolfo Alonso Hernandez780d81e2024-01-14 10:02:13 +0000296 @decorators.idempotent_id('4f8a2a1e-7fe9-4d99-9bff-5dc0e78b7e06')
297 def test_router_interface_update_and_remove_gateway_ip(self):
298 network = self.create_network()
299 subnet = self.create_subnet(network, allocation_pool_size=5)
300
301 # Update the subnet gateway IP, using the next one. Because the
302 # allocation pool is on the upper part of the CIDR, the lower IP
303 # addresses are free. This operation must be allowed because the subnet
304 # does not have yet a router port.
305 gateway_ip = netaddr.IPAddress(subnet['gateway_ip'])
306 self.client.update_subnet(subnet['id'], gateway_ip=str(gateway_ip + 1))
307
308 router = self._create_router(data_utils.rand_name('router'), True)
309 intf = self.create_router_interface(router['id'], subnet['id'])
310
311 def _status_active():
312 return self.client.show_port(
313 intf['port_id'])['port']['status'] == 'ACTIVE'
314
315 utils.wait_until_true(_status_active, exception=AssertionError)
316
317 # The gateway update must raise a ``GatewayIpInUse`` exception because
318 # there is an allocated router port.
319 gateway_ip = netaddr.IPAddress(subnet['gateway_ip'])
320 self.assertRaises(lib_exc.Conflict, self.client.update_subnet,
321 subnet['id'], gateway_ip=str(gateway_ip + 2))
322
323 # The gateway deletion returns the same exception.
324 gateway_ip = netaddr.IPAddress(subnet['gateway_ip'])
325 self.assertRaises(lib_exc.Conflict, self.client.update_subnet,
326 subnet['id'], gateway_ip=None)
327
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000328
329class RoutersIpV6Test(RoutersTest):
330 _ip_version = 6
331
332
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200333class DvrRoutersTest(base_routers.BaseRouterTest):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000334
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000335 required_extensions = ['dvr']
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000336
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000337 @decorators.idempotent_id('141297aa-3424-455d-aa8d-f2d95731e00a')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000338 def test_create_distributed_router(self):
339 name = data_utils.rand_name('router')
Brian Haleyee000852019-08-29 17:27:38 -0400340 router = self._create_admin_router(name, distributed=True)
341 self.assertTrue(router['distributed'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000342
Dongcan Yea71b8342018-05-02 06:56:26 +0000343
344class DvrRoutersTestToCentralized(base_routers.BaseRouterTest):
345
346 required_extensions = ['dvr', 'l3-ha']
347
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000348 @decorators.idempotent_id('644d7a4a-01a1-4b68-bb8d-0c0042cb1729')
Kailun Qince246d02018-07-20 21:38:07 +0800349 def test_convert_distributed_router_back_to_centralized(self):
350 # Convert a centralized router to distributed firstly
Takashi Kajinamida451772023-03-22 00:19:39 +0900351 router_args = {'tenant_id': self.client.project_id,
Brian Haley198a2d92017-06-16 16:23:44 -0400352 'distributed': False, 'ha': False}
Brian Haleyee000852019-08-29 17:27:38 -0400353 router = self._create_admin_router(
Brian Haley198a2d92017-06-16 16:23:44 -0400354 data_utils.rand_name('router'), admin_state_up=False,
Brian Haleyee000852019-08-29 17:27:38 -0400355 **router_args)
Brian Haley198a2d92017-06-16 16:23:44 -0400356 self.assertFalse(router['distributed'])
357 self.assertFalse(router['ha'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000358 update_body = self.admin_client.update_router(router['id'],
359 distributed=True)
360 self.assertTrue(update_body['router']['distributed'])
361 show_body = self.admin_client.show_router(router['id'])
362 self.assertTrue(show_body['router']['distributed'])
Kailun Qince246d02018-07-20 21:38:07 +0800363 self.assertFalse(show_body['router']['ha'])
364 # Then convert the distributed router back to centralized
365 update_body = self.admin_client.update_router(router['id'],
366 distributed=False)
367 self.assertFalse(update_body['router']['distributed'])
368 show_body = self.admin_client.show_router(router['id'])
369 self.assertFalse(show_body['router']['distributed'])
370 self.assertFalse(show_body['router']['ha'])
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000371 show_body = self.client.show_router(router['id'])
372 self.assertNotIn('distributed', show_body['router'])
Brian Haley198a2d92017-06-16 16:23:44 -0400373 self.assertNotIn('ha', show_body['router'])
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200374
375
Matt Welchffe9be82019-07-02 13:24:29 +0000376class DvrRoutersTestUpdateDistributedExtended(base_routers.BaseRouterTest):
377
378 required_extensions = ['dvr', 'l3-ha',
379 'router-admin-state-down-before-update']
380
381 @decorators.idempotent_id('0ffb9973-0c1a-4b76-a1f2-060178057661')
382 def test_convert_centralized_router_to_distributed_extended(self):
Takashi Kajinamida451772023-03-22 00:19:39 +0900383 router_args = {'tenant_id': self.client.project_id,
Matt Welchffe9be82019-07-02 13:24:29 +0000384 'distributed': False, 'ha': False}
Brian Haleyee000852019-08-29 17:27:38 -0400385 router = self._create_admin_router(
Matt Welchffe9be82019-07-02 13:24:29 +0000386 data_utils.rand_name('router'), admin_state_up=True,
Brian Haleyee000852019-08-29 17:27:38 -0400387 **router_args)
Matt Welchffe9be82019-07-02 13:24:29 +0000388 self.assertTrue(router['admin_state_up'])
389 self.assertFalse(router['distributed'])
390 # take router down to allow setting the router to distributed
391 update_body = self.admin_client.update_router(router['id'],
392 admin_state_up=False)
393 self.assertFalse(update_body['router']['admin_state_up'])
394 # set the router to distributed
395 update_body = self.admin_client.update_router(router['id'],
396 distributed=True)
397 self.assertTrue(update_body['router']['distributed'])
398 # bring the router back up
399 update_body = self.admin_client.update_router(router['id'],
400 admin_state_up=True)
401 self.assertTrue(update_body['router']['admin_state_up'])
402 self.assertTrue(update_body['router']['distributed'])
403
404 @decorators.idempotent_id('e9a8f55b-c535-44b7-8b0a-20af6a7c2921')
405 def test_convert_distributed_router_to_centralized_extended(self):
Takashi Kajinamida451772023-03-22 00:19:39 +0900406 router_args = {'tenant_id': self.client.project_id,
Matt Welchffe9be82019-07-02 13:24:29 +0000407 'distributed': True, 'ha': False}
Brian Haleyee000852019-08-29 17:27:38 -0400408 router = self._create_admin_router(
Matt Welchffe9be82019-07-02 13:24:29 +0000409 data_utils.rand_name('router'), admin_state_up=True,
Brian Haleyee000852019-08-29 17:27:38 -0400410 **router_args)
Matt Welchffe9be82019-07-02 13:24:29 +0000411 self.assertTrue(router['admin_state_up'])
412 self.assertTrue(router['distributed'])
413 # take router down to allow setting the router to centralized
414 update_body = self.admin_client.update_router(router['id'],
415 admin_state_up=False)
416 self.assertFalse(update_body['router']['admin_state_up'])
417 # set router to centralized
418 update_body = self.admin_client.update_router(router['id'],
419 distributed=False)
420 self.assertFalse(update_body['router']['distributed'])
421 # bring router back up
422 update_body = self.admin_client.update_router(router['id'],
423 admin_state_up=True)
424 self.assertTrue(update_body['router']['admin_state_up'])
425 self.assertFalse(update_body['router']['distributed'])
426
427
Dongcan Ye6d8ec4a2017-05-03 15:07:36 +0800428class HaRoutersTest(base_routers.BaseRouterTest):
429
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000430 required_extensions = ['l3-ha']
Dongcan Ye6d8ec4a2017-05-03 15:07:36 +0800431
432 @decorators.idempotent_id('77db8eae-3aa3-4e61-bf2a-e739ce042e53')
433 def test_convert_legacy_router(self):
434 router = self._create_router(data_utils.rand_name('router'))
435 self.assertNotIn('ha', router)
436 update_body = self.admin_client.update_router(router['id'],
437 ha=True)
438 self.assertTrue(update_body['router']['ha'])
439 show_body = self.admin_client.show_router(router['id'])
440 self.assertTrue(show_body['router']['ha'])
441 show_body = self.client.show_router(router['id'])
442 self.assertNotIn('ha', show_body['router'])
443
444
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200445class RoutersSearchCriteriaTest(base.BaseSearchCriteriaTest):
446
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000447 required_extensions = ['router']
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200448 resource = 'router'
449
450 @classmethod
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200451 def resource_setup(cls):
452 super(RoutersSearchCriteriaTest, cls).resource_setup()
453 for name in cls.resource_names:
454 cls.create_router(router_name=name)
455
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000456 @decorators.idempotent_id('03a69efb-90a7-435b-bb5c-3add3612085a')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200457 def test_list_sorts_asc(self):
458 self._test_list_sorts_asc()
459
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000460 @decorators.idempotent_id('95913d30-ff41-4b17-9f44-5258c651e78c')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200461 def test_list_sorts_desc(self):
462 self._test_list_sorts_desc()
463
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000464 @decorators.idempotent_id('7f7d40b1-e165-4817-8dc5-02f8e2f0dff3')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200465 def test_list_pagination(self):
466 self._test_list_pagination()
467
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000468 @decorators.idempotent_id('a5b83e83-3d98-45bb-a2c7-0ee179ffd42c')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200469 def test_list_pagination_with_marker(self):
470 self._test_list_pagination_with_marker()
471
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000472 @decorators.idempotent_id('40804af8-c25d-45f8-b8a8-b4c70345215d')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200473 def test_list_pagination_with_href_links(self):
474 self._test_list_pagination_with_href_links()
475
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000476 @decorators.idempotent_id('77b9676c-d3cb-43af-a0e8-a5b8c6099e70')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200477 def test_list_pagination_page_reverse_asc(self):
478 self._test_list_pagination_page_reverse_asc()
479
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000480 @decorators.idempotent_id('3133a2c5-1bb9-4fc7-833e-cf9a1d160255')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200481 def test_list_pagination_page_reverse_desc(self):
482 self._test_list_pagination_page_reverse_desc()
483
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000484 @decorators.idempotent_id('8252e2f0-b3da-4738-8e25-f6f8d878a2da')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200485 def test_list_pagination_page_reverse_with_href_links(self):
486 self._test_list_pagination_page_reverse_with_href_links()
487
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000488 @decorators.idempotent_id('fb102124-20f8-4cb3-8c81-f16f5e41d192')
Ihar Hrachyshka44d1d3f2016-06-14 11:51:37 +0200489 def test_list_no_pagination_limit_0(self):
490 self._test_list_no_pagination_limit_0()
Arkady Shtemplerb667ac32020-11-17 20:23:41 +0200491
492
493class RoutersDeleteTest(base_routers.BaseRouterTest):
494 """The only test in this class is a test that removes router!
495
496 * We cannot delete common and mandatory resources (router in this case)
497 * using the existing classes, as it will cause failure in other tests
498 * running in parallel.
499 """
500 @classmethod
501 def resource_setup(cls):
502 super(RoutersDeleteTest, cls).resource_setup()
503 cls.secgroup = cls.create_security_group(
504 name=data_utils.rand_name("test_port_secgroup"))
505 router_kwargs = {
506 'router_name': data_utils.rand_name('router_to_delete'),
507 'external_network_id': CONF.network.public_network_id}
508 cls.router = cls.create_router(**router_kwargs)
509
510 @decorators.idempotent_id('dbbc5c74-63c8-11eb-8881-74e5f9e2a801')
511 def test_delete_router(self):
512 # Create a port on tenant network and associate to the router.
513 # Try to delete router. Expected result: "Conflict Error" is raised.
514 network = self.create_network()
515 subnet = self.create_subnet(network)
516 self.create_router_interface(self.router['id'], subnet['id'])
517 port = self.create_port(
518 network, name=data_utils.rand_name("port"),
519 security_groups=[self.secgroup['id']])
520 self.create_floatingip(port=port)
521 self.assertRaises(
522 lib_exc.Conflict, self.client.delete_router, self.router['id'])
523 # Delete the associated port
524 # Try to delete router. Expected result: "Conflict Error" is raised.
525 # Note: there are still interfaces in use.
526 self.client.delete_port(port['id'])
527 self.assertRaises(
528 lib_exc.Conflict, self.client.delete_router, self.router['id'])
529 # Delete the rest of the router's ports
530 # Try to delete router. Expected result: "PASS"
531 interfaces = [
532 port for port in self.client.list_router_interfaces(
533 self.router['id'])['ports']
534 if port['device_owner'] in const.ROUTER_INTERFACE_OWNERS]
535 for i in interfaces:
536 try:
537 self.assertRaises(
538 lib_exc.Conflict, self.client.delete_router,
539 self.router['id'])
540 self.client.remove_router_interface_with_subnet_id(
541 self.router['id'], i['fixed_ips'][0]['subnet_id'])
542 except lib_exc.NotFound:
543 pass
544 self.client.delete_router(self.router['id'])