Kenji Yasui | 3f73184 | 2015-08-03 06:18:15 +0000 | [diff] [blame] | 1 | # 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 | |
| 15 | import copy |
| 16 | import httplib2 |
| 17 | |
Kenji Yasui | 3f73184 | 2015-08-03 06:18:15 +0000 | [diff] [blame] | 18 | from oslotest import mockpatch |
| 19 | |
| 20 | from tempest.services.compute.json import quotas_client |
Kenji Yasui | 3f73184 | 2015-08-03 06:18:15 +0000 | [diff] [blame] | 21 | from tempest.tests import fake_auth_provider |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 22 | from tempest.tests.services.compute import base |
Kenji Yasui | 3f73184 | 2015-08-03 06:18:15 +0000 | [diff] [blame] | 23 | |
| 24 | |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 25 | class TestQuotasClient(base.BaseComputeServiceTest): |
Kenji Yasui | 3f73184 | 2015-08-03 06:18:15 +0000 | [diff] [blame] | 26 | |
ghanshyam | 5265787 | 2015-08-24 16:39:10 +0900 | [diff] [blame] | 27 | 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 Yasui | 3f73184 | 2015-08-03 06:18:15 +0000 | [diff] [blame] | 45 | |
| 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 Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 55 | self.check_service_client_function( |
| 56 | self.client.show_quota_set, |
Kenji Yasui | 3f73184 | 2015-08-03 06:18:15 +0000 | [diff] [blame] | 57 | 'tempest.common.service_client.ServiceClient.get', |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 58 | self.FAKE_QUOTA_SET, |
| 59 | to_utf=bytes_body, |
| 60 | tenant_id=self.project_id) |
Kenji Yasui | 3f73184 | 2015-08-03 06:18:15 +0000 | [diff] [blame] | 61 | |
| 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 Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 69 | self.check_service_client_function( |
| 70 | self.client.show_default_quota_set, |
Kenji Yasui | 3f73184 | 2015-08-03 06:18:15 +0000 | [diff] [blame] | 71 | 'tempest.common.service_client.ServiceClient.get', |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 72 | self.FAKE_QUOTA_SET, |
| 73 | to_utf=bytes_body, |
| 74 | tenant_id=self.project_id) |
Kenji Yasui | 3f73184 | 2015-08-03 06:18:15 +0000 | [diff] [blame] | 75 | |
| 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) |
ghanshyam | 5265787 | 2015-08-24 16:39:10 +0900 | [diff] [blame] | 84 | fake_quota_set['quota_set'].pop("id") |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 85 | self.check_service_client_function( |
| 86 | self.client.update_quota_set, |
Kenji Yasui | 3f73184 | 2015-08-03 06:18:15 +0000 | [diff] [blame] | 87 | 'tempest.common.service_client.ServiceClient.put', |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 88 | fake_quota_set, |
| 89 | tenant_id=self.project_id) |
Kenji Yasui | 3f73184 | 2015-08-03 06:18:15 +0000 | [diff] [blame] | 90 | |
| 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) |