Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 1 | # 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 | |
| 15 | from tempest.api.compute import base |
| 16 | from tempest.common.utils import data_utils |
| 17 | from tempest import config |
| 18 | from tempest import exceptions |
| 19 | from tempest import test |
| 20 | |
| 21 | CONF = config.CONF |
| 22 | |
| 23 | |
| 24 | class QuotasAdminNegativeTestJSON(base.BaseV2ComputeAdminTest): |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 25 | 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 Frittoli | 9612e81 | 2014-03-13 10:57:26 +0000 | [diff] [blame] | 36 | cls.demo_tenant_id = cls.client.tenant_id |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 37 | |
| 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 |
Ken'ichi Ohmichi | 3efb456 | 2014-06-24 16:14:07 +0900 | [diff] [blame] | 47 | @test.skip_because(bug="1298131") |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 48 | @test.attr(type=['negative', 'gate']) |
| 49 | def test_create_server_when_cpu_quota_is_full(self): |
| 50 | # Disallow server creation when tenant's vcpu quota is full |
Zhi Kun Liu | 50eb71c | 2014-02-19 15:08:45 +0800 | [diff] [blame] | 51 | resp, quota_set = self.adm_client.get_quota_set(self.demo_tenant_id) |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 52 | default_vcpu_quota = quota_set['cores'] |
| 53 | vcpu_quota = 0 # Set the quota to zero to conserve resources |
| 54 | |
| 55 | resp, quota_set = self.adm_client.update_quota_set(self.demo_tenant_id, |
| 56 | force=True, |
| 57 | cores=vcpu_quota) |
| 58 | |
| 59 | self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id, |
| 60 | cores=default_vcpu_quota) |
Ken'ichi Ohmichi | 3efb456 | 2014-06-24 16:14:07 +0900 | [diff] [blame] | 61 | self.assertRaises(exceptions.Unauthorized, self.create_test_server) |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 62 | |
Ken'ichi Ohmichi | 3efb456 | 2014-06-24 16:14:07 +0900 | [diff] [blame] | 63 | @test.skip_because(bug="1298131") |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 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 Liu | 50eb71c | 2014-02-19 15:08:45 +0800 | [diff] [blame] | 67 | resp, quota_set = self.adm_client.get_quota_set(self.demo_tenant_id) |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 68 | 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) |
Ken'ichi Ohmichi | 3efb456 | 2014-06-24 16:14:07 +0900 | [diff] [blame] | 77 | self.assertRaises(exceptions.Unauthorized, self.create_test_server) |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 78 | |
Ken'ichi Ohmichi | 3efb456 | 2014-06-24 16:14:07 +0900 | [diff] [blame] | 79 | @test.skip_because(bug="1298131") |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 80 | @test.attr(type=['negative', 'gate']) |
| 81 | def test_create_server_when_instances_quota_is_full(self): |
| 82 | # Once instances quota limit is reached, disallow server creation |
Zhi Kun Liu | 50eb71c | 2014-02-19 15:08:45 +0800 | [diff] [blame] | 83 | resp, quota_set = self.adm_client.get_quota_set(self.demo_tenant_id) |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 84 | default_instances_quota = quota_set['instances'] |
| 85 | instances_quota = 0 # Set quota to zero to disallow server creation |
| 86 | |
| 87 | self.adm_client.update_quota_set(self.demo_tenant_id, |
| 88 | force=True, |
| 89 | instances=instances_quota) |
| 90 | self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id, |
| 91 | instances=default_instances_quota) |
Ken'ichi Ohmichi | 3efb456 | 2014-06-24 16:14:07 +0900 | [diff] [blame] | 92 | self.assertRaises(exceptions.Unauthorized, self.create_test_server) |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 93 | |
| 94 | @test.skip_because(bug="1186354", |
| 95 | condition=CONF.service_available.neutron) |
| 96 | @test.attr(type='gate') |
ekhugen | d9b5db7 | 2014-07-29 16:13:42 +0000 | [diff] [blame] | 97 | @test.services('network') |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 98 | def test_security_groups_exceed_limit(self): |
| 99 | # Negative test: Creation Security Groups over limit should FAIL |
| 100 | |
Zhi Kun Liu | 50eb71c | 2014-02-19 15:08:45 +0800 | [diff] [blame] | 101 | resp, quota_set = self.adm_client.get_quota_set(self.demo_tenant_id) |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 102 | default_sg_quota = quota_set['security_groups'] |
| 103 | sg_quota = 0 # Set the quota to zero to conserve resources |
| 104 | |
| 105 | resp, quota_set =\ |
| 106 | self.adm_client.update_quota_set(self.demo_tenant_id, |
| 107 | force=True, |
| 108 | security_groups=sg_quota) |
| 109 | |
| 110 | self.addCleanup(self.adm_client.update_quota_set, |
| 111 | self.demo_tenant_id, |
| 112 | security_groups=default_sg_quota) |
| 113 | |
| 114 | # Check we cannot create anymore |
Chris Yeoh | 60d5ce9 | 2014-06-27 13:59:23 +0930 | [diff] [blame] | 115 | # A 403 Forbidden or 413 Overlimit (old behaviour) exception |
| 116 | # will be raised when out of quota |
| 117 | self.assertRaises((exceptions.Unauthorized, exceptions.OverLimit), |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 118 | self.sg_client.create_security_group, |
| 119 | "sg-overlimit", "sg-desc") |
| 120 | |
| 121 | @test.skip_because(bug="1186354", |
| 122 | condition=CONF.service_available.neutron) |
| 123 | @test.attr(type=['negative', 'gate']) |
ekhugen | d9b5db7 | 2014-07-29 16:13:42 +0000 | [diff] [blame] | 124 | @test.services('network') |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 125 | def test_security_groups_rules_exceed_limit(self): |
| 126 | # Negative test: Creation of Security Group Rules should FAIL |
| 127 | # when we reach limit maxSecurityGroupRules |
| 128 | |
Zhi Kun Liu | 50eb71c | 2014-02-19 15:08:45 +0800 | [diff] [blame] | 129 | resp, quota_set = self.adm_client.get_quota_set(self.demo_tenant_id) |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 130 | default_sg_rules_quota = quota_set['security_group_rules'] |
| 131 | sg_rules_quota = 0 # Set the quota to zero to conserve resources |
| 132 | |
| 133 | resp, quota_set =\ |
| 134 | self.adm_client.update_quota_set( |
| 135 | self.demo_tenant_id, |
| 136 | force=True, |
| 137 | security_group_rules=sg_rules_quota) |
| 138 | |
| 139 | self.addCleanup(self.adm_client.update_quota_set, |
| 140 | self.demo_tenant_id, |
| 141 | security_group_rules=default_sg_rules_quota) |
| 142 | |
| 143 | s_name = data_utils.rand_name('securitygroup-') |
| 144 | s_description = data_utils.rand_name('description-') |
| 145 | resp, securitygroup =\ |
| 146 | self.sg_client.create_security_group(s_name, s_description) |
| 147 | self.addCleanup(self.sg_client.delete_security_group, |
| 148 | securitygroup['id']) |
| 149 | |
| 150 | secgroup_id = securitygroup['id'] |
| 151 | ip_protocol = 'tcp' |
| 152 | |
| 153 | # Check we cannot create SG rule anymore |
Chris Yeoh | 60d5ce9 | 2014-06-27 13:59:23 +0930 | [diff] [blame] | 154 | # A 403 Forbidden or 413 Overlimit (old behaviour) exception |
| 155 | # will be raised when out of quota |
| 156 | self.assertRaises((exceptions.OverLimit, exceptions.Unauthorized), |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 157 | self.sg_client.create_security_group_rule, |
| 158 | secgroup_id, ip_protocol, 1025, 1025) |
| 159 | |
| 160 | |
| 161 | class QuotasAdminNegativeTestXML(QuotasAdminNegativeTestJSON): |
| 162 | _interface = 'xml' |