1 # Copyright 2013 OpenStack Foundation
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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
19 from tempest_lib.common.utils import data_utils
20 from tempest_lib import exceptions as lib_exc
22 from neutron.tests.api import base_routers as base
23 from neutron.tests.tempest import config
24 from neutron.tests.tempest import test
29 class RoutersNegativeTest(base.BaseRouterTest):
32 def resource_setup(cls):
33 super(RoutersNegativeTest, cls).resource_setup()
34 if not test.is_extension_enabled('router', 'network'):
35 msg = "router extension not enabled."
36 raise cls.skipException(msg)
37 cls.router = cls.create_router(data_utils.rand_name('router-'))
38 cls.network = cls.create_network()
39 cls.subnet = cls.create_subnet(cls.network)
40 cls.tenant_cidr = (CONF.network.tenant_network_cidr
41 if cls._ip_version == 4 else
42 CONF.network.tenant_network_v6_cidr)
44 @test.attr(type=['negative', 'smoke'])
45 @test.idempotent_id('37a94fc0-a834-45b9-bd23-9a81d2fd1e22')
46 def test_router_add_gateway_invalid_network_returns_404(self):
47 self.assertRaises(lib_exc.NotFound,
48 self.client.update_router,
50 external_gateway_info={
51 'network_id': self.router['id']})
53 @test.attr(type=['negative', 'smoke'])
54 @test.idempotent_id('11836a18-0b15-4327-a50b-f0d9dc66bddd')
55 def test_router_add_gateway_net_not_external_returns_400(self):
56 alt_network = self.create_network(
57 network_name=data_utils.rand_name('router-negative-'))
58 sub_cidr = netaddr.IPNetwork(self.tenant_cidr).next()
59 self.create_subnet(alt_network, cidr=sub_cidr)
60 self.assertRaises(lib_exc.BadRequest,
61 self.client.update_router,
63 external_gateway_info={
64 'network_id': alt_network['id']})
66 @test.attr(type=['negative', 'smoke'])
67 @test.idempotent_id('957751a3-3c68-4fa2-93b6-eb52ea10db6e')
68 def test_add_router_interfaces_on_overlapping_subnets_returns_400(self):
69 network01 = self.create_network(
70 network_name=data_utils.rand_name('router-network01-'))
71 network02 = self.create_network(
72 network_name=data_utils.rand_name('router-network02-'))
73 subnet01 = self.create_subnet(network01)
74 subnet02 = self.create_subnet(network02)
75 self._add_router_interface_with_subnet_id(self.router['id'],
77 self.assertRaises(lib_exc.BadRequest,
78 self._add_router_interface_with_subnet_id,
82 @test.attr(type=['negative', 'smoke'])
83 @test.idempotent_id('04df80f9-224d-47f5-837a-bf23e33d1c20')
84 def test_router_remove_interface_in_use_returns_409(self):
85 self.client.add_router_interface_with_subnet_id(
86 self.router['id'], self.subnet['id'])
87 self.assertRaises(lib_exc.Conflict,
88 self.client.delete_router,
91 @test.attr(type=['negative', 'smoke'])
92 @test.idempotent_id('c2a70d72-8826-43a7-8208-0209e6360c47')
93 def test_show_non_existent_router_returns_404(self):
94 router = data_utils.rand_name('non_exist_router')
95 self.assertRaises(lib_exc.NotFound, self.client.show_router,
98 @test.attr(type=['negative', 'smoke'])
99 @test.idempotent_id('b23d1569-8b0c-4169-8d4b-6abd34fad5c7')
100 def test_update_non_existent_router_returns_404(self):
101 router = data_utils.rand_name('non_exist_router')
102 self.assertRaises(lib_exc.NotFound, self.client.update_router,
103 router, name="new_name")
105 @test.attr(type=['negative', 'smoke'])
106 @test.idempotent_id('c7edc5ad-d09d-41e6-a344-5c0c31e2e3e4')
107 def test_delete_non_existent_router_returns_404(self):
108 router = data_utils.rand_name('non_exist_router')
109 self.assertRaises(lib_exc.NotFound, self.client.delete_router,
113 class RoutersNegativeIpV6Test(RoutersNegativeTest):
117 class DvrRoutersNegativeTest(base.BaseRouterTest):
120 def skip_checks(cls):
121 super(DvrRoutersNegativeTest, cls).skip_checks()
122 if not test.is_extension_enabled('dvr', 'network'):
123 msg = "DVR extension not enabled."
124 raise cls.skipException(msg)
127 def resource_setup(cls):
128 super(DvrRoutersNegativeTest, cls).resource_setup()
129 cls.router = cls.create_router(data_utils.rand_name('router'))
130 cls.network = cls.create_network()
131 cls.subnet = cls.create_subnet(cls.network)
133 @test.attr(type=['negative', 'smoke'])
134 @test.idempotent_id('4990b055-8fc7-48ab-bba7-aa28beaad0b9')
135 def test_router_create_tenant_distributed_returns_forbidden(self):
136 with testtools.ExpectedException(lib_exc.Forbidden):
138 data_utils.rand_name('router'), distributed=True)