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 |
Andrea Frittoli | e1ed695 | 2017-09-14 06:31:52 -0600 | [diff] [blame] | 16 | from tempest.common import identity |
jeremy.zhang | 644b01d | 2017-04-13 12:59:49 +0800 | [diff] [blame] | 17 | from tempest.common import tempest_fixtures as fixtures |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 18 | from tempest.common import waiters |
Ken'ichi Ohmichi | ef1c1ce | 2017-03-10 11:07:10 -0800 | [diff] [blame] | 19 | from tempest.lib.common.utils import data_utils |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 20 | from tempest.lib import decorators |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 21 | |
lkuchlan | f31310f | 2017-06-11 16:00:09 +0300 | [diff] [blame] | 22 | QUOTA_KEYS = ['gigabytes', 'snapshots', 'volumes', 'backups', |
| 23 | 'backup_gigabytes', 'per_volume_gigabytes'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 24 | QUOTA_USAGE_KEYS = ['reserved', 'limit', 'in_use'] |
| 25 | |
| 26 | |
Ken'ichi Ohmichi | e8afb8c | 2017-03-27 11:25:37 -0700 | [diff] [blame] | 27 | class BaseVolumeQuotasAdminTestJSON(base.BaseVolumeAdminTest): |
Matt Riedemann | 5349cfd | 2014-03-12 07:38:55 -0700 | [diff] [blame] | 28 | force_tenant_isolation = True |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 29 | |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 30 | credentials = ['primary', 'alt', 'admin'] |
| 31 | |
jeremy.zhang | 644b01d | 2017-04-13 12:59:49 +0800 | [diff] [blame] | 32 | 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 Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 37 | @classmethod |
Rohan Kanade | 0574915 | 2015-01-30 17:15:18 +0530 | [diff] [blame] | 38 | def setup_credentials(cls): |
Ken'ichi Ohmichi | e8afb8c | 2017-03-27 11:25:37 -0700 | [diff] [blame] | 39 | super(BaseVolumeQuotasAdminTestJSON, cls).setup_credentials() |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 40 | cls.demo_tenant_id = cls.os_primary.credentials.tenant_id |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 41 | |
ghanshyam | 59614b4 | 2017-02-24 16:32:02 +0000 | [diff] [blame] | 42 | @classmethod |
| 43 | def setup_clients(cls): |
| 44 | super(BaseVolumeQuotasAdminTestJSON, cls).setup_clients() |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 45 | cls.transfer_client = cls.os_primary.volume_transfers_v2_client |
ghanshyam | 59614b4 | 2017-02-24 16:32:02 +0000 | [diff] [blame] | 46 | cls.alt_transfer_client = cls.os_alt.volume_transfers_v2_client |
| 47 | |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 48 | @decorators.idempotent_id('59eada70-403c-4cef-a2a3-a8ce2f1b07a0') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 49 | def test_list_quotas(self): |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 50 | quotas = (self.admin_quotas_client.show_quota_set(self.demo_tenant_id) |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 51 | ['quota_set']) |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 52 | for key in QUOTA_KEYS: |
| 53 | self.assertIn(key, quotas) |
| 54 | |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 55 | @decorators.idempotent_id('2be020a2-5fdd-423d-8d35-a7ffbc36e9f7') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 56 | def test_list_default_quotas(self): |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 57 | quotas = self.admin_quotas_client.show_default_quota_set( |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 58 | self.demo_tenant_id)['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 59 | for key in QUOTA_KEYS: |
| 60 | self.assertIn(key, quotas) |
| 61 | |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 62 | @decorators.idempotent_id('3d45c99e-cc42-4424-a56e-5cbd212b63a6') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 63 | def test_update_all_quota_resources_for_tenant(self): |
| 64 | # Admin can update all the resource quota limits for a tenant |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 65 | default_quota_set = self.admin_quotas_client.show_default_quota_set( |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 66 | self.demo_tenant_id)['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 67 | new_quota_set = {'gigabytes': 1009, |
| 68 | 'volumes': 11, |
lkuchlan | 070204b | 2016-08-29 14:48:53 +0300 | [diff] [blame] | 69 | 'snapshots': 11, |
lkuchlan | f31310f | 2017-06-11 16:00:09 +0300 | [diff] [blame] | 70 | 'backups': 11, |
| 71 | 'backup_gigabytes': 1009, |
| 72 | 'per_volume_gigabytes': 1009} |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 73 | |
| 74 | # Update limits for all quota resources |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 75 | quota_set = self.admin_quotas_client.update_quota_set( |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 76 | self.demo_tenant_id, |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 77 | **new_quota_set)['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 78 | |
Cory Stone | 2cb1826 | 2014-03-19 14:14:03 -0500 | [diff] [blame] | 79 | cleanup_quota_set = dict( |
guo yunxian | 7bbbec1 | 2016-08-21 20:03:10 +0800 | [diff] [blame] | 80 | (k, v) for k, v in default_quota_set.items() |
Cory Stone | 2cb1826 | 2014-03-19 14:14:03 -0500 | [diff] [blame] | 81 | if k in QUOTA_KEYS) |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 82 | self.addCleanup(self.admin_quotas_client.update_quota_set, |
Cory Stone | 2cb1826 | 2014-03-19 14:14:03 -0500 | [diff] [blame] | 83 | self.demo_tenant_id, **cleanup_quota_set) |
Sean Dague | 27a8c56 | 2014-03-19 07:46:42 -0400 | [diff] [blame] | 84 | # 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 Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 88 | |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 89 | @decorators.idempotent_id('18c51ae9-cb03-48fc-b234-14a19374dbed') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 90 | def test_show_quota_usage(self): |
Ken'ichi Ohmichi | 3cf9eaf | 2016-07-29 11:05:21 -0700 | [diff] [blame] | 91 | quota_usage = self.admin_quotas_client.show_quota_set( |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 92 | self.os_admin.credentials.tenant_id, |
Ken'ichi Ohmichi | 3cf9eaf | 2016-07-29 11:05:21 -0700 | [diff] [blame] | 93 | params={'usage': True})['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 94 | 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 Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 99 | @decorators.idempotent_id('ae8b6091-48ad-4bfa-a188-bbf5cc02115f') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 100 | def test_quota_usage(self): |
Ken'ichi Ohmichi | 3cf9eaf | 2016-07-29 11:05:21 -0700 | [diff] [blame] | 101 | quota_usage = self.admin_quotas_client.show_quota_set( |
| 102 | self.demo_tenant_id, params={'usage': True})['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 103 | |
Markus Zoeller | 3d2a21c | 2015-02-27 12:04:22 +0100 | [diff] [blame] | 104 | volume = self.create_volume() |
lkuchlan | 9bf9fac | 2016-06-19 15:32:33 +0300 | [diff] [blame] | 105 | self.addCleanup(self.delete_volume, |
lkuchlan | 5db1f11 | 2017-09-24 11:56:44 +0300 | [diff] [blame] | 106 | self.volumes_client, volume['id']) |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 107 | |
Ken'ichi Ohmichi | 3cf9eaf | 2016-07-29 11:05:21 -0700 | [diff] [blame] | 108 | new_quota_usage = self.admin_quotas_client.show_quota_set( |
| 109 | self.demo_tenant_id, params={'usage': True})['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 110 | |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 111 | self.assertEqual(quota_usage['volumes']['in_use'] + 1, |
| 112 | new_quota_usage['volumes']['in_use']) |
| 113 | |
Markus Zoeller | 56cb97c | 2015-03-10 16:06:34 +0100 | [diff] [blame] | 114 | self.assertEqual(quota_usage['gigabytes']['in_use'] + |
| 115 | volume["size"], |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 116 | new_quota_usage['gigabytes']['in_use']) |
| 117 | |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 118 | @decorators.idempotent_id('874b35a9-51f1-4258-bec5-cd561b6690d3') |
nayna-patel | 3d59e4a | 2014-04-24 14:28:38 +0000 | [diff] [blame] | 119 | def test_delete_quota(self): |
Jamie Lennox | 1535017 | 2015-08-17 10:54:25 +1000 | [diff] [blame] | 120 | # 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 Frittoli | e1ed695 | 2017-09-14 06:31:52 -0600 | [diff] [blame] | 123 | project = identity.identity_utils(self.os_admin).create_project( |
| 124 | project_name, description=description) |
Jamie Lennox | 1535017 | 2015-08-17 10:54:25 +1000 | [diff] [blame] | 125 | project_id = project['id'] |
Andrea Frittoli | e1ed695 | 2017-09-14 06:31:52 -0600 | [diff] [blame] | 126 | self.addCleanup(identity.identity_utils(self.os_admin).delete_project, |
| 127 | project_id) |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 128 | quota_set_default = self.admin_quotas_client.show_default_quota_set( |
Jamie Lennox | 1535017 | 2015-08-17 10:54:25 +1000 | [diff] [blame] | 129 | project_id)['quota_set'] |
nayna-patel | 3d59e4a | 2014-04-24 14:28:38 +0000 | [diff] [blame] | 130 | volume_default = quota_set_default['volumes'] |
| 131 | |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 132 | self.admin_quotas_client.update_quota_set( |
zhufl | 44cdf15 | 2017-02-21 11:21:57 +0800 | [diff] [blame] | 133 | project_id, volumes=(volume_default + 5)) |
nayna-patel | 3d59e4a | 2014-04-24 14:28:38 +0000 | [diff] [blame] | 134 | |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 135 | self.admin_quotas_client.delete_quota_set(project_id) |
| 136 | quota_set_new = (self.admin_quotas_client.show_quota_set(project_id) |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 137 | ['quota_set']) |
nayna-patel | 3d59e4a | 2014-04-24 14:28:38 +0000 | [diff] [blame] | 138 | self.assertEqual(volume_default, quota_set_new['volumes']) |
Chandan Kumar | dd23f63 | 2014-11-17 15:27:48 +0530 | [diff] [blame] | 139 | |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 140 | @decorators.idempotent_id('8911036f-9d54-4720-80cc-a1c9796a8805') |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 141 | def test_quota_usage_after_volume_transfer(self): |
| 142 | # Create a volume for transfer |
| 143 | volume = self.create_volume() |
lkuchlan | 9bf9fac | 2016-06-19 15:32:33 +0300 | [diff] [blame] | 144 | self.addCleanup(self.delete_volume, |
| 145 | self.admin_volume_client, volume['id']) |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 146 | |
| 147 | # List of tenants quota usage pre-transfer |
Ken'ichi Ohmichi | 3cf9eaf | 2016-07-29 11:05:21 -0700 | [diff] [blame] | 148 | primary_quota = self.admin_quotas_client.show_quota_set( |
| 149 | self.demo_tenant_id, params={'usage': True})['quota_set'] |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 150 | |
Ken'ichi Ohmichi | 3cf9eaf | 2016-07-29 11:05:21 -0700 | [diff] [blame] | 151 | alt_quota = self.admin_quotas_client.show_quota_set( |
rchouhan | 25bf8ce | 2018-01-29 17:39:36 +0530 | [diff] [blame] | 152 | self.os_alt.volumes_client_latest.tenant_id, |
| 153 | params={'usage': True})['quota_set'] |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 154 | |
| 155 | # Creates a volume transfer |
ghanshyam | 59614b4 | 2017-02-24 16:32:02 +0000 | [diff] [blame] | 156 | transfer = self.transfer_client.create_volume_transfer( |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 157 | volume_id=volume['id'])['transfer'] |
| 158 | transfer_id = transfer['id'] |
| 159 | auth_key = transfer['auth_key'] |
| 160 | |
| 161 | # Accepts a volume transfer |
ghanshyam | 59614b4 | 2017-02-24 16:32:02 +0000 | [diff] [blame] | 162 | self.alt_transfer_client.accept_volume_transfer( |
jeremy.zhang | e280f66 | 2017-06-30 17:38:58 +0800 | [diff] [blame] | 163 | transfer_id, auth_key=auth_key) |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 164 | |
| 165 | # Verify volume transferred is available |
lkuchlan | 52d7b0d | 2016-11-07 20:53:19 +0200 | [diff] [blame] | 166 | waiters.wait_for_volume_resource_status( |
rchouhan | 25bf8ce | 2018-01-29 17:39:36 +0530 | [diff] [blame] | 167 | self.os_alt.volumes_client_latest, volume['id'], 'available') |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 168 | |
| 169 | # List of tenants quota usage post transfer |
Ken'ichi Ohmichi | 3cf9eaf | 2016-07-29 11:05:21 -0700 | [diff] [blame] | 170 | new_primary_quota = self.admin_quotas_client.show_quota_set( |
| 171 | self.demo_tenant_id, params={'usage': True})['quota_set'] |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 172 | |
Ken'ichi Ohmichi | 3cf9eaf | 2016-07-29 11:05:21 -0700 | [diff] [blame] | 173 | new_alt_quota = self.admin_quotas_client.show_quota_set( |
rchouhan | 25bf8ce | 2018-01-29 17:39:36 +0530 | [diff] [blame] | 174 | self.os_alt.volumes_client_latest.tenant_id, |
| 175 | params={'usage': True})['quota_set'] |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 176 | |
| 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']) |