blob: ddd9aa0fac2bf83b5ef81a2d13cd8aa779e0d7b7 [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
Fei Long Wangd39431f2015-05-14 11:30:48 +120020from 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):
Ken'ichi Ohmichi88363cb2015-11-19 08:00:54 +000025 """Tests Aggregates API that require admin privileges"""
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090026
Mitsuhiko Yamazakiae8fc532013-04-22 11:17:35 +090027 _host_key = 'OS-EXT-SRV-ATTR:host'
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090028
29 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053030 def setup_clients(cls):
31 super(AggregatesAdminTestJSON, cls).setup_clients()
32 cls.client = cls.os_adm.aggregates_client
33
34 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010035 def resource_setup(cls):
36 super(AggregatesAdminTestJSON, cls).resource_setup()
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000037 cls.aggregate_name_prefix = 'test_aggregate'
38 cls.az_name_prefix = 'test_az'
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090039
ghanshyame1bd29e2015-08-18 16:47:24 +090040 hosts_all = cls.os_adm.hosts_client.list_hosts()['hosts']
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090041 hosts = map(lambda x: x['host_name'],
42 filter(lambda y: y['service'] == 'compute', hosts_all))
43 cls.host = hosts[0]
44
anju Tiwari0599f522014-04-17 17:10:40 +053045 def _try_delete_aggregate(self, aggregate_id):
46 # delete aggregate, if it exists
47 try:
48 self.client.delete_aggregate(aggregate_id)
49 # if aggregate not found, it depict it was deleted in the test
Masayuki Igawabfa07602015-01-20 18:47:17 +090050 except lib_exc.NotFound:
anju Tiwari0599f522014-04-17 17:10:40 +053051 pass
52
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)
ghanshyam2eb282d2015-08-04 15:05:19 +090057 aggregate = (self.client.create_aggregate(name=aggregate_name)
58 ['aggregate'])
anju Tiwari0599f522014-04-17 17:10:40 +053059 self.addCleanup(self._try_delete_aggregate, aggregate['id'])
Chang Bo Guofc77e932013-09-16 17:38:26 -070060 self.assertEqual(aggregate_name, aggregate['name'])
llg8212e4cd3922014-02-15 12:14:21 +080061 self.assertIsNone(aggregate['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090062
David Kranz0a735172015-01-16 10:51:18 -050063 self.client.delete_aggregate(aggregate['id'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090064 self.client.wait_for_resource_deletion(aggregate['id'])
65
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(
ghanshyam2eb282d2015-08-04 15:05:19 +090072 name=aggregate_name, availability_zone=az_name)['aggregate']
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
Chris Hoge7579c1a2015-02-26 14:12:15 -080080 @test.idempotent_id('68089c38-04b1-4758-bdf0-cf0daec4defd')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090081 def test_aggregate_create_verify_entry_in_list(self):
82 # Create an aggregate and ensure it is listed.
Masayuki Igawa259c1132013-10-31 17:48:44 +090083 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
ghanshyam2eb282d2015-08-04 15:05:19 +090084 aggregate = (self.client.create_aggregate(name=aggregate_name)
85 ['aggregate'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090086 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
87
ghanshyam2eb282d2015-08-04 15:05:19 +090088 aggregates = self.client.list_aggregates()['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
Chris Hoge7579c1a2015-02-26 14:12:15 -080093 @test.idempotent_id('36ec92ca-7a73-43bc-b920-7531809e8540')
ivan-zhu35e1f8e2013-10-18 15:51:16 +080094 def test_aggregate_create_update_metadata_get_details(self):
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090095 # Create an aggregate and ensure its details are returned.
Masayuki Igawa259c1132013-10-31 17:48:44 +090096 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
ghanshyam2eb282d2015-08-04 15:05:19 +090097 aggregate = (self.client.create_aggregate(name=aggregate_name)
98 ['aggregate'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090099 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
100
ghanshyam2eb282d2015-08-04 15:05:19 +0900101 body = self.client.show_aggregate(aggregate['id'])['aggregate']
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"}
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +0000109 body = self.client.set_metadata(aggregate['id'], metadata=meta)
ghanshyam2eb282d2015-08-04 15:05:19 +0900110 self.assertEqual(meta, body['aggregate']["metadata"])
ivan-zhu35e1f8e2013-10-18 15:51:16 +0800111
112 # verify the metadata has been set
ghanshyam2eb282d2015-08-04 15:05:19 +0900113 body = self.client.show_aggregate(aggregate['id'])['aggregate']
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(
ghanshyam2eb282d2015-08-04 15:05:19 +0900122 name=aggregate_name, availability_zone=az_name)['aggregate']
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
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +0000133 resp_aggregate = self.client.update_aggregate(
134 aggregate_id,
135 name=new_aggregate_name,
ghanshyam2eb282d2015-08-04 15:05:19 +0900136 availability_zone=new_az_name)['aggregate']
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
ghanshyam2eb282d2015-08-04 15:05:19 +0900140 aggregates = self.client.list_aggregates()['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
Chris Hoge7579c1a2015-02-26 14:12:15 -0800146 @test.idempotent_id('c8e85064-e79b-4906-9931-c11c24294d02')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900147 def test_aggregate_add_remove_host(self):
148 # Add an host to the given aggregate and remove.
Matthew Treinisha03ed792013-09-23 21:38:15 +0000149 self.useFixture(fixtures.LockFixture('availability_zone'))
Masayuki Igawa259c1132013-10-31 17:48:44 +0900150 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
ghanshyam2eb282d2015-08-04 15:05:19 +0900151 aggregate = (self.client.create_aggregate(name=aggregate_name)
152 ['aggregate'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900153 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
154
ghanshyam2eb282d2015-08-04 15:05:19 +0900155 body = (self.client.add_host(aggregate['id'], host=self.host)
156 ['aggregate'])
Chang Bo Guofc77e932013-09-16 17:38:26 -0700157 self.assertEqual(aggregate_name, body['name'])
158 self.assertEqual(aggregate['availability_zone'],
159 body['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900160 self.assertIn(self.host, body['hosts'])
161
ghanshyam2eb282d2015-08-04 15:05:19 +0900162 body = (self.client.remove_host(aggregate['id'], host=self.host)
163 ['aggregate'])
Chang Bo Guofc77e932013-09-16 17:38:26 -0700164 self.assertEqual(aggregate_name, body['name'])
165 self.assertEqual(aggregate['availability_zone'],
166 body['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900167 self.assertNotIn(self.host, body['hosts'])
168
Chris Hoge7579c1a2015-02-26 14:12:15 -0800169 @test.idempotent_id('7f6a1cc5-2446-4cdb-9baa-b6ae0a919b72')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900170 def test_aggregate_add_host_list(self):
171 # Add an host to the given aggregate and list.
Matthew Treinisha03ed792013-09-23 21:38:15 +0000172 self.useFixture(fixtures.LockFixture('availability_zone'))
Masayuki Igawa259c1132013-10-31 17:48:44 +0900173 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
ghanshyam2eb282d2015-08-04 15:05:19 +0900174 aggregate = (self.client.create_aggregate(name=aggregate_name)
175 ['aggregate'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900176 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
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']
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900182 aggs = filter(lambda x: x['id'] == aggregate['id'], aggregates)
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
Chris Hoge7579c1a2015-02-26 14:12:15 -0800189 @test.idempotent_id('eeef473c-7c52-494d-9f09-2ed7fc8fc036')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900190 def test_aggregate_add_host_get_details(self):
191 # Add an 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)
ghanshyam2eb282d2015-08-04 15:05:19 +0900194 aggregate = (self.client.create_aggregate(name=aggregate_name)
195 ['aggregate'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900196 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +0000197 self.client.add_host(aggregate['id'], host=self.host)
198 self.addCleanup(self.client.remove_host, aggregate['id'],
199 host=self.host)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900200
ghanshyam2eb282d2015-08-04 15:05:19 +0900201 body = self.client.show_aggregate(aggregate['id'])['aggregate']
Chang Bo Guofc77e932013-09-16 17:38:26 -0700202 self.assertEqual(aggregate_name, body['name'])
llg8212e4cd3922014-02-15 12:14:21 +0800203 self.assertIsNone(body['availability_zone'])
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900204 self.assertIn(self.host, body['hosts'])
205
Chris Hoge7579c1a2015-02-26 14:12:15 -0800206 @test.idempotent_id('96be03c7-570d-409c-90f8-e4db3c646996')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900207 def test_aggregate_add_host_create_server_with_az(self):
208 # Add an host to the given aggregate and create a server.
Matthew Treinisha03ed792013-09-23 21:38:15 +0000209 self.useFixture(fixtures.LockFixture('availability_zone'))
Masayuki Igawa259c1132013-10-31 17:48:44 +0900210 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
211 az_name = data_utils.rand_name(self.az_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -0500212 aggregate = self.client.create_aggregate(
ghanshyam2eb282d2015-08-04 15:05:19 +0900213 name=aggregate_name, availability_zone=az_name)['aggregate']
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900214 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +0000215 self.client.add_host(aggregate['id'], host=self.host)
216 self.addCleanup(self.client.remove_host, aggregate['id'],
217 host=self.host)
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +0000218 server_name = data_utils.rand_name('test_server')
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +0900219 admin_servers_client = self.os_adm.servers_client
David Kranz0fb14292015-02-11 15:55:20 -0500220 server = self.create_test_server(name=server_name,
221 availability_zone=az_name,
222 wait_until='ACTIVE')
ghanshyam0f825252015-08-25 16:02:50 +0900223 body = admin_servers_client.show_server(server['id'])['server']
Mitsuhiko Yamazakiae8fc532013-04-22 11:17:35 +0900224 self.assertEqual(self.host, body[self._host_key])