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 |
Matthew Treinish | a83a16e | 2012-12-07 13:44:02 -0500 | [diff] [blame] | 21 | from tempest.services.compute.admin.json import quotas_client as adm_quotas |
James E. Blair | e6d8ee1 | 2013-01-18 21:33:45 +0000 | [diff] [blame] | 22 | from tempest.tests.compute.base import BaseComputeTest |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 23 | |
| 24 | |
James E. Blair | e6d8ee1 | 2013-01-18 21:33:45 +0000 | [diff] [blame] | 25 | class QuotasTest(BaseComputeTest): |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 26 | |
| 27 | @classmethod |
| 28 | def setUpClass(cls): |
| 29 | super(QuotasTest, cls).setUpClass() |
Attila Fazekas | cadcb1f | 2013-01-21 23:10:53 +0100 | [diff] [blame] | 30 | c_adm_user = cls.config.compute_admin.username |
| 31 | c_adm_pass = cls.config.compute_admin.password |
| 32 | c_adm_tenant = cls.config.compute_admin.tenant_name |
Jay Pipes | 7c88eb2 | 2013-01-16 21:32:43 -0500 | [diff] [blame] | 33 | auth_url = cls.config.identity.uri |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 34 | |
Attila Fazekas | cadcb1f | 2013-01-21 23:10:53 +0100 | [diff] [blame] | 35 | cls.adm_client = adm_quotas.AdminQuotasClient(cls.config, c_adm_user, |
| 36 | c_adm_pass, auth_url, |
| 37 | c_adm_tenant) |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 38 | cls.client = cls.os.quotas_client |
| 39 | cls.identity_admin_client = cls._get_identity_admin_client() |
| 40 | resp, tenants = cls.identity_admin_client.list_tenants() |
| 41 | |
| 42 | if cls.config.compute.allow_tenant_isolation: |
| 43 | cls.demo_tenant_id = cls.isolated_creds[0][0]['tenantId'] |
| 44 | else: |
| 45 | 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] | 46 | == cls.config.identity.tenant_name][0] |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 47 | |
| 48 | cls.adm_tenant_id = [tnt['id'] for tnt in tenants if tnt['name'] == |
| 49 | cls.config.compute_admin.tenant_name][0] |
| 50 | |
| 51 | cls.default_quota_set = {'injected_file_content_bytes': 10240, |
| 52 | 'metadata_items': 128, 'injected_files': 5, |
| 53 | 'ram': 51200, 'floating_ips': 10, |
| 54 | 'key_pairs': 100, |
| 55 | 'injected_file_path_bytes': 255, |
| 56 | 'instances': 10, 'security_group_rules': 20, |
| 57 | 'cores': 20, 'security_groups': 10} |
| 58 | |
| 59 | @classmethod |
ivan-zhu | 1feeb38 | 2013-01-24 10:14:39 +0800 | [diff] [blame] | 60 | def tearDownClass(cls): |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 61 | for server in cls.servers: |
| 62 | try: |
| 63 | cls.servers_client.delete_server(server['id']) |
| 64 | except exceptions.NotFound: |
| 65 | continue |
ivan-zhu | 1feeb38 | 2013-01-24 10:14:39 +0800 | [diff] [blame] | 66 | super(QuotasTest, cls).tearDownClass() |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 67 | |
| 68 | @attr(type='smoke') |
| 69 | def test_get_default_quotas(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 70 | # Admin can get the default resource quota set for a tenant |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 71 | expected_quota_set = self.default_quota_set.copy() |
| 72 | expected_quota_set['id'] = self.demo_tenant_id |
| 73 | try: |
| 74 | resp, quota_set = self.client.get_quota_set(self.demo_tenant_id) |
| 75 | self.assertEqual(200, resp.status) |
| 76 | self.assertSequenceEqual(expected_quota_set, quota_set) |
Matthew Treinish | 05d9fb9 | 2012-12-07 16:14:05 -0500 | [diff] [blame] | 77 | except Exception: |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 78 | self.fail("Admin could not get the default quota set for a tenant") |
| 79 | |
| 80 | def test_update_all_quota_resources_for_tenant(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 81 | # Admin can update all the resource quota limits for a tenant |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 82 | new_quota_set = {'injected_file_content_bytes': 20480, |
| 83 | 'metadata_items': 256, 'injected_files': 10, |
| 84 | 'ram': 10240, 'floating_ips': 20, 'key_pairs': 200, |
| 85 | 'injected_file_path_bytes': 512, 'instances': 20, |
| 86 | 'security_group_rules': 20, 'cores': 2, |
| 87 | 'security_groups': 20} |
| 88 | try: |
| 89 | # Update limits for all quota resources |
| 90 | resp, quota_set = self.adm_client.update_quota_set( |
| 91 | self.demo_tenant_id, |
| 92 | **new_quota_set) |
| 93 | self.assertEqual(200, resp.status) |
| 94 | self.assertSequenceEqual(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 | |
| 105 | def test_get_updated_quotas(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 106 | # Verify that GET shows the updated quota set |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 107 | self.adm_client.update_quota_set(self.demo_tenant_id, |
| 108 | ram='5120') |
| 109 | try: |
| 110 | resp, quota_set = self.client.get_quota_set(self.demo_tenant_id) |
| 111 | self.assertEqual(200, resp.status) |
| 112 | self.assertEqual(quota_set['ram'], 5120) |
Matthew Treinish | 05d9fb9 | 2012-12-07 16:14:05 -0500 | [diff] [blame] | 113 | except Exception: |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 114 | self.fail("Could not get the update quota limit for resource") |
| 115 | finally: |
| 116 | # Reset quota resource limits to default values |
| 117 | resp, quota_set = self.adm_client.update_quota_set( |
| 118 | self.demo_tenant_id, |
| 119 | **self.default_quota_set) |
| 120 | self.assertEqual(200, resp.status, "Failed to reset quota " |
| 121 | "defaults") |
| 122 | |
| 123 | def test_create_server_when_cpu_quota_is_full(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 124 | # Disallow server creation when tenant's vcpu 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_vcpu_quota = quota_set['cores'] |
| 127 | vcpu_quota = 0 # Set the quota to zero to conserve resources |
| 128 | |
| 129 | resp, quota_set = self.adm_client.update_quota_set(self.demo_tenant_id, |
| 130 | cores=vcpu_quota) |
| 131 | try: |
| 132 | self.create_server() |
| 133 | except exceptions.OverLimit: |
| 134 | pass |
| 135 | else: |
| 136 | self.fail("Could create servers over the VCPU quota limit") |
| 137 | finally: |
| 138 | self.adm_client.update_quota_set(self.demo_tenant_id, |
| 139 | cores=default_vcpu_quota) |
| 140 | |
| 141 | def test_create_server_when_memory_quota_is_full(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 142 | # Disallow server creation when tenant's memory quota is full |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 143 | resp, quota_set = self.client.get_quota_set(self.demo_tenant_id) |
| 144 | default_mem_quota = quota_set['ram'] |
| 145 | mem_quota = 0 # Set the quota to zero to conserve resources |
| 146 | |
| 147 | self.adm_client.update_quota_set(self.demo_tenant_id, |
| 148 | ram=mem_quota) |
| 149 | try: |
| 150 | self.create_server() |
| 151 | except exceptions.OverLimit: |
| 152 | pass |
| 153 | else: |
| 154 | self.fail("Could create servers over the memory quota limit") |
| 155 | finally: |
| 156 | self.adm_client.update_quota_set(self.demo_tenant_id, |
| 157 | ram=default_mem_quota) |