ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 16 | from tempest.api.compute import base |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 17 | from tempest.common.utils import data_utils |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 18 | from tempest import test |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 19 | |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 20 | |
ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 21 | class QuotasAdminTestJSON(base.BaseV2ComputeAdminTest): |
Attila Fazekas | 430dae3 | 2013-10-17 15:19:32 +0200 | [diff] [blame] | 22 | force_tenant_isolation = True |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 23 | |
| 24 | @classmethod |
| 25 | def setUpClass(cls): |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 26 | super(QuotasAdminTestJSON, cls).setUpClass() |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 27 | cls.adm_client = cls.os_adm.quotas_client |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 28 | |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 29 | # NOTE(afazekas): these test cases should always create and use a new |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 30 | # 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] | 31 | cls.demo_tenant_id = cls.isolated_creds.get_primary_user().get( |
| 32 | 'tenantId') |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 33 | |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 34 | cls.default_quota_set = set(('injected_file_content_bytes', |
| 35 | 'metadata_items', 'injected_files', |
| 36 | 'ram', 'floating_ips', |
| 37 | 'fixed_ips', 'key_pairs', |
| 38 | 'injected_file_path_bytes', |
| 39 | 'instances', 'security_group_rules', |
| 40 | 'cores', 'security_groups')) |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 41 | |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 42 | @test.attr(type='smoke') |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 43 | def test_get_default_quotas(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 44 | # Admin can get the default resource quota set for a tenant |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 45 | expected_quota_set = self.default_quota_set | set(['id']) |
Zhi Kun Liu | 50eb71c | 2014-02-19 15:08:45 +0800 | [diff] [blame] | 46 | resp, quota_set = self.adm_client.get_default_quota_set( |
Leo Toyoda | 87a52b7 | 2013-04-09 10:34:40 +0900 | [diff] [blame] | 47 | self.demo_tenant_id) |
| 48 | self.assertEqual(200, resp.status) |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 49 | self.assertEqual(sorted(expected_quota_set), |
| 50 | sorted(quota_set.keys())) |
| 51 | self.assertEqual(quota_set['id'], self.demo_tenant_id) |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 52 | |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 53 | @test.attr(type='gate') |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 54 | def test_update_all_quota_resources_for_tenant(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 55 | # Admin can update all the resource quota limits for a tenant |
Zhi Kun Liu | 50eb71c | 2014-02-19 15:08:45 +0800 | [diff] [blame] | 56 | resp, default_quota_set = self.adm_client.get_default_quota_set( |
gengjh | 01ba9cc | 2013-06-15 10:14:48 +0800 | [diff] [blame] | 57 | self.demo_tenant_id) |
| 58 | new_quota_set = {'injected_file_content_bytes': 20480, |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 59 | 'metadata_items': 256, 'injected_files': 10, |
Michael Still | 9ac5bd0 | 2013-03-15 04:32:46 +1100 | [diff] [blame] | 60 | 'ram': 10240, 'floating_ips': 20, 'fixed_ips': 10, |
| 61 | 'key_pairs': 200, 'injected_file_path_bytes': 512, |
| 62 | 'instances': 20, 'security_group_rules': 20, |
| 63 | 'cores': 2, 'security_groups': 20} |
Matt Riedemann | bc8dbd3 | 2013-08-02 14:02:12 -0700 | [diff] [blame] | 64 | # Update limits for all quota resources |
| 65 | resp, quota_set = self.adm_client.update_quota_set( |
| 66 | self.demo_tenant_id, |
gengjh | 01ba9cc | 2013-06-15 10:14:48 +0800 | [diff] [blame] | 67 | force=True, |
Matt Riedemann | bc8dbd3 | 2013-08-02 14:02:12 -0700 | [diff] [blame] | 68 | **new_quota_set) |
gengjh | 01ba9cc | 2013-06-15 10:14:48 +0800 | [diff] [blame] | 69 | |
| 70 | default_quota_set.pop('id') |
Matt Riedemann | bc8dbd3 | 2013-08-02 14:02:12 -0700 | [diff] [blame] | 71 | self.addCleanup(self.adm_client.update_quota_set, |
gengjh | 01ba9cc | 2013-06-15 10:14:48 +0800 | [diff] [blame] | 72 | self.demo_tenant_id, **default_quota_set) |
Matt Riedemann | bc8dbd3 | 2013-08-02 14:02:12 -0700 | [diff] [blame] | 73 | self.assertEqual(200, resp.status) |
| 74 | self.assertEqual(new_quota_set, quota_set) |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 75 | |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 76 | # TODO(afazekas): merge these test cases |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 77 | @test.attr(type='gate') |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 78 | def test_get_updated_quotas(self): |
Zhi Kun Liu | 27e154f | 2014-03-24 03:51:12 -0500 | [diff] [blame] | 79 | # Verify that GET shows the updated quota set of tenant |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 80 | tenant_name = data_utils.rand_name('cpu_quota_tenant_') |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 81 | tenant_desc = tenant_name + '-desc' |
| 82 | identity_client = self.os_adm.identity_client |
| 83 | _, tenant = identity_client.create_tenant(name=tenant_name, |
| 84 | description=tenant_desc) |
| 85 | tenant_id = tenant['id'] |
Zhi Kun Liu | 27e154f | 2014-03-24 03:51:12 -0500 | [diff] [blame] | 86 | self.addCleanup(identity_client.delete_tenant, tenant_id) |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 87 | |
Zhi Kun Liu | 27e154f | 2014-03-24 03:51:12 -0500 | [diff] [blame] | 88 | self.adm_client.update_quota_set(tenant_id, ram='5120') |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 89 | resp, quota_set = self.adm_client.get_quota_set(tenant_id) |
| 90 | self.assertEqual(200, resp.status) |
Zhi Kun Liu | 27e154f | 2014-03-24 03:51:12 -0500 | [diff] [blame] | 91 | self.assertEqual(5120, quota_set['ram']) |
| 92 | |
| 93 | # Verify that GET shows the updated quota set of user |
| 94 | user_name = data_utils.rand_name('cpu_quota_user_') |
| 95 | password = data_utils.rand_name('password-') |
| 96 | email = user_name + '@testmail.tm' |
| 97 | _, user = identity_client.create_user(name=user_name, |
| 98 | password=password, |
| 99 | tenant_id=tenant_id, |
| 100 | email=email) |
| 101 | user_id = user['id'] |
| 102 | self.addCleanup(identity_client.delete_user, user_id) |
| 103 | |
| 104 | self.adm_client.update_quota_set(tenant_id, |
| 105 | user_id=user_id, |
| 106 | ram='2048') |
| 107 | resp, quota_set = self.adm_client.get_quota_set(tenant_id, |
| 108 | user_id=user_id) |
| 109 | self.assertEqual(200, resp.status) |
| 110 | self.assertEqual(2048, quota_set['ram']) |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 111 | |
Yuiko Takada | 2209cf5 | 2014-02-27 12:03:49 +0000 | [diff] [blame] | 112 | @test.attr(type='gate') |
| 113 | def test_delete_quota(self): |
| 114 | # Admin can delete the resource quota set for a tenant |
| 115 | tenant_name = data_utils.rand_name('ram_quota_tenant_') |
| 116 | tenant_desc = tenant_name + '-desc' |
| 117 | identity_client = self.os_adm.identity_client |
| 118 | _, tenant = identity_client.create_tenant(name=tenant_name, |
| 119 | description=tenant_desc) |
| 120 | tenant_id = tenant['id'] |
| 121 | self.addCleanup(identity_client.delete_tenant, tenant_id) |
| 122 | resp, quota_set_default = self.adm_client.get_quota_set(tenant_id) |
| 123 | ram_default = quota_set_default['ram'] |
| 124 | |
| 125 | resp, body = self.adm_client.update_quota_set(tenant_id, ram='5120') |
| 126 | self.assertEqual(200, resp.status) |
| 127 | |
| 128 | resp, body = self.adm_client.delete_quota_set(tenant_id) |
| 129 | self.assertEqual(202, resp.status) |
| 130 | |
| 131 | resp, quota_set_new = self.adm_client.get_quota_set(tenant_id) |
| 132 | self.assertEqual(200, resp.status) |
| 133 | self.assertEqual(ram_default, quota_set_new['ram']) |
| 134 | |
rajalakshmi-ganesan | 1982c3c | 2013-01-10 14:56:45 +0530 | [diff] [blame] | 135 | |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 136 | class QuotasAdminTestXML(QuotasAdminTestJSON): |
| 137 | _interface = 'xml' |