blob: 27162594fd4255bba84d620a939fc64b13efbcec [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
zhuflc2c2f012016-05-16 17:34:18 +080016import testtools
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
Ken'ichi Ohmichi49db4fe2016-08-12 15:26:51 -070020from tempest import config
Ken'ichi Ohmichi757833a2017-03-10 10:30:30 -080021from tempest.lib.common.utils import data_utils
Jordan Pittier9e227c52016-02-09 14:35:18 +010022from tempest.lib.common.utils import test_utils
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080023from tempest.lib import decorators
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090024
Ken'ichi Ohmichi49db4fe2016-08-12 15:26:51 -070025CONF = config.CONF
26
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090027
zhufl4af2c822018-08-06 14:38:53 +080028class AggregatesAdminTestBase(base.BaseV2ComputeAdminTest):
Ken'ichi Ohmichi88363cb2015-11-19 08:00:54 +000029 """Tests Aggregates API that require admin privileges"""
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090030
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090031 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053032 def setup_clients(cls):
zhufl4af2c822018-08-06 14:38:53 +080033 super(AggregatesAdminTestBase, cls).setup_clients()
Jordan Pittier8160d312017-04-18 11:52:23 +020034 cls.client = cls.os_admin.aggregates_client
Rohan Kanade60b73092015-02-04 17:58:19 +053035
36 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010037 def resource_setup(cls):
zhufl4af2c822018-08-06 14:38:53 +080038 super(AggregatesAdminTestBase, cls).resource_setup()
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000039 cls.aggregate_name_prefix = 'test_aggregate'
40 cls.az_name_prefix = 'test_az'
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090041
zhuflc2c2f012016-05-16 17:34:18 +080042 cls.host = None
Jordan Pittier8160d312017-04-18 11:52:23 +020043 hypers = cls.os_admin.hypervisor_client.list_hypervisors(
Jianghua Wangdbe76af2016-06-13 12:53:16 +080044 detail=True)['hypervisors']
Ken'ichi Ohmichi49db4fe2016-08-12 15:26:51 -070045
46 if CONF.compute.hypervisor_type:
47 hypers = [hyper for hyper in hypers
48 if (hyper['hypervisor_type'] ==
49 CONF.compute.hypervisor_type)]
50
zhufl34afeb22018-02-09 15:03:41 +080051 cls.hosts_available = [hyper['service']['host'] for hyper in hypers
52 if (hyper['state'] == 'up' and
53 hyper['status'] == 'enabled')]
54 if cls.hosts_available:
55 cls.host = cls.hosts_available[0]
zhuflc2c2f012016-05-16 17:34:18 +080056 else:
Ken'ichi Ohmichi49db4fe2016-08-12 15:26:51 -070057 msg = "no available compute node found"
58 if CONF.compute.hypervisor_type:
59 msg += " for hypervisor_type %s" % CONF.compute.hypervisor_type
60 raise testtools.TestCase.failureException(msg)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090061
zhuflb9266952017-05-04 15:41:57 +080062 def _create_test_aggregate(self, **kwargs):
63 if 'name' not in kwargs:
64 kwargs['name'] = data_utils.rand_name(self.aggregate_name_prefix)
65 aggregate = self.client.create_aggregate(**kwargs)['aggregate']
66 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
67 self.client.delete_aggregate, aggregate['id'])
68 self.assertEqual(kwargs['name'], aggregate['name'])
69
70 return aggregate
71
zhufl4af2c822018-08-06 14:38:53 +080072
73class AggregatesAdminTestJSON(AggregatesAdminTestBase):
zhufle354fa72020-08-12 17:07:50 +080074 """Tests Aggregates API that require admin privileges"""
zhufl4af2c822018-08-06 14:38:53 +080075
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080076 @decorators.idempotent_id('0d148aa3-d54c-4317-aa8d-42040a475e20')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090077 def test_aggregate_create_delete(self):
zhufle354fa72020-08-12 17:07:50 +080078 """Test create/delete aggregate"""
zhuflb9266952017-05-04 15:41:57 +080079 aggregate = self._create_test_aggregate()
llg8212e4cd3922014-02-15 12:14:21 +080080 self.assertIsNone(aggregate['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090081
David Kranz0a735172015-01-16 10:51:18 -050082 self.client.delete_aggregate(aggregate['id'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090083 self.client.wait_for_resource_deletion(aggregate['id'])
84
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080085 @decorators.idempotent_id('5873a6f8-671a-43ff-8838-7ce430bb6d0b')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090086 def test_aggregate_create_delete_with_az(self):
zhufle354fa72020-08-12 17:07:50 +080087 """Test create/delete aggregate with availability_zone"""
Masayuki Igawa259c1132013-10-31 17:48:44 +090088 az_name = data_utils.rand_name(self.az_name_prefix)
zhuflb9266952017-05-04 15:41:57 +080089 aggregate = self._create_test_aggregate(availability_zone=az_name)
Chang Bo Guofc77e932013-09-16 17:38:26 -070090 self.assertEqual(az_name, aggregate['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090091
David Kranz0a735172015-01-16 10:51:18 -050092 self.client.delete_aggregate(aggregate['id'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090093 self.client.wait_for_resource_deletion(aggregate['id'])
94
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080095 @decorators.idempotent_id('68089c38-04b1-4758-bdf0-cf0daec4defd')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090096 def test_aggregate_create_verify_entry_in_list(self):
zhufle354fa72020-08-12 17:07:50 +080097 """Test listing aggregate should contain the created aggregate"""
zhuflb9266952017-05-04 15:41:57 +080098 aggregate = self._create_test_aggregate()
ghanshyam2eb282d2015-08-04 15:05:19 +090099 aggregates = self.client.list_aggregates()['aggregates']
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900100 self.assertIn((aggregate['id'], aggregate['availability_zone']),
101 map(lambda x: (x['id'], x['availability_zone']),
102 aggregates))
103
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800104 @decorators.idempotent_id('36ec92ca-7a73-43bc-b920-7531809e8540')
ivan-zhu35e1f8e2013-10-18 15:51:16 +0800105 def test_aggregate_create_update_metadata_get_details(self):
zhufle354fa72020-08-12 17:07:50 +0800106 """Test set/get aggregate metadata"""
zhuflb9266952017-05-04 15:41:57 +0800107 aggregate = self._create_test_aggregate()
ghanshyam2eb282d2015-08-04 15:05:19 +0900108 body = self.client.show_aggregate(aggregate['id'])['aggregate']
Chang Bo Guofc77e932013-09-16 17:38:26 -0700109 self.assertEqual(aggregate['name'], body['name'])
110 self.assertEqual(aggregate['availability_zone'],
111 body['availability_zone'])
ivan-zhu35e1f8e2013-10-18 15:51:16 +0800112 self.assertEqual({}, body["metadata"])
113
114 # set the metadata of the aggregate
115 meta = {"key": "value"}
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +0000116 body = self.client.set_metadata(aggregate['id'], metadata=meta)
ghanshyam2eb282d2015-08-04 15:05:19 +0900117 self.assertEqual(meta, body['aggregate']["metadata"])
ivan-zhu35e1f8e2013-10-18 15:51:16 +0800118
119 # verify the metadata has been set
ghanshyam2eb282d2015-08-04 15:05:19 +0900120 body = self.client.show_aggregate(aggregate['id'])['aggregate']
ivan-zhu35e1f8e2013-10-18 15:51:16 +0800121 self.assertEqual(meta, body["metadata"])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900122
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800123 @decorators.idempotent_id('4d2b2004-40fa-40a1-aab2-66f4dab81beb')
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800124 def test_aggregate_create_update_with_az(self):
zhufle354fa72020-08-12 17:07:50 +0800125 """Test create/update aggregate with availability_zone"""
Masayuki Igawa259c1132013-10-31 17:48:44 +0900126 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
127 az_name = data_utils.rand_name(self.az_name_prefix)
zhuflb9266952017-05-04 15:41:57 +0800128 aggregate = self._create_test_aggregate(
129 name=aggregate_name, availability_zone=az_name)
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800130
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800131 self.assertEqual(az_name, aggregate['availability_zone'])
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800132
133 aggregate_id = aggregate['id']
134 new_aggregate_name = aggregate_name + '_new'
135 new_az_name = az_name + '_new'
136
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +0000137 resp_aggregate = self.client.update_aggregate(
138 aggregate_id,
139 name=new_aggregate_name,
ghanshyam2eb282d2015-08-04 15:05:19 +0900140 availability_zone=new_az_name)['aggregate']
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800141 self.assertEqual(new_aggregate_name, resp_aggregate['name'])
142 self.assertEqual(new_az_name, resp_aggregate['availability_zone'])
143
ghanshyam2eb282d2015-08-04 15:05:19 +0900144 aggregates = self.client.list_aggregates()['aggregates']
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800145 self.assertIn((aggregate_id, new_aggregate_name, new_az_name),
146 map(lambda x:
Matthew Treinish1d14c542014-06-17 20:25:40 -0400147 (x['id'], x['name'], x['availability_zone']),
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800148 aggregates))
149
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800150 @decorators.idempotent_id('c8e85064-e79b-4906-9931-c11c24294d02')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900151 def test_aggregate_add_remove_host(self):
zhufle354fa72020-08-12 17:07:50 +0800152 """Test adding host to and removing host from aggregate"""
Matthew Treinisha03ed792013-09-23 21:38:15 +0000153 self.useFixture(fixtures.LockFixture('availability_zone'))
Masayuki Igawa259c1132013-10-31 17:48:44 +0900154 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
zhuflb9266952017-05-04 15:41:57 +0800155 aggregate = self._create_test_aggregate(name=aggregate_name)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900156
ghanshyam2eb282d2015-08-04 15:05:19 +0900157 body = (self.client.add_host(aggregate['id'], host=self.host)
158 ['aggregate'])
Chang Bo Guofc77e932013-09-16 17:38:26 -0700159 self.assertEqual(aggregate_name, body['name'])
160 self.assertEqual(aggregate['availability_zone'],
161 body['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900162 self.assertIn(self.host, body['hosts'])
163
ghanshyam2eb282d2015-08-04 15:05:19 +0900164 body = (self.client.remove_host(aggregate['id'], host=self.host)
165 ['aggregate'])
Chang Bo Guofc77e932013-09-16 17:38:26 -0700166 self.assertEqual(aggregate_name, body['name'])
167 self.assertEqual(aggregate['availability_zone'],
168 body['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900169 self.assertNotIn(self.host, body['hosts'])
170
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800171 @decorators.idempotent_id('7f6a1cc5-2446-4cdb-9baa-b6ae0a919b72')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900172 def test_aggregate_add_host_list(self):
zhufle354fa72020-08-12 17:07:50 +0800173 """Test listing aggregate contains the host added to the aggregate
174
175 Add a host to the given aggregate and list.
176 """
Matthew Treinisha03ed792013-09-23 21:38:15 +0000177 self.useFixture(fixtures.LockFixture('availability_zone'))
Masayuki Igawa259c1132013-10-31 17:48:44 +0900178 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
zhuflb9266952017-05-04 15:41:57 +0800179 aggregate = self._create_test_aggregate(name=aggregate_name)
180
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +0000181 self.client.add_host(aggregate['id'], host=self.host)
182 self.addCleanup(self.client.remove_host, aggregate['id'],
183 host=self.host)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900184
ghanshyam2eb282d2015-08-04 15:05:19 +0900185 aggregates = self.client.list_aggregates()['aggregates']
Sirushti Murugesan935f2cc2016-07-12 19:48:24 +0530186 aggs = [agg for agg in aggregates if agg['id'] == aggregate['id']]
Chang Bo Guofc77e932013-09-16 17:38:26 -0700187 self.assertEqual(1, len(aggs))
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900188 agg = aggs[0]
Chang Bo Guofc77e932013-09-16 17:38:26 -0700189 self.assertEqual(aggregate_name, agg['name'])
llg8212e4cd3922014-02-15 12:14:21 +0800190 self.assertIsNone(agg['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900191 self.assertIn(self.host, agg['hosts'])
192
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800193 @decorators.idempotent_id('eeef473c-7c52-494d-9f09-2ed7fc8fc036')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900194 def test_aggregate_add_host_get_details(self):
zhufle354fa72020-08-12 17:07:50 +0800195 """Test showing aggregate contains the host added to the aggregate
196
197 Add a host to the given aggregate and get details.
198 """
Matthew Treinisha03ed792013-09-23 21:38:15 +0000199 self.useFixture(fixtures.LockFixture('availability_zone'))
Masayuki Igawa259c1132013-10-31 17:48:44 +0900200 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
zhuflb9266952017-05-04 15:41:57 +0800201 aggregate = self._create_test_aggregate(name=aggregate_name)
202
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +0000203 self.client.add_host(aggregate['id'], host=self.host)
204 self.addCleanup(self.client.remove_host, aggregate['id'],
205 host=self.host)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900206
ghanshyam2eb282d2015-08-04 15:05:19 +0900207 body = self.client.show_aggregate(aggregate['id'])['aggregate']
Chang Bo Guofc77e932013-09-16 17:38:26 -0700208 self.assertEqual(aggregate_name, body['name'])
llg8212e4cd3922014-02-15 12:14:21 +0800209 self.assertIsNone(body['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900210 self.assertIn(self.host, body['hosts'])
211
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800212 @decorators.idempotent_id('96be03c7-570d-409c-90f8-e4db3c646996')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900213 def test_aggregate_add_host_create_server_with_az(self):
zhufle354fa72020-08-12 17:07:50 +0800214 """Test adding a host to the given aggregate and creating a server"""
Matthew Treinisha03ed792013-09-23 21:38:15 +0000215 self.useFixture(fixtures.LockFixture('availability_zone'))
Masayuki Igawa259c1132013-10-31 17:48:44 +0900216 az_name = data_utils.rand_name(self.az_name_prefix)
zhuflb9266952017-05-04 15:41:57 +0800217 aggregate = self._create_test_aggregate(availability_zone=az_name)
218
ghanshyam676492a2018-07-31 05:40:22 +0000219 # Find a host that has not been added to other availability zone,
220 # for one host can't be added to different availability zones.
zhufl34afeb22018-02-09 15:03:41 +0800221 aggregates = self.client.list_aggregates()['aggregates']
222 hosts_in_zone = []
ghanshyam676492a2018-07-31 05:40:22 +0000223 for agg in aggregates:
224 if agg['availability_zone']:
225 hosts_in_zone.extend(agg['hosts'])
zhufl34afeb22018-02-09 15:03:41 +0800226 hosts = [v for v in self.hosts_available if v not in hosts_in_zone]
227 if not hosts:
ghanshyam676492a2018-07-31 05:40:22 +0000228 raise self.skipException("All hosts are already in other "
229 "availability zones, so can't add "
230 "host to aggregate. \nAggregates list: "
231 "%s" % aggregates)
zhufl34afeb22018-02-09 15:03:41 +0800232 host = hosts[0]
233
234 self.client.add_host(aggregate['id'], host=host)
235 self.addCleanup(self.client.remove_host, aggregate['id'], host=host)
zhufl7ae22682016-09-18 15:22:33 +0800236 server = self.create_test_server(availability_zone=az_name,
David Kranz0fb14292015-02-11 15:55:20 -0500237 wait_until='ACTIVE')
zhufl7bc916d2018-08-22 14:47:39 +0800238 server_host = self.get_host_for_server(server['id'])
239 self.assertEqual(host, server_host)
zhufl4af2c822018-08-06 14:38:53 +0800240
241
242class AggregatesAdminTestV241(AggregatesAdminTestBase):
zhufle354fa72020-08-12 17:07:50 +0800243 """Tests Aggregates API that require admin privileges
244
245 Tests Aggregates API that require admin privileges with compute
246 microversion greater than 2.40.
247 """
zhufl4af2c822018-08-06 14:38:53 +0800248 min_microversion = '2.41'
249
250 # NOTE(gmann): This test tests the Aggregate APIs response schema
251 # for 2.41 microversion. No specific assert or behaviour verification
252 # is needed.
253
254 @decorators.idempotent_id('fdf24d9e-8afa-4700-b6aa-9c498351504f')
255 def test_create_update_show_aggregate_add_remove_host(self):
zhufle354fa72020-08-12 17:07:50 +0800256 """Test response schema of aggregates API
257
258 Test response schema of aggregates API(create/update/show/add host/
259 remove host) with compute microversion greater than 2.40.
260 """
zhufl4af2c822018-08-06 14:38:53 +0800261 # Update and add a host to the given aggregate and get details.
262 self.useFixture(fixtures.LockFixture('availability_zone'))
263 # Checking create aggregate API response schema
264 aggregate = self._create_test_aggregate()
265
266 new_aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
267 # Checking update aggregate API response schema
268 self.client.update_aggregate(aggregate['id'], name=new_aggregate_name)
269 # Checking show aggregate API response schema
270 self.client.show_aggregate(aggregate['id'])['aggregate']
271 # Checking add host to aggregate API response schema
272 self.client.add_host(aggregate['id'], host=self.host)
273 # Checking rempve host from aggregate API response schema
274 self.client.remove_host(aggregate['id'], host=self.host)