blob: e2e6546baa6dedadcb615ee21187f0b882dd0b74 [file] [log] [blame]
Kenji Yasui3f731842015-08-03 06:18:15 +00001# Copyright 2015 NEC Corporation. All rights reserved.
2#
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
15import copy
16import httplib2
17
Kenji Yasui3f731842015-08-03 06:18:15 +000018from oslotest import mockpatch
19
20from tempest.services.compute.json import quotas_client
Kenji Yasui3f731842015-08-03 06:18:15 +000021from tempest.tests import fake_auth_provider
Marc Kodererdb19acd2015-09-03 16:03:58 +020022from tempest.tests.services.compute import base
Kenji Yasui3f731842015-08-03 06:18:15 +000023
24
Marc Kodererdb19acd2015-09-03 16:03:58 +020025class TestQuotasClient(base.BaseComputeServiceTest):
Kenji Yasui3f731842015-08-03 06:18:15 +000026
ghanshyam52657872015-08-24 16:39:10 +090027 FAKE_QUOTA_SET = {
28 "quota_set": {
29 "injected_file_content_bytes": 10240,
30 "metadata_items": 128,
31 "server_group_members": 10,
32 "server_groups": 10,
33 "ram": 51200,
34 "floating_ips": 10,
35 "key_pairs": 100,
36 "id": "8421f7be61064f50b680465c07f334af",
37 "instances": 10,
38 "security_group_rules": 20,
39 "injected_files": 5,
40 "cores": 20,
41 "fixed_ips": -1,
42 "injected_file_path_bytes": 255,
43 "security_groups": 10}
44 }
Kenji Yasui3f731842015-08-03 06:18:15 +000045
46 project_id = "8421f7be61064f50b680465c07f334af"
47
48 def setUp(self):
49 super(TestQuotasClient, self).setUp()
50 fake_auth = fake_auth_provider.FakeAuthProvider()
51 self.client = quotas_client.QuotasClient(
52 fake_auth, 'compute', 'regionOne')
53
54 def _test_show_quota_set(self, bytes_body=False):
Marc Kodererdb19acd2015-09-03 16:03:58 +020055 self.check_service_client_function(
56 self.client.show_quota_set,
Kenji Yasui3f731842015-08-03 06:18:15 +000057 'tempest.common.service_client.ServiceClient.get',
Marc Kodererdb19acd2015-09-03 16:03:58 +020058 self.FAKE_QUOTA_SET,
59 to_utf=bytes_body,
60 tenant_id=self.project_id)
Kenji Yasui3f731842015-08-03 06:18:15 +000061
62 def test_show_quota_set_with_str_body(self):
63 self._test_show_quota_set()
64
65 def test_show_quota_set_with_bytes_body(self):
66 self._test_show_quota_set(bytes_body=True)
67
68 def _test_show_default_quota_set(self, bytes_body=False):
Marc Kodererdb19acd2015-09-03 16:03:58 +020069 self.check_service_client_function(
70 self.client.show_default_quota_set,
Kenji Yasui3f731842015-08-03 06:18:15 +000071 'tempest.common.service_client.ServiceClient.get',
Marc Kodererdb19acd2015-09-03 16:03:58 +020072 self.FAKE_QUOTA_SET,
73 to_utf=bytes_body,
74 tenant_id=self.project_id)
Kenji Yasui3f731842015-08-03 06:18:15 +000075
76 def test_show_default_quota_set_with_str_body(self):
77 self._test_show_quota_set()
78
79 def test_show_default_quota_set_with_bytes_body(self):
80 self._test_show_quota_set(bytes_body=True)
81
82 def test_update_quota_set(self):
83 fake_quota_set = copy.deepcopy(self.FAKE_QUOTA_SET)
ghanshyam52657872015-08-24 16:39:10 +090084 fake_quota_set['quota_set'].pop("id")
Marc Kodererdb19acd2015-09-03 16:03:58 +020085 self.check_service_client_function(
86 self.client.update_quota_set,
Kenji Yasui3f731842015-08-03 06:18:15 +000087 'tempest.common.service_client.ServiceClient.put',
Marc Kodererdb19acd2015-09-03 16:03:58 +020088 fake_quota_set,
89 tenant_id=self.project_id)
Kenji Yasui3f731842015-08-03 06:18:15 +000090
91 def test_delete_quota_set(self):
92 expected = {}
93 mocked_resp = (httplib2.Response({'status': 202}), None)
94 self.useFixture(mockpatch.Patch(
95 'tempest.common.service_client.ServiceClient.delete',
96 return_value=mocked_resp))
97 resp = self.client.delete_quota_set(self.project_id)
98 self.assertEqual(expected, resp)