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 |
| 19 | from tempest import test |
| 20 | |
Kevin Benton | c66aa80 | 2016-07-23 22:36:37 -0700 | [diff] [blame^] | 21 | from neutron.common import utils |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 22 | from neutron.tests.tempest.api import base |
| 23 | from neutron.tests.tempest.api import base_routers |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 24 | from neutron.tests.tempest import config |
| 25 | |
| 26 | CONF = config.CONF |
| 27 | |
| 28 | |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 29 | class RoutersTest(base_routers.BaseRouterTest): |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 30 | |
| 31 | @classmethod |
| 32 | @test.requires_ext(extension="router", service="network") |
| 33 | def skip_checks(cls): |
| 34 | super(RoutersTest, cls).skip_checks() |
| 35 | |
| 36 | @classmethod |
| 37 | def resource_setup(cls): |
| 38 | super(RoutersTest, cls).resource_setup() |
| 39 | cls.tenant_cidr = ( |
| 40 | config.safe_get_config_value('network', 'project_network_cidr') |
| 41 | if cls._ip_version == 4 else |
| 42 | config.safe_get_config_value('network', 'project_network_v6_cidr')) |
| 43 | |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 44 | @test.idempotent_id('c72c1c0c-2193-4aca-eeee-b1442640eeee') |
| 45 | @test.requires_ext(extension="standard-attr-description", |
| 46 | service="network") |
| 47 | def test_create_update_router_description(self): |
| 48 | body = self.create_router(description='d1', router_name='test') |
| 49 | self.assertEqual('d1', body['description']) |
| 50 | body = self.client.show_router(body['id'])['router'] |
| 51 | self.assertEqual('d1', body['description']) |
| 52 | body = self.client.update_router(body['id'], description='d2') |
| 53 | self.assertEqual('d2', body['router']['description']) |
| 54 | body = self.client.show_router(body['router']['id'])['router'] |
| 55 | self.assertEqual('d2', body['description']) |
| 56 | |
| 57 | @test.idempotent_id('847257cc-6afd-4154-b8fb-af49f5670ce8') |
| 58 | @test.requires_ext(extension='ext-gw-mode', service='network') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 59 | def test_create_router_with_default_snat_value(self): |
| 60 | # Create a router with default snat rule |
| 61 | name = data_utils.rand_name('router') |
| 62 | router = self._create_router( |
| 63 | name, external_network_id=CONF.network.public_network_id) |
| 64 | self._verify_router_gateway( |
| 65 | router['id'], {'network_id': CONF.network.public_network_id, |
| 66 | 'enable_snat': True}) |
| 67 | |
| 68 | @test.idempotent_id('ea74068d-09e9-4fd7-8995-9b6a1ace920f') |
| 69 | @test.requires_ext(extension='ext-gw-mode', service='network') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 70 | def test_create_router_with_snat_explicit(self): |
| 71 | name = data_utils.rand_name('snat-router') |
| 72 | # Create a router enabling snat attributes |
| 73 | enable_snat_states = [False, True] |
| 74 | for enable_snat in enable_snat_states: |
| 75 | external_gateway_info = { |
| 76 | 'network_id': CONF.network.public_network_id, |
| 77 | 'enable_snat': enable_snat} |
| 78 | create_body = self.admin_client.create_router( |
| 79 | name, external_gateway_info=external_gateway_info) |
| 80 | self.addCleanup(self.admin_client.delete_router, |
| 81 | create_body['router']['id']) |
| 82 | # Verify snat attributes after router creation |
| 83 | self._verify_router_gateway(create_body['router']['id'], |
| 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 |
| 93 | for k, v in six.iteritems(exp_ext_gw_info): |
| 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) |
| 106 | public_subnet_id = public_net_body['network']['subnets'][0] |
| 107 | self.assertIn(public_subnet_id, |
| 108 | [x['subnet_id'] for x in fixed_ips]) |
| 109 | |
| 110 | @test.idempotent_id('b386c111-3b21-466d-880c-5e72b01e1a33') |
| 111 | @test.requires_ext(extension='ext-gw-mode', service='network') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 112 | def test_update_router_set_gateway_with_snat_explicit(self): |
| 113 | router = self._create_router(data_utils.rand_name('router-')) |
| 114 | self.admin_client.update_router_with_snat_gw_info( |
| 115 | router['id'], |
| 116 | external_gateway_info={ |
| 117 | 'network_id': CONF.network.public_network_id, |
| 118 | 'enable_snat': True}) |
| 119 | self._verify_router_gateway( |
| 120 | router['id'], |
| 121 | {'network_id': CONF.network.public_network_id, |
| 122 | 'enable_snat': True}) |
| 123 | self._verify_gateway_port(router['id']) |
| 124 | |
| 125 | @test.idempotent_id('96536bc7-8262-4fb2-9967-5c46940fa279') |
| 126 | @test.requires_ext(extension='ext-gw-mode', service='network') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 127 | def test_update_router_set_gateway_without_snat(self): |
| 128 | router = self._create_router(data_utils.rand_name('router-')) |
| 129 | self.admin_client.update_router_with_snat_gw_info( |
| 130 | router['id'], |
| 131 | external_gateway_info={ |
| 132 | 'network_id': CONF.network.public_network_id, |
| 133 | 'enable_snat': False}) |
| 134 | self._verify_router_gateway( |
| 135 | router['id'], |
| 136 | {'network_id': CONF.network.public_network_id, |
| 137 | 'enable_snat': False}) |
| 138 | self._verify_gateway_port(router['id']) |
| 139 | |
| 140 | @test.idempotent_id('f2faf994-97f4-410b-a831-9bc977b64374') |
| 141 | @test.requires_ext(extension='ext-gw-mode', service='network') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 142 | def test_update_router_reset_gateway_without_snat(self): |
| 143 | router = self._create_router( |
| 144 | data_utils.rand_name('router-'), |
| 145 | external_network_id=CONF.network.public_network_id) |
| 146 | self.admin_client.update_router_with_snat_gw_info( |
| 147 | router['id'], |
| 148 | external_gateway_info={ |
| 149 | 'network_id': CONF.network.public_network_id, |
| 150 | 'enable_snat': False}) |
| 151 | self._verify_router_gateway( |
| 152 | router['id'], |
| 153 | {'network_id': CONF.network.public_network_id, |
| 154 | 'enable_snat': False}) |
| 155 | self._verify_gateway_port(router['id']) |
| 156 | |
Kevin Benton | c66aa80 | 2016-07-23 22:36:37 -0700 | [diff] [blame^] | 157 | @test.idempotent_id('db3093b1-93b6-4893-be83-c4716c251b3e') |
| 158 | def test_router_interface_status(self): |
| 159 | network = self.create_network() |
| 160 | subnet = self.create_subnet(network) |
| 161 | # Add router interface with subnet id |
| 162 | router = self._create_router(data_utils.rand_name('router-'), True) |
| 163 | intf = self.create_router_interface(router['id'], subnet['id']) |
| 164 | status_active = lambda: self.client.show_port( |
| 165 | intf['port_id'])['port']['status'] == 'ACTIVE' |
| 166 | utils.wait_until_true(status_active) |
| 167 | |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 168 | @test.idempotent_id('c86ac3a8-50bd-4b00-a6b8-62af84a0765c') |
| 169 | @test.requires_ext(extension='extraroute', service='network') |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 170 | def test_update_extra_route(self): |
| 171 | self.network = self.create_network() |
| 172 | self.name = self.network['name'] |
| 173 | self.subnet = self.create_subnet(self.network) |
| 174 | # Add router interface with subnet id |
| 175 | self.router = self._create_router( |
| 176 | data_utils.rand_name('router-'), True) |
| 177 | self.create_router_interface(self.router['id'], self.subnet['id']) |
| 178 | self.addCleanup( |
| 179 | self._delete_extra_routes, |
| 180 | self.router['id']) |
| 181 | # Update router extra route, second ip of the range is |
| 182 | # used as next hop |
| 183 | cidr = netaddr.IPNetwork(self.subnet['cidr']) |
| 184 | next_hop = str(cidr[2]) |
| 185 | destination = str(self.subnet['cidr']) |
| 186 | extra_route = self.client.update_extra_routes(self.router['id'], |
| 187 | next_hop, destination) |
| 188 | self.assertEqual(1, len(extra_route['router']['routes'])) |
| 189 | self.assertEqual(destination, |
| 190 | extra_route['router']['routes'][0]['destination']) |
| 191 | self.assertEqual(next_hop, |
| 192 | extra_route['router']['routes'][0]['nexthop']) |
| 193 | show_body = self.client.show_router(self.router['id']) |
| 194 | self.assertEqual(destination, |
| 195 | show_body['router']['routes'][0]['destination']) |
| 196 | self.assertEqual(next_hop, |
| 197 | show_body['router']['routes'][0]['nexthop']) |
| 198 | |
| 199 | def _delete_extra_routes(self, router_id): |
| 200 | self.client.delete_extra_routes(router_id) |
| 201 | |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 202 | @test.idempotent_id('01f185d1-d1a6-4cf9-abf7-e0e1384c169c') |
| 203 | def test_network_attached_with_two_routers(self): |
| 204 | network = self.create_network(data_utils.rand_name('network1')) |
| 205 | self.create_subnet(network) |
| 206 | port1 = self.create_port(network) |
| 207 | port2 = self.create_port(network) |
| 208 | router1 = self._create_router(data_utils.rand_name('router1')) |
| 209 | router2 = self._create_router(data_utils.rand_name('router2')) |
| 210 | self.client.add_router_interface_with_port_id( |
| 211 | router1['id'], port1['id']) |
| 212 | self.client.add_router_interface_with_port_id( |
| 213 | router2['id'], port2['id']) |
| 214 | self.addCleanup(self.client.remove_router_interface_with_port_id, |
| 215 | router1['id'], port1['id']) |
| 216 | self.addCleanup(self.client.remove_router_interface_with_port_id, |
| 217 | router2['id'], port2['id']) |
| 218 | body = self.client.show_port(port1['id']) |
| 219 | port_show1 = body['port'] |
| 220 | body = self.client.show_port(port2['id']) |
| 221 | port_show2 = body['port'] |
| 222 | self.assertEqual(port_show1['network_id'], network['id']) |
| 223 | self.assertEqual(port_show2['network_id'], network['id']) |
| 224 | self.assertEqual(port_show1['device_id'], router1['id']) |
| 225 | self.assertEqual(port_show2['device_id'], router2['id']) |
| 226 | |
| 227 | |
| 228 | class RoutersIpV6Test(RoutersTest): |
| 229 | _ip_version = 6 |
| 230 | |
| 231 | |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 232 | class DvrRoutersTest(base_routers.BaseRouterTest): |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 233 | |
| 234 | @classmethod |
| 235 | @test.requires_ext(extension="dvr", service="network") |
| 236 | def skip_checks(cls): |
| 237 | super(DvrRoutersTest, cls).skip_checks() |
| 238 | |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 239 | @test.idempotent_id('141297aa-3424-455d-aa8d-f2d95731e00a') |
| 240 | def test_create_distributed_router(self): |
| 241 | name = data_utils.rand_name('router') |
| 242 | create_body = self.admin_client.create_router( |
| 243 | name, distributed=True) |
| 244 | self.addCleanup(self._delete_router, |
| 245 | create_body['router']['id'], |
| 246 | self.admin_client) |
| 247 | self.assertTrue(create_body['router']['distributed']) |
| 248 | |
Daniel Mellado | 3c0aeab | 2016-01-29 11:30:25 +0000 | [diff] [blame] | 249 | @test.idempotent_id('644d7a4a-01a1-4b68-bb8d-0c0042cb1729') |
| 250 | def test_convert_centralized_router(self): |
| 251 | router = self._create_router(data_utils.rand_name('router')) |
| 252 | self.assertNotIn('distributed', router) |
| 253 | update_body = self.admin_client.update_router(router['id'], |
| 254 | distributed=True) |
| 255 | self.assertTrue(update_body['router']['distributed']) |
| 256 | show_body = self.admin_client.show_router(router['id']) |
| 257 | self.assertTrue(show_body['router']['distributed']) |
| 258 | show_body = self.client.show_router(router['id']) |
| 259 | self.assertNotIn('distributed', show_body['router']) |
Ihar Hrachyshka | 44d1d3f | 2016-06-14 11:51:37 +0200 | [diff] [blame] | 260 | |
| 261 | |
| 262 | class RoutersSearchCriteriaTest(base.BaseSearchCriteriaTest): |
| 263 | |
| 264 | resource = 'router' |
| 265 | |
| 266 | @classmethod |
| 267 | @test.requires_ext(extension="router", service="network") |
| 268 | def skip_checks(cls): |
| 269 | super(RoutersSearchCriteriaTest, cls).skip_checks() |
| 270 | |
| 271 | @classmethod |
| 272 | def resource_setup(cls): |
| 273 | super(RoutersSearchCriteriaTest, cls).resource_setup() |
| 274 | for name in cls.resource_names: |
| 275 | cls.create_router(router_name=name) |
| 276 | |
| 277 | @test.attr(type='smoke') |
| 278 | @test.idempotent_id('03a69efb-90a7-435b-bb5c-3add3612085a') |
| 279 | def test_list_sorts_asc(self): |
| 280 | self._test_list_sorts_asc() |
| 281 | |
| 282 | @test.attr(type='smoke') |
| 283 | @test.idempotent_id('95913d30-ff41-4b17-9f44-5258c651e78c') |
| 284 | def test_list_sorts_desc(self): |
| 285 | self._test_list_sorts_desc() |
| 286 | |
| 287 | @test.attr(type='smoke') |
| 288 | @test.idempotent_id('7f7d40b1-e165-4817-8dc5-02f8e2f0dff3') |
| 289 | def test_list_pagination(self): |
| 290 | self._test_list_pagination() |
| 291 | |
| 292 | @test.attr(type='smoke') |
| 293 | @test.idempotent_id('a5b83e83-3d98-45bb-a2c7-0ee179ffd42c') |
| 294 | def test_list_pagination_with_marker(self): |
| 295 | self._test_list_pagination_with_marker() |
| 296 | |
| 297 | @test.attr(type='smoke') |
| 298 | @test.idempotent_id('40804af8-c25d-45f8-b8a8-b4c70345215d') |
| 299 | def test_list_pagination_with_href_links(self): |
| 300 | self._test_list_pagination_with_href_links() |
| 301 | |
| 302 | @test.attr(type='smoke') |
| 303 | @test.idempotent_id('77b9676c-d3cb-43af-a0e8-a5b8c6099e70') |
| 304 | def test_list_pagination_page_reverse_asc(self): |
| 305 | self._test_list_pagination_page_reverse_asc() |
| 306 | |
| 307 | @test.attr(type='smoke') |
| 308 | @test.idempotent_id('3133a2c5-1bb9-4fc7-833e-cf9a1d160255') |
| 309 | def test_list_pagination_page_reverse_desc(self): |
| 310 | self._test_list_pagination_page_reverse_desc() |
| 311 | |
| 312 | @test.attr(type='smoke') |
| 313 | @test.idempotent_id('8252e2f0-b3da-4738-8e25-f6f8d878a2da') |
| 314 | def test_list_pagination_page_reverse_with_href_links(self): |
| 315 | self._test_list_pagination_page_reverse_with_href_links() |
| 316 | |
| 317 | @test.attr(type='smoke') |
| 318 | @test.idempotent_id('fb102124-20f8-4cb3-8c81-f16f5e41d192') |
| 319 | def test_list_no_pagination_limit_0(self): |
| 320 | self._test_list_no_pagination_limit_0() |