blob: 2ca91aacec7d47959e8fe93fff63b02a134452a1 [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
Balazs Gibizer4f94ea02022-01-17 14:39:54 +010020from tempest.common import waiters
Ken'ichi Ohmichi49db4fe2016-08-12 15:26:51 -070021from tempest import config
Ken'ichi Ohmichi757833a2017-03-10 10:30:30 -080022from tempest.lib.common.utils import data_utils
Jordan Pittier9e227c52016-02-09 14:35:18 +010023from tempest.lib.common.utils import test_utils
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080024from tempest.lib import decorators
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090025
Ken'ichi Ohmichi49db4fe2016-08-12 15:26:51 -070026CONF = config.CONF
27
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090028
Balazs Gibizerdfb30432021-12-14 17:25:16 +010029@decorators.serial
zhufl4af2c822018-08-06 14:38:53 +080030class AggregatesAdminTestBase(base.BaseV2ComputeAdminTest):
Ken'ichi Ohmichi88363cb2015-11-19 08:00:54 +000031 """Tests Aggregates API that require admin privileges"""
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090032
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090033 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053034 def setup_clients(cls):
zhufl4af2c822018-08-06 14:38:53 +080035 super(AggregatesAdminTestBase, cls).setup_clients()
Jordan Pittier8160d312017-04-18 11:52:23 +020036 cls.client = cls.os_admin.aggregates_client
Rohan Kanade60b73092015-02-04 17:58:19 +053037
38 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010039 def resource_setup(cls):
zhufl4af2c822018-08-06 14:38:53 +080040 super(AggregatesAdminTestBase, cls).resource_setup()
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000041 cls.aggregate_name_prefix = 'test_aggregate'
42 cls.az_name_prefix = 'test_az'
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090043
zhuflc2c2f012016-05-16 17:34:18 +080044 cls.host = None
Jordan Pittier8160d312017-04-18 11:52:23 +020045 hypers = cls.os_admin.hypervisor_client.list_hypervisors(
Jianghua Wangdbe76af2016-06-13 12:53:16 +080046 detail=True)['hypervisors']
Ken'ichi Ohmichi49db4fe2016-08-12 15:26:51 -070047
48 if CONF.compute.hypervisor_type:
49 hypers = [hyper for hyper in hypers
50 if (hyper['hypervisor_type'] ==
51 CONF.compute.hypervisor_type)]
52
zhufl34afeb22018-02-09 15:03:41 +080053 cls.hosts_available = [hyper['service']['host'] for hyper in hypers
54 if (hyper['state'] == 'up' and
55 hyper['status'] == 'enabled')]
56 if cls.hosts_available:
57 cls.host = cls.hosts_available[0]
zhuflc2c2f012016-05-16 17:34:18 +080058 else:
Ken'ichi Ohmichi49db4fe2016-08-12 15:26:51 -070059 msg = "no available compute node found"
60 if CONF.compute.hypervisor_type:
61 msg += " for hypervisor_type %s" % CONF.compute.hypervisor_type
62 raise testtools.TestCase.failureException(msg)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090063
zhuflb9266952017-05-04 15:41:57 +080064 def _create_test_aggregate(self, **kwargs):
65 if 'name' not in kwargs:
66 kwargs['name'] = data_utils.rand_name(self.aggregate_name_prefix)
67 aggregate = self.client.create_aggregate(**kwargs)['aggregate']
68 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
69 self.client.delete_aggregate, aggregate['id'])
70 self.assertEqual(kwargs['name'], aggregate['name'])
71
72 return aggregate
73
zhufl4af2c822018-08-06 14:38:53 +080074
75class AggregatesAdminTestJSON(AggregatesAdminTestBase):
zhufle354fa72020-08-12 17:07:50 +080076 """Tests Aggregates API that require admin privileges"""
zhufl4af2c822018-08-06 14:38:53 +080077
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080078 @decorators.idempotent_id('0d148aa3-d54c-4317-aa8d-42040a475e20')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090079 def test_aggregate_create_delete(self):
zhufle354fa72020-08-12 17:07:50 +080080 """Test create/delete aggregate"""
zhuflb9266952017-05-04 15:41:57 +080081 aggregate = self._create_test_aggregate()
llg8212e4cd3922014-02-15 12:14:21 +080082 self.assertIsNone(aggregate['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090083
David Kranz0a735172015-01-16 10:51:18 -050084 self.client.delete_aggregate(aggregate['id'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090085 self.client.wait_for_resource_deletion(aggregate['id'])
86
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080087 @decorators.idempotent_id('5873a6f8-671a-43ff-8838-7ce430bb6d0b')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090088 def test_aggregate_create_delete_with_az(self):
zhufle354fa72020-08-12 17:07:50 +080089 """Test create/delete aggregate with availability_zone"""
Masayuki Igawa259c1132013-10-31 17:48:44 +090090 az_name = data_utils.rand_name(self.az_name_prefix)
zhuflb9266952017-05-04 15:41:57 +080091 aggregate = self._create_test_aggregate(availability_zone=az_name)
Chang Bo Guofc77e932013-09-16 17:38:26 -070092 self.assertEqual(az_name, aggregate['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090093
David Kranz0a735172015-01-16 10:51:18 -050094 self.client.delete_aggregate(aggregate['id'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090095 self.client.wait_for_resource_deletion(aggregate['id'])
96
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080097 @decorators.idempotent_id('68089c38-04b1-4758-bdf0-cf0daec4defd')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090098 def test_aggregate_create_verify_entry_in_list(self):
zhufle354fa72020-08-12 17:07:50 +080099 """Test listing aggregate should contain the created aggregate"""
zhuflb9266952017-05-04 15:41:57 +0800100 aggregate = self._create_test_aggregate()
ghanshyam2eb282d2015-08-04 15:05:19 +0900101 aggregates = self.client.list_aggregates()['aggregates']
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900102 self.assertIn((aggregate['id'], aggregate['availability_zone']),
103 map(lambda x: (x['id'], x['availability_zone']),
104 aggregates))
105
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800106 @decorators.idempotent_id('36ec92ca-7a73-43bc-b920-7531809e8540')
ivan-zhu35e1f8e2013-10-18 15:51:16 +0800107 def test_aggregate_create_update_metadata_get_details(self):
zhufle354fa72020-08-12 17:07:50 +0800108 """Test set/get aggregate metadata"""
zhuflb9266952017-05-04 15:41:57 +0800109 aggregate = self._create_test_aggregate()
ghanshyam2eb282d2015-08-04 15:05:19 +0900110 body = self.client.show_aggregate(aggregate['id'])['aggregate']
Chang Bo Guofc77e932013-09-16 17:38:26 -0700111 self.assertEqual(aggregate['name'], body['name'])
112 self.assertEqual(aggregate['availability_zone'],
113 body['availability_zone'])
ivan-zhu35e1f8e2013-10-18 15:51:16 +0800114 self.assertEqual({}, body["metadata"])
115
116 # set the metadata of the aggregate
117 meta = {"key": "value"}
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +0000118 body = self.client.set_metadata(aggregate['id'], metadata=meta)
ghanshyam2eb282d2015-08-04 15:05:19 +0900119 self.assertEqual(meta, body['aggregate']["metadata"])
ivan-zhu35e1f8e2013-10-18 15:51:16 +0800120
121 # verify the metadata has been set
ghanshyam2eb282d2015-08-04 15:05:19 +0900122 body = self.client.show_aggregate(aggregate['id'])['aggregate']
ivan-zhu35e1f8e2013-10-18 15:51:16 +0800123 self.assertEqual(meta, body["metadata"])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900124
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800125 @decorators.idempotent_id('4d2b2004-40fa-40a1-aab2-66f4dab81beb')
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800126 def test_aggregate_create_update_with_az(self):
zhufle354fa72020-08-12 17:07:50 +0800127 """Test create/update aggregate with availability_zone"""
Masayuki Igawa259c1132013-10-31 17:48:44 +0900128 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
129 az_name = data_utils.rand_name(self.az_name_prefix)
zhuflb9266952017-05-04 15:41:57 +0800130 aggregate = self._create_test_aggregate(
131 name=aggregate_name, availability_zone=az_name)
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800132
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800133 self.assertEqual(az_name, aggregate['availability_zone'])
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800134
135 aggregate_id = aggregate['id']
136 new_aggregate_name = aggregate_name + '_new'
137 new_az_name = az_name + '_new'
138
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +0000139 resp_aggregate = self.client.update_aggregate(
140 aggregate_id,
141 name=new_aggregate_name,
ghanshyam2eb282d2015-08-04 15:05:19 +0900142 availability_zone=new_az_name)['aggregate']
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800143 self.assertEqual(new_aggregate_name, resp_aggregate['name'])
144 self.assertEqual(new_az_name, resp_aggregate['availability_zone'])
145
ghanshyam2eb282d2015-08-04 15:05:19 +0900146 aggregates = self.client.list_aggregates()['aggregates']
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800147 self.assertIn((aggregate_id, new_aggregate_name, new_az_name),
148 map(lambda x:
Matthew Treinish1d14c542014-06-17 20:25:40 -0400149 (x['id'], x['name'], x['availability_zone']),
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800150 aggregates))
151
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800152 @decorators.idempotent_id('c8e85064-e79b-4906-9931-c11c24294d02')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900153 def test_aggregate_add_remove_host(self):
zhufle354fa72020-08-12 17:07:50 +0800154 """Test adding host to and removing host from aggregate"""
Matthew Treinisha03ed792013-09-23 21:38:15 +0000155 self.useFixture(fixtures.LockFixture('availability_zone'))
Masayuki Igawa259c1132013-10-31 17:48:44 +0900156 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
zhuflb9266952017-05-04 15:41:57 +0800157 aggregate = self._create_test_aggregate(name=aggregate_name)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900158
ghanshyam2eb282d2015-08-04 15:05:19 +0900159 body = (self.client.add_host(aggregate['id'], host=self.host)
160 ['aggregate'])
Chang Bo Guofc77e932013-09-16 17:38:26 -0700161 self.assertEqual(aggregate_name, body['name'])
162 self.assertEqual(aggregate['availability_zone'],
163 body['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900164 self.assertIn(self.host, body['hosts'])
165
ghanshyam2eb282d2015-08-04 15:05:19 +0900166 body = (self.client.remove_host(aggregate['id'], host=self.host)
167 ['aggregate'])
Chang Bo Guofc77e932013-09-16 17:38:26 -0700168 self.assertEqual(aggregate_name, body['name'])
169 self.assertEqual(aggregate['availability_zone'],
170 body['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900171 self.assertNotIn(self.host, body['hosts'])
172
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800173 @decorators.idempotent_id('7f6a1cc5-2446-4cdb-9baa-b6ae0a919b72')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900174 def test_aggregate_add_host_list(self):
zhufle354fa72020-08-12 17:07:50 +0800175 """Test listing aggregate contains the host added to the aggregate
176
177 Add a host to the given aggregate and list.
178 """
Matthew Treinisha03ed792013-09-23 21:38:15 +0000179 self.useFixture(fixtures.LockFixture('availability_zone'))
Masayuki Igawa259c1132013-10-31 17:48:44 +0900180 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
zhuflb9266952017-05-04 15:41:57 +0800181 aggregate = self._create_test_aggregate(name=aggregate_name)
182
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +0000183 self.client.add_host(aggregate['id'], host=self.host)
184 self.addCleanup(self.client.remove_host, aggregate['id'],
185 host=self.host)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900186
ghanshyam2eb282d2015-08-04 15:05:19 +0900187 aggregates = self.client.list_aggregates()['aggregates']
Sirushti Murugesan935f2cc2016-07-12 19:48:24 +0530188 aggs = [agg for agg in aggregates if agg['id'] == aggregate['id']]
Chang Bo Guofc77e932013-09-16 17:38:26 -0700189 self.assertEqual(1, len(aggs))
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900190 agg = aggs[0]
Chang Bo Guofc77e932013-09-16 17:38:26 -0700191 self.assertEqual(aggregate_name, agg['name'])
llg8212e4cd3922014-02-15 12:14:21 +0800192 self.assertIsNone(agg['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900193 self.assertIn(self.host, agg['hosts'])
194
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800195 @decorators.idempotent_id('eeef473c-7c52-494d-9f09-2ed7fc8fc036')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900196 def test_aggregate_add_host_get_details(self):
zhufle354fa72020-08-12 17:07:50 +0800197 """Test showing aggregate contains the host added to the aggregate
198
199 Add a host to the given aggregate and get details.
200 """
Matthew Treinisha03ed792013-09-23 21:38:15 +0000201 self.useFixture(fixtures.LockFixture('availability_zone'))
Masayuki Igawa259c1132013-10-31 17:48:44 +0900202 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
zhuflb9266952017-05-04 15:41:57 +0800203 aggregate = self._create_test_aggregate(name=aggregate_name)
204
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +0000205 self.client.add_host(aggregate['id'], host=self.host)
206 self.addCleanup(self.client.remove_host, aggregate['id'],
207 host=self.host)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900208
ghanshyam2eb282d2015-08-04 15:05:19 +0900209 body = self.client.show_aggregate(aggregate['id'])['aggregate']
Chang Bo Guofc77e932013-09-16 17:38:26 -0700210 self.assertEqual(aggregate_name, body['name'])
llg8212e4cd3922014-02-15 12:14:21 +0800211 self.assertIsNone(body['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900212 self.assertIn(self.host, body['hosts'])
213
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800214 @decorators.idempotent_id('96be03c7-570d-409c-90f8-e4db3c646996')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900215 def test_aggregate_add_host_create_server_with_az(self):
zhufle354fa72020-08-12 17:07:50 +0800216 """Test adding a host to the given aggregate and creating a server"""
Matthew Treinisha03ed792013-09-23 21:38:15 +0000217 self.useFixture(fixtures.LockFixture('availability_zone'))
Masayuki Igawa259c1132013-10-31 17:48:44 +0900218 az_name = data_utils.rand_name(self.az_name_prefix)
zhuflb9266952017-05-04 15:41:57 +0800219 aggregate = self._create_test_aggregate(availability_zone=az_name)
220
ghanshyam676492a2018-07-31 05:40:22 +0000221 # Find a host that has not been added to other availability zone,
222 # for one host can't be added to different availability zones.
zhufl34afeb22018-02-09 15:03:41 +0800223 aggregates = self.client.list_aggregates()['aggregates']
224 hosts_in_zone = []
ghanshyam676492a2018-07-31 05:40:22 +0000225 for agg in aggregates:
226 if agg['availability_zone']:
227 hosts_in_zone.extend(agg['hosts'])
zhufl34afeb22018-02-09 15:03:41 +0800228 hosts = [v for v in self.hosts_available if v not in hosts_in_zone]
229 if not hosts:
ghanshyam676492a2018-07-31 05:40:22 +0000230 raise self.skipException("All hosts are already in other "
231 "availability zones, so can't add "
232 "host to aggregate. \nAggregates list: "
233 "%s" % aggregates)
zhufl34afeb22018-02-09 15:03:41 +0800234 host = hosts[0]
235
236 self.client.add_host(aggregate['id'], host=host)
237 self.addCleanup(self.client.remove_host, aggregate['id'], host=host)
zhufl7ae22682016-09-18 15:22:33 +0800238 server = self.create_test_server(availability_zone=az_name,
David Kranz0fb14292015-02-11 15:55:20 -0500239 wait_until='ACTIVE')
zhufl7bc916d2018-08-22 14:47:39 +0800240 server_host = self.get_host_for_server(server['id'])
241 self.assertEqual(host, server_host)
Balazs Gibizer4f94ea02022-01-17 14:39:54 +0100242 self.servers_client.delete_server(server['id'])
243 # NOTE(gmann): We need to wait for the server to delete before
244 # addCleanup remove the host from aggregate.
245 waiters.wait_for_server_termination(self.servers_client, server['id'])
zhufl4af2c822018-08-06 14:38:53 +0800246
247
248class AggregatesAdminTestV241(AggregatesAdminTestBase):
zhufle354fa72020-08-12 17:07:50 +0800249 """Tests Aggregates API that require admin privileges
250
251 Tests Aggregates API that require admin privileges with compute
252 microversion greater than 2.40.
253 """
zhufl4af2c822018-08-06 14:38:53 +0800254 min_microversion = '2.41'
255
256 # NOTE(gmann): This test tests the Aggregate APIs response schema
257 # for 2.41 microversion. No specific assert or behaviour verification
258 # is needed.
259
260 @decorators.idempotent_id('fdf24d9e-8afa-4700-b6aa-9c498351504f')
261 def test_create_update_show_aggregate_add_remove_host(self):
zhufle354fa72020-08-12 17:07:50 +0800262 """Test response schema of aggregates API
263
264 Test response schema of aggregates API(create/update/show/add host/
265 remove host) with compute microversion greater than 2.40.
266 """
zhufl4af2c822018-08-06 14:38:53 +0800267 # Update and add a host to the given aggregate and get details.
268 self.useFixture(fixtures.LockFixture('availability_zone'))
269 # Checking create aggregate API response schema
270 aggregate = self._create_test_aggregate()
271
272 new_aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
273 # Checking update aggregate API response schema
274 self.client.update_aggregate(aggregate['id'], name=new_aggregate_name)
275 # Checking show aggregate API response schema
276 self.client.show_aggregate(aggregate['id'])['aggregate']
277 # Checking add host to aggregate API response schema
278 self.client.add_host(aggregate['id'], host=self.host)
279 # Checking rempve host from aggregate API response schema
280 self.client.remove_host(aggregate['id'], host=self.host)