blob: db2e28188d2120f59258b97a9e9c456683b4d36e [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Rohit Karajgi07599c52012-11-02 05:35:16 -07002# 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 Dague1937d092013-05-17 16:36:38 -040016from tempest.api.compute import base
Matt Riedemann848805f2014-06-16 13:23:51 -070017from tempest.common import tempest_fixtures as fixtures
Yuiko Takadae9999d62014-03-06 09:22:54 +000018from tempest import test
Rohit Karajgi07599c52012-11-02 05:35:16 -070019
20
ivan-zhuf2b00502013-10-18 10:06:52 +080021class QuotasTestJSON(base.BaseV2ComputeTest):
Rohit Karajgi07599c52012-11-02 05:35:16 -070022
Matt Riedemann848805f2014-06-16 13:23:51 -070023 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 Karajgi07599c52012-11-02 05:35:16 -070028 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010029 def resource_setup(cls):
30 super(QuotasTestJSON, cls).resource_setup()
Rohit Karajgi07599c52012-11-02 05:35:16 -070031 cls.client = cls.quotas_client
Andrea Frittoli9612e812014-03-13 10:57:26 +000032 cls.tenant_id = cls.client.tenant_id
33 cls.user_id = cls.client.user_id
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020034 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 Toyoda87a52b72013-04-09 10:34:40 +090041
Yuiko Takadae9999d62014-03-06 09:22:54 +000042 @test.attr(type='smoke')
Leo Toyoda87a52b72013-04-09 10:34:40 +090043 def test_get_quotas(self):
44 # User can get the quota set for it's tenant
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020045 expected_quota_set = self.default_quota_set | set(['id'])
David Kranz3e4c28b2015-02-09 12:35:18 -050046 quota_set = self.client.get_quota_set(self.tenant_id)
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020047 self.assertEqual(quota_set['id'], self.tenant_id)
Ken'ichi Ohmichi1c2a03c2014-08-07 04:59:32 +000048 for quota in expected_quota_set:
49 self.assertIn(quota, quota_set.keys())
Rohit Karajgi07599c52012-11-02 05:35:16 -070050
Zhi Kun Liu90e41312014-03-06 14:56:01 +080051 # get the quota set using user id
David Kranz3e4c28b2015-02-09 12:35:18 -050052 quota_set = self.client.get_quota_set(self.tenant_id,
53 self.user_id)
Zhi Kun Liu90e41312014-03-06 14:56:01 +080054 self.assertEqual(quota_set['id'], self.tenant_id)
Ken'ichi Ohmichi1c2a03c2014-08-07 04:59:32 +000055 for quota in expected_quota_set:
56 self.assertIn(quota, quota_set.keys())
Zhi Kun Liu90e41312014-03-06 14:56:01 +080057
Yuiko Takadae9999d62014-03-06 09:22:54 +000058 @test.attr(type='smoke')
Rohit Karajgi07599c52012-11-02 05:35:16 -070059 def test_get_default_quotas(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050060 # User can get the default quota set for it's tenant
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020061 expected_quota_set = self.default_quota_set | set(['id'])
David Kranz3e4c28b2015-02-09 12:35:18 -050062 quota_set = self.client.get_default_quota_set(self.tenant_id)
Attila Fazekasd9aef1e2013-07-13 17:33:45 +020063 self.assertEqual(quota_set['id'], self.tenant_id)
Ken'ichi Ohmichi1c2a03c2014-08-07 04:59:32 +000064 for quota in expected_quota_set:
65 self.assertIn(quota, quota_set.keys())
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053066
Yuiko Takadae9999d62014-03-06 09:22:54 +000067 @test.attr(type='smoke')
Daniel Korn6653c4e2013-10-28 10:51:23 +020068 def test_compare_tenant_quotas_with_default_quotas(self):
69 # Tenants are created with the default quota values
David Kranz3e4c28b2015-02-09 12:35:18 -050070 defualt_quota_set = \
Daniel Korn6653c4e2013-10-28 10:51:23 +020071 self.client.get_default_quota_set(self.tenant_id)
David Kranz3e4c28b2015-02-09 12:35:18 -050072 tenant_quota_set = self.client.get_quota_set(self.tenant_id)
Daniel Korn6653c4e2013-10-28 10:51:23 +020073 self.assertEqual(defualt_quota_set, tenant_quota_set)