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 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 36 | @test.idempotent_id('59eada70-403c-4cef-a2a3-a8ce2f1b07a0') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 37 | def test_list_quotas(self): |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 38 | quotas = (self.admin_quotas_client.show_quota_set(self.demo_tenant_id) |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 39 | ['quota_set']) |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 40 | for key in QUOTA_KEYS: |
| 41 | self.assertIn(key, quotas) |
| 42 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 43 | @test.idempotent_id('2be020a2-5fdd-423d-8d35-a7ffbc36e9f7') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 44 | def test_list_default_quotas(self): |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 45 | quotas = self.admin_quotas_client.show_default_quota_set( |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 46 | self.demo_tenant_id)['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 47 | for key in QUOTA_KEYS: |
| 48 | self.assertIn(key, quotas) |
| 49 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 50 | @test.idempotent_id('3d45c99e-cc42-4424-a56e-5cbd212b63a6') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 51 | def test_update_all_quota_resources_for_tenant(self): |
| 52 | # Admin can update all the resource quota limits for a tenant |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 53 | default_quota_set = self.admin_quotas_client.show_default_quota_set( |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 54 | self.demo_tenant_id)['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 55 | new_quota_set = {'gigabytes': 1009, |
| 56 | 'volumes': 11, |
| 57 | 'snapshots': 11} |
| 58 | |
| 59 | # Update limits for all quota resources |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 60 | quota_set = self.admin_quotas_client.update_quota_set( |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 61 | self.demo_tenant_id, |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 62 | **new_quota_set)['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 63 | |
Cory Stone | 2cb1826 | 2014-03-19 14:14:03 -0500 | [diff] [blame] | 64 | cleanup_quota_set = dict( |
Matthew Treinish | 7142668 | 2015-04-23 11:19:38 -0400 | [diff] [blame] | 65 | (k, v) for k, v in six.iteritems(default_quota_set) |
Cory Stone | 2cb1826 | 2014-03-19 14:14:03 -0500 | [diff] [blame] | 66 | if k in QUOTA_KEYS) |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 67 | self.addCleanup(self.admin_quotas_client.update_quota_set, |
Cory Stone | 2cb1826 | 2014-03-19 14:14:03 -0500 | [diff] [blame] | 68 | self.demo_tenant_id, **cleanup_quota_set) |
Sean Dague | 27a8c56 | 2014-03-19 07:46:42 -0400 | [diff] [blame] | 69 | # test that the specific values we set are actually in |
| 70 | # the final result. There is nothing here that ensures there |
| 71 | # would be no other values in there. |
| 72 | self.assertDictContainsSubset(new_quota_set, quota_set) |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 73 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 74 | @test.idempotent_id('18c51ae9-cb03-48fc-b234-14a19374dbed') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 75 | def test_show_quota_usage(self): |
Ken'ichi Ohmichi | 3cf9eaf | 2016-07-29 11:05:21 -0700 | [diff] [blame] | 76 | quota_usage = self.admin_quotas_client.show_quota_set( |
| 77 | self.os_adm.credentials.tenant_id, |
| 78 | params={'usage': True})['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 79 | for key in QUOTA_KEYS: |
| 80 | self.assertIn(key, quota_usage) |
| 81 | for usage_key in QUOTA_USAGE_KEYS: |
| 82 | self.assertIn(usage_key, quota_usage[key]) |
| 83 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 84 | @test.idempotent_id('ae8b6091-48ad-4bfa-a188-bbf5cc02115f') |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 85 | def test_quota_usage(self): |
Ken'ichi Ohmichi | 3cf9eaf | 2016-07-29 11:05:21 -0700 | [diff] [blame] | 86 | quota_usage = self.admin_quotas_client.show_quota_set( |
| 87 | self.demo_tenant_id, params={'usage': True})['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 88 | |
Markus Zoeller | 3d2a21c | 2015-02-27 12:04:22 +0100 | [diff] [blame] | 89 | volume = self.create_volume() |
lkuchlan | 9bf9fac | 2016-06-19 15:32:33 +0300 | [diff] [blame] | 90 | self.addCleanup(self.delete_volume, |
| 91 | self.admin_volume_client, volume['id']) |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 92 | |
Ken'ichi Ohmichi | 3cf9eaf | 2016-07-29 11:05:21 -0700 | [diff] [blame] | 93 | new_quota_usage = self.admin_quotas_client.show_quota_set( |
| 94 | self.demo_tenant_id, params={'usage': True})['quota_set'] |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 95 | |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 96 | self.assertEqual(quota_usage['volumes']['in_use'] + 1, |
| 97 | new_quota_usage['volumes']['in_use']) |
| 98 | |
Markus Zoeller | 56cb97c | 2015-03-10 16:06:34 +0100 | [diff] [blame] | 99 | self.assertEqual(quota_usage['gigabytes']['in_use'] + |
| 100 | volume["size"], |
Sylvain Baubeau | fdd3459 | 2014-02-20 18:40:10 +0100 | [diff] [blame] | 101 | new_quota_usage['gigabytes']['in_use']) |
| 102 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 103 | @test.idempotent_id('874b35a9-51f1-4258-bec5-cd561b6690d3') |
nayna-patel | 3d59e4a | 2014-04-24 14:28:38 +0000 | [diff] [blame] | 104 | def test_delete_quota(self): |
Jamie Lennox | 1535017 | 2015-08-17 10:54:25 +1000 | [diff] [blame] | 105 | # Admin can delete the resource quota set for a project |
| 106 | project_name = data_utils.rand_name('quota_tenant') |
| 107 | description = data_utils.rand_name('desc_') |
| 108 | project = self.identity_utils.create_project(project_name, |
| 109 | description=description) |
| 110 | project_id = project['id'] |
| 111 | self.addCleanup(self.identity_utils.delete_project, project_id) |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 112 | quota_set_default = self.admin_quotas_client.show_default_quota_set( |
Jamie Lennox | 1535017 | 2015-08-17 10:54:25 +1000 | [diff] [blame] | 113 | project_id)['quota_set'] |
nayna-patel | 3d59e4a | 2014-04-24 14:28:38 +0000 | [diff] [blame] | 114 | volume_default = quota_set_default['volumes'] |
| 115 | |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 116 | self.admin_quotas_client.update_quota_set( |
| 117 | project_id, volumes=(int(volume_default) + 5)) |
nayna-patel | 3d59e4a | 2014-04-24 14:28:38 +0000 | [diff] [blame] | 118 | |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 119 | self.admin_quotas_client.delete_quota_set(project_id) |
| 120 | quota_set_new = (self.admin_quotas_client.show_quota_set(project_id) |
ghanshyam | 08a73f9 | 2015-08-31 17:32:49 +0900 | [diff] [blame] | 121 | ['quota_set']) |
nayna-patel | 3d59e4a | 2014-04-24 14:28:38 +0000 | [diff] [blame] | 122 | self.assertEqual(volume_default, quota_set_new['volumes']) |
Chandan Kumar | dd23f63 | 2014-11-17 15:27:48 +0530 | [diff] [blame] | 123 | |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 124 | @test.idempotent_id('8911036f-9d54-4720-80cc-a1c9796a8805') |
| 125 | def test_quota_usage_after_volume_transfer(self): |
| 126 | # Create a volume for transfer |
| 127 | volume = self.create_volume() |
lkuchlan | 9bf9fac | 2016-06-19 15:32:33 +0300 | [diff] [blame] | 128 | self.addCleanup(self.delete_volume, |
| 129 | self.admin_volume_client, volume['id']) |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 130 | |
| 131 | # List of tenants quota usage pre-transfer |
Ken'ichi Ohmichi | 3cf9eaf | 2016-07-29 11:05:21 -0700 | [diff] [blame] | 132 | primary_quota = self.admin_quotas_client.show_quota_set( |
| 133 | self.demo_tenant_id, params={'usage': True})['quota_set'] |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 134 | |
Ken'ichi Ohmichi | 3cf9eaf | 2016-07-29 11:05:21 -0700 | [diff] [blame] | 135 | alt_quota = self.admin_quotas_client.show_quota_set( |
| 136 | self.alt_client.tenant_id, params={'usage': True})['quota_set'] |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 137 | |
| 138 | # Creates a volume transfer |
| 139 | transfer = self.volumes_client.create_volume_transfer( |
| 140 | volume_id=volume['id'])['transfer'] |
| 141 | transfer_id = transfer['id'] |
| 142 | auth_key = transfer['auth_key'] |
| 143 | |
| 144 | # Accepts a volume transfer |
| 145 | self.alt_client.accept_volume_transfer( |
| 146 | transfer_id, auth_key=auth_key)['transfer'] |
| 147 | |
| 148 | # Verify volume transferred is available |
| 149 | waiters.wait_for_volume_status( |
| 150 | self.alt_client, volume['id'], 'available') |
| 151 | |
| 152 | # List of tenants quota usage post transfer |
Ken'ichi Ohmichi | 3cf9eaf | 2016-07-29 11:05:21 -0700 | [diff] [blame] | 153 | new_primary_quota = self.admin_quotas_client.show_quota_set( |
| 154 | self.demo_tenant_id, params={'usage': True})['quota_set'] |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 155 | |
Ken'ichi Ohmichi | 3cf9eaf | 2016-07-29 11:05:21 -0700 | [diff] [blame] | 156 | new_alt_quota = self.admin_quotas_client.show_quota_set( |
| 157 | self.alt_client.tenant_id, params={'usage': True})['quota_set'] |
lkuchlan | 77c21af | 2016-04-20 11:31:14 +0300 | [diff] [blame] | 158 | |
| 159 | # Verify tenants quota usage was updated |
| 160 | self.assertEqual(primary_quota['volumes']['in_use'] - |
| 161 | new_primary_quota['volumes']['in_use'], |
| 162 | new_alt_quota['volumes']['in_use'] - |
| 163 | alt_quota['volumes']['in_use']) |
| 164 | |
| 165 | self.assertEqual(alt_quota['gigabytes']['in_use'] + |
| 166 | volume['size'], |
| 167 | new_alt_quota['gigabytes']['in_use']) |
| 168 | |
| 169 | self.assertEqual(primary_quota['gigabytes']['in_use'] - |
| 170 | volume['size'], |
| 171 | new_primary_quota['gigabytes']['in_use']) |
| 172 | |
Chandan Kumar | dd23f63 | 2014-11-17 15:27:48 +0530 | [diff] [blame] | 173 | |
| 174 | class VolumeQuotasAdminV1TestJSON(BaseVolumeQuotasAdminV2TestJSON): |
| 175 | _api_version = 1 |