Kenji Yasui | 1c695ee | 2015-07-15 08:10:19 +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 | |
Kenji Yasui | 1c695ee | 2015-07-15 08:10:19 +0000 | [diff] [blame] | 15 | from tempest.services.compute.json import aggregates_client |
Kenji Yasui | 1c695ee | 2015-07-15 08:10:19 +0000 | [diff] [blame] | 16 | from tempest.tests import fake_auth_provider |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 17 | from tempest.tests.services.compute import base |
Kenji Yasui | 1c695ee | 2015-07-15 08:10:19 +0000 | [diff] [blame] | 18 | |
| 19 | |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 20 | class TestAggregatesClient(base.BaseComputeServiceTest): |
| 21 | FAKE_SHOW_AGGREGATE = { |
| 22 | "aggregate": |
| 23 | { |
| 24 | "name": "hoge", |
| 25 | "availability_zone": None, |
| 26 | "deleted": False, |
| 27 | "created_at": |
| 28 | "2015-07-16T03:07:32.000000", |
| 29 | "updated_at": None, |
| 30 | "hosts": [], |
| 31 | "deleted_at": None, |
| 32 | "id": 1, |
| 33 | "metadata": {} |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | FAKE_CREATE_AGGREGATE = { |
| 38 | "aggregate": |
| 39 | { |
| 40 | "name": u'\xf4', |
| 41 | "availability_zone": None, |
| 42 | "deleted": False, |
| 43 | "created_at": "2015-07-21T04:11:18.000000", |
| 44 | "updated_at": None, |
| 45 | "deleted_at": None, |
| 46 | "id": 1 |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | FAKE_UPDATE_AGGREGATE = { |
| 51 | "aggregate": |
| 52 | { |
| 53 | "name": u'\xe9', |
| 54 | "availability_zone": None, |
| 55 | "deleted": False, |
| 56 | "created_at": "2015-07-16T03:07:32.000000", |
| 57 | "updated_at": "2015-07-23T05:16:29.000000", |
| 58 | "hosts": [], |
| 59 | "deleted_at": None, |
| 60 | "id": 1, |
| 61 | "metadata": {} |
| 62 | } |
| 63 | } |
Kenji Yasui | 1c695ee | 2015-07-15 08:10:19 +0000 | [diff] [blame] | 64 | |
| 65 | def setUp(self): |
| 66 | super(TestAggregatesClient, self).setUp() |
| 67 | fake_auth = fake_auth_provider.FakeAuthProvider() |
| 68 | self.client = aggregates_client.AggregatesClient( |
| 69 | fake_auth, 'compute', 'regionOne') |
| 70 | |
| 71 | def _test_list_aggregates(self, bytes_body=False): |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 72 | self.check_service_client_function( |
| 73 | self.client.list_aggregates, |
Kenji Yasui | 1c695ee | 2015-07-15 08:10:19 +0000 | [diff] [blame] | 74 | 'tempest.common.service_client.ServiceClient.get', |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 75 | {"aggregates": []}, |
| 76 | bytes_body) |
Kenji Yasui | 1c695ee | 2015-07-15 08:10:19 +0000 | [diff] [blame] | 77 | |
| 78 | def test_list_aggregates_with_str_body(self): |
| 79 | self._test_list_aggregates() |
| 80 | |
| 81 | def test_list_aggregates_with_bytes_body(self): |
| 82 | self._test_list_aggregates(bytes_body=True) |
Kenji Yasui | c03e13b | 2015-08-03 05:47:42 +0000 | [diff] [blame] | 83 | |
| 84 | def _test_show_aggregate(self, bytes_body=False): |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 85 | self.check_service_client_function( |
| 86 | self.client.show_aggregate, |
Kenji Yasui | c03e13b | 2015-08-03 05:47:42 +0000 | [diff] [blame] | 87 | 'tempest.common.service_client.ServiceClient.get', |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 88 | self.FAKE_SHOW_AGGREGATE, |
| 89 | bytes_body, |
| 90 | aggregate_id=1) |
Kenji Yasui | c03e13b | 2015-08-03 05:47:42 +0000 | [diff] [blame] | 91 | |
| 92 | def test_show_aggregate_with_str_body(self): |
| 93 | self._test_show_aggregate() |
| 94 | |
| 95 | def test_show_aggregate_with_bytes_body(self): |
| 96 | self._test_show_aggregate(bytes_body=True) |
| 97 | |
| 98 | def _test_create_aggregate(self, bytes_body=False): |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 99 | self.check_service_client_function( |
| 100 | self.client.create_aggregate, |
Kenji Yasui | c03e13b | 2015-08-03 05:47:42 +0000 | [diff] [blame] | 101 | 'tempest.common.service_client.ServiceClient.post', |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 102 | self.FAKE_CREATE_AGGREGATE, |
| 103 | bytes_body, |
| 104 | name='hoge') |
Kenji Yasui | c03e13b | 2015-08-03 05:47:42 +0000 | [diff] [blame] | 105 | |
| 106 | def test_create_aggregate_with_str_body(self): |
| 107 | self._test_create_aggregate() |
| 108 | |
| 109 | def test_create_aggregate_with_bytes_body(self): |
| 110 | self._test_create_aggregate(bytes_body=True) |
| 111 | |
| 112 | def test_delete_aggregate(self): |
Anusha Ramineni | c254c7a | 2015-09-07 15:32:23 +0530 | [diff] [blame] | 113 | self.check_service_client_function( |
| 114 | self.client.delete_aggregate, |
Kenji Yasui | c03e13b | 2015-08-03 05:47:42 +0000 | [diff] [blame] | 115 | 'tempest.common.service_client.ServiceClient.delete', |
Anusha Ramineni | c254c7a | 2015-09-07 15:32:23 +0530 | [diff] [blame] | 116 | {}, aggregate_id="1") |
Kenji Yasui | c03e13b | 2015-08-03 05:47:42 +0000 | [diff] [blame] | 117 | |
| 118 | def _test_update_aggregate(self, bytes_body=False): |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 119 | self.check_service_client_function( |
| 120 | self.client.update_aggregate, |
Kenji Yasui | c03e13b | 2015-08-03 05:47:42 +0000 | [diff] [blame] | 121 | 'tempest.common.service_client.ServiceClient.put', |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 122 | self.FAKE_UPDATE_AGGREGATE, |
| 123 | bytes_body, |
| 124 | aggregate_id=1) |
Kenji Yasui | c03e13b | 2015-08-03 05:47:42 +0000 | [diff] [blame] | 125 | |
| 126 | def test_update_aggregate_with_str_body(self): |
| 127 | self._test_update_aggregate() |
| 128 | |
| 129 | def test_update_aggregate_with_bytes_body(self): |
| 130 | self._test_update_aggregate(bytes_body=True) |