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 |
| 36 | cls.demo_tenant_id = cls.isolated_creds.get_primary_user().get( |
| 37 | 'tenantId') |
| 38 | |
| 39 | @test.attr(type=['negative', 'gate']) |
| 40 | def test_update_quota_normal_user(self): |
| 41 | self.assertRaises(exceptions.Unauthorized, |
| 42 | self.client.update_quota_set, |
| 43 | self.demo_tenant_id, |
| 44 | ram=0) |
| 45 | |
| 46 | # TODO(afazekas): Add dedicated tenant to the skiped quota tests |
| 47 | # it can be moved into the setUpClass as well |
| 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) |
| 61 | self.assertRaises(exceptions.OverLimit, self.create_test_server) |
| 62 | |
| 63 | @test.attr(type=['negative', 'gate']) |
| 64 | def test_create_server_when_memory_quota_is_full(self): |
| 65 | # Disallow server creation when tenant's memory quota is full |
Zhi Kun Liu | 50eb71c | 2014-02-19 15:08:45 +0800 | [diff] [blame] | 66 | 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] | 67 | default_mem_quota = quota_set['ram'] |
| 68 | mem_quota = 0 # Set the quota to zero to conserve resources |
| 69 | |
| 70 | self.adm_client.update_quota_set(self.demo_tenant_id, |
| 71 | force=True, |
| 72 | ram=mem_quota) |
| 73 | |
| 74 | self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id, |
| 75 | ram=default_mem_quota) |
| 76 | self.assertRaises(exceptions.OverLimit, self.create_test_server) |
| 77 | |
| 78 | @test.attr(type=['negative', 'gate']) |
| 79 | def test_create_server_when_instances_quota_is_full(self): |
| 80 | # Once instances quota limit is reached, disallow server creation |
Zhi Kun Liu | 50eb71c | 2014-02-19 15:08:45 +0800 | [diff] [blame] | 81 | 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] | 82 | default_instances_quota = quota_set['instances'] |
| 83 | instances_quota = 0 # Set quota to zero to disallow server creation |
| 84 | |
| 85 | self.adm_client.update_quota_set(self.demo_tenant_id, |
| 86 | force=True, |
| 87 | instances=instances_quota) |
| 88 | self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id, |
| 89 | instances=default_instances_quota) |
| 90 | self.assertRaises(exceptions.OverLimit, self.create_test_server) |
| 91 | |
| 92 | @test.skip_because(bug="1186354", |
| 93 | condition=CONF.service_available.neutron) |
| 94 | @test.attr(type='gate') |
| 95 | def test_security_groups_exceed_limit(self): |
| 96 | # Negative test: Creation Security Groups over limit should FAIL |
| 97 | |
Zhi Kun Liu | 50eb71c | 2014-02-19 15:08:45 +0800 | [diff] [blame] | 98 | 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] | 99 | default_sg_quota = quota_set['security_groups'] |
| 100 | sg_quota = 0 # Set the quota to zero to conserve resources |
| 101 | |
| 102 | resp, quota_set =\ |
| 103 | self.adm_client.update_quota_set(self.demo_tenant_id, |
| 104 | force=True, |
| 105 | security_groups=sg_quota) |
| 106 | |
| 107 | self.addCleanup(self.adm_client.update_quota_set, |
| 108 | self.demo_tenant_id, |
| 109 | security_groups=default_sg_quota) |
| 110 | |
| 111 | # Check we cannot create anymore |
| 112 | self.assertRaises(exceptions.OverLimit, |
| 113 | self.sg_client.create_security_group, |
| 114 | "sg-overlimit", "sg-desc") |
| 115 | |
| 116 | @test.skip_because(bug="1186354", |
| 117 | condition=CONF.service_available.neutron) |
| 118 | @test.attr(type=['negative', 'gate']) |
| 119 | def test_security_groups_rules_exceed_limit(self): |
| 120 | # Negative test: Creation of Security Group Rules should FAIL |
| 121 | # when we reach limit maxSecurityGroupRules |
| 122 | |
Zhi Kun Liu | 50eb71c | 2014-02-19 15:08:45 +0800 | [diff] [blame] | 123 | 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] | 124 | default_sg_rules_quota = quota_set['security_group_rules'] |
| 125 | sg_rules_quota = 0 # Set the quota to zero to conserve resources |
| 126 | |
| 127 | resp, quota_set =\ |
| 128 | self.adm_client.update_quota_set( |
| 129 | self.demo_tenant_id, |
| 130 | force=True, |
| 131 | security_group_rules=sg_rules_quota) |
| 132 | |
| 133 | self.addCleanup(self.adm_client.update_quota_set, |
| 134 | self.demo_tenant_id, |
| 135 | security_group_rules=default_sg_rules_quota) |
| 136 | |
| 137 | s_name = data_utils.rand_name('securitygroup-') |
| 138 | s_description = data_utils.rand_name('description-') |
| 139 | resp, securitygroup =\ |
| 140 | self.sg_client.create_security_group(s_name, s_description) |
| 141 | self.addCleanup(self.sg_client.delete_security_group, |
| 142 | securitygroup['id']) |
| 143 | |
| 144 | secgroup_id = securitygroup['id'] |
| 145 | ip_protocol = 'tcp' |
| 146 | |
| 147 | # Check we cannot create SG rule anymore |
| 148 | self.assertRaises(exceptions.OverLimit, |
| 149 | self.sg_client.create_security_group_rule, |
| 150 | secgroup_id, ip_protocol, 1025, 1025) |
| 151 | |
| 152 | |
| 153 | class QuotasAdminNegativeTestXML(QuotasAdminNegativeTestJSON): |
| 154 | _interface = 'xml' |