blob: 8184a46c20243253b40298639ff527a585700dc2 [file] [log] [blame]
Kenji Yasui1c695ee2015-07-15 08:10:19 +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
Kenji Yasui1c695ee2015-07-15 08:10:19 +000015from tempest.services.compute.json import aggregates_client
Kenji Yasui1c695ee2015-07-15 08:10:19 +000016from tempest.tests import fake_auth_provider
Marc Kodererdb19acd2015-09-03 16:03:58 +020017from tempest.tests.services.compute import base
Kenji Yasui1c695ee2015-07-15 08:10:19 +000018
19
Marc Kodererdb19acd2015-09-03 16:03:58 +020020class 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 Yasui1c695ee2015-07-15 08:10:19 +000064
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 Kodererdb19acd2015-09-03 16:03:58 +020072 self.check_service_client_function(
73 self.client.list_aggregates,
Kenji Yasui1c695ee2015-07-15 08:10:19 +000074 'tempest.common.service_client.ServiceClient.get',
Marc Kodererdb19acd2015-09-03 16:03:58 +020075 {"aggregates": []},
76 bytes_body)
Kenji Yasui1c695ee2015-07-15 08:10:19 +000077
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 Yasuic03e13b2015-08-03 05:47:42 +000083
84 def _test_show_aggregate(self, bytes_body=False):
Marc Kodererdb19acd2015-09-03 16:03:58 +020085 self.check_service_client_function(
86 self.client.show_aggregate,
Kenji Yasuic03e13b2015-08-03 05:47:42 +000087 'tempest.common.service_client.ServiceClient.get',
Marc Kodererdb19acd2015-09-03 16:03:58 +020088 self.FAKE_SHOW_AGGREGATE,
89 bytes_body,
90 aggregate_id=1)
Kenji Yasuic03e13b2015-08-03 05:47:42 +000091
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 Kodererdb19acd2015-09-03 16:03:58 +020099 self.check_service_client_function(
100 self.client.create_aggregate,
Kenji Yasuic03e13b2015-08-03 05:47:42 +0000101 'tempest.common.service_client.ServiceClient.post',
Marc Kodererdb19acd2015-09-03 16:03:58 +0200102 self.FAKE_CREATE_AGGREGATE,
103 bytes_body,
104 name='hoge')
Kenji Yasuic03e13b2015-08-03 05:47:42 +0000105
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 Raminenic254c7a2015-09-07 15:32:23 +0530113 self.check_service_client_function(
114 self.client.delete_aggregate,
Kenji Yasuic03e13b2015-08-03 05:47:42 +0000115 'tempest.common.service_client.ServiceClient.delete',
Anusha Raminenic254c7a2015-09-07 15:32:23 +0530116 {}, aggregate_id="1")
Kenji Yasuic03e13b2015-08-03 05:47:42 +0000117
118 def _test_update_aggregate(self, bytes_body=False):
Marc Kodererdb19acd2015-09-03 16:03:58 +0200119 self.check_service_client_function(
120 self.client.update_aggregate,
Kenji Yasuic03e13b2015-08-03 05:47:42 +0000121 'tempest.common.service_client.ServiceClient.put',
Marc Kodererdb19acd2015-09-03 16:03:58 +0200122 self.FAKE_UPDATE_AGGREGATE,
123 bytes_body,
124 aggregate_id=1)
Kenji Yasuic03e13b2015-08-03 05:47:42 +0000125
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)