blob: 7a3bfdf3877b96ce5ea3849c0c72132c6e856847 [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):
74
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080075 @decorators.idempotent_id('0d148aa3-d54c-4317-aa8d-42040a475e20')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090076 def test_aggregate_create_delete(self):
77 # Create and delete an aggregate.
zhuflb9266952017-05-04 15:41:57 +080078 aggregate = self._create_test_aggregate()
llg8212e4cd3922014-02-15 12:14:21 +080079 self.assertIsNone(aggregate['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090080
David Kranz0a735172015-01-16 10:51:18 -050081 self.client.delete_aggregate(aggregate['id'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090082 self.client.wait_for_resource_deletion(aggregate['id'])
83
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080084 @decorators.idempotent_id('5873a6f8-671a-43ff-8838-7ce430bb6d0b')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090085 def test_aggregate_create_delete_with_az(self):
86 # Create and delete an aggregate.
Masayuki Igawa259c1132013-10-31 17:48:44 +090087 az_name = data_utils.rand_name(self.az_name_prefix)
zhuflb9266952017-05-04 15:41:57 +080088 aggregate = self._create_test_aggregate(availability_zone=az_name)
Chang Bo Guofc77e932013-09-16 17:38:26 -070089 self.assertEqual(az_name, aggregate['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090090
David Kranz0a735172015-01-16 10:51:18 -050091 self.client.delete_aggregate(aggregate['id'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090092 self.client.wait_for_resource_deletion(aggregate['id'])
93
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080094 @decorators.idempotent_id('68089c38-04b1-4758-bdf0-cf0daec4defd')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090095 def test_aggregate_create_verify_entry_in_list(self):
96 # Create an aggregate and ensure it is listed.
zhuflb9266952017-05-04 15:41:57 +080097 aggregate = self._create_test_aggregate()
ghanshyam2eb282d2015-08-04 15:05:19 +090098 aggregates = self.client.list_aggregates()['aggregates']
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090099 self.assertIn((aggregate['id'], aggregate['availability_zone']),
100 map(lambda x: (x['id'], x['availability_zone']),
101 aggregates))
102
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800103 @decorators.idempotent_id('36ec92ca-7a73-43bc-b920-7531809e8540')
ivan-zhu35e1f8e2013-10-18 15:51:16 +0800104 def test_aggregate_create_update_metadata_get_details(self):
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900105 # Create an aggregate and ensure its details are returned.
zhuflb9266952017-05-04 15:41:57 +0800106 aggregate = self._create_test_aggregate()
ghanshyam2eb282d2015-08-04 15:05:19 +0900107 body = self.client.show_aggregate(aggregate['id'])['aggregate']
Chang Bo Guofc77e932013-09-16 17:38:26 -0700108 self.assertEqual(aggregate['name'], body['name'])
109 self.assertEqual(aggregate['availability_zone'],
110 body['availability_zone'])
ivan-zhu35e1f8e2013-10-18 15:51:16 +0800111 self.assertEqual({}, body["metadata"])
112
113 # set the metadata of the aggregate
114 meta = {"key": "value"}
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +0000115 body = self.client.set_metadata(aggregate['id'], metadata=meta)
ghanshyam2eb282d2015-08-04 15:05:19 +0900116 self.assertEqual(meta, body['aggregate']["metadata"])
ivan-zhu35e1f8e2013-10-18 15:51:16 +0800117
118 # verify the metadata has been set
ghanshyam2eb282d2015-08-04 15:05:19 +0900119 body = self.client.show_aggregate(aggregate['id'])['aggregate']
ivan-zhu35e1f8e2013-10-18 15:51:16 +0800120 self.assertEqual(meta, body["metadata"])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900121
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800122 @decorators.idempotent_id('4d2b2004-40fa-40a1-aab2-66f4dab81beb')
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800123 def test_aggregate_create_update_with_az(self):
124 # Update an aggregate and ensure properties are updated correctly
Masayuki Igawa259c1132013-10-31 17:48:44 +0900125 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
126 az_name = data_utils.rand_name(self.az_name_prefix)
zhuflb9266952017-05-04 15:41:57 +0800127 aggregate = self._create_test_aggregate(
128 name=aggregate_name, availability_zone=az_name)
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800129
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800130 self.assertEqual(az_name, aggregate['availability_zone'])
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800131
132 aggregate_id = aggregate['id']
133 new_aggregate_name = aggregate_name + '_new'
134 new_az_name = az_name + '_new'
135
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +0000136 resp_aggregate = self.client.update_aggregate(
137 aggregate_id,
138 name=new_aggregate_name,
ghanshyam2eb282d2015-08-04 15:05:19 +0900139 availability_zone=new_az_name)['aggregate']
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800140 self.assertEqual(new_aggregate_name, resp_aggregate['name'])
141 self.assertEqual(new_az_name, resp_aggregate['availability_zone'])
142
ghanshyam2eb282d2015-08-04 15:05:19 +0900143 aggregates = self.client.list_aggregates()['aggregates']
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800144 self.assertIn((aggregate_id, new_aggregate_name, new_az_name),
145 map(lambda x:
Matthew Treinish1d14c542014-06-17 20:25:40 -0400146 (x['id'], x['name'], x['availability_zone']),
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800147 aggregates))
148
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800149 @decorators.idempotent_id('c8e85064-e79b-4906-9931-c11c24294d02')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900150 def test_aggregate_add_remove_host(self):
Alanad42cf22016-01-04 05:34:37 -0500151 # Add a host to the given aggregate and remove.
Matthew Treinisha03ed792013-09-23 21:38:15 +0000152 self.useFixture(fixtures.LockFixture('availability_zone'))
Masayuki Igawa259c1132013-10-31 17:48:44 +0900153 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
zhuflb9266952017-05-04 15:41:57 +0800154 aggregate = self._create_test_aggregate(name=aggregate_name)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900155
ghanshyam2eb282d2015-08-04 15:05:19 +0900156 body = (self.client.add_host(aggregate['id'], host=self.host)
157 ['aggregate'])
Chang Bo Guofc77e932013-09-16 17:38:26 -0700158 self.assertEqual(aggregate_name, body['name'])
159 self.assertEqual(aggregate['availability_zone'],
160 body['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900161 self.assertIn(self.host, body['hosts'])
162
ghanshyam2eb282d2015-08-04 15:05:19 +0900163 body = (self.client.remove_host(aggregate['id'], host=self.host)
164 ['aggregate'])
Chang Bo Guofc77e932013-09-16 17:38:26 -0700165 self.assertEqual(aggregate_name, body['name'])
166 self.assertEqual(aggregate['availability_zone'],
167 body['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900168 self.assertNotIn(self.host, body['hosts'])
169
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800170 @decorators.idempotent_id('7f6a1cc5-2446-4cdb-9baa-b6ae0a919b72')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900171 def test_aggregate_add_host_list(self):
Alanad42cf22016-01-04 05:34:37 -0500172 # Add a host to the given aggregate and list.
Matthew Treinisha03ed792013-09-23 21:38:15 +0000173 self.useFixture(fixtures.LockFixture('availability_zone'))
Masayuki Igawa259c1132013-10-31 17:48:44 +0900174 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
zhuflb9266952017-05-04 15:41:57 +0800175 aggregate = self._create_test_aggregate(name=aggregate_name)
176
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +0000177 self.client.add_host(aggregate['id'], host=self.host)
178 self.addCleanup(self.client.remove_host, aggregate['id'],
179 host=self.host)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900180
ghanshyam2eb282d2015-08-04 15:05:19 +0900181 aggregates = self.client.list_aggregates()['aggregates']
Sirushti Murugesan935f2cc2016-07-12 19:48:24 +0530182 aggs = [agg for agg in aggregates if agg['id'] == aggregate['id']]
Chang Bo Guofc77e932013-09-16 17:38:26 -0700183 self.assertEqual(1, len(aggs))
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900184 agg = aggs[0]
Chang Bo Guofc77e932013-09-16 17:38:26 -0700185 self.assertEqual(aggregate_name, agg['name'])
llg8212e4cd3922014-02-15 12:14:21 +0800186 self.assertIsNone(agg['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900187 self.assertIn(self.host, agg['hosts'])
188
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800189 @decorators.idempotent_id('eeef473c-7c52-494d-9f09-2ed7fc8fc036')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900190 def test_aggregate_add_host_get_details(self):
Alanad42cf22016-01-04 05:34:37 -0500191 # Add a host to the given aggregate and get details.
Matthew Treinisha03ed792013-09-23 21:38:15 +0000192 self.useFixture(fixtures.LockFixture('availability_zone'))
Masayuki Igawa259c1132013-10-31 17:48:44 +0900193 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
zhuflb9266952017-05-04 15:41:57 +0800194 aggregate = self._create_test_aggregate(name=aggregate_name)
195
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +0000196 self.client.add_host(aggregate['id'], host=self.host)
197 self.addCleanup(self.client.remove_host, aggregate['id'],
198 host=self.host)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900199
ghanshyam2eb282d2015-08-04 15:05:19 +0900200 body = self.client.show_aggregate(aggregate['id'])['aggregate']
Chang Bo Guofc77e932013-09-16 17:38:26 -0700201 self.assertEqual(aggregate_name, body['name'])
llg8212e4cd3922014-02-15 12:14:21 +0800202 self.assertIsNone(body['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900203 self.assertIn(self.host, body['hosts'])
204
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800205 @decorators.idempotent_id('96be03c7-570d-409c-90f8-e4db3c646996')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900206 def test_aggregate_add_host_create_server_with_az(self):
Alanad42cf22016-01-04 05:34:37 -0500207 # Add a host to the given aggregate and create a server.
Matthew Treinisha03ed792013-09-23 21:38:15 +0000208 self.useFixture(fixtures.LockFixture('availability_zone'))
Masayuki Igawa259c1132013-10-31 17:48:44 +0900209 az_name = data_utils.rand_name(self.az_name_prefix)
zhuflb9266952017-05-04 15:41:57 +0800210 aggregate = self._create_test_aggregate(availability_zone=az_name)
211
ghanshyam676492a2018-07-31 05:40:22 +0000212 # Find a host that has not been added to other availability zone,
213 # for one host can't be added to different availability zones.
zhufl34afeb22018-02-09 15:03:41 +0800214 aggregates = self.client.list_aggregates()['aggregates']
215 hosts_in_zone = []
ghanshyam676492a2018-07-31 05:40:22 +0000216 for agg in aggregates:
217 if agg['availability_zone']:
218 hosts_in_zone.extend(agg['hosts'])
zhufl34afeb22018-02-09 15:03:41 +0800219 hosts = [v for v in self.hosts_available if v not in hosts_in_zone]
220 if not hosts:
ghanshyam676492a2018-07-31 05:40:22 +0000221 raise self.skipException("All hosts are already in other "
222 "availability zones, so can't add "
223 "host to aggregate. \nAggregates list: "
224 "%s" % aggregates)
zhufl34afeb22018-02-09 15:03:41 +0800225 host = hosts[0]
226
227 self.client.add_host(aggregate['id'], host=host)
228 self.addCleanup(self.client.remove_host, aggregate['id'], host=host)
zhufl7ae22682016-09-18 15:22:33 +0800229 server = self.create_test_server(availability_zone=az_name,
David Kranz0fb14292015-02-11 15:55:20 -0500230 wait_until='ACTIVE')
zhufl7bc916d2018-08-22 14:47:39 +0800231 server_host = self.get_host_for_server(server['id'])
232 self.assertEqual(host, server_host)
zhufl4af2c822018-08-06 14:38:53 +0800233
234
235class AggregatesAdminTestV241(AggregatesAdminTestBase):
236 min_microversion = '2.41'
237
238 # NOTE(gmann): This test tests the Aggregate APIs response schema
239 # for 2.41 microversion. No specific assert or behaviour verification
240 # is needed.
241
242 @decorators.idempotent_id('fdf24d9e-8afa-4700-b6aa-9c498351504f')
243 def test_create_update_show_aggregate_add_remove_host(self):
244 # Update and add a host to the given aggregate and get details.
245 self.useFixture(fixtures.LockFixture('availability_zone'))
246 # Checking create aggregate API response schema
247 aggregate = self._create_test_aggregate()
248
249 new_aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
250 # Checking update aggregate API response schema
251 self.client.update_aggregate(aggregate['id'], name=new_aggregate_name)
252 # Checking show aggregate API response schema
253 self.client.show_aggregate(aggregate['id'])['aggregate']
254 # Checking add host to aggregate API response schema
255 self.client.add_host(aggregate['id'], host=self.host)
256 # Checking rempve host from aggregate API response schema
257 self.client.remove_host(aggregate['id'], host=self.host)