Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 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 |
Dongcan Ye | a71b834 | 2018-05-02 06:56:26 +0000 | [diff] [blame] | 17 | |
Arkady Shtempler | b667ac3 | 2020-11-17 20:23:41 +0200 | [diff] [blame] | 18 | from neutron_lib import constants as const |
| 19 | |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 20 | from tempest.common import utils as tutils |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 21 | from tempest.lib.common.utils import data_utils |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 22 | from tempest.lib import decorators |
Arkady Shtempler | b667ac3 | 2020-11-17 20:23:41 +0200 | [diff] [blame] | 23 | from tempest.lib import exceptions as lib_exc |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 24 | |
Chandan Kumar | 667d3d3 | 2017-09-22 12:24:06 +0530 | [diff] [blame] | 25 | from neutron_tempest_plugin.api import base |
| 26 | from neutron_tempest_plugin.api import base_routers |
| 27 | from neutron_tempest_plugin.common import utils |
| 28 | from neutron_tempest_plugin import config |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 29 | |
| 30 | CONF = config.CONF |
| 31 | |
| 32 | |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 33 | class RoutersTest(base_routers.BaseRouterTest): |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 34 | |
Jakub Libosvar | 1982aa1 | 2017-05-30 11:15:33 +0000 | [diff] [blame] | 35 | required_extensions = ['router'] |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 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ński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 45 | @decorators.idempotent_id('c72c1c0c-2193-4aca-eeee-b1442640eeee') |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 46 | @tutils.requires_ext(extension="standard-attr-description", |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 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ński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 58 | @decorators.idempotent_id('847257cc-6afd-4154-b8fb-af49f5670ce8') |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 59 | @tutils.requires_ext(extension='ext-gw-mode', service='network') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 60 | 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ński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 69 | @decorators.idempotent_id('ea74068d-09e9-4fd7-8995-9b6a1ace920f') |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 70 | @tutils.requires_ext(extension='ext-gw-mode', service='network') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 71 | 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 Haley | ee00085 | 2019-08-29 17:27:38 -0400 | [diff] [blame] | 79 | router = self._create_admin_router( |
| 80 | name, external_network_id=CONF.network.public_network_id, |
| 81 | enable_snat=enable_snat) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 82 | # Verify snat attributes after router creation |
Brian Haley | ee00085 | 2019-08-29 17:27:38 -0400 | [diff] [blame] | 83 | self._verify_router_gateway(router['id'], |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 84 | 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 |
fpxie | aa3bace | 2017-04-07 17:12:15 +0800 | [diff] [blame] | 93 | for k, v in exp_ext_gw_info.items(): |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 94 | 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 Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 106 | 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 Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 110 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 111 | @decorators.idempotent_id('b386c111-3b21-466d-880c-5e72b01e1a33') |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 112 | @tutils.requires_ext(extension='ext-gw-mode', service='network') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 113 | def test_update_router_set_gateway_with_snat_explicit(self): |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 114 | router = self._create_router(data_utils.rand_name('router')) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 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ński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 126 | @decorators.idempotent_id('96536bc7-8262-4fb2-9967-5c46940fa279') |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 127 | @tutils.requires_ext(extension='ext-gw-mode', service='network') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 128 | def test_update_router_set_gateway_without_snat(self): |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 129 | router = self._create_router(data_utils.rand_name('router')) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 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ński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 141 | @decorators.idempotent_id('f2faf994-97f4-410b-a831-9bc977b64374') |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 142 | @tutils.requires_ext(extension='ext-gw-mode', service='network') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 143 | def test_update_router_reset_gateway_without_snat(self): |
| 144 | router = self._create_router( |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 145 | data_utils.rand_name('router'), |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 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ński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 158 | @decorators.idempotent_id('db3093b1-93b6-4893-be83-c4716c251b3e') |
Kevin Benton | c66aa80 | 2016-07-23 22:36:37 -0700 | [diff] [blame] | 159 | 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 Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 163 | router = self._create_router(data_utils.rand_name('router'), True) |
Kevin Benton | c66aa80 | 2016-07-23 22:36:37 -0700 | [diff] [blame] | 164 | intf = self.create_router_interface(router['id'], subnet['id']) |
Brian Haley | 33ef460 | 2018-04-26 14:37:49 -0400 | [diff] [blame] | 165 | |
| 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 Benton | c66aa80 | 2016-07-23 22:36:37 -0700 | [diff] [blame] | 171 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 172 | @decorators.idempotent_id('c86ac3a8-50bd-4b00-a6b8-62af84a0765c') |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 173 | @tutils.requires_ext(extension='extraroute', service='network') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 174 | 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 Romsics | 46bd3af | 2019-09-13 10:52:41 +0200 | [diff] [blame] | 206 | @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ński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 271 | @decorators.idempotent_id('01f185d1-d1a6-4cf9-abf7-e0e1384c169c') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 272 | 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 | |
| 296 | |
| 297 | class RoutersIpV6Test(RoutersTest): |
| 298 | _ip_version = 6 |
| 299 | |
| 300 | |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 301 | class DvrRoutersTest(base_routers.BaseRouterTest): |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 302 | |
Jakub Libosvar | 1982aa1 | 2017-05-30 11:15:33 +0000 | [diff] [blame] | 303 | required_extensions = ['dvr'] |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 304 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 305 | @decorators.idempotent_id('141297aa-3424-455d-aa8d-f2d95731e00a') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 306 | def test_create_distributed_router(self): |
| 307 | name = data_utils.rand_name('router') |
Brian Haley | ee00085 | 2019-08-29 17:27:38 -0400 | [diff] [blame] | 308 | router = self._create_admin_router(name, distributed=True) |
| 309 | self.assertTrue(router['distributed']) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 310 | |
Dongcan Ye | a71b834 | 2018-05-02 06:56:26 +0000 | [diff] [blame] | 311 | |
| 312 | class DvrRoutersTestToCentralized(base_routers.BaseRouterTest): |
| 313 | |
| 314 | required_extensions = ['dvr', 'l3-ha'] |
| 315 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 316 | @decorators.idempotent_id('644d7a4a-01a1-4b68-bb8d-0c0042cb1729') |
Kailun Qin | ce246d0 | 2018-07-20 21:38:07 +0800 | [diff] [blame] | 317 | def test_convert_distributed_router_back_to_centralized(self): |
| 318 | # Convert a centralized router to distributed firstly |
Brian Haley | 198a2d9 | 2017-06-16 16:23:44 -0400 | [diff] [blame] | 319 | router_args = {'tenant_id': self.client.tenant_id, |
| 320 | 'distributed': False, 'ha': False} |
Brian Haley | ee00085 | 2019-08-29 17:27:38 -0400 | [diff] [blame] | 321 | router = self._create_admin_router( |
Brian Haley | 198a2d9 | 2017-06-16 16:23:44 -0400 | [diff] [blame] | 322 | data_utils.rand_name('router'), admin_state_up=False, |
Brian Haley | ee00085 | 2019-08-29 17:27:38 -0400 | [diff] [blame] | 323 | **router_args) |
Brian Haley | 198a2d9 | 2017-06-16 16:23:44 -0400 | [diff] [blame] | 324 | self.assertFalse(router['distributed']) |
| 325 | self.assertFalse(router['ha']) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 326 | update_body = self.admin_client.update_router(router['id'], |
| 327 | distributed=True) |
| 328 | self.assertTrue(update_body['router']['distributed']) |
| 329 | show_body = self.admin_client.show_router(router['id']) |
| 330 | self.assertTrue(show_body['router']['distributed']) |
Kailun Qin | ce246d0 | 2018-07-20 21:38:07 +0800 | [diff] [blame] | 331 | self.assertFalse(show_body['router']['ha']) |
| 332 | # Then convert the distributed router back to centralized |
| 333 | update_body = self.admin_client.update_router(router['id'], |
| 334 | distributed=False) |
| 335 | self.assertFalse(update_body['router']['distributed']) |
| 336 | show_body = self.admin_client.show_router(router['id']) |
| 337 | self.assertFalse(show_body['router']['distributed']) |
| 338 | self.assertFalse(show_body['router']['ha']) |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 339 | show_body = self.client.show_router(router['id']) |
| 340 | self.assertNotIn('distributed', show_body['router']) |
Brian Haley | 198a2d9 | 2017-06-16 16:23:44 -0400 | [diff] [blame] | 341 | self.assertNotIn('ha', show_body['router']) |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 342 | |
| 343 | |
Matt Welch | ffe9be8 | 2019-07-02 13:24:29 +0000 | [diff] [blame] | 344 | class DvrRoutersTestUpdateDistributedExtended(base_routers.BaseRouterTest): |
| 345 | |
| 346 | required_extensions = ['dvr', 'l3-ha', |
| 347 | 'router-admin-state-down-before-update'] |
| 348 | |
| 349 | @decorators.idempotent_id('0ffb9973-0c1a-4b76-a1f2-060178057661') |
| 350 | def test_convert_centralized_router_to_distributed_extended(self): |
| 351 | router_args = {'tenant_id': self.client.tenant_id, |
| 352 | 'distributed': False, 'ha': False} |
Brian Haley | ee00085 | 2019-08-29 17:27:38 -0400 | [diff] [blame] | 353 | router = self._create_admin_router( |
Matt Welch | ffe9be8 | 2019-07-02 13:24:29 +0000 | [diff] [blame] | 354 | data_utils.rand_name('router'), admin_state_up=True, |
Brian Haley | ee00085 | 2019-08-29 17:27:38 -0400 | [diff] [blame] | 355 | **router_args) |
Matt Welch | ffe9be8 | 2019-07-02 13:24:29 +0000 | [diff] [blame] | 356 | self.assertTrue(router['admin_state_up']) |
| 357 | self.assertFalse(router['distributed']) |
| 358 | # take router down to allow setting the router to distributed |
| 359 | update_body = self.admin_client.update_router(router['id'], |
| 360 | admin_state_up=False) |
| 361 | self.assertFalse(update_body['router']['admin_state_up']) |
| 362 | # set the router to distributed |
| 363 | update_body = self.admin_client.update_router(router['id'], |
| 364 | distributed=True) |
| 365 | self.assertTrue(update_body['router']['distributed']) |
| 366 | # bring the router back up |
| 367 | update_body = self.admin_client.update_router(router['id'], |
| 368 | admin_state_up=True) |
| 369 | self.assertTrue(update_body['router']['admin_state_up']) |
| 370 | self.assertTrue(update_body['router']['distributed']) |
| 371 | |
| 372 | @decorators.idempotent_id('e9a8f55b-c535-44b7-8b0a-20af6a7c2921') |
| 373 | def test_convert_distributed_router_to_centralized_extended(self): |
| 374 | router_args = {'tenant_id': self.client.tenant_id, |
| 375 | 'distributed': True, 'ha': False} |
Brian Haley | ee00085 | 2019-08-29 17:27:38 -0400 | [diff] [blame] | 376 | router = self._create_admin_router( |
Matt Welch | ffe9be8 | 2019-07-02 13:24:29 +0000 | [diff] [blame] | 377 | data_utils.rand_name('router'), admin_state_up=True, |
Brian Haley | ee00085 | 2019-08-29 17:27:38 -0400 | [diff] [blame] | 378 | **router_args) |
Matt Welch | ffe9be8 | 2019-07-02 13:24:29 +0000 | [diff] [blame] | 379 | self.assertTrue(router['admin_state_up']) |
| 380 | self.assertTrue(router['distributed']) |
| 381 | # take router down to allow setting the router to centralized |
| 382 | update_body = self.admin_client.update_router(router['id'], |
| 383 | admin_state_up=False) |
| 384 | self.assertFalse(update_body['router']['admin_state_up']) |
| 385 | # set router to centralized |
| 386 | update_body = self.admin_client.update_router(router['id'], |
| 387 | distributed=False) |
| 388 | self.assertFalse(update_body['router']['distributed']) |
| 389 | # bring router back up |
| 390 | update_body = self.admin_client.update_router(router['id'], |
| 391 | admin_state_up=True) |
| 392 | self.assertTrue(update_body['router']['admin_state_up']) |
| 393 | self.assertFalse(update_body['router']['distributed']) |
| 394 | |
| 395 | |
Dongcan Ye | 6d8ec4a | 2017-05-03 15:07:36 +0800 | [diff] [blame] | 396 | class HaRoutersTest(base_routers.BaseRouterTest): |
| 397 | |
Jakub Libosvar | 1982aa1 | 2017-05-30 11:15:33 +0000 | [diff] [blame] | 398 | required_extensions = ['l3-ha'] |
Dongcan Ye | 6d8ec4a | 2017-05-03 15:07:36 +0800 | [diff] [blame] | 399 | |
| 400 | @decorators.idempotent_id('77db8eae-3aa3-4e61-bf2a-e739ce042e53') |
| 401 | def test_convert_legacy_router(self): |
| 402 | router = self._create_router(data_utils.rand_name('router')) |
| 403 | self.assertNotIn('ha', router) |
| 404 | update_body = self.admin_client.update_router(router['id'], |
| 405 | ha=True) |
| 406 | self.assertTrue(update_body['router']['ha']) |
| 407 | show_body = self.admin_client.show_router(router['id']) |
| 408 | self.assertTrue(show_body['router']['ha']) |
| 409 | show_body = self.client.show_router(router['id']) |
| 410 | self.assertNotIn('ha', show_body['router']) |
| 411 | |
| 412 | |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 413 | class RoutersSearchCriteriaTest(base.BaseSearchCriteriaTest): |
| 414 | |
Jakub Libosvar | 1982aa1 | 2017-05-30 11:15:33 +0000 | [diff] [blame] | 415 | required_extensions = ['router'] |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 416 | resource = 'router' |
| 417 | |
| 418 | @classmethod |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 419 | def resource_setup(cls): |
| 420 | super(RoutersSearchCriteriaTest, cls).resource_setup() |
| 421 | for name in cls.resource_names: |
| 422 | cls.create_router(router_name=name) |
| 423 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 424 | @decorators.idempotent_id('03a69efb-90a7-435b-bb5c-3add3612085a') |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 425 | def test_list_sorts_asc(self): |
| 426 | self._test_list_sorts_asc() |
| 427 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 428 | @decorators.idempotent_id('95913d30-ff41-4b17-9f44-5258c651e78c') |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 429 | def test_list_sorts_desc(self): |
| 430 | self._test_list_sorts_desc() |
| 431 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 432 | @decorators.idempotent_id('7f7d40b1-e165-4817-8dc5-02f8e2f0dff3') |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 433 | def test_list_pagination(self): |
| 434 | self._test_list_pagination() |
| 435 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 436 | @decorators.idempotent_id('a5b83e83-3d98-45bb-a2c7-0ee179ffd42c') |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 437 | def test_list_pagination_with_marker(self): |
| 438 | self._test_list_pagination_with_marker() |
| 439 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 440 | @decorators.idempotent_id('40804af8-c25d-45f8-b8a8-b4c70345215d') |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 441 | def test_list_pagination_with_href_links(self): |
| 442 | self._test_list_pagination_with_href_links() |
| 443 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 444 | @decorators.idempotent_id('77b9676c-d3cb-43af-a0e8-a5b8c6099e70') |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 445 | def test_list_pagination_page_reverse_asc(self): |
| 446 | self._test_list_pagination_page_reverse_asc() |
| 447 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 448 | @decorators.idempotent_id('3133a2c5-1bb9-4fc7-833e-cf9a1d160255') |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 449 | def test_list_pagination_page_reverse_desc(self): |
| 450 | self._test_list_pagination_page_reverse_desc() |
| 451 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 452 | @decorators.idempotent_id('8252e2f0-b3da-4738-8e25-f6f8d878a2da') |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 453 | def test_list_pagination_page_reverse_with_href_links(self): |
| 454 | self._test_list_pagination_page_reverse_with_href_links() |
| 455 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 456 | @decorators.idempotent_id('fb102124-20f8-4cb3-8c81-f16f5e41d192') |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 457 | def test_list_no_pagination_limit_0(self): |
| 458 | self._test_list_no_pagination_limit_0() |
Arkady Shtempler | b667ac3 | 2020-11-17 20:23:41 +0200 | [diff] [blame] | 459 | |
| 460 | |
| 461 | class RoutersDeleteTest(base_routers.BaseRouterTest): |
| 462 | """The only test in this class is a test that removes router! |
| 463 | |
| 464 | * We cannot delete common and mandatory resources (router in this case) |
| 465 | * using the existing classes, as it will cause failure in other tests |
| 466 | * running in parallel. |
| 467 | """ |
| 468 | @classmethod |
| 469 | def resource_setup(cls): |
| 470 | super(RoutersDeleteTest, cls).resource_setup() |
| 471 | cls.secgroup = cls.create_security_group( |
| 472 | name=data_utils.rand_name("test_port_secgroup")) |
| 473 | router_kwargs = { |
| 474 | 'router_name': data_utils.rand_name('router_to_delete'), |
| 475 | 'external_network_id': CONF.network.public_network_id} |
| 476 | cls.router = cls.create_router(**router_kwargs) |
| 477 | |
| 478 | @decorators.idempotent_id('dbbc5c74-63c8-11eb-8881-74e5f9e2a801') |
| 479 | def test_delete_router(self): |
| 480 | # Create a port on tenant network and associate to the router. |
| 481 | # Try to delete router. Expected result: "Conflict Error" is raised. |
| 482 | network = self.create_network() |
| 483 | subnet = self.create_subnet(network) |
| 484 | self.create_router_interface(self.router['id'], subnet['id']) |
| 485 | port = self.create_port( |
| 486 | network, name=data_utils.rand_name("port"), |
| 487 | security_groups=[self.secgroup['id']]) |
| 488 | self.create_floatingip(port=port) |
| 489 | self.assertRaises( |
| 490 | lib_exc.Conflict, self.client.delete_router, self.router['id']) |
| 491 | # Delete the associated port |
| 492 | # Try to delete router. Expected result: "Conflict Error" is raised. |
| 493 | # Note: there are still interfaces in use. |
| 494 | self.client.delete_port(port['id']) |
| 495 | self.assertRaises( |
| 496 | lib_exc.Conflict, self.client.delete_router, self.router['id']) |
| 497 | # Delete the rest of the router's ports |
| 498 | # Try to delete router. Expected result: "PASS" |
| 499 | interfaces = [ |
| 500 | port for port in self.client.list_router_interfaces( |
| 501 | self.router['id'])['ports'] |
| 502 | if port['device_owner'] in const.ROUTER_INTERFACE_OWNERS] |
| 503 | for i in interfaces: |
| 504 | try: |
| 505 | self.assertRaises( |
| 506 | lib_exc.Conflict, self.client.delete_router, |
| 507 | self.router['id']) |
| 508 | self.client.remove_router_interface_with_subnet_id( |
| 509 | self.router['id'], i['fixed_ips'][0]['subnet_id']) |
| 510 | except lib_exc.NotFound: |
| 511 | pass |
| 512 | self.client.delete_router(self.router['id']) |