ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 16 | from tempest.api.compute import base |
Matt Riedemann | 848805f | 2014-06-16 13:23:51 -0700 | [diff] [blame] | 17 | from tempest.common import tempest_fixtures as fixtures |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 18 | from tempest import test |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 19 | |
| 20 | |
ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 21 | class QuotasTestJSON(base.BaseV2ComputeTest): |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 22 | |
Matt Riedemann | 848805f | 2014-06-16 13:23:51 -0700 | [diff] [blame] | 23 | def setUp(self): |
| 24 | # NOTE(mriedem): Avoid conflicts with os-quota-class-sets tests. |
| 25 | self.useFixture(fixtures.LockFixture('compute_quotas')) |
| 26 | super(QuotasTestJSON, self).setUp() |
| 27 | |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 28 | @classmethod |
Andrea Frittoli | 50bb80d | 2014-09-15 12:34:27 +0100 | [diff] [blame] | 29 | def resource_setup(cls): |
| 30 | super(QuotasTestJSON, cls).resource_setup() |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 31 | cls.client = cls.quotas_client |
Andrea Frittoli | 9612e81 | 2014-03-13 10:57:26 +0000 | [diff] [blame] | 32 | cls.tenant_id = cls.client.tenant_id |
| 33 | cls.user_id = cls.client.user_id |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 34 | cls.default_quota_set = set(('injected_file_content_bytes', |
| 35 | 'metadata_items', 'injected_files', |
| 36 | 'ram', 'floating_ips', |
| 37 | 'fixed_ips', 'key_pairs', |
| 38 | 'injected_file_path_bytes', |
| 39 | 'instances', 'security_group_rules', |
| 40 | 'cores', 'security_groups')) |
Leo Toyoda | 87a52b7 | 2013-04-09 10:34:40 +0900 | [diff] [blame] | 41 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 42 | @test.attr(type='smoke') |
Leo Toyoda | 87a52b7 | 2013-04-09 10:34:40 +0900 | [diff] [blame] | 43 | def test_get_quotas(self): |
| 44 | # User can get the quota set for it's tenant |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 45 | expected_quota_set = self.default_quota_set | set(['id']) |
David Kranz | 3e4c28b | 2015-02-09 12:35:18 -0500 | [diff] [blame] | 46 | quota_set = self.client.get_quota_set(self.tenant_id) |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 47 | self.assertEqual(quota_set['id'], self.tenant_id) |
Ken'ichi Ohmichi | 1c2a03c | 2014-08-07 04:59:32 +0000 | [diff] [blame] | 48 | for quota in expected_quota_set: |
| 49 | self.assertIn(quota, quota_set.keys()) |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 50 | |
Zhi Kun Liu | 90e4131 | 2014-03-06 14:56:01 +0800 | [diff] [blame] | 51 | # get the quota set using user id |
David Kranz | 3e4c28b | 2015-02-09 12:35:18 -0500 | [diff] [blame] | 52 | quota_set = self.client.get_quota_set(self.tenant_id, |
| 53 | self.user_id) |
Zhi Kun Liu | 90e4131 | 2014-03-06 14:56:01 +0800 | [diff] [blame] | 54 | self.assertEqual(quota_set['id'], self.tenant_id) |
Ken'ichi Ohmichi | 1c2a03c | 2014-08-07 04:59:32 +0000 | [diff] [blame] | 55 | for quota in expected_quota_set: |
| 56 | self.assertIn(quota, quota_set.keys()) |
Zhi Kun Liu | 90e4131 | 2014-03-06 14:56:01 +0800 | [diff] [blame] | 57 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 58 | @test.attr(type='smoke') |
Rohit Karajgi | 07599c5 | 2012-11-02 05:35:16 -0700 | [diff] [blame] | 59 | def test_get_default_quotas(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 60 | # User can get the default quota set for it's tenant |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 61 | expected_quota_set = self.default_quota_set | set(['id']) |
David Kranz | 3e4c28b | 2015-02-09 12:35:18 -0500 | [diff] [blame] | 62 | quota_set = self.client.get_default_quota_set(self.tenant_id) |
Attila Fazekas | d9aef1e | 2013-07-13 17:33:45 +0200 | [diff] [blame] | 63 | self.assertEqual(quota_set['id'], self.tenant_id) |
Ken'ichi Ohmichi | 1c2a03c | 2014-08-07 04:59:32 +0000 | [diff] [blame] | 64 | for quota in expected_quota_set: |
| 65 | self.assertIn(quota, quota_set.keys()) |
rajalakshmi-ganesan | 1982c3c | 2013-01-10 14:56:45 +0530 | [diff] [blame] | 66 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 67 | @test.attr(type='smoke') |
Daniel Korn | 6653c4e | 2013-10-28 10:51:23 +0200 | [diff] [blame] | 68 | def test_compare_tenant_quotas_with_default_quotas(self): |
| 69 | # Tenants are created with the default quota values |
David Kranz | 3e4c28b | 2015-02-09 12:35:18 -0500 | [diff] [blame] | 70 | defualt_quota_set = \ |
Daniel Korn | 6653c4e | 2013-10-28 10:51:23 +0200 | [diff] [blame] | 71 | self.client.get_default_quota_set(self.tenant_id) |
David Kranz | 3e4c28b | 2015-02-09 12:35:18 -0500 | [diff] [blame] | 72 | tenant_quota_set = self.client.get_quota_set(self.tenant_id) |
Daniel Korn | 6653c4e | 2013-10-28 10:51:23 +0200 | [diff] [blame] | 73 | self.assertEqual(defualt_quota_set, tenant_quota_set) |