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