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 | |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 18 | from tempest import exceptions |
Chris Yeoh | 9465b0b | 2013-02-09 22:19:15 +1030 | [diff] [blame] | 19 | from tempest.test import attr |
rajalakshmi-ganesan | 1982c3c | 2013-01-10 14:56:45 +0530 | [diff] [blame] | 20 | from tempest.tests.compute import base |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 21 | |
| 22 | |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 23 | class QuotasAdminTestJSON(base.BaseComputeAdminTest): |
| 24 | _interface = 'json' |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 25 | |
| 26 | @classmethod |
| 27 | def setUpClass(cls): |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 28 | super(QuotasAdminTestJSON, cls).setUpClass() |
rajalakshmi-ganesan | 1982c3c | 2013-01-10 14:56:45 +0530 | [diff] [blame] | 29 | cls.auth_url = cls.config.identity.uri |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 30 | cls.client = cls.os.quotas_client |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 31 | cls.adm_client = cls.os_adm.quotas_client |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 32 | cls.identity_admin_client = cls._get_identity_admin_client() |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 33 | |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 34 | resp, tenants = cls.identity_admin_client.list_tenants() |
| 35 | |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 36 | #NOTE(afazekas): these test cases should always create and use a new |
| 37 | # 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] | 38 | if cls.config.compute.allow_tenant_isolation: |
| 39 | cls.demo_tenant_id = cls.isolated_creds[0][0]['tenantId'] |
| 40 | else: |
| 41 | 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] | 42 | == cls.config.identity.tenant_name][0] |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 43 | |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 44 | cls.default_quota_set = {'injected_file_content_bytes': 10240, |
| 45 | 'metadata_items': 128, 'injected_files': 5, |
| 46 | 'ram': 51200, 'floating_ips': 10, |
| 47 | 'key_pairs': 100, |
| 48 | 'injected_file_path_bytes': 255, |
| 49 | 'instances': 10, 'security_group_rules': 20, |
| 50 | 'cores': 20, 'security_groups': 10} |
| 51 | |
| 52 | @classmethod |
ivan-zhu | 1feeb38 | 2013-01-24 10:14:39 +0800 | [diff] [blame] | 53 | def tearDownClass(cls): |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 54 | for server in cls.servers: |
| 55 | try: |
| 56 | cls.servers_client.delete_server(server['id']) |
| 57 | except exceptions.NotFound: |
| 58 | continue |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 59 | super(QuotasAdminTestJSON, cls).tearDownClass() |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 60 | |
| 61 | @attr(type='smoke') |
| 62 | def test_get_default_quotas(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 63 | # Admin can get the default resource quota set for a tenant |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 64 | expected_quota_set = self.default_quota_set.copy() |
| 65 | expected_quota_set['id'] = self.demo_tenant_id |
| 66 | try: |
| 67 | resp, quota_set = self.client.get_quota_set(self.demo_tenant_id) |
| 68 | self.assertEqual(200, resp.status) |
Michael J Fork | 7a31365 | 2013-02-11 23:23:02 +0000 | [diff] [blame] | 69 | self.assertEqual(expected_quota_set, quota_set) |
Matthew Treinish | 05d9fb9 | 2012-12-07 16:14:05 -0500 | [diff] [blame] | 70 | except Exception: |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 71 | self.fail("Admin could not get the default quota set for a tenant") |
| 72 | |
| 73 | def test_update_all_quota_resources_for_tenant(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 74 | # Admin can update all the resource quota limits for a tenant |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 75 | new_quota_set = {'injected_file_content_bytes': 20480, |
| 76 | 'metadata_items': 256, 'injected_files': 10, |
| 77 | 'ram': 10240, 'floating_ips': 20, 'key_pairs': 200, |
| 78 | 'injected_file_path_bytes': 512, 'instances': 20, |
| 79 | 'security_group_rules': 20, 'cores': 2, |
| 80 | 'security_groups': 20} |
| 81 | try: |
| 82 | # Update limits for all quota resources |
| 83 | resp, quota_set = self.adm_client.update_quota_set( |
| 84 | self.demo_tenant_id, |
| 85 | **new_quota_set) |
| 86 | self.assertEqual(200, resp.status) |
Michael J Fork | 7a31365 | 2013-02-11 23:23:02 +0000 | [diff] [blame] | 87 | self.assertEqual(new_quota_set, quota_set) |
Matthew Treinish | 05d9fb9 | 2012-12-07 16:14:05 -0500 | [diff] [blame] | 88 | except Exception: |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 89 | self.fail("Admin could not update quota set for the tenant") |
| 90 | finally: |
| 91 | # Reset quota resource limits to default values |
| 92 | resp, quota_set = self.adm_client.update_quota_set( |
| 93 | self.demo_tenant_id, |
| 94 | **self.default_quota_set) |
| 95 | self.assertEqual(200, resp.status, "Failed to reset quota " |
| 96 | "defaults") |
| 97 | |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 98 | #TODO(afazekas): merge these test cases |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 99 | def test_get_updated_quotas(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 100 | # Verify that GET shows the updated quota set |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 101 | self.adm_client.update_quota_set(self.demo_tenant_id, |
| 102 | ram='5120') |
| 103 | try: |
| 104 | resp, quota_set = self.client.get_quota_set(self.demo_tenant_id) |
| 105 | self.assertEqual(200, resp.status) |
| 106 | self.assertEqual(quota_set['ram'], 5120) |
Matthew Treinish | 05d9fb9 | 2012-12-07 16:14:05 -0500 | [diff] [blame] | 107 | except Exception: |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 108 | self.fail("Could not get the update quota limit for resource") |
| 109 | finally: |
| 110 | # Reset quota resource limits to default values |
| 111 | resp, quota_set = self.adm_client.update_quota_set( |
| 112 | self.demo_tenant_id, |
| 113 | **self.default_quota_set) |
| 114 | self.assertEqual(200, resp.status, "Failed to reset quota " |
| 115 | "defaults") |
| 116 | |
| 117 | def test_create_server_when_cpu_quota_is_full(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 118 | # Disallow server creation when tenant's vcpu quota is full |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 119 | resp, quota_set = self.client.get_quota_set(self.demo_tenant_id) |
| 120 | default_vcpu_quota = quota_set['cores'] |
| 121 | vcpu_quota = 0 # Set the quota to zero to conserve resources |
| 122 | |
| 123 | resp, quota_set = self.adm_client.update_quota_set(self.demo_tenant_id, |
| 124 | cores=vcpu_quota) |
| 125 | try: |
| 126 | self.create_server() |
| 127 | except exceptions.OverLimit: |
| 128 | pass |
| 129 | else: |
| 130 | self.fail("Could create servers over the VCPU quota limit") |
| 131 | finally: |
| 132 | self.adm_client.update_quota_set(self.demo_tenant_id, |
| 133 | cores=default_vcpu_quota) |
| 134 | |
| 135 | def test_create_server_when_memory_quota_is_full(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 136 | # Disallow server creation when tenant's memory quota is full |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 137 | resp, quota_set = self.client.get_quota_set(self.demo_tenant_id) |
| 138 | default_mem_quota = quota_set['ram'] |
| 139 | mem_quota = 0 # Set the quota to zero to conserve resources |
| 140 | |
| 141 | self.adm_client.update_quota_set(self.demo_tenant_id, |
| 142 | ram=mem_quota) |
| 143 | try: |
| 144 | self.create_server() |
| 145 | except exceptions.OverLimit: |
| 146 | pass |
| 147 | else: |
| 148 | self.fail("Could create servers over the memory quota limit") |
| 149 | finally: |
| 150 | self.adm_client.update_quota_set(self.demo_tenant_id, |
| 151 | ram=default_mem_quota) |
rajalakshmi-ganesan | 1982c3c | 2013-01-10 14:56:45 +0530 | [diff] [blame] | 152 | |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 153 | #TODO(afazekas): Add test that tried to update the quota_set as a regular user |
| 154 | |
hi2suresh | b546db0 | 2013-02-21 10:21:32 +0000 | [diff] [blame] | 155 | @attr(type='negative') |
| 156 | def test_create_server_when_instances_quota_is_full(self): |
| 157 | #Once instances quota limit is reached, disallow server creation |
| 158 | resp, quota_set = self.client.get_quota_set(self.demo_tenant_id) |
| 159 | default_instances_quota = quota_set['instances'] |
| 160 | instances_quota = 0 # Set quota to zero to disallow server creation |
| 161 | |
| 162 | self.adm_client.update_quota_set(self.demo_tenant_id, |
| 163 | instances=instances_quota) |
| 164 | self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id, |
| 165 | instances=default_instances_quota) |
| 166 | self.assertRaises(exceptions.OverLimit, self.create_server) |
| 167 | |
rajalakshmi-ganesan | 1982c3c | 2013-01-10 14:56:45 +0530 | [diff] [blame] | 168 | |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 169 | class QuotasAdminTestXML(QuotasAdminTestJSON): |
| 170 | _interface = 'xml' |