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 |
jeremy.zhang | 644b01d | 2017-04-13 12:59:49 +0800 | [diff] [blame] | 16 | from tempest.common import tempest_fixtures as fixtures |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 17 | from tempest.common import waiters |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 18 | from tempest.lib import decorators |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 19 | |
lkuchlan | f31310f | 2017-06-11 16:00:09 +0300 | [diff] [blame] | 20 | QUOTA_KEYS = ['gigabytes', 'snapshots', 'volumes', 'backups', |
| 21 | 'backup_gigabytes', 'per_volume_gigabytes'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 22 | QUOTA_USAGE_KEYS = ['reserved', 'limit', 'in_use'] |
| 23 | |
| 24 | |
Ken'ichi Ohmichi | e8afb8c | 2017-03-27 11:25:37 -0700 | [diff] [blame] | 25 | class BaseVolumeQuotasAdminTestJSON(base.BaseVolumeAdminTest): |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 26 | credentials = ['primary', 'alt', 'admin'] |
| 27 | |
jeremy.zhang | 644b01d | 2017-04-13 12:59:49 +0800 | [diff] [blame] | 28 | def setUp(self): |
| 29 | # NOTE(jeremy.zhang): Avoid conflicts with volume quota class tests. |
| 30 | self.useFixture(fixtures.LockFixture('volume_quotas')) |
| 31 | super(BaseVolumeQuotasAdminTestJSON, self).setUp() |
| 32 | |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 33 | @classmethod |
Rohan Kanade | 0574915 | 2015-01-30 17:15:18 +0530 | [diff] [blame] | 34 | def setup_credentials(cls): |
Ken'ichi Ohmichi | e8afb8c | 2017-03-27 11:25:37 -0700 | [diff] [blame] | 35 | super(BaseVolumeQuotasAdminTestJSON, cls).setup_credentials() |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 36 | cls.demo_tenant_id = cls.os_primary.credentials.tenant_id |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 37 | |
ghanshyam | 59614b4 | 2017-02-24 16:32:02 +0000 | [diff] [blame] | 38 | @classmethod |
| 39 | def setup_clients(cls): |
| 40 | super(BaseVolumeQuotasAdminTestJSON, cls).setup_clients() |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 41 | cls.transfer_client = cls.os_primary.volume_transfers_v2_client |
ghanshyam | 59614b4 | 2017-02-24 16:32:02 +0000 | [diff] [blame] | 42 | cls.alt_transfer_client = cls.os_alt.volume_transfers_v2_client |
| 43 | |
Cliff Parsons | c460c42 | 2017-11-27 16:05:32 -0600 | [diff] [blame] | 44 | @classmethod |
| 45 | def resource_setup(cls): |
| 46 | super(BaseVolumeQuotasAdminTestJSON, cls).resource_setup() |
| 47 | |
| 48 | # Save the current set of quotas so that some tests may use it |
| 49 | # to restore the quotas to their original values after they are |
| 50 | # done. |
| 51 | cls.original_quota_set = (cls.admin_quotas_client.show_quota_set( |
| 52 | cls.demo_tenant_id)['quota_set']) |
| 53 | cls.cleanup_quota_set = dict( |
| 54 | (k, v) for k, v in cls.original_quota_set.items() |
| 55 | if k in QUOTA_KEYS) |
| 56 | |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 57 | @decorators.idempotent_id('59eada70-403c-4cef-a2a3-a8ce2f1b07a0') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 58 | def test_list_quotas(self): |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 59 | quotas = (self.admin_quotas_client.show_quota_set(self.demo_tenant_id) |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 60 | ['quota_set']) |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 61 | for key in QUOTA_KEYS: |
| 62 | self.assertIn(key, quotas) |
| 63 | |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 64 | @decorators.idempotent_id('2be020a2-5fdd-423d-8d35-a7ffbc36e9f7') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 65 | def test_list_default_quotas(self): |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 66 | quotas = self.admin_quotas_client.show_default_quota_set( |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 67 | self.demo_tenant_id)['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 68 | for key in QUOTA_KEYS: |
| 69 | self.assertIn(key, quotas) |
| 70 | |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 71 | @decorators.idempotent_id('3d45c99e-cc42-4424-a56e-5cbd212b63a6') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 72 | def test_update_all_quota_resources_for_tenant(self): |
| 73 | # Admin can update all the resource quota limits for a tenant |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 74 | new_quota_set = {'gigabytes': 1009, |
| 75 | 'volumes': 11, |
lkuchlan | 070204b | 2016-08-29 14:48:53 +0300 | [diff] [blame] | 76 | 'snapshots': 11, |
lkuchlan | f31310f | 2017-06-11 16:00:09 +0300 | [diff] [blame] | 77 | 'backups': 11, |
| 78 | 'backup_gigabytes': 1009, |
| 79 | 'per_volume_gigabytes': 1009} |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 80 | |
| 81 | # Update limits for all quota resources |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 82 | quota_set = self.admin_quotas_client.update_quota_set( |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 83 | self.demo_tenant_id, |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 84 | **new_quota_set)['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 85 | |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 86 | self.addCleanup(self.admin_quotas_client.update_quota_set, |
Cliff Parsons | c460c42 | 2017-11-27 16:05:32 -0600 | [diff] [blame] | 87 | self.demo_tenant_id, **self.cleanup_quota_set) |
| 88 | |
Sean Dague | 27a8c56 | 2014-03-19 07:46:42 -0400 | [diff] [blame] | 89 | # test that the specific values we set are actually in |
| 90 | # the final result. There is nothing here that ensures there |
| 91 | # would be no other values in there. |
| 92 | self.assertDictContainsSubset(new_quota_set, quota_set) |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 93 | |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 94 | @decorators.idempotent_id('18c51ae9-cb03-48fc-b234-14a19374dbed') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 95 | def test_show_quota_usage(self): |
Ken'ichi Ohmichi | 3cf9eaf | 2016-07-29 11:05:21 -0700 | [diff] [blame] | 96 | quota_usage = self.admin_quotas_client.show_quota_set( |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 97 | self.os_admin.credentials.tenant_id, |
Ken'ichi Ohmichi | 3cf9eaf | 2016-07-29 11:05:21 -0700 | [diff] [blame] | 98 | params={'usage': True})['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 99 | for key in QUOTA_KEYS: |
| 100 | self.assertIn(key, quota_usage) |
| 101 | for usage_key in QUOTA_USAGE_KEYS: |
| 102 | self.assertIn(usage_key, quota_usage[key]) |
| 103 | |
Cliff Parsons | c460c42 | 2017-11-27 16:05:32 -0600 | [diff] [blame] | 104 | @decorators.idempotent_id('874b35a9-51f1-4258-bec5-cd561b6690d3') |
| 105 | def test_delete_quota(self): |
| 106 | # Admin can delete the resource quota set for a project |
| 107 | |
| 108 | self.addCleanup(self.admin_quotas_client.update_quota_set, |
| 109 | self.demo_tenant_id, **self.cleanup_quota_set) |
| 110 | |
| 111 | quota_set_default = self.admin_quotas_client.show_default_quota_set( |
| 112 | self.demo_tenant_id)['quota_set'] |
| 113 | volume_default = quota_set_default['volumes'] |
| 114 | |
| 115 | self.admin_quotas_client.update_quota_set( |
| 116 | self.demo_tenant_id, volumes=(volume_default + 5)) |
| 117 | |
| 118 | self.admin_quotas_client.delete_quota_set(self.demo_tenant_id) |
| 119 | quota_set_new = (self.admin_quotas_client.show_quota_set( |
| 120 | self.demo_tenant_id)['quota_set']) |
| 121 | self.assertEqual(volume_default, quota_set_new['volumes']) |
| 122 | |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 123 | @decorators.idempotent_id('ae8b6091-48ad-4bfa-a188-bbf5cc02115f') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 124 | def test_quota_usage(self): |
Ken'ichi Ohmichi | 3cf9eaf | 2016-07-29 11:05:21 -0700 | [diff] [blame] | 125 | quota_usage = self.admin_quotas_client.show_quota_set( |
| 126 | self.demo_tenant_id, params={'usage': True})['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 127 | |
Markus Zoeller | 3d2a21c | 2015-02-27 12:04:22 +0100 | [diff] [blame] | 128 | volume = self.create_volume() |
lkuchlan | 9bf9fac | 2016-06-19 15:32:33 +0300 | [diff] [blame] | 129 | self.addCleanup(self.delete_volume, |
lkuchlan | 5db1f11 | 2017-09-24 11:56:44 +0300 | [diff] [blame] | 130 | self.volumes_client, volume['id']) |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 131 | |
Ken'ichi Ohmichi | 3cf9eaf | 2016-07-29 11:05:21 -0700 | [diff] [blame] | 132 | new_quota_usage = self.admin_quotas_client.show_quota_set( |
| 133 | self.demo_tenant_id, params={'usage': True})['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 134 | |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 135 | self.assertEqual(quota_usage['volumes']['in_use'] + 1, |
| 136 | new_quota_usage['volumes']['in_use']) |
| 137 | |
Markus Zoeller | 56cb97c | 2015-03-10 16:06:34 +0100 | [diff] [blame] | 138 | self.assertEqual(quota_usage['gigabytes']['in_use'] + |
| 139 | volume["size"], |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 140 | new_quota_usage['gigabytes']['in_use']) |
| 141 | |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 142 | @decorators.idempotent_id('8911036f-9d54-4720-80cc-a1c9796a8805') |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 143 | def test_quota_usage_after_volume_transfer(self): |
| 144 | # Create a volume for transfer |
| 145 | volume = self.create_volume() |
lkuchlan | 9bf9fac | 2016-06-19 15:32:33 +0300 | [diff] [blame] | 146 | self.addCleanup(self.delete_volume, |
| 147 | self.admin_volume_client, volume['id']) |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 148 | |
| 149 | # List of tenants quota usage pre-transfer |
Ken'ichi Ohmichi | 3cf9eaf | 2016-07-29 11:05:21 -0700 | [diff] [blame] | 150 | primary_quota = self.admin_quotas_client.show_quota_set( |
| 151 | self.demo_tenant_id, params={'usage': True})['quota_set'] |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 152 | |
Ken'ichi Ohmichi | 3cf9eaf | 2016-07-29 11:05:21 -0700 | [diff] [blame] | 153 | alt_quota = self.admin_quotas_client.show_quota_set( |
rchouhan | 25bf8ce | 2018-01-29 17:39:36 +0530 | [diff] [blame] | 154 | self.os_alt.volumes_client_latest.tenant_id, |
| 155 | params={'usage': True})['quota_set'] |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 156 | |
| 157 | # Creates a volume transfer |
ghanshyam | 59614b4 | 2017-02-24 16:32:02 +0000 | [diff] [blame] | 158 | transfer = self.transfer_client.create_volume_transfer( |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 159 | volume_id=volume['id'])['transfer'] |
| 160 | transfer_id = transfer['id'] |
| 161 | auth_key = transfer['auth_key'] |
| 162 | |
| 163 | # Accepts a volume transfer |
ghanshyam | 59614b4 | 2017-02-24 16:32:02 +0000 | [diff] [blame] | 164 | self.alt_transfer_client.accept_volume_transfer( |
jeremy.zhang | e280f66 | 2017-06-30 17:38:58 +0800 | [diff] [blame] | 165 | transfer_id, auth_key=auth_key) |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 166 | |
| 167 | # Verify volume transferred is available |
lkuchlan | 52d7b0d | 2016-11-07 20:53:19 +0200 | [diff] [blame] | 168 | waiters.wait_for_volume_resource_status( |
rchouhan | 25bf8ce | 2018-01-29 17:39:36 +0530 | [diff] [blame] | 169 | self.os_alt.volumes_client_latest, volume['id'], 'available') |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 170 | |
| 171 | # List of tenants quota usage post transfer |
Ken'ichi Ohmichi | 3cf9eaf | 2016-07-29 11:05:21 -0700 | [diff] [blame] | 172 | new_primary_quota = self.admin_quotas_client.show_quota_set( |
| 173 | self.demo_tenant_id, params={'usage': True})['quota_set'] |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 174 | |
Ken'ichi Ohmichi | 3cf9eaf | 2016-07-29 11:05:21 -0700 | [diff] [blame] | 175 | new_alt_quota = self.admin_quotas_client.show_quota_set( |
rchouhan | 25bf8ce | 2018-01-29 17:39:36 +0530 | [diff] [blame] | 176 | self.os_alt.volumes_client_latest.tenant_id, |
| 177 | params={'usage': True})['quota_set'] |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 178 | |
| 179 | # Verify tenants quota usage was updated |
| 180 | self.assertEqual(primary_quota['volumes']['in_use'] - |
| 181 | new_primary_quota['volumes']['in_use'], |
| 182 | new_alt_quota['volumes']['in_use'] - |
| 183 | alt_quota['volumes']['in_use']) |
| 184 | |
| 185 | self.assertEqual(alt_quota['gigabytes']['in_use'] + |
| 186 | volume['size'], |
| 187 | new_alt_quota['gigabytes']['in_use']) |
| 188 | |
| 189 | self.assertEqual(primary_quota['gigabytes']['in_use'] - |
| 190 | volume['size'], |
| 191 | new_primary_quota['gigabytes']['in_use']) |