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 | |
| 18 | from nose.plugins.attrib import attr |
| 19 | |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 20 | from tempest import exceptions |
rajalakshmi-ganesan | 1982c3c | 2013-01-10 14:56:45 +0530 | [diff] [blame] | 21 | from tempest.services.compute.admin.json \ |
| 22 | import quotas_client as adm_quotas_json |
| 23 | from tempest.services.compute.admin.xml import quotas_client as adm_quotas_xml |
| 24 | from tempest.tests import compute |
| 25 | from tempest.tests.compute import base |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 26 | |
| 27 | |
rajalakshmi-ganesan | 1982c3c | 2013-01-10 14:56:45 +0530 | [diff] [blame] | 28 | class QuotasAdminTestBase(object): |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 29 | |
| 30 | @classmethod |
| 31 | def setUpClass(cls): |
rajalakshmi-ganesan | 1982c3c | 2013-01-10 14:56:45 +0530 | [diff] [blame] | 32 | cls.c_adm_user = cls.config.compute_admin.username |
| 33 | cls.c_adm_pass = cls.config.compute_admin.password |
| 34 | cls.c_adm_tenant = cls.config.compute_admin.tenant_name |
| 35 | cls.auth_url = cls.config.identity.uri |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 36 | cls.client = cls.os.quotas_client |
| 37 | cls.identity_admin_client = cls._get_identity_admin_client() |
| 38 | resp, tenants = cls.identity_admin_client.list_tenants() |
| 39 | |
| 40 | if cls.config.compute.allow_tenant_isolation: |
| 41 | cls.demo_tenant_id = cls.isolated_creds[0][0]['tenantId'] |
| 42 | else: |
| 43 | 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] | 44 | == cls.config.identity.tenant_name][0] |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 45 | |
| 46 | cls.adm_tenant_id = [tnt['id'] for tnt in tenants if tnt['name'] == |
| 47 | cls.config.compute_admin.tenant_name][0] |
| 48 | |
| 49 | cls.default_quota_set = {'injected_file_content_bytes': 10240, |
| 50 | 'metadata_items': 128, 'injected_files': 5, |
| 51 | 'ram': 51200, 'floating_ips': 10, |
| 52 | 'key_pairs': 100, |
| 53 | 'injected_file_path_bytes': 255, |
| 54 | 'instances': 10, 'security_group_rules': 20, |
| 55 | 'cores': 20, 'security_groups': 10} |
| 56 | |
| 57 | @classmethod |
ivan-zhu | 1feeb38 | 2013-01-24 10:14:39 +0800 | [diff] [blame] | 58 | def tearDownClass(cls): |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 59 | for server in cls.servers: |
| 60 | try: |
| 61 | cls.servers_client.delete_server(server['id']) |
| 62 | except exceptions.NotFound: |
| 63 | continue |
| 64 | |
| 65 | @attr(type='smoke') |
| 66 | def test_get_default_quotas(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 67 | # Admin can get the default resource quota set for a tenant |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 68 | expected_quota_set = self.default_quota_set.copy() |
| 69 | expected_quota_set['id'] = self.demo_tenant_id |
| 70 | try: |
| 71 | resp, quota_set = self.client.get_quota_set(self.demo_tenant_id) |
| 72 | self.assertEqual(200, resp.status) |
| 73 | self.assertSequenceEqual(expected_quota_set, quota_set) |
Matthew Treinish | 05d9fb9 | 2012-12-07 16:14:05 -0500 | [diff] [blame] | 74 | except Exception: |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 75 | self.fail("Admin could not get the default quota set for a tenant") |
| 76 | |
| 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 |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 79 | new_quota_set = {'injected_file_content_bytes': 20480, |
| 80 | 'metadata_items': 256, 'injected_files': 10, |
| 81 | 'ram': 10240, 'floating_ips': 20, 'key_pairs': 200, |
| 82 | 'injected_file_path_bytes': 512, 'instances': 20, |
| 83 | 'security_group_rules': 20, 'cores': 2, |
| 84 | 'security_groups': 20} |
| 85 | try: |
| 86 | # Update limits for all quota resources |
| 87 | resp, quota_set = self.adm_client.update_quota_set( |
| 88 | self.demo_tenant_id, |
| 89 | **new_quota_set) |
| 90 | self.assertEqual(200, resp.status) |
| 91 | self.assertSequenceEqual(new_quota_set, quota_set) |
Matthew Treinish | 05d9fb9 | 2012-12-07 16:14:05 -0500 | [diff] [blame] | 92 | except Exception: |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 93 | self.fail("Admin could not update quota set for the tenant") |
| 94 | finally: |
| 95 | # Reset quota resource limits to default values |
| 96 | resp, quota_set = self.adm_client.update_quota_set( |
| 97 | self.demo_tenant_id, |
| 98 | **self.default_quota_set) |
| 99 | self.assertEqual(200, resp.status, "Failed to reset quota " |
| 100 | "defaults") |
| 101 | |
| 102 | def test_get_updated_quotas(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 103 | # Verify that GET shows the updated quota set |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 104 | self.adm_client.update_quota_set(self.demo_tenant_id, |
| 105 | ram='5120') |
| 106 | try: |
| 107 | resp, quota_set = self.client.get_quota_set(self.demo_tenant_id) |
| 108 | self.assertEqual(200, resp.status) |
| 109 | self.assertEqual(quota_set['ram'], 5120) |
Matthew Treinish | 05d9fb9 | 2012-12-07 16:14:05 -0500 | [diff] [blame] | 110 | except Exception: |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 111 | self.fail("Could not get the update quota limit for resource") |
| 112 | finally: |
| 113 | # Reset quota resource limits to default values |
| 114 | resp, quota_set = self.adm_client.update_quota_set( |
| 115 | self.demo_tenant_id, |
| 116 | **self.default_quota_set) |
| 117 | self.assertEqual(200, resp.status, "Failed to reset quota " |
| 118 | "defaults") |
| 119 | |
| 120 | def test_create_server_when_cpu_quota_is_full(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 121 | # Disallow server creation when tenant's vcpu quota is full |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 122 | resp, quota_set = self.client.get_quota_set(self.demo_tenant_id) |
| 123 | default_vcpu_quota = quota_set['cores'] |
| 124 | vcpu_quota = 0 # Set the quota to zero to conserve resources |
| 125 | |
| 126 | resp, quota_set = self.adm_client.update_quota_set(self.demo_tenant_id, |
| 127 | cores=vcpu_quota) |
| 128 | try: |
| 129 | self.create_server() |
| 130 | except exceptions.OverLimit: |
| 131 | pass |
| 132 | else: |
| 133 | self.fail("Could create servers over the VCPU quota limit") |
| 134 | finally: |
| 135 | self.adm_client.update_quota_set(self.demo_tenant_id, |
| 136 | cores=default_vcpu_quota) |
| 137 | |
| 138 | def test_create_server_when_memory_quota_is_full(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 139 | # Disallow server creation when tenant's memory quota is full |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 140 | resp, quota_set = self.client.get_quota_set(self.demo_tenant_id) |
| 141 | default_mem_quota = quota_set['ram'] |
| 142 | mem_quota = 0 # Set the quota to zero to conserve resources |
| 143 | |
| 144 | self.adm_client.update_quota_set(self.demo_tenant_id, |
| 145 | ram=mem_quota) |
| 146 | try: |
| 147 | self.create_server() |
| 148 | except exceptions.OverLimit: |
| 149 | pass |
| 150 | else: |
| 151 | self.fail("Could create servers over the memory quota limit") |
| 152 | finally: |
| 153 | self.adm_client.update_quota_set(self.demo_tenant_id, |
| 154 | ram=default_mem_quota) |
rajalakshmi-ganesan | 1982c3c | 2013-01-10 14:56:45 +0530 | [diff] [blame] | 155 | |
| 156 | |
| 157 | class QuotasAdminTestJSON(QuotasAdminTestBase, base.BaseComputeAdminTestJSON, |
| 158 | base.BaseComputeTest): |
| 159 | |
| 160 | @classmethod |
| 161 | def setUpClass(cls): |
| 162 | base.BaseComputeAdminTestJSON.setUpClass() |
| 163 | base.BaseComputeTest.setUpClass() |
| 164 | super(QuotasAdminTestJSON, cls).setUpClass() |
| 165 | |
| 166 | cls.adm_client = adm_quotas_json.AdminQuotasClientJSON( |
| 167 | cls.config, cls.c_adm_user, cls.c_adm_pass, |
| 168 | cls.auth_url, cls.c_adm_tenant) |
| 169 | |
| 170 | @classmethod |
| 171 | def tearDownClass(cls): |
| 172 | super(QuotasAdminTestJSON, cls).tearDownClass() |
| 173 | base.BaseComputeTest.tearDownClass() |
| 174 | |
| 175 | |
| 176 | class QuotasAdminTestXML(QuotasAdminTestBase, base.BaseComputeAdminTestXML, |
| 177 | base.BaseComputeTest): |
| 178 | |
| 179 | @classmethod |
| 180 | def setUpClass(cls): |
| 181 | base.BaseComputeAdminTestXML.setUpClass() |
| 182 | base.BaseComputeTest.setUpClass() |
| 183 | super(QuotasAdminTestXML, cls).setUpClass() |
| 184 | |
| 185 | cls.adm_client = adm_quotas_xml.AdminQuotasClientXML(cls.config, |
| 186 | cls.c_adm_user, |
| 187 | cls.c_adm_pass, |
| 188 | cls.auth_url, |
| 189 | cls.c_adm_tenant) |
| 190 | |
| 191 | @classmethod |
| 192 | def tearDownClass(cls): |
| 193 | super(QuotasAdminTestXML, cls).tearDownClass() |
| 194 | base.BaseComputeTest.tearDownClass() |