Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 1 | # Copyright (C) 2014 eNovance SAS <licensing@enovance.com> |
| 2 | # |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
Matthew Treinish | 7142668 | 2015-04-23 11:19:38 -0400 | [diff] [blame] | 15 | import six |
Matthew Treinish | 01472ff | 2015-02-20 17:26:52 -0500 | [diff] [blame] | 16 | |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 17 | from tempest.api.volume import base |
Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [diff] [blame] | 18 | from tempest.common.utils import data_utils |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 19 | from tempest import test |
| 20 | |
| 21 | QUOTA_KEYS = ['gigabytes', 'snapshots', 'volumes'] |
| 22 | QUOTA_USAGE_KEYS = ['reserved', 'limit', 'in_use'] |
| 23 | |
| 24 | |
Chandan Kumar | dd23f63 | 2014-11-17 15:27:48 +0530 | [diff] [blame] | 25 | class BaseVolumeQuotasAdminV2TestJSON(base.BaseVolumeAdminTest): |
Matt Riedemann | 5349cfd | 2014-03-12 07:38:55 -0700 | [diff] [blame] | 26 | force_tenant_isolation = True |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 27 | |
| 28 | @classmethod |
Rohan Kanade | 0574915 | 2015-01-30 17:15:18 +0530 | [diff] [blame] | 29 | def setup_credentials(cls): |
| 30 | super(BaseVolumeQuotasAdminV2TestJSON, cls).setup_credentials() |
Andrea Frittoli | b21de6c | 2015-02-06 20:12:38 +0000 | [diff] [blame] | 31 | cls.demo_tenant_id = cls.os.credentials.tenant_id |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 32 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 33 | @test.idempotent_id('59eada70-403c-4cef-a2a3-a8ce2f1b07a0') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 34 | def test_list_quotas(self): |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 35 | quotas = (self.quotas_client.show_quota_set(self.demo_tenant_id) |
| 36 | ['quota_set']) |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 37 | for key in QUOTA_KEYS: |
| 38 | self.assertIn(key, quotas) |
| 39 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 40 | @test.idempotent_id('2be020a2-5fdd-423d-8d35-a7ffbc36e9f7') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 41 | def test_list_default_quotas(self): |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 42 | quotas = self.quotas_client.show_default_quota_set( |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 43 | self.demo_tenant_id)['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 44 | for key in QUOTA_KEYS: |
| 45 | self.assertIn(key, quotas) |
| 46 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 47 | @test.idempotent_id('3d45c99e-cc42-4424-a56e-5cbd212b63a6') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 48 | def test_update_all_quota_resources_for_tenant(self): |
| 49 | # Admin can update all the resource quota limits for a tenant |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 50 | default_quota_set = self.quotas_client.show_default_quota_set( |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 51 | self.demo_tenant_id)['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 52 | new_quota_set = {'gigabytes': 1009, |
| 53 | 'volumes': 11, |
| 54 | 'snapshots': 11} |
| 55 | |
| 56 | # Update limits for all quota resources |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 57 | quota_set = self.quotas_client.update_quota_set( |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 58 | self.demo_tenant_id, |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 59 | **new_quota_set)['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 60 | |
Cory Stone | 2cb1826 | 2014-03-19 14:14:03 -0500 | [diff] [blame] | 61 | cleanup_quota_set = dict( |
Matthew Treinish | 7142668 | 2015-04-23 11:19:38 -0400 | [diff] [blame] | 62 | (k, v) for k, v in six.iteritems(default_quota_set) |
Cory Stone | 2cb1826 | 2014-03-19 14:14:03 -0500 | [diff] [blame] | 63 | if k in QUOTA_KEYS) |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 64 | self.addCleanup(self.quotas_client.update_quota_set, |
Cory Stone | 2cb1826 | 2014-03-19 14:14:03 -0500 | [diff] [blame] | 65 | self.demo_tenant_id, **cleanup_quota_set) |
Sean Dague | 27a8c56 | 2014-03-19 07:46:42 -0400 | [diff] [blame] | 66 | # test that the specific values we set are actually in |
| 67 | # the final result. There is nothing here that ensures there |
| 68 | # would be no other values in there. |
| 69 | self.assertDictContainsSubset(new_quota_set, quota_set) |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 70 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 71 | @test.idempotent_id('18c51ae9-cb03-48fc-b234-14a19374dbed') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 72 | def test_show_quota_usage(self): |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 73 | quota_usage = self.quotas_client.show_quota_usage( |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 74 | self.os_adm.credentials.tenant_id)['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 75 | for key in QUOTA_KEYS: |
| 76 | self.assertIn(key, quota_usage) |
| 77 | for usage_key in QUOTA_USAGE_KEYS: |
| 78 | self.assertIn(usage_key, quota_usage[key]) |
| 79 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 80 | @test.idempotent_id('ae8b6091-48ad-4bfa-a188-bbf5cc02115f') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 81 | def test_quota_usage(self): |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 82 | quota_usage = self.quotas_client.show_quota_usage( |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 83 | self.demo_tenant_id)['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 84 | |
Markus Zoeller | 3d2a21c | 2015-02-27 12:04:22 +0100 | [diff] [blame] | 85 | volume = self.create_volume() |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 86 | self.addCleanup(self.admin_volume_client.delete_volume, |
| 87 | volume['id']) |
| 88 | |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 89 | new_quota_usage = self.quotas_client.show_quota_usage( |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 90 | self.demo_tenant_id)['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 91 | |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 92 | self.assertEqual(quota_usage['volumes']['in_use'] + 1, |
| 93 | new_quota_usage['volumes']['in_use']) |
| 94 | |
Markus Zoeller | 56cb97c | 2015-03-10 16:06:34 +0100 | [diff] [blame] | 95 | self.assertEqual(quota_usage['gigabytes']['in_use'] + |
| 96 | volume["size"], |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 97 | new_quota_usage['gigabytes']['in_use']) |
| 98 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 99 | @test.idempotent_id('874b35a9-51f1-4258-bec5-cd561b6690d3') |
nayna-patel | 3d59e4a | 2014-04-24 14:28:38 +0000 | [diff] [blame] | 100 | def test_delete_quota(self): |
Jamie Lennox | 1535017 | 2015-08-17 10:54:25 +1000 | [diff] [blame^] | 101 | # Admin can delete the resource quota set for a project |
| 102 | project_name = data_utils.rand_name('quota_tenant') |
| 103 | description = data_utils.rand_name('desc_') |
| 104 | project = self.identity_utils.create_project(project_name, |
| 105 | description=description) |
| 106 | project_id = project['id'] |
| 107 | self.addCleanup(self.identity_utils.delete_project, project_id) |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 108 | quota_set_default = self.quotas_client.show_default_quota_set( |
Jamie Lennox | 1535017 | 2015-08-17 10:54:25 +1000 | [diff] [blame^] | 109 | project_id)['quota_set'] |
nayna-patel | 3d59e4a | 2014-04-24 14:28:38 +0000 | [diff] [blame] | 110 | volume_default = quota_set_default['volumes'] |
| 111 | |
Jamie Lennox | 1535017 | 2015-08-17 10:54:25 +1000 | [diff] [blame^] | 112 | self.quotas_client.update_quota_set(project_id, |
nayna-patel | 3d59e4a | 2014-04-24 14:28:38 +0000 | [diff] [blame] | 113 | volumes=(int(volume_default) + 5)) |
| 114 | |
Jamie Lennox | 1535017 | 2015-08-17 10:54:25 +1000 | [diff] [blame^] | 115 | self.quotas_client.delete_quota_set(project_id) |
| 116 | quota_set_new = (self.quotas_client.show_quota_set(project_id) |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 117 | ['quota_set']) |
nayna-patel | 3d59e4a | 2014-04-24 14:28:38 +0000 | [diff] [blame] | 118 | self.assertEqual(volume_default, quota_set_new['volumes']) |
Chandan Kumar | dd23f63 | 2014-11-17 15:27:48 +0530 | [diff] [blame] | 119 | |
| 120 | |
| 121 | class VolumeQuotasAdminV1TestJSON(BaseVolumeQuotasAdminV2TestJSON): |
| 122 | _api_version = 1 |