Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 1 | # Copyright (C) 2014 eNovance SAS <licensing@enovance.com> |
| 2 | # |
| 3 | # Author: Sylvain Baubeau <sylvain.baubeau@enovance.com> |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
| 17 | from tempest.api.volume import base |
nayna-patel | 3d59e4a | 2014-04-24 14:28:38 +0000 | [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): |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 26 | _interface = "json" |
Matt Riedemann | 5349cfd | 2014-03-12 07:38:55 -0700 | [diff] [blame] | 27 | force_tenant_isolation = True |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 28 | |
| 29 | @classmethod |
Andrea Frittoli | 61a12e2 | 2014-09-15 13:14:54 +0100 | [diff] [blame] | 30 | def resource_setup(cls): |
Chandan Kumar | dd23f63 | 2014-11-17 15:27:48 +0530 | [diff] [blame] | 31 | super(BaseVolumeQuotasAdminV2TestJSON, cls).resource_setup() |
Andrea Frittoli | 86ad28d | 2014-03-20 10:09:12 +0000 | [diff] [blame] | 32 | cls.demo_tenant_id = cls.isolated_creds.get_primary_creds().tenant_id |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 33 | |
| 34 | @test.attr(type='gate') |
| 35 | def test_list_quotas(self): |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 36 | quotas = self.quotas_client.get_quota_set(self.demo_tenant_id) |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 37 | for key in QUOTA_KEYS: |
| 38 | self.assertIn(key, quotas) |
| 39 | |
| 40 | @test.attr(type='gate') |
| 41 | def test_list_default_quotas(self): |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 42 | quotas = self.quotas_client.get_default_quota_set( |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 43 | self.demo_tenant_id) |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 44 | for key in QUOTA_KEYS: |
| 45 | self.assertIn(key, quotas) |
| 46 | |
| 47 | @test.attr(type='gate') |
| 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') |
| 72 | def test_show_quota_usage(self): |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 73 | quota_usage = self.quotas_client.get_quota_usage( |
Harshada Mangesh Kakad | 7519a52 | 2014-11-05 22:52:58 -0800 | [diff] [blame] | 74 | self.os_adm.credentials.tenant_id) |
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 | |
| 80 | @test.attr(type='gate') |
| 81 | def test_quota_usage(self): |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 82 | quota_usage = self.quotas_client.get_quota_usage( |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 83 | self.demo_tenant_id) |
| 84 | |
| 85 | volume = self.create_volume(size=1) |
| 86 | self.addCleanup(self.admin_volume_client.delete_volume, |
| 87 | volume['id']) |
| 88 | |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 89 | new_quota_usage = self.quotas_client.get_quota_usage( |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 90 | self.demo_tenant_id) |
| 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 | |
| 95 | self.assertEqual(quota_usage['gigabytes']['in_use'] + 1, |
| 96 | new_quota_usage['gigabytes']['in_use']) |
| 97 | |
nayna-patel | 3d59e4a | 2014-04-24 14:28:38 +0000 | [diff] [blame] | 98 | @test.attr(type='gate') |
| 99 | def test_delete_quota(self): |
| 100 | # Admin can delete the resource quota set for a tenant |
| 101 | tenant_name = data_utils.rand_name('quota_tenant_') |
| 102 | identity_client = self.os_adm.identity_client |
David Kranz | b7afa92 | 2014-12-30 10:56:26 -0500 | [diff] [blame] | 103 | tenant = identity_client.create_tenant(tenant_name) |
nayna-patel | 3d59e4a | 2014-04-24 14:28:38 +0000 | [diff] [blame] | 104 | tenant_id = tenant['id'] |
| 105 | self.addCleanup(identity_client.delete_tenant, tenant_id) |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 106 | quota_set_default = self.quotas_client.get_default_quota_set( |
nayna-patel | 3d59e4a | 2014-04-24 14:28:38 +0000 | [diff] [blame] | 107 | tenant_id) |
| 108 | volume_default = quota_set_default['volumes'] |
| 109 | |
| 110 | self.quotas_client.update_quota_set(tenant_id, |
| 111 | volumes=(int(volume_default) + 5)) |
| 112 | |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 113 | self.quotas_client.delete_quota_set(tenant_id) |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 114 | quota_set_new = self.quotas_client.get_quota_set(tenant_id) |
nayna-patel | 3d59e4a | 2014-04-24 14:28:38 +0000 | [diff] [blame] | 115 | self.assertEqual(volume_default, quota_set_new['volumes']) |
Chandan Kumar | dd23f63 | 2014-11-17 15:27:48 +0530 | [diff] [blame] | 116 | |
| 117 | |
| 118 | class VolumeQuotasAdminV1TestJSON(BaseVolumeQuotasAdminV2TestJSON): |
| 119 | _api_version = 1 |