blob: 35a6479577412f8e77b23a5d894f01f5398b76f1 [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
Matthew Treinish01472ff2015-02-20 17:26:52 -050016from tempest_lib.common.utils import data_utils
Masayuki Igawabfa07602015-01-20 18:47:17 +090017from tempest_lib import exceptions as lib_exc
18
Sean Dague1937d092013-05-17 16:36:38 -040019from tempest.api.compute import base
Matthew Treinisha03ed792013-09-23 21:38:15 +000020from tempest.common import tempest_fixtures as fixtures
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
Rohan Kanade60b73092015-02-04 17:58:19 +053033 def setup_clients(cls):
34 super(AggregatesAdminTestJSON, cls).setup_clients()
35 cls.client = cls.os_adm.aggregates_client
36
37 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010038 def resource_setup(cls):
39 super(AggregatesAdminTestJSON, cls).resource_setup()
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000040 cls.aggregate_name_prefix = 'test_aggregate'
41 cls.az_name_prefix = 'test_az'
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090042
David Kranz0a735172015-01-16 10:51:18 -050043 hosts_all = cls.os_adm.hosts_client.list_hosts()
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090044 hosts = map(lambda x: x['host_name'],
45 filter(lambda y: y['service'] == 'compute', hosts_all))
46 cls.host = hosts[0]
47
anju Tiwari0599f522014-04-17 17:10:40 +053048 def _try_delete_aggregate(self, aggregate_id):
49 # delete aggregate, if it exists
50 try:
51 self.client.delete_aggregate(aggregate_id)
52 # if aggregate not found, it depict it was deleted in the test
Masayuki Igawabfa07602015-01-20 18:47:17 +090053 except lib_exc.NotFound:
anju Tiwari0599f522014-04-17 17:10:40 +053054 pass
55
Chris Hoge7579c1a2015-02-26 14:12:15 -080056 @test.idempotent_id('0d148aa3-d54c-4317-aa8d-42040a475e20')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090057 def test_aggregate_create_delete(self):
58 # Create and delete an aggregate.
Masayuki Igawa259c1132013-10-31 17:48:44 +090059 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -050060 aggregate = self.client.create_aggregate(name=aggregate_name)
anju Tiwari0599f522014-04-17 17:10:40 +053061 self.addCleanup(self._try_delete_aggregate, aggregate['id'])
Chang Bo Guofc77e932013-09-16 17:38:26 -070062 self.assertEqual(aggregate_name, aggregate['name'])
llg8212e4cd3922014-02-15 12:14:21 +080063 self.assertIsNone(aggregate['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090064
David Kranz0a735172015-01-16 10:51:18 -050065 self.client.delete_aggregate(aggregate['id'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090066 self.client.wait_for_resource_deletion(aggregate['id'])
67
Chris Hoge7579c1a2015-02-26 14:12:15 -080068 @test.idempotent_id('5873a6f8-671a-43ff-8838-7ce430bb6d0b')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090069 def test_aggregate_create_delete_with_az(self):
70 # Create and delete an aggregate.
Masayuki Igawa259c1132013-10-31 17:48:44 +090071 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
72 az_name = data_utils.rand_name(self.az_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -050073 aggregate = self.client.create_aggregate(
Yuiko Takadaf93d2482014-01-30 16:25:08 +000074 name=aggregate_name, availability_zone=az_name)
anju Tiwari0599f522014-04-17 17:10:40 +053075 self.addCleanup(self._try_delete_aggregate, aggregate['id'])
Chang Bo Guofc77e932013-09-16 17:38:26 -070076 self.assertEqual(aggregate_name, aggregate['name'])
77 self.assertEqual(az_name, aggregate['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090078
David Kranz0a735172015-01-16 10:51:18 -050079 self.client.delete_aggregate(aggregate['id'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090080 self.client.wait_for_resource_deletion(aggregate['id'])
81
Chris Hoge7579c1a2015-02-26 14:12:15 -080082 @test.idempotent_id('68089c38-04b1-4758-bdf0-cf0daec4defd')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090083 def test_aggregate_create_verify_entry_in_list(self):
84 # Create an aggregate and ensure it is listed.
Masayuki Igawa259c1132013-10-31 17:48:44 +090085 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -050086 aggregate = self.client.create_aggregate(name=aggregate_name)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090087 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
88
David Kranz0a735172015-01-16 10:51:18 -050089 aggregates = self.client.list_aggregates()
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090090 self.assertIn((aggregate['id'], aggregate['availability_zone']),
91 map(lambda x: (x['id'], x['availability_zone']),
92 aggregates))
93
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
Ken'ichi Ohmichi3de6d982015-04-13 00:20:41 +0000101 body = self.client.show_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
Ken'ichi Ohmichi3de6d982015-04-13 00:20:41 +0000113 body = self.client.show_aggregate(aggregate['id'])
ivan-zhu35e1f8e2013-10-18 15:51:16 +0800114 self.assertEqual(meta, body["metadata"])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900115
Chris Hoge7579c1a2015-02-26 14:12:15 -0800116 @test.idempotent_id('4d2b2004-40fa-40a1-aab2-66f4dab81beb')
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800117 def test_aggregate_create_update_with_az(self):
118 # Update an aggregate and ensure properties are updated correctly
Masayuki Igawa259c1132013-10-31 17:48:44 +0900119 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
120 az_name = data_utils.rand_name(self.az_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -0500121 aggregate = self.client.create_aggregate(
Yuiko Takadaf93d2482014-01-30 16:25:08 +0000122 name=aggregate_name, availability_zone=az_name)
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800123 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
124
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800125 self.assertEqual(aggregate_name, aggregate['name'])
126 self.assertEqual(az_name, aggregate['availability_zone'])
127 self.assertIsNotNone(aggregate['id'])
128
129 aggregate_id = aggregate['id']
130 new_aggregate_name = aggregate_name + '_new'
131 new_az_name = az_name + '_new'
132
David Kranz0a735172015-01-16 10:51:18 -0500133 resp_aggregate = self.client.update_aggregate(aggregate_id,
134 new_aggregate_name,
135 new_az_name)
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800136 self.assertEqual(new_aggregate_name, resp_aggregate['name'])
137 self.assertEqual(new_az_name, resp_aggregate['availability_zone'])
138
David Kranz0a735172015-01-16 10:51:18 -0500139 aggregates = self.client.list_aggregates()
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800140 self.assertIn((aggregate_id, new_aggregate_name, new_az_name),
141 map(lambda x:
Matthew Treinish1d14c542014-06-17 20:25:40 -0400142 (x['id'], x['name'], x['availability_zone']),
Zhu Zhu7b5f6292013-09-22 15:47:54 +0800143 aggregates))
144
Chris Hoge7579c1a2015-02-26 14:12:15 -0800145 @test.idempotent_id('c8e85064-e79b-4906-9931-c11c24294d02')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900146 def test_aggregate_add_remove_host(self):
147 # Add an host to the given aggregate and remove.
Matthew Treinisha03ed792013-09-23 21:38:15 +0000148 self.useFixture(fixtures.LockFixture('availability_zone'))
Masayuki Igawa259c1132013-10-31 17:48:44 +0900149 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -0500150 aggregate = self.client.create_aggregate(name=aggregate_name)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900151 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
152
David Kranz0a735172015-01-16 10:51:18 -0500153 body = self.client.add_host(aggregate['id'], self.host)
Chang Bo Guofc77e932013-09-16 17:38:26 -0700154 self.assertEqual(aggregate_name, body['name'])
155 self.assertEqual(aggregate['availability_zone'],
156 body['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900157 self.assertIn(self.host, body['hosts'])
158
David Kranz0a735172015-01-16 10:51:18 -0500159 body = self.client.remove_host(aggregate['id'], self.host)
Chang Bo Guofc77e932013-09-16 17:38:26 -0700160 self.assertEqual(aggregate_name, body['name'])
161 self.assertEqual(aggregate['availability_zone'],
162 body['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900163 self.assertNotIn(self.host, body['hosts'])
164
Chris Hoge7579c1a2015-02-26 14:12:15 -0800165 @test.idempotent_id('7f6a1cc5-2446-4cdb-9baa-b6ae0a919b72')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900166 def test_aggregate_add_host_list(self):
167 # Add an host to the given aggregate and list.
Matthew Treinisha03ed792013-09-23 21:38:15 +0000168 self.useFixture(fixtures.LockFixture('availability_zone'))
Masayuki Igawa259c1132013-10-31 17:48:44 +0900169 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -0500170 aggregate = self.client.create_aggregate(name=aggregate_name)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900171 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
172 self.client.add_host(aggregate['id'], self.host)
173 self.addCleanup(self.client.remove_host, aggregate['id'], self.host)
174
David Kranz0a735172015-01-16 10:51:18 -0500175 aggregates = self.client.list_aggregates()
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900176 aggs = filter(lambda x: x['id'] == aggregate['id'], aggregates)
Chang Bo Guofc77e932013-09-16 17:38:26 -0700177 self.assertEqual(1, len(aggs))
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900178 agg = aggs[0]
Chang Bo Guofc77e932013-09-16 17:38:26 -0700179 self.assertEqual(aggregate_name, agg['name'])
llg8212e4cd3922014-02-15 12:14:21 +0800180 self.assertIsNone(agg['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900181 self.assertIn(self.host, agg['hosts'])
182
Chris Hoge7579c1a2015-02-26 14:12:15 -0800183 @test.idempotent_id('eeef473c-7c52-494d-9f09-2ed7fc8fc036')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900184 def test_aggregate_add_host_get_details(self):
185 # Add an host to the given aggregate and get details.
Matthew Treinisha03ed792013-09-23 21:38:15 +0000186 self.useFixture(fixtures.LockFixture('availability_zone'))
Masayuki Igawa259c1132013-10-31 17:48:44 +0900187 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -0500188 aggregate = self.client.create_aggregate(name=aggregate_name)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900189 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
190 self.client.add_host(aggregate['id'], self.host)
191 self.addCleanup(self.client.remove_host, aggregate['id'], self.host)
192
Ken'ichi Ohmichi3de6d982015-04-13 00:20:41 +0000193 body = self.client.show_aggregate(aggregate['id'])
Chang Bo Guofc77e932013-09-16 17:38:26 -0700194 self.assertEqual(aggregate_name, body['name'])
llg8212e4cd3922014-02-15 12:14:21 +0800195 self.assertIsNone(body['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900196 self.assertIn(self.host, body['hosts'])
197
Chris Hoge7579c1a2015-02-26 14:12:15 -0800198 @test.idempotent_id('96be03c7-570d-409c-90f8-e4db3c646996')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900199 def test_aggregate_add_host_create_server_with_az(self):
200 # Add an host to the given aggregate and create a server.
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)
203 az_name = data_utils.rand_name(self.az_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -0500204 aggregate = self.client.create_aggregate(
Yuiko Takadaf93d2482014-01-30 16:25:08 +0000205 name=aggregate_name, availability_zone=az_name)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900206 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
207 self.client.add_host(aggregate['id'], self.host)
208 self.addCleanup(self.client.remove_host, aggregate['id'], self.host)
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +0000209 server_name = data_utils.rand_name('test_server')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900210 admin_servers_client = self.os_adm.servers_client
David Kranz0fb14292015-02-11 15:55:20 -0500211 server = self.create_test_server(name=server_name,
212 availability_zone=az_name,
213 wait_until='ACTIVE')
214 body = admin_servers_client.get_server(server['id'])
Mitsuhiko Yamazakiae8fc532013-04-22 11:17:35 +0900215 self.assertEqual(self.host, body[self._host_key])