blob: b4fc749a88208c0756f1ae965e33848bd04830ac [file] [log] [blame]
Haiwei Xuc367d912014-01-14 19:51:10 +09001# Copyright 2014 NEC Corporation. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
Matthew Treinishc49fcbe2015-02-05 23:37:34 -050015from tempest_lib import decorators
Masayuki Igawa90c914e2015-01-20 14:48:16 +090016from tempest_lib import exceptions as lib_exc
Matthew Treinishc49fcbe2015-02-05 23:37:34 -050017
Haiwei Xuc367d912014-01-14 19:51:10 +090018from tempest.api.compute import base
Fei Long Wangd39431f2015-05-14 11:30:48 +120019from tempest.common.utils import data_utils
Haiwei Xuc367d912014-01-14 19:51:10 +090020from tempest import config
Haiwei Xuc367d912014-01-14 19:51:10 +090021from tempest import test
22
23CONF = config.CONF
24
25
26class QuotasAdminNegativeTestJSON(base.BaseV2ComputeAdminTest):
Haiwei Xuc367d912014-01-14 19:51:10 +090027 force_tenant_isolation = True
28
29 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053030 def setup_clients(cls):
31 super(QuotasAdminNegativeTestJSON, cls).setup_clients()
Haiwei Xuc367d912014-01-14 19:51:10 +090032 cls.client = cls.os.quotas_client
33 cls.adm_client = cls.os_adm.quotas_client
34 cls.sg_client = cls.security_groups_client
Ken'ichi Ohmichi685cd172015-07-13 01:29:57 +000035 cls.sgr_client = cls.security_group_rules_client
Haiwei Xuc367d912014-01-14 19:51:10 +090036
Rohan Kanade60b73092015-02-04 17:58:19 +053037 @classmethod
38 def resource_setup(cls):
39 super(QuotasAdminNegativeTestJSON, cls).resource_setup()
Haiwei Xuc367d912014-01-14 19:51:10 +090040 # NOTE(afazekas): these test cases should always create and use a new
41 # tenant most of them should be skipped if we can't do that
Andrea Frittoli9612e812014-03-13 10:57:26 +000042 cls.demo_tenant_id = cls.client.tenant_id
Haiwei Xuc367d912014-01-14 19:51:10 +090043
Sean Dague639f2fa2015-04-27 09:00:33 -040044 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080045 @test.idempotent_id('733abfe8-166e-47bb-8363-23dbd7ff3476')
Haiwei Xuc367d912014-01-14 19:51:10 +090046 def test_update_quota_normal_user(self):
Masayuki Igawa6b1cd292015-02-16 11:11:55 +090047 self.assertRaises(lib_exc.Forbidden,
Haiwei Xuc367d912014-01-14 19:51:10 +090048 self.client.update_quota_set,
49 self.demo_tenant_id,
50 ram=0)
51
52 # TODO(afazekas): Add dedicated tenant to the skiped quota tests
53 # it can be moved into the setUpClass as well
Sean Dague639f2fa2015-04-27 09:00:33 -040054 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080055 @test.idempotent_id('91058876-9947-4807-9f22-f6eb17140d9b')
Haiwei Xuc367d912014-01-14 19:51:10 +090056 def test_create_server_when_cpu_quota_is_full(self):
57 # Disallow server creation when tenant's vcpu quota is full
Ken'ichi Ohmichif9868fc2015-06-17 02:36:06 +000058 quota_set = self.adm_client.show_quota_set(self.demo_tenant_id)
Haiwei Xuc367d912014-01-14 19:51:10 +090059 default_vcpu_quota = quota_set['cores']
60 vcpu_quota = 0 # Set the quota to zero to conserve resources
61
David Kranz3e4c28b2015-02-09 12:35:18 -050062 quota_set = self.adm_client.update_quota_set(self.demo_tenant_id,
63 force=True,
64 cores=vcpu_quota)
Haiwei Xuc367d912014-01-14 19:51:10 +090065
66 self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
67 cores=default_vcpu_quota)
Masayuki Igawa6b1cd292015-02-16 11:11:55 +090068 self.assertRaises((lib_exc.Forbidden, lib_exc.OverLimit),
ZHU ZHU35762542014-09-01 01:58:49 -050069 self.create_test_server)
Haiwei Xuc367d912014-01-14 19:51:10 +090070
Sean Dague639f2fa2015-04-27 09:00:33 -040071 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080072 @test.idempotent_id('6fdd7012-584d-4327-a61c-49122e0d5864')
Haiwei Xuc367d912014-01-14 19:51:10 +090073 def test_create_server_when_memory_quota_is_full(self):
74 # Disallow server creation when tenant's memory quota is full
Ken'ichi Ohmichif9868fc2015-06-17 02:36:06 +000075 quota_set = self.adm_client.show_quota_set(self.demo_tenant_id)
Haiwei Xuc367d912014-01-14 19:51:10 +090076 default_mem_quota = quota_set['ram']
77 mem_quota = 0 # Set the quota to zero to conserve resources
78
79 self.adm_client.update_quota_set(self.demo_tenant_id,
80 force=True,
81 ram=mem_quota)
82
83 self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
84 ram=default_mem_quota)
Masayuki Igawa6b1cd292015-02-16 11:11:55 +090085 self.assertRaises((lib_exc.Forbidden, lib_exc.OverLimit),
ZHU ZHU35762542014-09-01 01:58:49 -050086 self.create_test_server)
Haiwei Xuc367d912014-01-14 19:51:10 +090087
Sean Dague639f2fa2015-04-27 09:00:33 -040088 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080089 @test.idempotent_id('7c6be468-0274-449a-81c3-ac1c32ee0161')
Haiwei Xuc367d912014-01-14 19:51:10 +090090 def test_create_server_when_instances_quota_is_full(self):
91 # Once instances quota limit is reached, disallow server creation
Ken'ichi Ohmichif9868fc2015-06-17 02:36:06 +000092 quota_set = self.adm_client.show_quota_set(self.demo_tenant_id)
Haiwei Xuc367d912014-01-14 19:51:10 +090093 default_instances_quota = quota_set['instances']
94 instances_quota = 0 # Set quota to zero to disallow server creation
95
96 self.adm_client.update_quota_set(self.demo_tenant_id,
97 force=True,
98 instances=instances_quota)
99 self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
100 instances=default_instances_quota)
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900101 self.assertRaises((lib_exc.Forbidden, lib_exc.OverLimit),
ZHU ZHU35762542014-09-01 01:58:49 -0500102 self.create_test_server)
Haiwei Xuc367d912014-01-14 19:51:10 +0900103
Matthew Treinishc49fcbe2015-02-05 23:37:34 -0500104 @decorators.skip_because(bug="1186354",
105 condition=CONF.service_available.neutron)
Chris Hoge7579c1a2015-02-26 14:12:15 -0800106 @test.idempotent_id('7c6c8f3b-2bf6-4918-b240-57b136a66aa0')
ekhugend9b5db72014-07-29 16:13:42 +0000107 @test.services('network')
Haiwei Xuc367d912014-01-14 19:51:10 +0900108 def test_security_groups_exceed_limit(self):
109 # Negative test: Creation Security Groups over limit should FAIL
110
Ken'ichi Ohmichif9868fc2015-06-17 02:36:06 +0000111 quota_set = self.adm_client.show_quota_set(self.demo_tenant_id)
Haiwei Xuc367d912014-01-14 19:51:10 +0900112 default_sg_quota = quota_set['security_groups']
Joseph Lanouxffe09dd2015-03-18 16:45:33 +0000113
114 # Set the quota to number of used security groups
115 sg_quota = self.limits_client.show_limits()['absolute'][
116 'totalSecurityGroupsUsed']
Haiwei Xuc367d912014-01-14 19:51:10 +0900117
David Kranz3e4c28b2015-02-09 12:35:18 -0500118 quota_set =\
Haiwei Xuc367d912014-01-14 19:51:10 +0900119 self.adm_client.update_quota_set(self.demo_tenant_id,
120 force=True,
121 security_groups=sg_quota)
122
123 self.addCleanup(self.adm_client.update_quota_set,
124 self.demo_tenant_id,
125 security_groups=default_sg_quota)
126
127 # Check we cannot create anymore
Chris Yeoh60d5ce92014-06-27 13:59:23 +0930128 # A 403 Forbidden or 413 Overlimit (old behaviour) exception
129 # will be raised when out of quota
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900130 self.assertRaises((lib_exc.Forbidden, lib_exc.OverLimit),
Haiwei Xuc367d912014-01-14 19:51:10 +0900131 self.sg_client.create_security_group,
Ken'ichi Ohmichi34563cc2015-07-21 00:53:17 +0000132 name="sg-overlimit", description="sg-desc")
Haiwei Xuc367d912014-01-14 19:51:10 +0900133
Matthew Treinishc49fcbe2015-02-05 23:37:34 -0500134 @decorators.skip_because(bug="1186354",
135 condition=CONF.service_available.neutron)
Sean Dague639f2fa2015-04-27 09:00:33 -0400136 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800137 @test.idempotent_id('6e9f436d-f1ed-4f8e-a493-7275dfaa4b4d')
ekhugend9b5db72014-07-29 16:13:42 +0000138 @test.services('network')
Haiwei Xuc367d912014-01-14 19:51:10 +0900139 def test_security_groups_rules_exceed_limit(self):
140 # Negative test: Creation of Security Group Rules should FAIL
141 # when we reach limit maxSecurityGroupRules
142
Ken'ichi Ohmichif9868fc2015-06-17 02:36:06 +0000143 quota_set = self.adm_client.show_quota_set(self.demo_tenant_id)
Haiwei Xuc367d912014-01-14 19:51:10 +0900144 default_sg_rules_quota = quota_set['security_group_rules']
145 sg_rules_quota = 0 # Set the quota to zero to conserve resources
146
David Kranz3e4c28b2015-02-09 12:35:18 -0500147 quota_set =\
Haiwei Xuc367d912014-01-14 19:51:10 +0900148 self.adm_client.update_quota_set(
149 self.demo_tenant_id,
150 force=True,
151 security_group_rules=sg_rules_quota)
152
153 self.addCleanup(self.adm_client.update_quota_set,
154 self.demo_tenant_id,
155 security_group_rules=default_sg_rules_quota)
156
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +0000157 s_name = data_utils.rand_name('securitygroup')
158 s_description = data_utils.rand_name('description')
ghanshyamb610b772015-08-24 17:29:38 +0900159 securitygroup = self.sg_client.create_security_group(
160 name=s_name, description=s_description)['security_group']
Haiwei Xuc367d912014-01-14 19:51:10 +0900161 self.addCleanup(self.sg_client.delete_security_group,
162 securitygroup['id'])
163
164 secgroup_id = securitygroup['id']
165 ip_protocol = 'tcp'
166
167 # Check we cannot create SG rule anymore
Chris Yeoh60d5ce92014-06-27 13:59:23 +0930168 # A 403 Forbidden or 413 Overlimit (old behaviour) exception
169 # will be raised when out of quota
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900170 self.assertRaises((lib_exc.OverLimit, lib_exc.Forbidden),
Ken'ichi Ohmichi685cd172015-07-13 01:29:57 +0000171 self.sgr_client.create_security_group_rule,
Ken'ichi Ohmichieb7eeec2015-07-21 01:00:06 +0000172 parent_group_id=secgroup_id, ip_protocol=ip_protocol,
173 from_port=1025, to_port=1025)