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 | |
Matthew Treinish | 7142668 | 2015-04-23 11:19:38 -0400 | [diff] [blame] | 15 | import six |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 16 | from tempest.api.volume import base |
Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [diff] [blame] | 17 | from tempest.common.utils import data_utils |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 18 | from tempest.common import waiters |
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): |
Matt Riedemann | 5349cfd | 2014-03-12 07:38:55 -0700 | [diff] [blame] | 26 | force_tenant_isolation = True |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 27 | |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 28 | credentials = ['primary', 'alt', 'admin'] |
| 29 | |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 30 | @classmethod |
Rohan Kanade | 0574915 | 2015-01-30 17:15:18 +0530 | [diff] [blame] | 31 | def setup_credentials(cls): |
| 32 | super(BaseVolumeQuotasAdminV2TestJSON, cls).setup_credentials() |
Andrea Frittoli | b21de6c | 2015-02-06 20:12:38 +0000 | [diff] [blame] | 33 | cls.demo_tenant_id = cls.os.credentials.tenant_id |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 34 | cls.alt_client = cls.os_alt.volumes_client |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 35 | |
lkuchlan | 3f49008 | 2016-05-08 15:34:13 +0300 | [diff] [blame] | 36 | 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 Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 41 | @test.idempotent_id('59eada70-403c-4cef-a2a3-a8ce2f1b07a0') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 42 | def test_list_quotas(self): |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 43 | quotas = (self.admin_quotas_client.show_quota_set(self.demo_tenant_id) |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 44 | ['quota_set']) |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 45 | for key in QUOTA_KEYS: |
| 46 | self.assertIn(key, quotas) |
| 47 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 48 | @test.idempotent_id('2be020a2-5fdd-423d-8d35-a7ffbc36e9f7') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 49 | def test_list_default_quotas(self): |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 50 | quotas = self.admin_quotas_client.show_default_quota_set( |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 51 | self.demo_tenant_id)['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 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 55 | @test.idempotent_id('3d45c99e-cc42-4424-a56e-5cbd212b63a6') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 56 | def test_update_all_quota_resources_for_tenant(self): |
| 57 | # Admin can update all the resource quota limits for a tenant |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 58 | default_quota_set = self.admin_quotas_client.show_default_quota_set( |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 59 | self.demo_tenant_id)['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 60 | new_quota_set = {'gigabytes': 1009, |
| 61 | 'volumes': 11, |
| 62 | 'snapshots': 11} |
| 63 | |
| 64 | # Update limits for all quota resources |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 65 | quota_set = self.admin_quotas_client.update_quota_set( |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 66 | self.demo_tenant_id, |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 67 | **new_quota_set)['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 68 | |
Cory Stone | 2cb1826 | 2014-03-19 14:14:03 -0500 | [diff] [blame] | 69 | cleanup_quota_set = dict( |
Matthew Treinish | 7142668 | 2015-04-23 11:19:38 -0400 | [diff] [blame] | 70 | (k, v) for k, v in six.iteritems(default_quota_set) |
Cory Stone | 2cb1826 | 2014-03-19 14:14:03 -0500 | [diff] [blame] | 71 | if k in QUOTA_KEYS) |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 72 | self.addCleanup(self.admin_quotas_client.update_quota_set, |
Cory Stone | 2cb1826 | 2014-03-19 14:14:03 -0500 | [diff] [blame] | 73 | self.demo_tenant_id, **cleanup_quota_set) |
Sean Dague | 27a8c56 | 2014-03-19 07:46:42 -0400 | [diff] [blame] | 74 | # 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 Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 78 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 79 | @test.idempotent_id('18c51ae9-cb03-48fc-b234-14a19374dbed') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 80 | def test_show_quota_usage(self): |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 81 | quota_usage = self.admin_quotas_client.show_quota_usage( |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 82 | self.os_adm.credentials.tenant_id)['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 83 | 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 Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 88 | @test.idempotent_id('ae8b6091-48ad-4bfa-a188-bbf5cc02115f') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 89 | def test_quota_usage(self): |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 90 | quota_usage = self.admin_quotas_client.show_quota_usage( |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 91 | self.demo_tenant_id)['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 92 | |
Markus Zoeller | 3d2a21c | 2015-02-27 12:04:22 +0100 | [diff] [blame] | 93 | volume = self.create_volume() |
lkuchlan | 3f49008 | 2016-05-08 15:34:13 +0300 | [diff] [blame] | 94 | self.addCleanup(self._delete_volume, volume['id']) |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 95 | |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 96 | new_quota_usage = self.admin_quotas_client.show_quota_usage( |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 97 | self.demo_tenant_id)['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 98 | |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 99 | self.assertEqual(quota_usage['volumes']['in_use'] + 1, |
| 100 | new_quota_usage['volumes']['in_use']) |
| 101 | |
Markus Zoeller | 56cb97c | 2015-03-10 16:06:34 +0100 | [diff] [blame] | 102 | self.assertEqual(quota_usage['gigabytes']['in_use'] + |
| 103 | volume["size"], |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 104 | new_quota_usage['gigabytes']['in_use']) |
| 105 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 106 | @test.idempotent_id('874b35a9-51f1-4258-bec5-cd561b6690d3') |
nayna-patel | 3d59e4a | 2014-04-24 14:28:38 +0000 | [diff] [blame] | 107 | def test_delete_quota(self): |
Jamie Lennox | 1535017 | 2015-08-17 10:54:25 +1000 | [diff] [blame] | 108 | # 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) |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 115 | quota_set_default = self.admin_quotas_client.show_default_quota_set( |
Jamie Lennox | 1535017 | 2015-08-17 10:54:25 +1000 | [diff] [blame] | 116 | project_id)['quota_set'] |
nayna-patel | 3d59e4a | 2014-04-24 14:28:38 +0000 | [diff] [blame] | 117 | volume_default = quota_set_default['volumes'] |
| 118 | |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 119 | self.admin_quotas_client.update_quota_set( |
| 120 | project_id, volumes=(int(volume_default) + 5)) |
nayna-patel | 3d59e4a | 2014-04-24 14:28:38 +0000 | [diff] [blame] | 121 | |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 122 | self.admin_quotas_client.delete_quota_set(project_id) |
| 123 | quota_set_new = (self.admin_quotas_client.show_quota_set(project_id) |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 124 | ['quota_set']) |
nayna-patel | 3d59e4a | 2014-04-24 14:28:38 +0000 | [diff] [blame] | 125 | self.assertEqual(volume_default, quota_set_new['volumes']) |
Chandan Kumar | dd23f63 | 2014-11-17 15:27:48 +0530 | [diff] [blame] | 126 | |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 127 | @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 Kumar | dd23f63 | 2014-11-17 15:27:48 +0530 | [diff] [blame] | 175 | |
| 176 | class VolumeQuotasAdminV1TestJSON(BaseVolumeQuotasAdminV2TestJSON): |
| 177 | _api_version = 1 |