blob: e3b01517a4de012b5e115c432ed9b6b89a7a9929 [file] [log] [blame]
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +09001# Copyright 2013 NEC Corporation.
2# 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
Masayuki Igawabfa07602015-01-20 18:47:17 +090016from tempest_lib import exceptions as lib_exc
17
Sean Dague1937d092013-05-17 16:36:38 -040018from tempest.api.compute import base
Matthew Treinisha03ed792013-09-23 21:38:15 +000019from tempest.common import tempest_fixtures as fixtures
Masayuki Igawa259c1132013-10-31 17:48:44 +090020from tempest.common.utils import data_utils
Masayuki Igawa394d8d92014-03-04 17:21:56 +090021from tempest import test
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090022
23
ivan-zhuf2b00502013-10-18 10:06:52 +080024class AggregatesAdminTestJSON(base.BaseV2ComputeAdminTest):
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090025
26 """
27 Tests Aggregates API that require admin privileges
28 """
29
Mitsuhiko Yamazakiae8fc532013-04-22 11:17:35 +090030 _host_key = 'OS-EXT-SRV-ATTR:host'
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090031
32 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010033 def resource_setup(cls):
34 super(AggregatesAdminTestJSON, cls).resource_setup()
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090035 cls.client = cls.os_adm.aggregates_client
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090036 cls.aggregate_name_prefix = 'test_aggregate_'
37 cls.az_name_prefix = 'test_az_'
38
David Kranz0a735172015-01-16 10:51:18 -050039 hosts_all = cls.os_adm.hosts_client.list_hosts()
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090040 hosts = map(lambda x: x['host_name'],
41 filter(lambda y: y['service'] == 'compute', hosts_all))
42 cls.host = hosts[0]
43
anju Tiwari0599f522014-04-17 17:10:40 +053044 def _try_delete_aggregate(self, aggregate_id):
45 # delete aggregate, if it exists
46 try:
47 self.client.delete_aggregate(aggregate_id)
48 # if aggregate not found, it depict it was deleted in the test
Masayuki Igawabfa07602015-01-20 18:47:17 +090049 except lib_exc.NotFound:
anju Tiwari0599f522014-04-17 17:10:40 +053050 pass
51
Masayuki Igawa394d8d92014-03-04 17:21:56 +090052 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -080053 @test.idempotent_id('0d148aa3-d54c-4317-aa8d-42040a475e20')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090054 def test_aggregate_create_delete(self):
55 # Create and delete an aggregate.
Masayuki Igawa259c1132013-10-31 17:48:44 +090056 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -050057 aggregate = self.client.create_aggregate(name=aggregate_name)
anju Tiwari0599f522014-04-17 17:10:40 +053058 self.addCleanup(self._try_delete_aggregate, aggregate['id'])
Chang Bo Guofc77e932013-09-16 17:38:26 -070059 self.assertEqual(aggregate_name, aggregate['name'])
llg8212e4cd3922014-02-15 12:14:21 +080060 self.assertIsNone(aggregate['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090061
David Kranz0a735172015-01-16 10:51:18 -050062 self.client.delete_aggregate(aggregate['id'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090063 self.client.wait_for_resource_deletion(aggregate['id'])
64
Masayuki Igawa394d8d92014-03-04 17:21:56 +090065 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -080066 @test.idempotent_id('5873a6f8-671a-43ff-8838-7ce430bb6d0b')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090067 def test_aggregate_create_delete_with_az(self):
68 # Create and delete an aggregate.
Masayuki Igawa259c1132013-10-31 17:48:44 +090069 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
70 az_name = data_utils.rand_name(self.az_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -050071 aggregate = self.client.create_aggregate(
Yuiko Takadaf93d2482014-01-30 16:25:08 +000072 name=aggregate_name, availability_zone=az_name)
anju Tiwari0599f522014-04-17 17:10:40 +053073 self.addCleanup(self._try_delete_aggregate, aggregate['id'])
Chang Bo Guofc77e932013-09-16 17:38:26 -070074 self.assertEqual(aggregate_name, aggregate['name'])
75 self.assertEqual(az_name, aggregate['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090076
David Kranz0a735172015-01-16 10:51:18 -050077 self.client.delete_aggregate(aggregate['id'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090078 self.client.wait_for_resource_deletion(aggregate['id'])
79
Masayuki Igawa394d8d92014-03-04 17:21:56 +090080 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -080081 @test.idempotent_id('68089c38-04b1-4758-bdf0-cf0daec4defd')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090082 def test_aggregate_create_verify_entry_in_list(self):
83 # Create an aggregate and ensure it is listed.
Masayuki Igawa259c1132013-10-31 17:48:44 +090084 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -050085 aggregate = self.client.create_aggregate(name=aggregate_name)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090086 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
87
David Kranz0a735172015-01-16 10:51:18 -050088 aggregates = self.client.list_aggregates()
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090089 self.assertIn((aggregate['id'], aggregate['availability_zone']),
90 map(lambda x: (x['id'], x['availability_zone']),
91 aggregates))
92
Masayuki Igawa394d8d92014-03-04 17:21:56 +090093 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -080094 @test.idempotent_id('36ec92ca-7a73-43bc-b920-7531809e8540')
ivan-zhu35e1f8e2013-10-18 15:51:16 +080095 def test_aggregate_create_update_metadata_get_details(self):
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090096 # Create an aggregate and ensure its details are returned.
Masayuki Igawa259c1132013-10-31 17:48:44 +090097 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -050098 aggregate = self.client.create_aggregate(name=aggregate_name)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090099 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
100
David Kranz0a735172015-01-16 10:51:18 -0500101 body = self.client.get_aggregate(aggregate['id'])
Chang Bo Guofc77e932013-09-16 17:38:26 -0700102 self.assertEqual(aggregate['name'], body['name'])
103 self.assertEqual(aggregate['availability_zone'],
104 body['availability_zone'])
ivan-zhu35e1f8e2013-10-18 15:51:16 +0800105 self.assertEqual({}, body["metadata"])
106
107 # set the metadata of the aggregate
108 meta = {"key": "value"}
David Kranz0a735172015-01-16 10:51:18 -0500109 body = self.client.set_metadata(aggregate['id'], meta)
ivan-zhu35e1f8e2013-10-18 15:51:16 +0800110 self.assertEqual(meta, body["metadata"])
111
112 # verify the metadata has been set
David Kranz0a735172015-01-16 10:51:18 -0500113 body = self.client.get_aggregate(aggregate['id'])
ivan-zhu35e1f8e2013-10-18 15:51:16 +0800114 self.assertEqual(meta, body["metadata"])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900115
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900116 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800117 @test.idempotent_id('4d2b2004-40fa-40a1-aab2-66f4dab81beb')
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800118 def test_aggregate_create_update_with_az(self):
119 # Update an aggregate and ensure properties are updated correctly
Masayuki Igawa259c1132013-10-31 17:48:44 +0900120 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
121 az_name = data_utils.rand_name(self.az_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -0500122 aggregate = self.client.create_aggregate(
Yuiko Takadaf93d2482014-01-30 16:25:08 +0000123 name=aggregate_name, availability_zone=az_name)
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800124 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
125
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800126 self.assertEqual(aggregate_name, aggregate['name'])
127 self.assertEqual(az_name, aggregate['availability_zone'])
128 self.assertIsNotNone(aggregate['id'])
129
130 aggregate_id = aggregate['id']
131 new_aggregate_name = aggregate_name + '_new'
132 new_az_name = az_name + '_new'
133
David Kranz0a735172015-01-16 10:51:18 -0500134 resp_aggregate = self.client.update_aggregate(aggregate_id,
135 new_aggregate_name,
136 new_az_name)
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800137 self.assertEqual(new_aggregate_name, resp_aggregate['name'])
138 self.assertEqual(new_az_name, resp_aggregate['availability_zone'])
139
David Kranz0a735172015-01-16 10:51:18 -0500140 aggregates = self.client.list_aggregates()
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800141 self.assertIn((aggregate_id, new_aggregate_name, new_az_name),
142 map(lambda x:
Matthew Treinish1d14c542014-06-17 20:25:40 -0400143 (x['id'], x['name'], x['availability_zone']),
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800144 aggregates))
145
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900146 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800147 @test.idempotent_id('c8e85064-e79b-4906-9931-c11c24294d02')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900148 def test_aggregate_add_remove_host(self):
149 # Add an host to the given aggregate and remove.
Matthew Treinisha03ed792013-09-23 21:38:15 +0000150 self.useFixture(fixtures.LockFixture('availability_zone'))
Masayuki Igawa259c1132013-10-31 17:48:44 +0900151 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -0500152 aggregate = self.client.create_aggregate(name=aggregate_name)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900153 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
154
David Kranz0a735172015-01-16 10:51:18 -0500155 body = self.client.add_host(aggregate['id'], self.host)
Chang Bo Guofc77e932013-09-16 17:38:26 -0700156 self.assertEqual(aggregate_name, body['name'])
157 self.assertEqual(aggregate['availability_zone'],
158 body['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900159 self.assertIn(self.host, body['hosts'])
160
David Kranz0a735172015-01-16 10:51:18 -0500161 body = self.client.remove_host(aggregate['id'], self.host)
Chang Bo Guofc77e932013-09-16 17:38:26 -0700162 self.assertEqual(aggregate_name, body['name'])
163 self.assertEqual(aggregate['availability_zone'],
164 body['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900165 self.assertNotIn(self.host, body['hosts'])
166
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900167 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800168 @test.idempotent_id('7f6a1cc5-2446-4cdb-9baa-b6ae0a919b72')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900169 def test_aggregate_add_host_list(self):
170 # Add an host to the given aggregate and list.
Matthew Treinisha03ed792013-09-23 21:38:15 +0000171 self.useFixture(fixtures.LockFixture('availability_zone'))
Masayuki Igawa259c1132013-10-31 17:48:44 +0900172 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -0500173 aggregate = self.client.create_aggregate(name=aggregate_name)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900174 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
175 self.client.add_host(aggregate['id'], self.host)
176 self.addCleanup(self.client.remove_host, aggregate['id'], self.host)
177
David Kranz0a735172015-01-16 10:51:18 -0500178 aggregates = self.client.list_aggregates()
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900179 aggs = filter(lambda x: x['id'] == aggregate['id'], aggregates)
Chang Bo Guofc77e932013-09-16 17:38:26 -0700180 self.assertEqual(1, len(aggs))
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900181 agg = aggs[0]
Chang Bo Guofc77e932013-09-16 17:38:26 -0700182 self.assertEqual(aggregate_name, agg['name'])
llg8212e4cd3922014-02-15 12:14:21 +0800183 self.assertIsNone(agg['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900184 self.assertIn(self.host, agg['hosts'])
185
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900186 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800187 @test.idempotent_id('eeef473c-7c52-494d-9f09-2ed7fc8fc036')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900188 def test_aggregate_add_host_get_details(self):
189 # Add an host to the given aggregate and get details.
Matthew Treinisha03ed792013-09-23 21:38:15 +0000190 self.useFixture(fixtures.LockFixture('availability_zone'))
Masayuki Igawa259c1132013-10-31 17:48:44 +0900191 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -0500192 aggregate = self.client.create_aggregate(name=aggregate_name)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900193 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
194 self.client.add_host(aggregate['id'], self.host)
195 self.addCleanup(self.client.remove_host, aggregate['id'], self.host)
196
David Kranz0a735172015-01-16 10:51:18 -0500197 body = self.client.get_aggregate(aggregate['id'])
Chang Bo Guofc77e932013-09-16 17:38:26 -0700198 self.assertEqual(aggregate_name, body['name'])
llg8212e4cd3922014-02-15 12:14:21 +0800199 self.assertIsNone(body['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900200 self.assertIn(self.host, body['hosts'])
201
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900202 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800203 @test.idempotent_id('96be03c7-570d-409c-90f8-e4db3c646996')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900204 def test_aggregate_add_host_create_server_with_az(self):
205 # Add an host to the given aggregate and create a server.
Matthew Treinisha03ed792013-09-23 21:38:15 +0000206 self.useFixture(fixtures.LockFixture('availability_zone'))
Masayuki Igawa259c1132013-10-31 17:48:44 +0900207 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
208 az_name = data_utils.rand_name(self.az_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -0500209 aggregate = self.client.create_aggregate(
Yuiko Takadaf93d2482014-01-30 16:25:08 +0000210 name=aggregate_name, availability_zone=az_name)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900211 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
212 self.client.add_host(aggregate['id'], self.host)
213 self.addCleanup(self.client.remove_host, aggregate['id'], self.host)
Masayuki Igawa259c1132013-10-31 17:48:44 +0900214 server_name = data_utils.rand_name('test_server_')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900215 admin_servers_client = self.os_adm.servers_client
David Kranz0fb14292015-02-11 15:55:20 -0500216 server = self.create_test_server(name=server_name,
217 availability_zone=az_name,
218 wait_until='ACTIVE')
219 body = admin_servers_client.get_server(server['id'])
Mitsuhiko Yamazakiae8fc532013-04-22 11:17:35 +0900220 self.assertEqual(self.host, body[self._host_key])