blob: fdd8dd8644ca1868a6331356a0163f0adcb62f61 [file] [log] [blame]
rossellae02431e2013-11-15 17:58:29 +01001# 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
armando-migliaccioee90a4d2014-05-06 11:54:07 -070016import netaddr
lianghaof37da962017-03-10 20:16:21 +080017import testtools
armando-migliaccioee90a4d2014-05-06 11:54:07 -070018
rossellae02431e2013-11-15 17:58:29 +010019from tempest.api.network import base_routers as base
armando-migliaccioee90a4d2014-05-06 11:54:07 -070020from tempest import config
Ken'ichi Ohmichif50e4df2017-03-10 10:52:53 -080021from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -080022from tempest.lib import decorators
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050023from tempest.lib import exceptions as lib_exc
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090024from tempest import test
rossellae02431e2013-11-15 17:58:29 +010025
armando-migliaccioee90a4d2014-05-06 11:54:07 -070026CONF = config.CONF
27
rossellae02431e2013-11-15 17:58:29 +010028
29class RoutersNegativeTest(base.BaseRouterTest):
rossellae02431e2013-11-15 17:58:29 +010030
31 @classmethod
Rohan Kanadea565e452015-01-27 14:00:13 +053032 def skip_checks(cls):
33 super(RoutersNegativeTest, cls).skip_checks()
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090034 if not test.is_extension_enabled('router', 'network'):
35 msg = "router extension not enabled."
36 raise cls.skipException(msg)
Rohan Kanadea565e452015-01-27 14:00:13 +053037
38 @classmethod
39 def resource_setup(cls):
40 super(RoutersNegativeTest, cls).resource_setup()
zhufld2c40ca2016-10-18 17:03:07 +080041 cls.router = cls.create_router()
rossellae02431e2013-11-15 17:58:29 +010042 cls.network = cls.create_network()
43 cls.subnet = cls.create_subnet(cls.network)
Sean Dagueed6e5862016-04-04 10:49:13 -040044 cls.tenant_cidr = (CONF.network.project_network_cidr
Sergey Shnaidman97e6a0f2014-11-12 20:00:53 +030045 if cls._ip_version == 4 else
Sean Dagueed6e5862016-04-04 10:49:13 -040046 CONF.network.project_network_v6_cidr)
rossellae02431e2013-11-15 17:58:29 +010047
Jordan Pittier3b46d272017-04-12 16:17:28 +020048 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -080049 @decorators.idempotent_id('37a94fc0-a834-45b9-bd23-9a81d2fd1e22')
rossellae02431e2013-11-15 17:58:29 +010050 def test_router_add_gateway_invalid_network_returns_404(self):
Masayuki Igawabfa07602015-01-20 18:47:17 +090051 self.assertRaises(lib_exc.NotFound,
Ken'ichi Ohmichie35f4722015-12-22 04:57:11 +000052 self.routers_client.update_router,
rossellae02431e2013-11-15 17:58:29 +010053 self.router['id'],
54 external_gateway_info={
55 'network_id': self.router['id']})
56
Jordan Pittier3b46d272017-04-12 16:17:28 +020057 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -080058 @decorators.idempotent_id('11836a18-0b15-4327-a50b-f0d9dc66bddd')
rossellae02431e2013-11-15 17:58:29 +010059 def test_router_add_gateway_net_not_external_returns_400(self):
zhufld2c40ca2016-10-18 17:03:07 +080060 alt_network = self.create_network()
Sergey Shnaidman97e6a0f2014-11-12 20:00:53 +030061 sub_cidr = netaddr.IPNetwork(self.tenant_cidr).next()
armando-migliaccioee90a4d2014-05-06 11:54:07 -070062 self.create_subnet(alt_network, cidr=sub_cidr)
Masayuki Igawa4b29e472015-02-16 10:41:54 +090063 self.assertRaises(lib_exc.BadRequest,
Ken'ichi Ohmichie35f4722015-12-22 04:57:11 +000064 self.routers_client.update_router,
rossellae02431e2013-11-15 17:58:29 +010065 self.router['id'],
66 external_gateway_info={
armando-migliaccioee90a4d2014-05-06 11:54:07 -070067 'network_id': alt_network['id']})
68
Jordan Pittier3b46d272017-04-12 16:17:28 +020069 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -080070 @decorators.idempotent_id('957751a3-3c68-4fa2-93b6-eb52ea10db6e')
armando-migliaccioee90a4d2014-05-06 11:54:07 -070071 def test_add_router_interfaces_on_overlapping_subnets_returns_400(self):
72 network01 = self.create_network(
73 network_name=data_utils.rand_name('router-network01-'))
74 network02 = self.create_network(
75 network_name=data_utils.rand_name('router-network02-'))
76 subnet01 = self.create_subnet(network01)
77 subnet02 = self.create_subnet(network02)
78 self._add_router_interface_with_subnet_id(self.router['id'],
79 subnet01['id'])
Masayuki Igawa4b29e472015-02-16 10:41:54 +090080 self.assertRaises(lib_exc.BadRequest,
armando-migliaccioee90a4d2014-05-06 11:54:07 -070081 self._add_router_interface_with_subnet_id,
82 self.router['id'],
83 subnet02['id'])
rossellae02431e2013-11-15 17:58:29 +010084
Jordan Pittier3b46d272017-04-12 16:17:28 +020085 @decorators.attr(type=['negative'])
lianghaof37da962017-03-10 20:16:21 +080086 @decorators.idempotent_id('7101cc02-058a-11e7-93e1-fa163e4fa634')
87 @test.requires_ext(extension='ext-gw-mode', service='network')
88 @testtools.skipUnless(CONF.network.public_network_id,
89 'The public_network_id option must be specified.')
90 def test_router_set_gateway_used_ip_returns_409(self):
91 # At first create a address from public_network_id
92 port = self.admin_ports_client.create_port(
93 network_id=CONF.network.public_network_id)['port']
94 self.addCleanup(self.admin_ports_client.delete_port,
95 port_id=port['id'])
96 # Add used ip and subnet_id in external_fixed_ips
97 fixed_ip = {
98 'subnet_id': port['fixed_ips'][0]['subnet_id'],
99 'ip_address': port['fixed_ips'][0]['ip_address']
100 }
101 external_gateway_info = {
102 'network_id': CONF.network.public_network_id,
103 'external_fixed_ips': [fixed_ip]
104 }
105 # Create a router and set gateway to used ip
106 self.assertRaises(lib_exc.Conflict,
107 self.admin_routers_client.create_router,
108 external_gateway_info=external_gateway_info)
109
Jordan Pittier3b46d272017-04-12 16:17:28 +0200110 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800111 @decorators.idempotent_id('04df80f9-224d-47f5-837a-bf23e33d1c20')
rossellae02431e2013-11-15 17:58:29 +0100112 def test_router_remove_interface_in_use_returns_409(self):
Ken'ichi Ohmichie35f4722015-12-22 04:57:11 +0000113 self.routers_client.add_router_interface(self.router['id'],
114 subnet_id=self.subnet['id'])
Masayuki Igawad9388762015-01-20 14:56:42 +0900115 self.assertRaises(lib_exc.Conflict,
Ken'ichi Ohmichie35f4722015-12-22 04:57:11 +0000116 self.routers_client.delete_router,
rossellae02431e2013-11-15 17:58:29 +0100117 self.router['id'])
Sergey Shnaidman97e6a0f2014-11-12 20:00:53 +0300118
Jordan Pittier3b46d272017-04-12 16:17:28 +0200119 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800120 @decorators.idempotent_id('c2a70d72-8826-43a7-8208-0209e6360c47')
Rajkumar Thiyagarajan18fd41c2014-07-28 03:05:11 -0700121 def test_show_non_existent_router_returns_404(self):
122 router = data_utils.rand_name('non_exist_router')
Ken'ichi Ohmichie35f4722015-12-22 04:57:11 +0000123 self.assertRaises(lib_exc.NotFound, self.routers_client.show_router,
Rajkumar Thiyagarajan18fd41c2014-07-28 03:05:11 -0700124 router)
125
Jordan Pittier3b46d272017-04-12 16:17:28 +0200126 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800127 @decorators.idempotent_id('b23d1569-8b0c-4169-8d4b-6abd34fad5c7')
Rajkumar Thiyagarajan18fd41c2014-07-28 03:05:11 -0700128 def test_update_non_existent_router_returns_404(self):
129 router = data_utils.rand_name('non_exist_router')
Ken'ichi Ohmichie35f4722015-12-22 04:57:11 +0000130 self.assertRaises(lib_exc.NotFound, self.routers_client.update_router,
Rajkumar Thiyagarajan18fd41c2014-07-28 03:05:11 -0700131 router, name="new_name")
132
Jordan Pittier3b46d272017-04-12 16:17:28 +0200133 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800134 @decorators.idempotent_id('c7edc5ad-d09d-41e6-a344-5c0c31e2e3e4')
Rajkumar Thiyagarajan18fd41c2014-07-28 03:05:11 -0700135 def test_delete_non_existent_router_returns_404(self):
136 router = data_utils.rand_name('non_exist_router')
Ken'ichi Ohmichie35f4722015-12-22 04:57:11 +0000137 self.assertRaises(lib_exc.NotFound, self.routers_client.delete_router,
Rajkumar Thiyagarajan18fd41c2014-07-28 03:05:11 -0700138 router)
139
Sergey Shnaidman97e6a0f2014-11-12 20:00:53 +0300140
141class RoutersNegativeIpV6Test(RoutersNegativeTest):
142 _ip_version = 6
armando-migliaccio88f7b702014-06-05 12:59:09 -0700143
144
145class DvrRoutersNegativeTest(base.BaseRouterTest):
146
147 @classmethod
148 def skip_checks(cls):
149 super(DvrRoutersNegativeTest, cls).skip_checks()
150 if not test.is_extension_enabled('dvr', 'network'):
151 msg = "DVR extension not enabled."
152 raise cls.skipException(msg)
153
154 @classmethod
155 def resource_setup(cls):
156 super(DvrRoutersNegativeTest, cls).resource_setup()
zhufld2c40ca2016-10-18 17:03:07 +0800157 cls.router = cls.create_router()
armando-migliaccio88f7b702014-06-05 12:59:09 -0700158 cls.network = cls.create_network()
159 cls.subnet = cls.create_subnet(cls.network)
160
Jordan Pittier3b46d272017-04-12 16:17:28 +0200161 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800162 @decorators.idempotent_id('4990b055-8fc7-48ab-bba7-aa28beaad0b9')
armando-migliaccio88f7b702014-06-05 12:59:09 -0700163 def test_router_create_tenant_distributed_returns_forbidden(self):
zhufl39ac5682016-10-24 17:11:34 +0800164 self.assertRaises(lib_exc.Forbidden, self.create_router,
armando-migliaccio88f7b702014-06-05 12:59:09 -0700165 distributed=True)