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 | |
Matthew Treinish | c49fcbe | 2015-02-05 23:37:34 -0500 | [diff] [blame] | 15 | from tempest_lib import decorators |
Masayuki Igawa | 90c914e | 2015-01-20 14:48:16 +0900 | [diff] [blame] | 16 | from tempest_lib import exceptions as lib_exc |
Matthew Treinish | c49fcbe | 2015-02-05 23:37:34 -0500 | [diff] [blame] | 17 | |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 18 | from tempest.api.compute import base |
Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [diff] [blame] | 19 | from tempest.common.utils import data_utils |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 20 | from tempest import config |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 21 | from tempest import test |
| 22 | |
| 23 | CONF = config.CONF |
| 24 | |
| 25 | |
| 26 | class QuotasAdminNegativeTestJSON(base.BaseV2ComputeAdminTest): |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 27 | force_tenant_isolation = True |
| 28 | |
| 29 | @classmethod |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 30 | def setup_clients(cls): |
| 31 | super(QuotasAdminNegativeTestJSON, cls).setup_clients() |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 32 | cls.client = cls.os.quotas_client |
| 33 | cls.adm_client = cls.os_adm.quotas_client |
| 34 | cls.sg_client = cls.security_groups_client |
| 35 | |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 36 | @classmethod |
| 37 | def resource_setup(cls): |
| 38 | super(QuotasAdminNegativeTestJSON, cls).resource_setup() |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 39 | # NOTE(afazekas): these test cases should always create and use a new |
| 40 | # 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] | 41 | cls.demo_tenant_id = cls.client.tenant_id |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 42 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 43 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 44 | @test.idempotent_id('733abfe8-166e-47bb-8363-23dbd7ff3476') |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 45 | def test_update_quota_normal_user(self): |
Masayuki Igawa | 6b1cd29 | 2015-02-16 11:11:55 +0900 | [diff] [blame] | 46 | self.assertRaises(lib_exc.Forbidden, |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 47 | self.client.update_quota_set, |
| 48 | self.demo_tenant_id, |
| 49 | ram=0) |
| 50 | |
| 51 | # TODO(afazekas): Add dedicated tenant to the skiped quota tests |
| 52 | # it can be moved into the setUpClass as well |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 53 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 54 | @test.idempotent_id('91058876-9947-4807-9f22-f6eb17140d9b') |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 55 | def test_create_server_when_cpu_quota_is_full(self): |
| 56 | # Disallow server creation when tenant's vcpu quota is full |
Ken'ichi Ohmichi | f9868fc | 2015-06-17 02:36:06 +0000 | [diff] [blame] | 57 | quota_set = self.adm_client.show_quota_set(self.demo_tenant_id) |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 58 | default_vcpu_quota = quota_set['cores'] |
| 59 | vcpu_quota = 0 # Set the quota to zero to conserve resources |
| 60 | |
David Kranz | 3e4c28b | 2015-02-09 12:35:18 -0500 | [diff] [blame] | 61 | quota_set = self.adm_client.update_quota_set(self.demo_tenant_id, |
| 62 | force=True, |
| 63 | cores=vcpu_quota) |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 64 | |
| 65 | self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id, |
| 66 | cores=default_vcpu_quota) |
Masayuki Igawa | 6b1cd29 | 2015-02-16 11:11:55 +0900 | [diff] [blame] | 67 | self.assertRaises((lib_exc.Forbidden, lib_exc.OverLimit), |
ZHU ZHU | 3576254 | 2014-09-01 01:58:49 -0500 | [diff] [blame] | 68 | self.create_test_server) |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 69 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 70 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 71 | @test.idempotent_id('6fdd7012-584d-4327-a61c-49122e0d5864') |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 72 | def test_create_server_when_memory_quota_is_full(self): |
| 73 | # Disallow server creation when tenant's memory quota is full |
Ken'ichi Ohmichi | f9868fc | 2015-06-17 02:36:06 +0000 | [diff] [blame] | 74 | quota_set = self.adm_client.show_quota_set(self.demo_tenant_id) |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 75 | default_mem_quota = quota_set['ram'] |
| 76 | mem_quota = 0 # Set the quota to zero to conserve resources |
| 77 | |
| 78 | self.adm_client.update_quota_set(self.demo_tenant_id, |
| 79 | force=True, |
| 80 | ram=mem_quota) |
| 81 | |
| 82 | self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id, |
| 83 | ram=default_mem_quota) |
Masayuki Igawa | 6b1cd29 | 2015-02-16 11:11:55 +0900 | [diff] [blame] | 84 | self.assertRaises((lib_exc.Forbidden, lib_exc.OverLimit), |
ZHU ZHU | 3576254 | 2014-09-01 01:58:49 -0500 | [diff] [blame] | 85 | self.create_test_server) |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 86 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 87 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 88 | @test.idempotent_id('7c6be468-0274-449a-81c3-ac1c32ee0161') |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 89 | def test_create_server_when_instances_quota_is_full(self): |
| 90 | # Once instances quota limit is reached, disallow server creation |
Ken'ichi Ohmichi | f9868fc | 2015-06-17 02:36:06 +0000 | [diff] [blame] | 91 | quota_set = self.adm_client.show_quota_set(self.demo_tenant_id) |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 92 | default_instances_quota = quota_set['instances'] |
| 93 | instances_quota = 0 # Set quota to zero to disallow server creation |
| 94 | |
| 95 | self.adm_client.update_quota_set(self.demo_tenant_id, |
| 96 | force=True, |
| 97 | instances=instances_quota) |
| 98 | self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id, |
| 99 | instances=default_instances_quota) |
Masayuki Igawa | 6b1cd29 | 2015-02-16 11:11:55 +0900 | [diff] [blame] | 100 | self.assertRaises((lib_exc.Forbidden, lib_exc.OverLimit), |
ZHU ZHU | 3576254 | 2014-09-01 01:58:49 -0500 | [diff] [blame] | 101 | self.create_test_server) |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 102 | |
Matthew Treinish | c49fcbe | 2015-02-05 23:37:34 -0500 | [diff] [blame] | 103 | @decorators.skip_because(bug="1186354", |
| 104 | condition=CONF.service_available.neutron) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 105 | @test.idempotent_id('7c6c8f3b-2bf6-4918-b240-57b136a66aa0') |
ekhugen | d9b5db7 | 2014-07-29 16:13:42 +0000 | [diff] [blame] | 106 | @test.services('network') |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 107 | def test_security_groups_exceed_limit(self): |
| 108 | # Negative test: Creation Security Groups over limit should FAIL |
| 109 | |
Ken'ichi Ohmichi | f9868fc | 2015-06-17 02:36:06 +0000 | [diff] [blame] | 110 | quota_set = self.adm_client.show_quota_set(self.demo_tenant_id) |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 111 | default_sg_quota = quota_set['security_groups'] |
Joseph Lanoux | ffe09dd | 2015-03-18 16:45:33 +0000 | [diff] [blame] | 112 | |
| 113 | # Set the quota to number of used security groups |
| 114 | sg_quota = self.limits_client.show_limits()['absolute'][ |
| 115 | 'totalSecurityGroupsUsed'] |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 116 | |
David Kranz | 3e4c28b | 2015-02-09 12:35:18 -0500 | [diff] [blame] | 117 | quota_set =\ |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 118 | self.adm_client.update_quota_set(self.demo_tenant_id, |
| 119 | force=True, |
| 120 | security_groups=sg_quota) |
| 121 | |
| 122 | self.addCleanup(self.adm_client.update_quota_set, |
| 123 | self.demo_tenant_id, |
| 124 | security_groups=default_sg_quota) |
| 125 | |
| 126 | # Check we cannot create anymore |
Chris Yeoh | 60d5ce9 | 2014-06-27 13:59:23 +0930 | [diff] [blame] | 127 | # A 403 Forbidden or 413 Overlimit (old behaviour) exception |
| 128 | # will be raised when out of quota |
Masayuki Igawa | 6b1cd29 | 2015-02-16 11:11:55 +0900 | [diff] [blame] | 129 | self.assertRaises((lib_exc.Forbidden, lib_exc.OverLimit), |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 130 | self.sg_client.create_security_group, |
| 131 | "sg-overlimit", "sg-desc") |
| 132 | |
Matthew Treinish | c49fcbe | 2015-02-05 23:37:34 -0500 | [diff] [blame] | 133 | @decorators.skip_because(bug="1186354", |
| 134 | condition=CONF.service_available.neutron) |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 135 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 136 | @test.idempotent_id('6e9f436d-f1ed-4f8e-a493-7275dfaa4b4d') |
ekhugen | d9b5db7 | 2014-07-29 16:13:42 +0000 | [diff] [blame] | 137 | @test.services('network') |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 138 | def test_security_groups_rules_exceed_limit(self): |
| 139 | # Negative test: Creation of Security Group Rules should FAIL |
| 140 | # when we reach limit maxSecurityGroupRules |
| 141 | |
Ken'ichi Ohmichi | f9868fc | 2015-06-17 02:36:06 +0000 | [diff] [blame] | 142 | quota_set = self.adm_client.show_quota_set(self.demo_tenant_id) |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 143 | default_sg_rules_quota = quota_set['security_group_rules'] |
| 144 | sg_rules_quota = 0 # Set the quota to zero to conserve resources |
| 145 | |
David Kranz | 3e4c28b | 2015-02-09 12:35:18 -0500 | [diff] [blame] | 146 | quota_set =\ |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 147 | self.adm_client.update_quota_set( |
| 148 | self.demo_tenant_id, |
| 149 | force=True, |
| 150 | security_group_rules=sg_rules_quota) |
| 151 | |
| 152 | self.addCleanup(self.adm_client.update_quota_set, |
| 153 | self.demo_tenant_id, |
| 154 | security_group_rules=default_sg_rules_quota) |
| 155 | |
Ken'ichi Ohmichi | 4937f56 | 2015-03-23 00:15:01 +0000 | [diff] [blame] | 156 | s_name = data_utils.rand_name('securitygroup') |
| 157 | s_description = data_utils.rand_name('description') |
David Kranz | 9964b4e | 2015-02-06 15:45:29 -0500 | [diff] [blame] | 158 | securitygroup =\ |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 159 | self.sg_client.create_security_group(s_name, s_description) |
| 160 | self.addCleanup(self.sg_client.delete_security_group, |
| 161 | securitygroup['id']) |
| 162 | |
| 163 | secgroup_id = securitygroup['id'] |
| 164 | ip_protocol = 'tcp' |
| 165 | |
| 166 | # Check we cannot create SG rule anymore |
Chris Yeoh | 60d5ce9 | 2014-06-27 13:59:23 +0930 | [diff] [blame] | 167 | # A 403 Forbidden or 413 Overlimit (old behaviour) exception |
| 168 | # will be raised when out of quota |
Masayuki Igawa | 6b1cd29 | 2015-02-16 11:11:55 +0900 | [diff] [blame] | 169 | self.assertRaises((lib_exc.OverLimit, lib_exc.Forbidden), |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 170 | self.sg_client.create_security_group_rule, |
| 171 | secgroup_id, ip_protocol, 1025, 1025) |