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 | |
| 15 | from tempest.api.volume import base |
nayna-patel | 3d59e4a | 2014-04-24 14:28:38 +0000 | [diff] [blame] | 16 | from tempest.common.utils import data_utils |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 17 | from tempest import test |
| 18 | |
| 19 | QUOTA_KEYS = ['gigabytes', 'snapshots', 'volumes'] |
| 20 | QUOTA_USAGE_KEYS = ['reserved', 'limit', 'in_use'] |
| 21 | |
| 22 | |
Chandan Kumar | dd23f63 | 2014-11-17 15:27:48 +0530 | [diff] [blame] | 23 | class BaseVolumeQuotasAdminV2TestJSON(base.BaseVolumeAdminTest): |
Matt Riedemann | 5349cfd | 2014-03-12 07:38:55 -0700 | [diff] [blame] | 24 | force_tenant_isolation = True |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 25 | |
| 26 | @classmethod |
Rohan Kanade | 0574915 | 2015-01-30 17:15:18 +0530 | [diff] [blame] | 27 | def setup_credentials(cls): |
| 28 | super(BaseVolumeQuotasAdminV2TestJSON, cls).setup_credentials() |
Andrea Frittoli | 86ad28d | 2014-03-20 10:09:12 +0000 | [diff] [blame] | 29 | cls.demo_tenant_id = cls.isolated_creds.get_primary_creds().tenant_id |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 30 | |
| 31 | @test.attr(type='gate') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 32 | @test.idempotent_id('59eada70-403c-4cef-a2a3-a8ce2f1b07a0') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 33 | def test_list_quotas(self): |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 34 | quotas = self.quotas_client.get_quota_set(self.demo_tenant_id) |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 35 | for key in QUOTA_KEYS: |
| 36 | self.assertIn(key, quotas) |
| 37 | |
| 38 | @test.attr(type='gate') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 39 | @test.idempotent_id('2be020a2-5fdd-423d-8d35-a7ffbc36e9f7') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 40 | def test_list_default_quotas(self): |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 41 | quotas = self.quotas_client.get_default_quota_set( |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 42 | self.demo_tenant_id) |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 43 | for key in QUOTA_KEYS: |
| 44 | self.assertIn(key, quotas) |
| 45 | |
| 46 | @test.attr(type='gate') |
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 |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 50 | default_quota_set = self.quotas_client.get_default_quota_set( |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 51 | self.demo_tenant_id) |
| 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, |
| 59 | **new_quota_set) |
| 60 | |
Cory Stone | 2cb1826 | 2014-03-19 14:14:03 -0500 | [diff] [blame] | 61 | cleanup_quota_set = dict( |
| 62 | (k, v) for k, v in default_quota_set.iteritems() |
| 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 | |
| 71 | @test.attr(type='gate') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 72 | @test.idempotent_id('18c51ae9-cb03-48fc-b234-14a19374dbed') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 73 | def test_show_quota_usage(self): |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 74 | quota_usage = self.quotas_client.get_quota_usage( |
Harshada Mangesh Kakad | 7519a52 | 2014-11-05 22:52:58 -0800 | [diff] [blame] | 75 | self.os_adm.credentials.tenant_id) |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 76 | for key in QUOTA_KEYS: |
| 77 | self.assertIn(key, quota_usage) |
| 78 | for usage_key in QUOTA_USAGE_KEYS: |
| 79 | self.assertIn(usage_key, quota_usage[key]) |
| 80 | |
| 81 | @test.attr(type='gate') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 82 | @test.idempotent_id('ae8b6091-48ad-4bfa-a188-bbf5cc02115f') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 83 | def test_quota_usage(self): |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 84 | quota_usage = self.quotas_client.get_quota_usage( |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 85 | self.demo_tenant_id) |
| 86 | |
Markus Zoeller | 3d2a21c | 2015-02-27 12:04:22 +0100 | [diff] [blame] | 87 | volume = self.create_volume() |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 88 | self.addCleanup(self.admin_volume_client.delete_volume, |
| 89 | volume['id']) |
| 90 | |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 91 | new_quota_usage = self.quotas_client.get_quota_usage( |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 92 | self.demo_tenant_id) |
| 93 | |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 94 | self.assertEqual(quota_usage['volumes']['in_use'] + 1, |
| 95 | new_quota_usage['volumes']['in_use']) |
| 96 | |
| 97 | self.assertEqual(quota_usage['gigabytes']['in_use'] + 1, |
| 98 | new_quota_usage['gigabytes']['in_use']) |
| 99 | |
nayna-patel | 3d59e4a | 2014-04-24 14:28:38 +0000 | [diff] [blame] | 100 | @test.attr(type='gate') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 101 | @test.idempotent_id('874b35a9-51f1-4258-bec5-cd561b6690d3') |
nayna-patel | 3d59e4a | 2014-04-24 14:28:38 +0000 | [diff] [blame] | 102 | def test_delete_quota(self): |
| 103 | # Admin can delete the resource quota set for a tenant |
| 104 | tenant_name = data_utils.rand_name('quota_tenant_') |
| 105 | identity_client = self.os_adm.identity_client |
David Kranz | b7afa92 | 2014-12-30 10:56:26 -0500 | [diff] [blame] | 106 | tenant = identity_client.create_tenant(tenant_name) |
nayna-patel | 3d59e4a | 2014-04-24 14:28:38 +0000 | [diff] [blame] | 107 | tenant_id = tenant['id'] |
| 108 | self.addCleanup(identity_client.delete_tenant, tenant_id) |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 109 | quota_set_default = self.quotas_client.get_default_quota_set( |
nayna-patel | 3d59e4a | 2014-04-24 14:28:38 +0000 | [diff] [blame] | 110 | tenant_id) |
| 111 | volume_default = quota_set_default['volumes'] |
| 112 | |
| 113 | self.quotas_client.update_quota_set(tenant_id, |
| 114 | volumes=(int(volume_default) + 5)) |
| 115 | |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 116 | self.quotas_client.delete_quota_set(tenant_id) |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 117 | quota_set_new = self.quotas_client.get_quota_set(tenant_id) |
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 |