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 |
| 17 | import six |
| 18 | from tempest.lib.common.utils import data_utils |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 19 | from tempest.lib import decorators |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 20 | from tempest import test |
| 21 | |
Kevin Benton | c66aa80 | 2016-07-23 22:36:37 -0700 | [diff] [blame] | 22 | from neutron.common import utils |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 23 | from neutron.tests.tempest.api import base |
| 24 | from neutron.tests.tempest.api import base_routers |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 25 | from neutron.tests.tempest import config |
| 26 | |
| 27 | CONF = config.CONF |
| 28 | |
| 29 | |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 30 | class RoutersTest(base_routers.BaseRouterTest): |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 31 | |
| 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ński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 45 | @decorators.idempotent_id('c72c1c0c-2193-4aca-eeee-b1442640eeee') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 46 | @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ński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 58 | @decorators.idempotent_id('847257cc-6afd-4154-b8fb-af49f5670ce8') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 59 | @test.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') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 70 | @test.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} |
| 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ński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 111 | @decorators.idempotent_id('b386c111-3b21-466d-880c-5e72b01e1a33') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 112 | @test.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): |
| 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ński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 126 | @decorators.idempotent_id('96536bc7-8262-4fb2-9967-5c46940fa279') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 127 | @test.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): |
| 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ński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 141 | @decorators.idempotent_id('f2faf994-97f4-410b-a831-9bc977b64374') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 142 | @test.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( |
| 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ń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 |
| 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 Clercq | f09b6e5 | 2017-01-05 16:01:27 +0100 | [diff] [blame] | 167 | utils.wait_until_true(status_active, exception=AssertionError) |
Kevin Benton | c66aa80 | 2016-07-23 22:36:37 -0700 | [diff] [blame] | 168 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 169 | @decorators.idempotent_id('c86ac3a8-50bd-4b00-a6b8-62af84a0765c') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 170 | @test.requires_ext(extension='extraroute', service='network') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 171 | 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ński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 203 | @decorators.idempotent_id('01f185d1-d1a6-4cf9-abf7-e0e1384c169c') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 204 | 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 | |
| 229 | class RoutersIpV6Test(RoutersTest): |
| 230 | _ip_version = 6 |
| 231 | |
| 232 | |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 233 | class DvrRoutersTest(base_routers.BaseRouterTest): |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 234 | |
| 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ński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 240 | @decorators.idempotent_id('141297aa-3424-455d-aa8d-f2d95731e00a') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 241 | 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ński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 250 | @decorators.idempotent_id('644d7a4a-01a1-4b68-bb8d-0c0042cb1729') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 251 | 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 Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 261 | |
| 262 | |
| 263 | class 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ński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 278 | @decorators.idempotent_id('03a69efb-90a7-435b-bb5c-3add3612085a') |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 279 | def test_list_sorts_asc(self): |
| 280 | self._test_list_sorts_asc() |
| 281 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 282 | @decorators.idempotent_id('95913d30-ff41-4b17-9f44-5258c651e78c') |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 283 | def test_list_sorts_desc(self): |
| 284 | self._test_list_sorts_desc() |
| 285 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 286 | @decorators.idempotent_id('7f7d40b1-e165-4817-8dc5-02f8e2f0dff3') |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 287 | def test_list_pagination(self): |
| 288 | self._test_list_pagination() |
| 289 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 290 | @decorators.idempotent_id('a5b83e83-3d98-45bb-a2c7-0ee179ffd42c') |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 291 | def test_list_pagination_with_marker(self): |
| 292 | self._test_list_pagination_with_marker() |
| 293 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 294 | @decorators.idempotent_id('40804af8-c25d-45f8-b8a8-b4c70345215d') |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 295 | def test_list_pagination_with_href_links(self): |
| 296 | self._test_list_pagination_with_href_links() |
| 297 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 298 | @decorators.idempotent_id('77b9676c-d3cb-43af-a0e8-a5b8c6099e70') |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 299 | def test_list_pagination_page_reverse_asc(self): |
| 300 | self._test_list_pagination_page_reverse_asc() |
| 301 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 302 | @decorators.idempotent_id('3133a2c5-1bb9-4fc7-833e-cf9a1d160255') |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 303 | def test_list_pagination_page_reverse_desc(self): |
| 304 | self._test_list_pagination_page_reverse_desc() |
| 305 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 306 | @decorators.idempotent_id('8252e2f0-b3da-4738-8e25-f6f8d878a2da') |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 307 | 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ński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 310 | @decorators.idempotent_id('fb102124-20f8-4cb3-8c81-f16f5e41d192') |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 311 | def test_list_no_pagination_limit_0(self): |
| 312 | self._test_list_no_pagination_limit_0() |