blob: cd24d17b71eea059e3603597507c1eb0dae264e4 [file] [log] [blame]
Sylvain Baubeaufdd34592014-02-20 18:40:10 +01001# Copyright (C) 2014 eNovance SAS <licensing@enovance.com>
2#
Sylvain Baubeaufdd34592014-02-20 18:40:10 +01003# 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 Treinish71426682015-04-23 11:19:38 -040015import six
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010016from tempest.api.volume import base
Fei Long Wangd39431f2015-05-14 11:30:48 +120017from tempest.common.utils import data_utils
lkuchlan77c21af2016-04-20 11:31:14 +030018from tempest.common import waiters
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010019from tempest import test
20
21QUOTA_KEYS = ['gigabytes', 'snapshots', 'volumes']
22QUOTA_USAGE_KEYS = ['reserved', 'limit', 'in_use']
23
24
Chandan Kumardd23f632014-11-17 15:27:48 +053025class BaseVolumeQuotasAdminV2TestJSON(base.BaseVolumeAdminTest):
Matt Riedemann5349cfd2014-03-12 07:38:55 -070026 force_tenant_isolation = True
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010027
lkuchlan77c21af2016-04-20 11:31:14 +030028 credentials = ['primary', 'alt', 'admin']
29
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010030 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053031 def setup_credentials(cls):
32 super(BaseVolumeQuotasAdminV2TestJSON, cls).setup_credentials()
Andrea Frittolib21de6c2015-02-06 20:12:38 +000033 cls.demo_tenant_id = cls.os.credentials.tenant_id
lkuchlan77c21af2016-04-20 11:31:14 +030034 cls.alt_client = cls.os_alt.volumes_client
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010035
lkuchlan3f490082016-05-08 15:34:13 +030036 def _delete_volume(self, volume_id):
37 # Delete the specified volume using admin credentials
38 self.admin_volume_client.delete_volume(volume_id)
39 self.admin_volume_client.wait_for_resource_deletion(volume_id)
40
Chris Hoge7579c1a2015-02-26 14:12:15 -080041 @test.idempotent_id('59eada70-403c-4cef-a2a3-a8ce2f1b07a0')
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010042 def test_list_quotas(self):
bkopilov62d21752016-06-08 10:16:11 +030043 quotas = (self.admin_quotas_client.show_quota_set(self.demo_tenant_id)
ghanshyam08a73f92015-08-31 17:32:49 +090044 ['quota_set'])
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010045 for key in QUOTA_KEYS:
46 self.assertIn(key, quotas)
47
Chris Hoge7579c1a2015-02-26 14:12:15 -080048 @test.idempotent_id('2be020a2-5fdd-423d-8d35-a7ffbc36e9f7')
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010049 def test_list_default_quotas(self):
bkopilov62d21752016-06-08 10:16:11 +030050 quotas = self.admin_quotas_client.show_default_quota_set(
ghanshyam08a73f92015-08-31 17:32:49 +090051 self.demo_tenant_id)['quota_set']
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010052 for key in QUOTA_KEYS:
53 self.assertIn(key, quotas)
54
Chris Hoge7579c1a2015-02-26 14:12:15 -080055 @test.idempotent_id('3d45c99e-cc42-4424-a56e-5cbd212b63a6')
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010056 def test_update_all_quota_resources_for_tenant(self):
57 # Admin can update all the resource quota limits for a tenant
bkopilov62d21752016-06-08 10:16:11 +030058 default_quota_set = self.admin_quotas_client.show_default_quota_set(
ghanshyam08a73f92015-08-31 17:32:49 +090059 self.demo_tenant_id)['quota_set']
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010060 new_quota_set = {'gigabytes': 1009,
61 'volumes': 11,
62 'snapshots': 11}
63
64 # Update limits for all quota resources
bkopilov62d21752016-06-08 10:16:11 +030065 quota_set = self.admin_quotas_client.update_quota_set(
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010066 self.demo_tenant_id,
ghanshyam08a73f92015-08-31 17:32:49 +090067 **new_quota_set)['quota_set']
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010068
Cory Stone2cb18262014-03-19 14:14:03 -050069 cleanup_quota_set = dict(
Matthew Treinish71426682015-04-23 11:19:38 -040070 (k, v) for k, v in six.iteritems(default_quota_set)
Cory Stone2cb18262014-03-19 14:14:03 -050071 if k in QUOTA_KEYS)
bkopilov62d21752016-06-08 10:16:11 +030072 self.addCleanup(self.admin_quotas_client.update_quota_set,
Cory Stone2cb18262014-03-19 14:14:03 -050073 self.demo_tenant_id, **cleanup_quota_set)
Sean Dague27a8c562014-03-19 07:46:42 -040074 # test that the specific values we set are actually in
75 # the final result. There is nothing here that ensures there
76 # would be no other values in there.
77 self.assertDictContainsSubset(new_quota_set, quota_set)
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010078
Chris Hoge7579c1a2015-02-26 14:12:15 -080079 @test.idempotent_id('18c51ae9-cb03-48fc-b234-14a19374dbed')
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010080 def test_show_quota_usage(self):
bkopilov62d21752016-06-08 10:16:11 +030081 quota_usage = self.admin_quotas_client.show_quota_usage(
ghanshyam08a73f92015-08-31 17:32:49 +090082 self.os_adm.credentials.tenant_id)['quota_set']
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010083 for key in QUOTA_KEYS:
84 self.assertIn(key, quota_usage)
85 for usage_key in QUOTA_USAGE_KEYS:
86 self.assertIn(usage_key, quota_usage[key])
87
Chris Hoge7579c1a2015-02-26 14:12:15 -080088 @test.idempotent_id('ae8b6091-48ad-4bfa-a188-bbf5cc02115f')
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010089 def test_quota_usage(self):
bkopilov62d21752016-06-08 10:16:11 +030090 quota_usage = self.admin_quotas_client.show_quota_usage(
ghanshyam08a73f92015-08-31 17:32:49 +090091 self.demo_tenant_id)['quota_set']
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010092
Markus Zoeller3d2a21c2015-02-27 12:04:22 +010093 volume = self.create_volume()
lkuchlan3f490082016-05-08 15:34:13 +030094 self.addCleanup(self._delete_volume, volume['id'])
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010095
bkopilov62d21752016-06-08 10:16:11 +030096 new_quota_usage = self.admin_quotas_client.show_quota_usage(
ghanshyam08a73f92015-08-31 17:32:49 +090097 self.demo_tenant_id)['quota_set']
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010098
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010099 self.assertEqual(quota_usage['volumes']['in_use'] + 1,
100 new_quota_usage['volumes']['in_use'])
101
Markus Zoeller56cb97c2015-03-10 16:06:34 +0100102 self.assertEqual(quota_usage['gigabytes']['in_use'] +
103 volume["size"],
Sylvain Baubeaufdd34592014-02-20 18:40:10 +0100104 new_quota_usage['gigabytes']['in_use'])
105
Chris Hoge7579c1a2015-02-26 14:12:15 -0800106 @test.idempotent_id('874b35a9-51f1-4258-bec5-cd561b6690d3')
nayna-patel3d59e4a2014-04-24 14:28:38 +0000107 def test_delete_quota(self):
Jamie Lennox15350172015-08-17 10:54:25 +1000108 # Admin can delete the resource quota set for a project
109 project_name = data_utils.rand_name('quota_tenant')
110 description = data_utils.rand_name('desc_')
111 project = self.identity_utils.create_project(project_name,
112 description=description)
113 project_id = project['id']
114 self.addCleanup(self.identity_utils.delete_project, project_id)
bkopilov62d21752016-06-08 10:16:11 +0300115 quota_set_default = self.admin_quotas_client.show_default_quota_set(
Jamie Lennox15350172015-08-17 10:54:25 +1000116 project_id)['quota_set']
nayna-patel3d59e4a2014-04-24 14:28:38 +0000117 volume_default = quota_set_default['volumes']
118
bkopilov62d21752016-06-08 10:16:11 +0300119 self.admin_quotas_client.update_quota_set(
120 project_id, volumes=(int(volume_default) + 5))
nayna-patel3d59e4a2014-04-24 14:28:38 +0000121
bkopilov62d21752016-06-08 10:16:11 +0300122 self.admin_quotas_client.delete_quota_set(project_id)
123 quota_set_new = (self.admin_quotas_client.show_quota_set(project_id)
ghanshyam08a73f92015-08-31 17:32:49 +0900124 ['quota_set'])
nayna-patel3d59e4a2014-04-24 14:28:38 +0000125 self.assertEqual(volume_default, quota_set_new['volumes'])
Chandan Kumardd23f632014-11-17 15:27:48 +0530126
lkuchlan77c21af2016-04-20 11:31:14 +0300127 @test.idempotent_id('8911036f-9d54-4720-80cc-a1c9796a8805')
128 def test_quota_usage_after_volume_transfer(self):
129 # Create a volume for transfer
130 volume = self.create_volume()
131 self.addCleanup(self._delete_volume, volume['id'])
132
133 # List of tenants quota usage pre-transfer
134 primary_quota = self.admin_quotas_client.show_quota_usage(
135 self.demo_tenant_id)['quota_set']
136
137 alt_quota = self.admin_quotas_client.show_quota_usage(
138 self.alt_client.tenant_id)['quota_set']
139
140 # Creates a volume transfer
141 transfer = self.volumes_client.create_volume_transfer(
142 volume_id=volume['id'])['transfer']
143 transfer_id = transfer['id']
144 auth_key = transfer['auth_key']
145
146 # Accepts a volume transfer
147 self.alt_client.accept_volume_transfer(
148 transfer_id, auth_key=auth_key)['transfer']
149
150 # Verify volume transferred is available
151 waiters.wait_for_volume_status(
152 self.alt_client, volume['id'], 'available')
153
154 # List of tenants quota usage post transfer
155 new_primary_quota = self.admin_quotas_client.show_quota_usage(
156 self.demo_tenant_id)['quota_set']
157
158 new_alt_quota = self.admin_quotas_client.show_quota_usage(
159 self.alt_client.tenant_id)['quota_set']
160
161 # Verify tenants quota usage was updated
162 self.assertEqual(primary_quota['volumes']['in_use'] -
163 new_primary_quota['volumes']['in_use'],
164 new_alt_quota['volumes']['in_use'] -
165 alt_quota['volumes']['in_use'])
166
167 self.assertEqual(alt_quota['gigabytes']['in_use'] +
168 volume['size'],
169 new_alt_quota['gigabytes']['in_use'])
170
171 self.assertEqual(primary_quota['gigabytes']['in_use'] -
172 volume['size'],
173 new_primary_quota['gigabytes']['in_use'])
174
Chandan Kumardd23f632014-11-17 15:27:48 +0530175
176class VolumeQuotasAdminV1TestJSON(BaseVolumeQuotasAdminV2TestJSON):
177 _api_version = 1