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 |
Vasyl Khomenko | 96d8ca3 | 2013-04-17 09:54:07 -0700 | [diff] [blame] | 19 | from tempest.common.utils.data_utils import rand_name |
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 | |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 26 | class QuotasAdminTestJSON(base.BaseComputeAdminTest): |
| 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 | |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 39 | resp, tenants = cls.identity_admin_client.list_tenants() |
| 40 | |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 41 | # NOTE(afazekas): these test cases should always create and use a new |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 42 | # 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^] | 43 | cls.demo_tenant_id = cls.isolated_creds.get_primary_user().get( |
| 44 | 'tenantId') |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 45 | |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 46 | cls.default_quota_set = set(('injected_file_content_bytes', |
| 47 | 'metadata_items', 'injected_files', |
| 48 | 'ram', 'floating_ips', |
| 49 | 'fixed_ips', 'key_pairs', |
| 50 | 'injected_file_path_bytes', |
| 51 | 'instances', 'security_group_rules', |
| 52 | 'cores', 'security_groups')) |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 53 | |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 54 | @attr(type='smoke') |
| 55 | def test_get_default_quotas(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 56 | # Admin can get the default resource quota set for a tenant |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 57 | expected_quota_set = self.default_quota_set | set(['id']) |
Leo Toyoda | 87a52b7 | 2013-04-09 10:34:40 +0900 | [diff] [blame] | 58 | resp, quota_set = self.client.get_default_quota_set( |
| 59 | self.demo_tenant_id) |
| 60 | self.assertEqual(200, resp.status) |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 61 | self.assertEqual(sorted(expected_quota_set), |
| 62 | sorted(quota_set.keys())) |
| 63 | self.assertEqual(quota_set['id'], self.demo_tenant_id) |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 64 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 65 | @attr(type='gate') |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 66 | def test_update_all_quota_resources_for_tenant(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 67 | # Admin can update all the resource quota limits for a tenant |
gengjh | 01ba9cc | 2013-06-15 10:14:48 +0800 | [diff] [blame] | 68 | resp, default_quota_set = self.client.get_default_quota_set( |
| 69 | self.demo_tenant_id) |
| 70 | new_quota_set = {'injected_file_content_bytes': 20480, |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 71 | 'metadata_items': 256, 'injected_files': 10, |
Michael Still | 9ac5bd0 | 2013-03-15 04:32:46 +1100 | [diff] [blame] | 72 | 'ram': 10240, 'floating_ips': 20, 'fixed_ips': 10, |
| 73 | 'key_pairs': 200, 'injected_file_path_bytes': 512, |
| 74 | 'instances': 20, 'security_group_rules': 20, |
| 75 | 'cores': 2, 'security_groups': 20} |
Matt Riedemann | bc8dbd3 | 2013-08-02 14:02:12 -0700 | [diff] [blame] | 76 | # Update limits for all quota resources |
| 77 | resp, quota_set = self.adm_client.update_quota_set( |
| 78 | self.demo_tenant_id, |
gengjh | 01ba9cc | 2013-06-15 10:14:48 +0800 | [diff] [blame] | 79 | force=True, |
Matt Riedemann | bc8dbd3 | 2013-08-02 14:02:12 -0700 | [diff] [blame] | 80 | **new_quota_set) |
gengjh | 01ba9cc | 2013-06-15 10:14:48 +0800 | [diff] [blame] | 81 | |
| 82 | default_quota_set.pop('id') |
Matt Riedemann | bc8dbd3 | 2013-08-02 14:02:12 -0700 | [diff] [blame] | 83 | self.addCleanup(self.adm_client.update_quota_set, |
gengjh | 01ba9cc | 2013-06-15 10:14:48 +0800 | [diff] [blame] | 84 | self.demo_tenant_id, **default_quota_set) |
Matt Riedemann | bc8dbd3 | 2013-08-02 14:02:12 -0700 | [diff] [blame] | 85 | self.assertEqual(200, resp.status) |
| 86 | self.assertEqual(new_quota_set, quota_set) |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 87 | |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 88 | # TODO(afazekas): merge these test cases |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 89 | @attr(type='gate') |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 90 | def test_get_updated_quotas(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 91 | # Verify that GET shows the updated quota set |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 92 | tenant_name = rand_name('cpu_quota_tenant_') |
| 93 | tenant_desc = tenant_name + '-desc' |
| 94 | identity_client = self.os_adm.identity_client |
| 95 | _, tenant = identity_client.create_tenant(name=tenant_name, |
| 96 | description=tenant_desc) |
| 97 | tenant_id = tenant['id'] |
| 98 | self.addCleanup(identity_client.delete_tenant, |
| 99 | tenant_id) |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 100 | |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 101 | self.adm_client.update_quota_set(tenant_id, |
| 102 | ram='5120') |
| 103 | resp, quota_set = self.adm_client.get_quota_set(tenant_id) |
| 104 | self.assertEqual(200, resp.status) |
| 105 | self.assertEqual(quota_set['ram'], 5120) |
| 106 | |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 107 | # TODO(afazekas): Add dedicated tenant to the skiped quota tests |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 108 | # it can be moved into the setUpClass as well |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 109 | @attr(type='gate') |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 110 | def test_create_server_when_cpu_quota_is_full(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 111 | # Disallow server creation when tenant's vcpu quota is full |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 112 | resp, quota_set = self.client.get_quota_set(self.demo_tenant_id) |
| 113 | default_vcpu_quota = quota_set['cores'] |
| 114 | vcpu_quota = 0 # Set the quota to zero to conserve resources |
| 115 | |
| 116 | resp, quota_set = self.adm_client.update_quota_set(self.demo_tenant_id, |
gengjh | 07fe830 | 2013-04-17 16:15:22 +0800 | [diff] [blame] | 117 | force=True, |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 118 | cores=vcpu_quota) |
hi2suresh | aab7b48 | 2013-03-12 04:41:38 +0000 | [diff] [blame] | 119 | |
| 120 | self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id, |
| 121 | cores=default_vcpu_quota) |
| 122 | self.assertRaises(exceptions.OverLimit, self.create_server) |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 123 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 124 | @attr(type='gate') |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 125 | def test_create_server_when_memory_quota_is_full(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 126 | # Disallow server creation when tenant's memory quota is full |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 127 | resp, quota_set = self.client.get_quota_set(self.demo_tenant_id) |
| 128 | default_mem_quota = quota_set['ram'] |
| 129 | mem_quota = 0 # Set the quota to zero to conserve resources |
| 130 | |
| 131 | self.adm_client.update_quota_set(self.demo_tenant_id, |
gengjh | 07fe830 | 2013-04-17 16:15:22 +0800 | [diff] [blame] | 132 | force=True, |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 133 | ram=mem_quota) |
hi2suresh | da748f1 | 2013-03-13 03:31:14 +0000 | [diff] [blame] | 134 | |
| 135 | self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id, |
| 136 | ram=default_mem_quota) |
| 137 | self.assertRaises(exceptions.OverLimit, self.create_server) |
rajalakshmi-ganesan | 1982c3c | 2013-01-10 14:56:45 +0530 | [diff] [blame] | 138 | |
gengjh | 01ba9cc | 2013-06-15 10:14:48 +0800 | [diff] [blame] | 139 | @attr(type='gate') |
| 140 | def test_update_quota_normal_user(self): |
| 141 | self.assertRaises(exceptions.Unauthorized, |
| 142 | self.client.update_quota_set, |
| 143 | self.demo_tenant_id, |
| 144 | ram=0) |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 145 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 146 | @attr(type=['negative', 'gate']) |
hi2suresh | b546db0 | 2013-02-21 10:21:32 +0000 | [diff] [blame] | 147 | def test_create_server_when_instances_quota_is_full(self): |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 148 | # Once instances quota limit is reached, disallow server creation |
hi2suresh | b546db0 | 2013-02-21 10:21:32 +0000 | [diff] [blame] | 149 | resp, quota_set = self.client.get_quota_set(self.demo_tenant_id) |
| 150 | default_instances_quota = quota_set['instances'] |
| 151 | instances_quota = 0 # Set quota to zero to disallow server creation |
| 152 | |
| 153 | self.adm_client.update_quota_set(self.demo_tenant_id, |
gengjh | 07fe830 | 2013-04-17 16:15:22 +0800 | [diff] [blame] | 154 | force=True, |
hi2suresh | b546db0 | 2013-02-21 10:21:32 +0000 | [diff] [blame] | 155 | instances=instances_quota) |
| 156 | self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id, |
| 157 | instances=default_instances_quota) |
| 158 | self.assertRaises(exceptions.OverLimit, self.create_server) |
| 159 | |
Matt Riedemann | 6ac8a10 | 2013-10-16 13:39:07 -0700 | [diff] [blame] | 160 | @skip_because(bug="1186354", |
| 161 | condition=config.TempestConfig().service_available.neutron) |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 162 | @attr(type=['negative', 'gate']) |
Vasyl Khomenko | 96d8ca3 | 2013-04-17 09:54:07 -0700 | [diff] [blame] | 163 | def test_security_groups_exceed_limit(self): |
| 164 | # Negative test: Creation Security Groups over limit should FAIL |
| 165 | |
| 166 | resp, quota_set = self.client.get_quota_set(self.demo_tenant_id) |
| 167 | default_sg_quota = quota_set['security_groups'] |
| 168 | sg_quota = 0 # Set the quota to zero to conserve resources |
| 169 | |
| 170 | resp, quota_set =\ |
| 171 | self.adm_client.update_quota_set(self.demo_tenant_id, |
gengjh | 01ba9cc | 2013-06-15 10:14:48 +0800 | [diff] [blame] | 172 | force=True, |
Vasyl Khomenko | 96d8ca3 | 2013-04-17 09:54:07 -0700 | [diff] [blame] | 173 | security_groups=sg_quota) |
| 174 | |
| 175 | self.addCleanup(self.adm_client.update_quota_set, |
| 176 | self.demo_tenant_id, |
| 177 | security_groups=default_sg_quota) |
| 178 | |
| 179 | # Check we cannot create anymore |
| 180 | self.assertRaises(exceptions.OverLimit, |
| 181 | self.sg_client.create_security_group, |
| 182 | "sg-overlimit", "sg-desc") |
| 183 | |
Matt Riedemann | 6ac8a10 | 2013-10-16 13:39:07 -0700 | [diff] [blame] | 184 | @skip_because(bug="1186354", |
| 185 | condition=config.TempestConfig().service_available.neutron) |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 186 | @attr(type=['negative', 'gate']) |
Vasyl Khomenko | 96d8ca3 | 2013-04-17 09:54:07 -0700 | [diff] [blame] | 187 | def test_security_groups_rules_exceed_limit(self): |
| 188 | # Negative test: Creation of Security Group Rules should FAIL |
| 189 | # when we reach limit maxSecurityGroupRules |
| 190 | |
| 191 | resp, quota_set = self.client.get_quota_set(self.demo_tenant_id) |
| 192 | default_sg_rules_quota = quota_set['security_group_rules'] |
| 193 | sg_rules_quota = 0 # Set the quota to zero to conserve resources |
| 194 | |
| 195 | resp, quota_set =\ |
| 196 | self.adm_client.update_quota_set( |
| 197 | self.demo_tenant_id, |
gengjh | 01ba9cc | 2013-06-15 10:14:48 +0800 | [diff] [blame] | 198 | force=True, |
Vasyl Khomenko | 96d8ca3 | 2013-04-17 09:54:07 -0700 | [diff] [blame] | 199 | security_group_rules=sg_rules_quota) |
| 200 | |
| 201 | self.addCleanup(self.adm_client.update_quota_set, |
| 202 | self.demo_tenant_id, |
| 203 | security_group_rules=default_sg_rules_quota) |
| 204 | |
| 205 | s_name = rand_name('securitygroup-') |
| 206 | s_description = rand_name('description-') |
| 207 | resp, securitygroup =\ |
| 208 | self.sg_client.create_security_group(s_name, s_description) |
| 209 | self.addCleanup(self.sg_client.delete_security_group, |
| 210 | securitygroup['id']) |
| 211 | |
| 212 | secgroup_id = securitygroup['id'] |
| 213 | ip_protocol = 'tcp' |
| 214 | |
| 215 | # Check we cannot create SG rule anymore |
| 216 | self.assertRaises(exceptions.OverLimit, |
| 217 | self.sg_client.create_security_group_rule, |
| 218 | secgroup_id, ip_protocol, 1025, 1025) |
| 219 | |
rajalakshmi-ganesan | 1982c3c | 2013-01-10 14:56:45 +0530 | [diff] [blame] | 220 | |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 221 | class QuotasAdminTestXML(QuotasAdminTestJSON): |
| 222 | _interface = 'xml' |