blob: 4c4acd46d9697ac19cd770b19b77a6de143f948c [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
15from tempest.api.compute import base
16from tempest.common.utils import data_utils
17from tempest import config
18from tempest import exceptions
19from tempest import test
20
21CONF = config.CONF
22
23
24class QuotasAdminNegativeTestJSON(base.BaseV2ComputeAdminTest):
25 _interface = 'json'
26 force_tenant_isolation = True
27
28 @classmethod
29 def setUpClass(cls):
30 super(QuotasAdminNegativeTestJSON, cls).setUpClass()
31 cls.client = cls.os.quotas_client
32 cls.adm_client = cls.os_adm.quotas_client
33 cls.sg_client = cls.security_groups_client
34
35 # NOTE(afazekas): these test cases should always create and use a new
36 # tenant most of them should be skipped if we can't do that
37 cls.demo_tenant_id = cls.isolated_creds.get_primary_user().get(
38 'tenantId')
39
40 @test.attr(type=['negative', 'gate'])
41 def test_update_quota_normal_user(self):
42 self.assertRaises(exceptions.Unauthorized,
43 self.client.update_quota_set,
44 self.demo_tenant_id,
45 ram=0)
46
47 # TODO(afazekas): Add dedicated tenant to the skiped quota tests
48 # it can be moved into the setUpClass as well
49 @test.attr(type=['negative', 'gate'])
50 def test_create_server_when_cpu_quota_is_full(self):
51 # Disallow server creation when tenant's vcpu quota is full
Zhi Kun Liu50eb71c2014-02-19 15:08:45 +080052 resp, quota_set = self.adm_client.get_quota_set(self.demo_tenant_id)
Haiwei Xuc367d912014-01-14 19:51:10 +090053 default_vcpu_quota = quota_set['cores']
54 vcpu_quota = 0 # Set the quota to zero to conserve resources
55
56 resp, quota_set = self.adm_client.update_quota_set(self.demo_tenant_id,
57 force=True,
58 cores=vcpu_quota)
59
60 self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
61 cores=default_vcpu_quota)
62 self.assertRaises(exceptions.OverLimit, self.create_test_server)
63
64 @test.attr(type=['negative', 'gate'])
65 def test_create_server_when_memory_quota_is_full(self):
66 # Disallow server creation when tenant's memory quota is full
Zhi Kun Liu50eb71c2014-02-19 15:08:45 +080067 resp, quota_set = self.adm_client.get_quota_set(self.demo_tenant_id)
Haiwei Xuc367d912014-01-14 19:51:10 +090068 default_mem_quota = quota_set['ram']
69 mem_quota = 0 # Set the quota to zero to conserve resources
70
71 self.adm_client.update_quota_set(self.demo_tenant_id,
72 force=True,
73 ram=mem_quota)
74
75 self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
76 ram=default_mem_quota)
77 self.assertRaises(exceptions.OverLimit, self.create_test_server)
78
79 @test.attr(type=['negative', 'gate'])
80 def test_create_server_when_instances_quota_is_full(self):
81 # Once instances quota limit is reached, disallow server creation
Zhi Kun Liu50eb71c2014-02-19 15:08:45 +080082 resp, quota_set = self.adm_client.get_quota_set(self.demo_tenant_id)
Haiwei Xuc367d912014-01-14 19:51:10 +090083 default_instances_quota = quota_set['instances']
84 instances_quota = 0 # Set quota to zero to disallow server creation
85
86 self.adm_client.update_quota_set(self.demo_tenant_id,
87 force=True,
88 instances=instances_quota)
89 self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
90 instances=default_instances_quota)
91 self.assertRaises(exceptions.OverLimit, self.create_test_server)
92
93 @test.skip_because(bug="1186354",
94 condition=CONF.service_available.neutron)
95 @test.attr(type='gate')
96 def test_security_groups_exceed_limit(self):
97 # Negative test: Creation Security Groups over limit should FAIL
98
Zhi Kun Liu50eb71c2014-02-19 15:08:45 +080099 resp, quota_set = self.adm_client.get_quota_set(self.demo_tenant_id)
Haiwei Xuc367d912014-01-14 19:51:10 +0900100 default_sg_quota = quota_set['security_groups']
101 sg_quota = 0 # Set the quota to zero to conserve resources
102
103 resp, quota_set =\
104 self.adm_client.update_quota_set(self.demo_tenant_id,
105 force=True,
106 security_groups=sg_quota)
107
108 self.addCleanup(self.adm_client.update_quota_set,
109 self.demo_tenant_id,
110 security_groups=default_sg_quota)
111
112 # Check we cannot create anymore
113 self.assertRaises(exceptions.OverLimit,
114 self.sg_client.create_security_group,
115 "sg-overlimit", "sg-desc")
116
117 @test.skip_because(bug="1186354",
118 condition=CONF.service_available.neutron)
119 @test.attr(type=['negative', 'gate'])
120 def test_security_groups_rules_exceed_limit(self):
121 # Negative test: Creation of Security Group Rules should FAIL
122 # when we reach limit maxSecurityGroupRules
123
Zhi Kun Liu50eb71c2014-02-19 15:08:45 +0800124 resp, quota_set = self.adm_client.get_quota_set(self.demo_tenant_id)
Haiwei Xuc367d912014-01-14 19:51:10 +0900125 default_sg_rules_quota = quota_set['security_group_rules']
126 sg_rules_quota = 0 # Set the quota to zero to conserve resources
127
128 resp, quota_set =\
129 self.adm_client.update_quota_set(
130 self.demo_tenant_id,
131 force=True,
132 security_group_rules=sg_rules_quota)
133
134 self.addCleanup(self.adm_client.update_quota_set,
135 self.demo_tenant_id,
136 security_group_rules=default_sg_rules_quota)
137
138 s_name = data_utils.rand_name('securitygroup-')
139 s_description = data_utils.rand_name('description-')
140 resp, securitygroup =\
141 self.sg_client.create_security_group(s_name, s_description)
142 self.addCleanup(self.sg_client.delete_security_group,
143 securitygroup['id'])
144
145 secgroup_id = securitygroup['id']
146 ip_protocol = 'tcp'
147
148 # Check we cannot create SG rule anymore
149 self.assertRaises(exceptions.OverLimit,
150 self.sg_client.create_security_group_rule,
151 secgroup_id, ip_protocol, 1025, 1025)
152
153
154class QuotasAdminNegativeTestXML(QuotasAdminNegativeTestJSON):
155 _interface = 'xml'