blob: 6f9daa8f0e25676d418e2c0144fb6dcf2d6fe1ea [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
15from tempest.api.volume import base
Andrea Frittolie1ed6952017-09-14 06:31:52 -060016from tempest.common import identity
jeremy.zhang644b01d2017-04-13 12:59:49 +080017from tempest.common import tempest_fixtures as fixtures
lkuchlan77c21af2016-04-20 11:31:14 +030018from tempest.common import waiters
Ken'ichi Ohmichief1c1ce2017-03-10 11:07:10 -080019from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080020from tempest.lib import decorators
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010021
lkuchlanf31310f2017-06-11 16:00:09 +030022QUOTA_KEYS = ['gigabytes', 'snapshots', 'volumes', 'backups',
23 'backup_gigabytes', 'per_volume_gigabytes']
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010024QUOTA_USAGE_KEYS = ['reserved', 'limit', 'in_use']
25
26
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070027class BaseVolumeQuotasAdminTestJSON(base.BaseVolumeAdminTest):
Matt Riedemann5349cfd2014-03-12 07:38:55 -070028 force_tenant_isolation = True
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010029
lkuchlan77c21af2016-04-20 11:31:14 +030030 credentials = ['primary', 'alt', 'admin']
31
jeremy.zhang644b01d2017-04-13 12:59:49 +080032 def setUp(self):
33 # NOTE(jeremy.zhang): Avoid conflicts with volume quota class tests.
34 self.useFixture(fixtures.LockFixture('volume_quotas'))
35 super(BaseVolumeQuotasAdminTestJSON, self).setUp()
36
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010037 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053038 def setup_credentials(cls):
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070039 super(BaseVolumeQuotasAdminTestJSON, cls).setup_credentials()
Jordan Pittier8160d312017-04-18 11:52:23 +020040 cls.demo_tenant_id = cls.os_primary.credentials.tenant_id
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010041
ghanshyam59614b42017-02-24 16:32:02 +000042 @classmethod
43 def setup_clients(cls):
44 super(BaseVolumeQuotasAdminTestJSON, cls).setup_clients()
Jordan Pittier8160d312017-04-18 11:52:23 +020045 cls.transfer_client = cls.os_primary.volume_transfers_v2_client
ghanshyam59614b42017-02-24 16:32:02 +000046 cls.alt_transfer_client = cls.os_alt.volume_transfers_v2_client
47
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080048 @decorators.idempotent_id('59eada70-403c-4cef-a2a3-a8ce2f1b07a0')
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010049 def test_list_quotas(self):
bkopilov62d21752016-06-08 10:16:11 +030050 quotas = (self.admin_quotas_client.show_quota_set(self.demo_tenant_id)
ghanshyam08a73f92015-08-31 17:32:49 +090051 ['quota_set'])
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010052 for key in QUOTA_KEYS:
53 self.assertIn(key, quotas)
54
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080055 @decorators.idempotent_id('2be020a2-5fdd-423d-8d35-a7ffbc36e9f7')
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010056 def test_list_default_quotas(self):
bkopilov62d21752016-06-08 10:16:11 +030057 quotas = self.admin_quotas_client.show_default_quota_set(
ghanshyam08a73f92015-08-31 17:32:49 +090058 self.demo_tenant_id)['quota_set']
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010059 for key in QUOTA_KEYS:
60 self.assertIn(key, quotas)
61
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080062 @decorators.idempotent_id('3d45c99e-cc42-4424-a56e-5cbd212b63a6')
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010063 def test_update_all_quota_resources_for_tenant(self):
64 # Admin can update all the resource quota limits for a tenant
bkopilov62d21752016-06-08 10:16:11 +030065 default_quota_set = self.admin_quotas_client.show_default_quota_set(
ghanshyam08a73f92015-08-31 17:32:49 +090066 self.demo_tenant_id)['quota_set']
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010067 new_quota_set = {'gigabytes': 1009,
68 'volumes': 11,
lkuchlan070204b2016-08-29 14:48:53 +030069 'snapshots': 11,
lkuchlanf31310f2017-06-11 16:00:09 +030070 'backups': 11,
71 'backup_gigabytes': 1009,
72 'per_volume_gigabytes': 1009}
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010073
74 # Update limits for all quota resources
bkopilov62d21752016-06-08 10:16:11 +030075 quota_set = self.admin_quotas_client.update_quota_set(
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010076 self.demo_tenant_id,
ghanshyam08a73f92015-08-31 17:32:49 +090077 **new_quota_set)['quota_set']
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010078
Cory Stone2cb18262014-03-19 14:14:03 -050079 cleanup_quota_set = dict(
guo yunxian7bbbec12016-08-21 20:03:10 +080080 (k, v) for k, v in default_quota_set.items()
Cory Stone2cb18262014-03-19 14:14:03 -050081 if k in QUOTA_KEYS)
bkopilov62d21752016-06-08 10:16:11 +030082 self.addCleanup(self.admin_quotas_client.update_quota_set,
Cory Stone2cb18262014-03-19 14:14:03 -050083 self.demo_tenant_id, **cleanup_quota_set)
Sean Dague27a8c562014-03-19 07:46:42 -040084 # test that the specific values we set are actually in
85 # the final result. There is nothing here that ensures there
86 # would be no other values in there.
87 self.assertDictContainsSubset(new_quota_set, quota_set)
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010088
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080089 @decorators.idempotent_id('18c51ae9-cb03-48fc-b234-14a19374dbed')
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010090 def test_show_quota_usage(self):
Ken'ichi Ohmichi3cf9eaf2016-07-29 11:05:21 -070091 quota_usage = self.admin_quotas_client.show_quota_set(
Jordan Pittier8160d312017-04-18 11:52:23 +020092 self.os_admin.credentials.tenant_id,
Ken'ichi Ohmichi3cf9eaf2016-07-29 11:05:21 -070093 params={'usage': True})['quota_set']
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010094 for key in QUOTA_KEYS:
95 self.assertIn(key, quota_usage)
96 for usage_key in QUOTA_USAGE_KEYS:
97 self.assertIn(usage_key, quota_usage[key])
98
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080099 @decorators.idempotent_id('ae8b6091-48ad-4bfa-a188-bbf5cc02115f')
Sylvain Baubeaufdd34592014-02-20 18:40:10 +0100100 def test_quota_usage(self):
Ken'ichi Ohmichi3cf9eaf2016-07-29 11:05:21 -0700101 quota_usage = self.admin_quotas_client.show_quota_set(
102 self.demo_tenant_id, params={'usage': True})['quota_set']
Sylvain Baubeaufdd34592014-02-20 18:40:10 +0100103
Markus Zoeller3d2a21c2015-02-27 12:04:22 +0100104 volume = self.create_volume()
lkuchlan9bf9fac2016-06-19 15:32:33 +0300105 self.addCleanup(self.delete_volume,
lkuchlan5db1f112017-09-24 11:56:44 +0300106 self.volumes_client, volume['id'])
Sylvain Baubeaufdd34592014-02-20 18:40:10 +0100107
Ken'ichi Ohmichi3cf9eaf2016-07-29 11:05:21 -0700108 new_quota_usage = self.admin_quotas_client.show_quota_set(
109 self.demo_tenant_id, params={'usage': True})['quota_set']
Sylvain Baubeaufdd34592014-02-20 18:40:10 +0100110
Sylvain Baubeaufdd34592014-02-20 18:40:10 +0100111 self.assertEqual(quota_usage['volumes']['in_use'] + 1,
112 new_quota_usage['volumes']['in_use'])
113
Markus Zoeller56cb97c2015-03-10 16:06:34 +0100114 self.assertEqual(quota_usage['gigabytes']['in_use'] +
115 volume["size"],
Sylvain Baubeaufdd34592014-02-20 18:40:10 +0100116 new_quota_usage['gigabytes']['in_use'])
117
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800118 @decorators.idempotent_id('874b35a9-51f1-4258-bec5-cd561b6690d3')
nayna-patel3d59e4a2014-04-24 14:28:38 +0000119 def test_delete_quota(self):
Jamie Lennox15350172015-08-17 10:54:25 +1000120 # Admin can delete the resource quota set for a project
121 project_name = data_utils.rand_name('quota_tenant')
122 description = data_utils.rand_name('desc_')
Andrea Frittolie1ed6952017-09-14 06:31:52 -0600123 project = identity.identity_utils(self.os_admin).create_project(
124 project_name, description=description)
Jamie Lennox15350172015-08-17 10:54:25 +1000125 project_id = project['id']
Andrea Frittolie1ed6952017-09-14 06:31:52 -0600126 self.addCleanup(identity.identity_utils(self.os_admin).delete_project,
127 project_id)
bkopilov62d21752016-06-08 10:16:11 +0300128 quota_set_default = self.admin_quotas_client.show_default_quota_set(
Jamie Lennox15350172015-08-17 10:54:25 +1000129 project_id)['quota_set']
nayna-patel3d59e4a2014-04-24 14:28:38 +0000130 volume_default = quota_set_default['volumes']
131
bkopilov62d21752016-06-08 10:16:11 +0300132 self.admin_quotas_client.update_quota_set(
zhufl44cdf152017-02-21 11:21:57 +0800133 project_id, volumes=(volume_default + 5))
nayna-patel3d59e4a2014-04-24 14:28:38 +0000134
bkopilov62d21752016-06-08 10:16:11 +0300135 self.admin_quotas_client.delete_quota_set(project_id)
136 quota_set_new = (self.admin_quotas_client.show_quota_set(project_id)
ghanshyam08a73f92015-08-31 17:32:49 +0900137 ['quota_set'])
nayna-patel3d59e4a2014-04-24 14:28:38 +0000138 self.assertEqual(volume_default, quota_set_new['volumes'])
Chandan Kumardd23f632014-11-17 15:27:48 +0530139
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800140 @decorators.idempotent_id('8911036f-9d54-4720-80cc-a1c9796a8805')
lkuchlan77c21af2016-04-20 11:31:14 +0300141 def test_quota_usage_after_volume_transfer(self):
142 # Create a volume for transfer
143 volume = self.create_volume()
lkuchlan9bf9fac2016-06-19 15:32:33 +0300144 self.addCleanup(self.delete_volume,
145 self.admin_volume_client, volume['id'])
lkuchlan77c21af2016-04-20 11:31:14 +0300146
147 # List of tenants quota usage pre-transfer
Ken'ichi Ohmichi3cf9eaf2016-07-29 11:05:21 -0700148 primary_quota = self.admin_quotas_client.show_quota_set(
149 self.demo_tenant_id, params={'usage': True})['quota_set']
lkuchlan77c21af2016-04-20 11:31:14 +0300150
Ken'ichi Ohmichi3cf9eaf2016-07-29 11:05:21 -0700151 alt_quota = self.admin_quotas_client.show_quota_set(
rchouhan25bf8ce2018-01-29 17:39:36 +0530152 self.os_alt.volumes_client_latest.tenant_id,
153 params={'usage': True})['quota_set']
lkuchlan77c21af2016-04-20 11:31:14 +0300154
155 # Creates a volume transfer
ghanshyam59614b42017-02-24 16:32:02 +0000156 transfer = self.transfer_client.create_volume_transfer(
lkuchlan77c21af2016-04-20 11:31:14 +0300157 volume_id=volume['id'])['transfer']
158 transfer_id = transfer['id']
159 auth_key = transfer['auth_key']
160
161 # Accepts a volume transfer
ghanshyam59614b42017-02-24 16:32:02 +0000162 self.alt_transfer_client.accept_volume_transfer(
jeremy.zhange280f662017-06-30 17:38:58 +0800163 transfer_id, auth_key=auth_key)
lkuchlan77c21af2016-04-20 11:31:14 +0300164
165 # Verify volume transferred is available
lkuchlan52d7b0d2016-11-07 20:53:19 +0200166 waiters.wait_for_volume_resource_status(
rchouhan25bf8ce2018-01-29 17:39:36 +0530167 self.os_alt.volumes_client_latest, volume['id'], 'available')
lkuchlan77c21af2016-04-20 11:31:14 +0300168
169 # List of tenants quota usage post transfer
Ken'ichi Ohmichi3cf9eaf2016-07-29 11:05:21 -0700170 new_primary_quota = self.admin_quotas_client.show_quota_set(
171 self.demo_tenant_id, params={'usage': True})['quota_set']
lkuchlan77c21af2016-04-20 11:31:14 +0300172
Ken'ichi Ohmichi3cf9eaf2016-07-29 11:05:21 -0700173 new_alt_quota = self.admin_quotas_client.show_quota_set(
rchouhan25bf8ce2018-01-29 17:39:36 +0530174 self.os_alt.volumes_client_latest.tenant_id,
175 params={'usage': True})['quota_set']
lkuchlan77c21af2016-04-20 11:31:14 +0300176
177 # Verify tenants quota usage was updated
178 self.assertEqual(primary_quota['volumes']['in_use'] -
179 new_primary_quota['volumes']['in_use'],
180 new_alt_quota['volumes']['in_use'] -
181 alt_quota['volumes']['in_use'])
182
183 self.assertEqual(alt_quota['gigabytes']['in_use'] +
184 volume['size'],
185 new_alt_quota['gigabytes']['in_use'])
186
187 self.assertEqual(primary_quota['gigabytes']['in_use'] -
188 volume['size'],
189 new_primary_quota['gigabytes']['in_use'])