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 | |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 16 | from oslo_log import log as logging |
Matt Riedemann | 848805f | 2014-06-16 13:23:51 -0700 | [diff] [blame] | 17 | import six |
| 18 | from testtools import matchers |
| 19 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 20 | from tempest.api.compute import base |
Matt Riedemann | 848805f | 2014-06-16 13:23:51 -0700 | [diff] [blame] | 21 | from tempest.common import tempest_fixtures as fixtures |
Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [diff] [blame] | 22 | from tempest.common.utils import data_utils |
Haiwei Xu | c367d91 | 2014-01-14 19:51:10 +0900 | [diff] [blame] | 23 | from tempest import test |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 24 | |
Matt Riedemann | 848805f | 2014-06-16 13:23:51 -0700 | [diff] [blame] | 25 | LOG = logging.getLogger(__name__) |
| 26 | |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 27 | |
ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 28 | class QuotasAdminTestJSON(base.BaseV2ComputeAdminTest): |
Attila Fazekas | 430dae3 | 2013-10-17 15:19:32 +0200 | [diff] [blame] | 29 | force_tenant_isolation = True |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 30 | |
Matt Riedemann | 848805f | 2014-06-16 13:23:51 -0700 | [diff] [blame] | 31 | def setUp(self): |
| 32 | # NOTE(mriedem): Avoid conflicts with os-quota-class-sets tests. |
| 33 | self.useFixture(fixtures.LockFixture('compute_quotas')) |
| 34 | super(QuotasAdminTestJSON, self).setUp() |
| 35 | |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 36 | @classmethod |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 37 | def setup_clients(cls): |
| 38 | super(QuotasAdminTestJSON, cls).setup_clients() |
| 39 | cls.adm_client = cls.os_adm.quotas_client |
| 40 | |
| 41 | @classmethod |
Andrea Frittoli | 50bb80d | 2014-09-15 12:34:27 +0100 | [diff] [blame] | 42 | def resource_setup(cls): |
| 43 | super(QuotasAdminTestJSON, cls).resource_setup() |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 44 | |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 45 | # NOTE(afazekas): these test cases should always create and use a new |
Attila Fazekas | 4ba3658 | 2013-02-12 08:26:17 +0100 | [diff] [blame] | 46 | # tenant most of them should be skipped if we can't do that |
Andrea Frittoli | 9612e81 | 2014-03-13 10:57:26 +0000 | [diff] [blame] | 47 | cls.demo_tenant_id = cls.quotas_client.tenant_id |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 48 | |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 49 | cls.default_quota_set = set(('injected_file_content_bytes', |
| 50 | 'metadata_items', 'injected_files', |
| 51 | 'ram', 'floating_ips', |
| 52 | 'fixed_ips', 'key_pairs', |
| 53 | 'injected_file_path_bytes', |
| 54 | 'instances', 'security_group_rules', |
| 55 | 'cores', 'security_groups')) |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 56 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 57 | @test.idempotent_id('3b0a7c8f-cf58-46b8-a60c-715a32a8ba7d') |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 58 | def test_get_default_quotas(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 59 | # Admin can get the default resource quota set for a tenant |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 60 | expected_quota_set = self.default_quota_set | set(['id']) |
Ken'ichi Ohmichi | f9868fc | 2015-06-17 02:36:06 +0000 | [diff] [blame] | 61 | quota_set = self.adm_client.show_default_quota_set( |
ghanshyam | 5265787 | 2015-08-24 16:39:10 +0900 | [diff] [blame] | 62 | self.demo_tenant_id)['quota_set'] |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 63 | self.assertEqual(quota_set['id'], self.demo_tenant_id) |
Phil Day | 5f61539 | 2014-09-10 12:10:16 +0000 | [diff] [blame] | 64 | for quota in expected_quota_set: |
| 65 | self.assertIn(quota, quota_set.keys()) |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 66 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 67 | @test.idempotent_id('55fbe2bf-21a9-435b-bbd2-4162b0ed799a') |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 68 | def test_update_all_quota_resources_for_tenant(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 69 | # Admin can update all the resource quota limits for a tenant |
Ken'ichi Ohmichi | f9868fc | 2015-06-17 02:36:06 +0000 | [diff] [blame] | 70 | default_quota_set = self.adm_client.show_default_quota_set( |
ghanshyam | 5265787 | 2015-08-24 16:39:10 +0900 | [diff] [blame] | 71 | self.demo_tenant_id)['quota_set'] |
gengjh | 01ba9cc | 2013-06-15 10:14:48 +0800 | [diff] [blame] | 72 | new_quota_set = {'injected_file_content_bytes': 20480, |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 73 | 'metadata_items': 256, 'injected_files': 10, |
Michael Still | 9ac5bd0 | 2013-03-15 04:32:46 +1100 | [diff] [blame] | 74 | 'ram': 10240, 'floating_ips': 20, 'fixed_ips': 10, |
| 75 | 'key_pairs': 200, 'injected_file_path_bytes': 512, |
| 76 | 'instances': 20, 'security_group_rules': 20, |
| 77 | 'cores': 2, 'security_groups': 20} |
Matt Riedemann | bc8dbd3 | 2013-08-02 14:02:12 -0700 | [diff] [blame] | 78 | # Update limits for all quota resources |
David Kranz | 3e4c28b | 2015-02-09 12:35:18 -0500 | [diff] [blame] | 79 | quota_set = self.adm_client.update_quota_set( |
Matt Riedemann | bc8dbd3 | 2013-08-02 14:02:12 -0700 | [diff] [blame] | 80 | self.demo_tenant_id, |
gengjh | 01ba9cc | 2013-06-15 10:14:48 +0800 | [diff] [blame] | 81 | force=True, |
ghanshyam | 5265787 | 2015-08-24 16:39:10 +0900 | [diff] [blame] | 82 | **new_quota_set)['quota_set'] |
gengjh | 01ba9cc | 2013-06-15 10:14:48 +0800 | [diff] [blame] | 83 | |
| 84 | default_quota_set.pop('id') |
Phil Day | 5f61539 | 2014-09-10 12:10:16 +0000 | [diff] [blame] | 85 | # NOTE(PhilDay) The following is safe as we're not updating these |
| 86 | # two quota values yet. Once the Nova change to add these is merged |
| 87 | # and the client updated to support them this can be removed |
| 88 | if 'server_groups' in default_quota_set: |
| 89 | default_quota_set.pop('server_groups') |
| 90 | if 'server_group_members' in default_quota_set: |
| 91 | default_quota_set.pop('server_group_members') |
Matt Riedemann | bc8dbd3 | 2013-08-02 14:02:12 -0700 | [diff] [blame] | 92 | self.addCleanup(self.adm_client.update_quota_set, |
gengjh | 01ba9cc | 2013-06-15 10:14:48 +0800 | [diff] [blame] | 93 | self.demo_tenant_id, **default_quota_set) |
Phil Day | 5f61539 | 2014-09-10 12:10:16 +0000 | [diff] [blame] | 94 | for quota in new_quota_set: |
| 95 | self.assertIn(quota, quota_set.keys()) |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 96 | |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 97 | # TODO(afazekas): merge these test cases |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 98 | @test.idempotent_id('ce9e0815-8091-4abd-8345-7fe5b85faa1d') |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 99 | def test_get_updated_quotas(self): |
Jamie Lennox | 1535017 | 2015-08-17 10:54:25 +1000 | [diff] [blame] | 100 | # Verify that GET shows the updated quota set of project |
| 101 | project_name = data_utils.rand_name('cpu_quota_project') |
| 102 | project_desc = project_name + '-desc' |
| 103 | project = self.identity_utils.create_project(name=project_name, |
| 104 | description=project_desc) |
| 105 | project_id = project['id'] |
| 106 | self.addCleanup(self.identity_utils.delete_project, project_id) |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 107 | |
Jamie Lennox | 1535017 | 2015-08-17 10:54:25 +1000 | [diff] [blame] | 108 | self.adm_client.update_quota_set(project_id, ram='5120') |
| 109 | quota_set = self.adm_client.show_quota_set(project_id)['quota_set'] |
Zhi Kun Liu | 27e154f | 2014-03-24 03:51:12 -0500 | [diff] [blame] | 110 | self.assertEqual(5120, quota_set['ram']) |
| 111 | |
| 112 | # Verify that GET shows the updated quota set of user |
Ken'ichi Ohmichi | 4937f56 | 2015-03-23 00:15:01 +0000 | [diff] [blame] | 113 | user_name = data_utils.rand_name('cpu_quota_user') |
Zack Feldstein | d8c5f7a | 2015-12-14 10:44:07 -0600 | [diff] [blame] | 114 | password = data_utils.rand_password() |
Zhi Kun Liu | 27e154f | 2014-03-24 03:51:12 -0500 | [diff] [blame] | 115 | email = user_name + '@testmail.tm' |
Jamie Lennox | 1535017 | 2015-08-17 10:54:25 +1000 | [diff] [blame] | 116 | user = self.identity_utils.create_user(username=user_name, |
| 117 | password=password, |
| 118 | project=project, |
| 119 | email=email) |
Zhi Kun Liu | 27e154f | 2014-03-24 03:51:12 -0500 | [diff] [blame] | 120 | user_id = user['id'] |
Jamie Lennox | 1535017 | 2015-08-17 10:54:25 +1000 | [diff] [blame] | 121 | self.addCleanup(self.identity_utils.delete_user, user_id) |
Zhi Kun Liu | 27e154f | 2014-03-24 03:51:12 -0500 | [diff] [blame] | 122 | |
Jamie Lennox | 1535017 | 2015-08-17 10:54:25 +1000 | [diff] [blame] | 123 | self.adm_client.update_quota_set(project_id, |
Zhi Kun Liu | 27e154f | 2014-03-24 03:51:12 -0500 | [diff] [blame] | 124 | user_id=user_id, |
| 125 | ram='2048') |
ghanshyam | 5265787 | 2015-08-24 16:39:10 +0900 | [diff] [blame] | 126 | quota_set = self.adm_client.show_quota_set( |
Jamie Lennox | 1535017 | 2015-08-17 10:54:25 +1000 | [diff] [blame] | 127 | project_id, user_id=user_id)['quota_set'] |
Zhi Kun Liu | 27e154f | 2014-03-24 03:51:12 -0500 | [diff] [blame] | 128 | self.assertEqual(2048, quota_set['ram']) |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 129 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 130 | @test.idempotent_id('389d04f0-3a41-405f-9317-e5f86e3c44f0') |
Yuiko Takada | 2209cf5 | 2014-02-27 12:03:49 +0000 | [diff] [blame] | 131 | def test_delete_quota(self): |
Jamie Lennox | 1535017 | 2015-08-17 10:54:25 +1000 | [diff] [blame] | 132 | # Admin can delete the resource quota set for a project |
| 133 | project_name = data_utils.rand_name('ram_quota_project') |
| 134 | project_desc = project_name + '-desc' |
| 135 | project = self.identity_utils.create_project(name=project_name, |
| 136 | description=project_desc) |
| 137 | project_id = project['id'] |
| 138 | self.addCleanup(self.identity_utils.delete_project, project_id) |
| 139 | quota_set_default = (self.adm_client.show_quota_set(project_id) |
ghanshyam | 5265787 | 2015-08-24 16:39:10 +0900 | [diff] [blame] | 140 | ['quota_set']) |
Yuiko Takada | 2209cf5 | 2014-02-27 12:03:49 +0000 | [diff] [blame] | 141 | ram_default = quota_set_default['ram'] |
| 142 | |
Jamie Lennox | 1535017 | 2015-08-17 10:54:25 +1000 | [diff] [blame] | 143 | self.adm_client.update_quota_set(project_id, ram='5120') |
Yuiko Takada | 2209cf5 | 2014-02-27 12:03:49 +0000 | [diff] [blame] | 144 | |
Jamie Lennox | 1535017 | 2015-08-17 10:54:25 +1000 | [diff] [blame] | 145 | self.adm_client.delete_quota_set(project_id) |
Yuiko Takada | 2209cf5 | 2014-02-27 12:03:49 +0000 | [diff] [blame] | 146 | |
Jamie Lennox | 1535017 | 2015-08-17 10:54:25 +1000 | [diff] [blame] | 147 | quota_set_new = self.adm_client.show_quota_set(project_id)['quota_set'] |
Yuiko Takada | 2209cf5 | 2014-02-27 12:03:49 +0000 | [diff] [blame] | 148 | self.assertEqual(ram_default, quota_set_new['ram']) |
| 149 | |
rajalakshmi-ganesan | 1982c3c | 2013-01-10 14:56:45 +0530 | [diff] [blame] | 150 | |
Matt Riedemann | 848805f | 2014-06-16 13:23:51 -0700 | [diff] [blame] | 151 | class QuotaClassesAdminTestJSON(base.BaseV2ComputeAdminTest): |
Ken'ichi Ohmichi | 88363cb | 2015-11-19 08:00:54 +0000 | [diff] [blame] | 152 | """Tests the os-quota-class-sets API to update default quotas.""" |
Matt Riedemann | 848805f | 2014-06-16 13:23:51 -0700 | [diff] [blame] | 153 | |
| 154 | def setUp(self): |
| 155 | # All test cases in this class need to externally lock on doing |
| 156 | # anything with default quota values. |
| 157 | self.useFixture(fixtures.LockFixture('compute_quotas')) |
| 158 | super(QuotaClassesAdminTestJSON, self).setUp() |
| 159 | |
| 160 | @classmethod |
Andrea Frittoli | 50bb80d | 2014-09-15 12:34:27 +0100 | [diff] [blame] | 161 | def resource_setup(cls): |
| 162 | super(QuotaClassesAdminTestJSON, cls).resource_setup() |
Matt Riedemann | 848805f | 2014-06-16 13:23:51 -0700 | [diff] [blame] | 163 | cls.adm_client = cls.os_adm.quota_classes_client |
| 164 | |
| 165 | def _restore_default_quotas(self, original_defaults): |
| 166 | LOG.debug("restoring quota class defaults") |
David Kranz | 3e4c28b | 2015-02-09 12:35:18 -0500 | [diff] [blame] | 167 | self.adm_client.update_quota_class_set( |
ghanshyam | 5265787 | 2015-08-24 16:39:10 +0900 | [diff] [blame] | 168 | 'default', **original_defaults)['quota_class_set'] |
Matt Riedemann | 848805f | 2014-06-16 13:23:51 -0700 | [diff] [blame] | 169 | |
Sean Dague | e3e9da7 | 2014-07-09 07:11:59 -0400 | [diff] [blame] | 170 | # NOTE(sdague): this test is problematic as it changes |
| 171 | # global state, and possibly needs to be part of a set of |
| 172 | # tests that get run all by themselves at the end under a |
| 173 | # 'danger' flag. |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 174 | @test.idempotent_id('7932ab0f-5136-4075-b201-c0e2338df51a') |
Matt Riedemann | 848805f | 2014-06-16 13:23:51 -0700 | [diff] [blame] | 175 | def test_update_default_quotas(self): |
| 176 | LOG.debug("get the current 'default' quota class values") |
ghanshyam | 5265787 | 2015-08-24 16:39:10 +0900 | [diff] [blame] | 177 | body = (self.adm_client.show_quota_class_set('default') |
| 178 | ['quota_class_set']) |
Matt Riedemann | 848805f | 2014-06-16 13:23:51 -0700 | [diff] [blame] | 179 | self.assertIn('id', body) |
| 180 | self.assertEqual('default', body.pop('id')) |
| 181 | # restore the defaults when the test is done |
| 182 | self.addCleanup(self._restore_default_quotas, body.copy()) |
| 183 | # increment all of the values for updating the default quota class |
| 184 | for quota, default in six.iteritems(body): |
Sean Dague | e3e9da7 | 2014-07-09 07:11:59 -0400 | [diff] [blame] | 185 | # NOTE(sdague): we need to increment a lot, otherwise |
zhufl | 0892cb2 | 2016-05-06 14:46:00 +0800 | [diff] [blame] | 186 | # there is a real chance that we go from -1 (unlimited) |
Sean Dague | e3e9da7 | 2014-07-09 07:11:59 -0400 | [diff] [blame] | 187 | # to a very small number which causes issues. |
| 188 | body[quota] = default + 100 |
Matt Riedemann | 848805f | 2014-06-16 13:23:51 -0700 | [diff] [blame] | 189 | LOG.debug("update limits for the default quota class set") |
ghanshyam | 5265787 | 2015-08-24 16:39:10 +0900 | [diff] [blame] | 190 | update_body = self.adm_client.update_quota_class_set( |
| 191 | 'default', **body)['quota_class_set'] |
Matt Riedemann | 848805f | 2014-06-16 13:23:51 -0700 | [diff] [blame] | 192 | LOG.debug("assert that the response has all of the changed values") |
| 193 | self.assertThat(update_body.items(), |
| 194 | matchers.ContainsAll(body.items())) |