Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 3 | # Copyright 2012 OpenStack Foundation |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 7 | # not use this file except in compliance with the License. You may obtain |
| 8 | # a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | # License for the specific language governing permissions and limitations |
| 16 | # under the License. |
| 17 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 18 | from tempest.api.compute import base |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 19 | from tempest.common.utils import data_utils |
Matt Riedemann | 6ac8a10 | 2013-10-16 13:39:07 -0700 | [diff] [blame] | 20 | from tempest import config |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 21 | from tempest import exceptions |
Chris Yeoh | 9465b0b | 2013-02-09 22:19:15 +1030 | [diff] [blame] | 22 | from tempest.test import attr |
Matt Riedemann | 6ac8a10 | 2013-10-16 13:39:07 -0700 | [diff] [blame] | 23 | from tempest.test import skip_because |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 24 | |
| 25 | |
ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 26 | class QuotasAdminTestJSON(base.BaseV2ComputeAdminTest): |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 27 | _interface = 'json' |
Attila Fazekas | 430dae3 | 2013-10-17 15:19:32 +0200 | [diff] [blame] | 28 | force_tenant_isolation = True |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 29 | |
| 30 | @classmethod |
| 31 | def setUpClass(cls): |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 32 | super(QuotasAdminTestJSON, cls).setUpClass() |
rajalakshmi-ganesan | 1982c3c | 2013-01-10 14:56:45 +0530 | [diff] [blame] | 33 | cls.auth_url = cls.config.identity.uri |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 34 | cls.client = cls.os.quotas_client |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 35 | cls.adm_client = cls.os_adm.quotas_client |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 36 | cls.identity_admin_client = cls._get_identity_admin_client() |
Vasyl Khomenko | 96d8ca3 | 2013-04-17 09:54:07 -0700 | [diff] [blame] | 37 | cls.sg_client = cls.security_groups_client |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 38 | |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 39 | # NOTE(afazekas): these test cases should always create and use a new |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 40 | # tenant most of them should be skipped if we can't do that |
Attila Fazekas | 430dae3 | 2013-10-17 15:19:32 +0200 | [diff] [blame] | 41 | cls.demo_tenant_id = cls.isolated_creds.get_primary_user().get( |
| 42 | 'tenantId') |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 43 | |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 44 | cls.default_quota_set = set(('injected_file_content_bytes', |
| 45 | 'metadata_items', 'injected_files', |
| 46 | 'ram', 'floating_ips', |
| 47 | 'fixed_ips', 'key_pairs', |
| 48 | 'injected_file_path_bytes', |
| 49 | 'instances', 'security_group_rules', |
| 50 | 'cores', 'security_groups')) |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 51 | |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 52 | @attr(type='smoke') |
| 53 | def test_get_default_quotas(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 54 | # Admin can get the default resource quota set for a tenant |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 55 | expected_quota_set = self.default_quota_set | set(['id']) |
Leo Toyoda | 87a52b7 | 2013-04-09 10:34:40 +0900 | [diff] [blame] | 56 | resp, quota_set = self.client.get_default_quota_set( |
| 57 | self.demo_tenant_id) |
| 58 | self.assertEqual(200, resp.status) |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 59 | self.assertEqual(sorted(expected_quota_set), |
| 60 | sorted(quota_set.keys())) |
| 61 | self.assertEqual(quota_set['id'], self.demo_tenant_id) |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 62 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 63 | @attr(type='gate') |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 64 | def test_update_all_quota_resources_for_tenant(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 65 | # Admin can update all the resource quota limits for a tenant |
gengjh | 01ba9cc | 2013-06-15 10:14:48 +0800 | [diff] [blame] | 66 | resp, default_quota_set = self.client.get_default_quota_set( |
| 67 | self.demo_tenant_id) |
| 68 | new_quota_set = {'injected_file_content_bytes': 20480, |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 69 | 'metadata_items': 256, 'injected_files': 10, |
Michael Still | 9ac5bd0 | 2013-03-15 04:32:46 +1100 | [diff] [blame] | 70 | 'ram': 10240, 'floating_ips': 20, 'fixed_ips': 10, |
| 71 | 'key_pairs': 200, 'injected_file_path_bytes': 512, |
| 72 | 'instances': 20, 'security_group_rules': 20, |
| 73 | 'cores': 2, 'security_groups': 20} |
Matt Riedemann | bc8dbd3 | 2013-08-02 14:02:12 -0700 | [diff] [blame] | 74 | # Update limits for all quota resources |
| 75 | resp, quota_set = self.adm_client.update_quota_set( |
| 76 | self.demo_tenant_id, |
gengjh | 01ba9cc | 2013-06-15 10:14:48 +0800 | [diff] [blame] | 77 | force=True, |
Matt Riedemann | bc8dbd3 | 2013-08-02 14:02:12 -0700 | [diff] [blame] | 78 | **new_quota_set) |
gengjh | 01ba9cc | 2013-06-15 10:14:48 +0800 | [diff] [blame] | 79 | |
| 80 | default_quota_set.pop('id') |
Matt Riedemann | bc8dbd3 | 2013-08-02 14:02:12 -0700 | [diff] [blame] | 81 | self.addCleanup(self.adm_client.update_quota_set, |
gengjh | 01ba9cc | 2013-06-15 10:14:48 +0800 | [diff] [blame] | 82 | self.demo_tenant_id, **default_quota_set) |
Matt Riedemann | bc8dbd3 | 2013-08-02 14:02:12 -0700 | [diff] [blame] | 83 | self.assertEqual(200, resp.status) |
| 84 | self.assertEqual(new_quota_set, quota_set) |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 85 | |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 86 | # TODO(afazekas): merge these test cases |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 87 | @attr(type='gate') |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 88 | def test_get_updated_quotas(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 89 | # Verify that GET shows the updated quota set |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 90 | tenant_name = data_utils.rand_name('cpu_quota_tenant_') |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 91 | tenant_desc = tenant_name + '-desc' |
| 92 | identity_client = self.os_adm.identity_client |
| 93 | _, tenant = identity_client.create_tenant(name=tenant_name, |
| 94 | description=tenant_desc) |
| 95 | tenant_id = tenant['id'] |
| 96 | self.addCleanup(identity_client.delete_tenant, |
| 97 | tenant_id) |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 98 | |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 99 | self.adm_client.update_quota_set(tenant_id, |
| 100 | ram='5120') |
| 101 | resp, quota_set = self.adm_client.get_quota_set(tenant_id) |
| 102 | self.assertEqual(200, resp.status) |
| 103 | self.assertEqual(quota_set['ram'], 5120) |
| 104 | |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 105 | # TODO(afazekas): Add dedicated tenant to the skiped quota tests |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 106 | # it can be moved into the setUpClass as well |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 107 | @attr(type='gate') |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 108 | def test_create_server_when_cpu_quota_is_full(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 109 | # Disallow server creation when tenant's vcpu quota is full |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 110 | resp, quota_set = self.client.get_quota_set(self.demo_tenant_id) |
| 111 | default_vcpu_quota = quota_set['cores'] |
| 112 | vcpu_quota = 0 # Set the quota to zero to conserve resources |
| 113 | |
| 114 | resp, quota_set = self.adm_client.update_quota_set(self.demo_tenant_id, |
gengjh | 07fe830 | 2013-04-17 16:15:22 +0800 | [diff] [blame] | 115 | force=True, |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 116 | cores=vcpu_quota) |
hi2suresh | aab7b48 | 2013-03-12 04:41:38 +0000 | [diff] [blame] | 117 | |
| 118 | self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id, |
| 119 | cores=default_vcpu_quota) |
Ken'ichi Ohmichi | cfc052e | 2013-10-23 11:50:04 +0900 | [diff] [blame] | 120 | self.assertRaises(exceptions.OverLimit, self.create_test_server) |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 121 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 122 | @attr(type='gate') |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 123 | def test_create_server_when_memory_quota_is_full(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 124 | # Disallow server creation when tenant's memory quota is full |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 125 | resp, quota_set = self.client.get_quota_set(self.demo_tenant_id) |
| 126 | default_mem_quota = quota_set['ram'] |
| 127 | mem_quota = 0 # Set the quota to zero to conserve resources |
| 128 | |
| 129 | self.adm_client.update_quota_set(self.demo_tenant_id, |
gengjh | 07fe830 | 2013-04-17 16:15:22 +0800 | [diff] [blame] | 130 | force=True, |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 131 | ram=mem_quota) |
hi2suresh | da748f1 | 2013-03-13 03:31:14 +0000 | [diff] [blame] | 132 | |
| 133 | self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id, |
| 134 | ram=default_mem_quota) |
Ken'ichi Ohmichi | cfc052e | 2013-10-23 11:50:04 +0900 | [diff] [blame] | 135 | self.assertRaises(exceptions.OverLimit, self.create_test_server) |
rajalakshmi-ganesan | 1982c3c | 2013-01-10 14:56:45 +0530 | [diff] [blame] | 136 | |
gengjh | 01ba9cc | 2013-06-15 10:14:48 +0800 | [diff] [blame] | 137 | @attr(type='gate') |
| 138 | def test_update_quota_normal_user(self): |
| 139 | self.assertRaises(exceptions.Unauthorized, |
| 140 | self.client.update_quota_set, |
| 141 | self.demo_tenant_id, |
| 142 | ram=0) |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 143 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 144 | @attr(type=['negative', 'gate']) |
hi2suresh | b546db0 | 2013-02-21 10:21:32 +0000 | [diff] [blame] | 145 | def test_create_server_when_instances_quota_is_full(self): |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 146 | # Once instances quota limit is reached, disallow server creation |
hi2suresh | b546db0 | 2013-02-21 10:21:32 +0000 | [diff] [blame] | 147 | resp, quota_set = self.client.get_quota_set(self.demo_tenant_id) |
| 148 | default_instances_quota = quota_set['instances'] |
| 149 | instances_quota = 0 # Set quota to zero to disallow server creation |
| 150 | |
| 151 | self.adm_client.update_quota_set(self.demo_tenant_id, |
gengjh | 07fe830 | 2013-04-17 16:15:22 +0800 | [diff] [blame] | 152 | force=True, |
hi2suresh | b546db0 | 2013-02-21 10:21:32 +0000 | [diff] [blame] | 153 | instances=instances_quota) |
| 154 | self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id, |
| 155 | instances=default_instances_quota) |
Ken'ichi Ohmichi | cfc052e | 2013-10-23 11:50:04 +0900 | [diff] [blame] | 156 | self.assertRaises(exceptions.OverLimit, self.create_test_server) |
hi2suresh | b546db0 | 2013-02-21 10:21:32 +0000 | [diff] [blame] | 157 | |
Matt Riedemann | 6ac8a10 | 2013-10-16 13:39:07 -0700 | [diff] [blame] | 158 | @skip_because(bug="1186354", |
| 159 | condition=config.TempestConfig().service_available.neutron) |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 160 | @attr(type=['negative', 'gate']) |
Vasyl Khomenko | 96d8ca3 | 2013-04-17 09:54:07 -0700 | [diff] [blame] | 161 | def test_security_groups_exceed_limit(self): |
| 162 | # Negative test: Creation Security Groups over limit should FAIL |
| 163 | |
| 164 | resp, quota_set = self.client.get_quota_set(self.demo_tenant_id) |
| 165 | default_sg_quota = quota_set['security_groups'] |
| 166 | sg_quota = 0 # Set the quota to zero to conserve resources |
| 167 | |
| 168 | resp, quota_set =\ |
| 169 | self.adm_client.update_quota_set(self.demo_tenant_id, |
gengjh | 01ba9cc | 2013-06-15 10:14:48 +0800 | [diff] [blame] | 170 | force=True, |
Vasyl Khomenko | 96d8ca3 | 2013-04-17 09:54:07 -0700 | [diff] [blame] | 171 | security_groups=sg_quota) |
| 172 | |
| 173 | self.addCleanup(self.adm_client.update_quota_set, |
| 174 | self.demo_tenant_id, |
| 175 | security_groups=default_sg_quota) |
| 176 | |
| 177 | # Check we cannot create anymore |
| 178 | self.assertRaises(exceptions.OverLimit, |
| 179 | self.sg_client.create_security_group, |
| 180 | "sg-overlimit", "sg-desc") |
| 181 | |
Matt Riedemann | 6ac8a10 | 2013-10-16 13:39:07 -0700 | [diff] [blame] | 182 | @skip_because(bug="1186354", |
| 183 | condition=config.TempestConfig().service_available.neutron) |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 184 | @attr(type=['negative', 'gate']) |
Vasyl Khomenko | 96d8ca3 | 2013-04-17 09:54:07 -0700 | [diff] [blame] | 185 | def test_security_groups_rules_exceed_limit(self): |
| 186 | # Negative test: Creation of Security Group Rules should FAIL |
| 187 | # when we reach limit maxSecurityGroupRules |
| 188 | |
| 189 | resp, quota_set = self.client.get_quota_set(self.demo_tenant_id) |
| 190 | default_sg_rules_quota = quota_set['security_group_rules'] |
| 191 | sg_rules_quota = 0 # Set the quota to zero to conserve resources |
| 192 | |
| 193 | resp, quota_set =\ |
| 194 | self.adm_client.update_quota_set( |
| 195 | self.demo_tenant_id, |
gengjh | 01ba9cc | 2013-06-15 10:14:48 +0800 | [diff] [blame] | 196 | force=True, |
Vasyl Khomenko | 96d8ca3 | 2013-04-17 09:54:07 -0700 | [diff] [blame] | 197 | security_group_rules=sg_rules_quota) |
| 198 | |
| 199 | self.addCleanup(self.adm_client.update_quota_set, |
| 200 | self.demo_tenant_id, |
| 201 | security_group_rules=default_sg_rules_quota) |
| 202 | |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 203 | s_name = data_utils.rand_name('securitygroup-') |
| 204 | s_description = data_utils.rand_name('description-') |
Vasyl Khomenko | 96d8ca3 | 2013-04-17 09:54:07 -0700 | [diff] [blame] | 205 | resp, securitygroup =\ |
| 206 | self.sg_client.create_security_group(s_name, s_description) |
| 207 | self.addCleanup(self.sg_client.delete_security_group, |
| 208 | securitygroup['id']) |
| 209 | |
| 210 | secgroup_id = securitygroup['id'] |
| 211 | ip_protocol = 'tcp' |
| 212 | |
| 213 | # Check we cannot create SG rule anymore |
| 214 | self.assertRaises(exceptions.OverLimit, |
| 215 | self.sg_client.create_security_group_rule, |
| 216 | secgroup_id, ip_protocol, 1025, 1025) |
| 217 | |
rajalakshmi-ganesan | 1982c3c | 2013-01-10 14:56:45 +0530 | [diff] [blame] | 218 | |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 219 | class QuotasAdminTestXML(QuotasAdminTestJSON): |
| 220 | _interface = 'xml' |