blob: e1dc685c63da5a47568bf617f1817c9675603640 [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):
Haiwei Xuc367d912014-01-14 19:51:10 +090025 force_tenant_isolation = True
26
27 @classmethod
28 def setUpClass(cls):
29 super(QuotasAdminNegativeTestJSON, cls).setUpClass()
30 cls.client = cls.os.quotas_client
31 cls.adm_client = cls.os_adm.quotas_client
32 cls.sg_client = cls.security_groups_client
33
34 # NOTE(afazekas): these test cases should always create and use a new
35 # tenant most of them should be skipped if we can't do that
Andrea Frittoli9612e812014-03-13 10:57:26 +000036 cls.demo_tenant_id = cls.client.tenant_id
Haiwei Xuc367d912014-01-14 19:51:10 +090037
38 @test.attr(type=['negative', 'gate'])
39 def test_update_quota_normal_user(self):
40 self.assertRaises(exceptions.Unauthorized,
41 self.client.update_quota_set,
42 self.demo_tenant_id,
43 ram=0)
44
45 # TODO(afazekas): Add dedicated tenant to the skiped quota tests
46 # it can be moved into the setUpClass as well
47 @test.attr(type=['negative', 'gate'])
48 def test_create_server_when_cpu_quota_is_full(self):
49 # Disallow server creation when tenant's vcpu quota is full
Zhi Kun Liu50eb71c2014-02-19 15:08:45 +080050 resp, quota_set = self.adm_client.get_quota_set(self.demo_tenant_id)
Haiwei Xuc367d912014-01-14 19:51:10 +090051 default_vcpu_quota = quota_set['cores']
52 vcpu_quota = 0 # Set the quota to zero to conserve resources
53
54 resp, quota_set = self.adm_client.update_quota_set(self.demo_tenant_id,
55 force=True,
56 cores=vcpu_quota)
57
58 self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
59 cores=default_vcpu_quota)
60 self.assertRaises(exceptions.OverLimit, self.create_test_server)
61
62 @test.attr(type=['negative', 'gate'])
63 def test_create_server_when_memory_quota_is_full(self):
64 # Disallow server creation when tenant's memory quota is full
Zhi Kun Liu50eb71c2014-02-19 15:08:45 +080065 resp, quota_set = self.adm_client.get_quota_set(self.demo_tenant_id)
Haiwei Xuc367d912014-01-14 19:51:10 +090066 default_mem_quota = quota_set['ram']
67 mem_quota = 0 # Set the quota to zero to conserve resources
68
69 self.adm_client.update_quota_set(self.demo_tenant_id,
70 force=True,
71 ram=mem_quota)
72
73 self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
74 ram=default_mem_quota)
75 self.assertRaises(exceptions.OverLimit, self.create_test_server)
76
77 @test.attr(type=['negative', 'gate'])
78 def test_create_server_when_instances_quota_is_full(self):
79 # Once instances quota limit is reached, disallow server creation
Zhi Kun Liu50eb71c2014-02-19 15:08:45 +080080 resp, quota_set = self.adm_client.get_quota_set(self.demo_tenant_id)
Haiwei Xuc367d912014-01-14 19:51:10 +090081 default_instances_quota = quota_set['instances']
82 instances_quota = 0 # Set quota to zero to disallow server creation
83
84 self.adm_client.update_quota_set(self.demo_tenant_id,
85 force=True,
86 instances=instances_quota)
87 self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
88 instances=default_instances_quota)
89 self.assertRaises(exceptions.OverLimit, self.create_test_server)
90
91 @test.skip_because(bug="1186354",
92 condition=CONF.service_available.neutron)
93 @test.attr(type='gate')
94 def test_security_groups_exceed_limit(self):
95 # Negative test: Creation Security Groups over limit should FAIL
96
Zhi Kun Liu50eb71c2014-02-19 15:08:45 +080097 resp, quota_set = self.adm_client.get_quota_set(self.demo_tenant_id)
Haiwei Xuc367d912014-01-14 19:51:10 +090098 default_sg_quota = quota_set['security_groups']
99 sg_quota = 0 # Set the quota to zero to conserve resources
100
101 resp, quota_set =\
102 self.adm_client.update_quota_set(self.demo_tenant_id,
103 force=True,
104 security_groups=sg_quota)
105
106 self.addCleanup(self.adm_client.update_quota_set,
107 self.demo_tenant_id,
108 security_groups=default_sg_quota)
109
110 # Check we cannot create anymore
111 self.assertRaises(exceptions.OverLimit,
112 self.sg_client.create_security_group,
113 "sg-overlimit", "sg-desc")
114
115 @test.skip_because(bug="1186354",
116 condition=CONF.service_available.neutron)
117 @test.attr(type=['negative', 'gate'])
118 def test_security_groups_rules_exceed_limit(self):
119 # Negative test: Creation of Security Group Rules should FAIL
120 # when we reach limit maxSecurityGroupRules
121
Zhi Kun Liu50eb71c2014-02-19 15:08:45 +0800122 resp, quota_set = self.adm_client.get_quota_set(self.demo_tenant_id)
Haiwei Xuc367d912014-01-14 19:51:10 +0900123 default_sg_rules_quota = quota_set['security_group_rules']
124 sg_rules_quota = 0 # Set the quota to zero to conserve resources
125
126 resp, quota_set =\
127 self.adm_client.update_quota_set(
128 self.demo_tenant_id,
129 force=True,
130 security_group_rules=sg_rules_quota)
131
132 self.addCleanup(self.adm_client.update_quota_set,
133 self.demo_tenant_id,
134 security_group_rules=default_sg_rules_quota)
135
136 s_name = data_utils.rand_name('securitygroup-')
137 s_description = data_utils.rand_name('description-')
138 resp, securitygroup =\
139 self.sg_client.create_security_group(s_name, s_description)
140 self.addCleanup(self.sg_client.delete_security_group,
141 securitygroup['id'])
142
143 secgroup_id = securitygroup['id']
144 ip_protocol = 'tcp'
145
146 # Check we cannot create SG rule anymore
147 self.assertRaises(exceptions.OverLimit,
148 self.sg_client.create_security_group_rule,
149 secgroup_id, ip_protocol, 1025, 1025)
150
151
152class QuotasAdminNegativeTestXML(QuotasAdminNegativeTestJSON):
153 _interface = 'xml'