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