blob: 6df8410c1a5434bb4bff7b1494db5d574172e88b [file] [log] [blame]
Lingxian Kongbf2d5172013-10-01 22:00:24 +08001# Copyright 2013 Huawei Technologies Co.,LTD.
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
16from tempest.api.compute import base
17from tempest.common import tempest_fixtures as fixtures
Ken'ichi Ohmichi757833a2017-03-10 10:30:30 -080018from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080019from tempest.lib import decorators
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050020from tempest.lib import exceptions as lib_exc
Lingxian Kongbf2d5172013-10-01 22:00:24 +080021
22
23class AggregatesAdminNegativeTestJSON(base.BaseV2ComputeAdminTest):
Ken'ichi Ohmichi88363cb2015-11-19 08:00:54 +000024 """Tests Aggregates API that require admin privileges"""
Lingxian Kongbf2d5172013-10-01 22:00:24 +080025
Lingxian Kongbf2d5172013-10-01 22:00:24 +080026 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053027 def setup_clients(cls):
28 super(AggregatesAdminNegativeTestJSON, cls).setup_clients()
Jordan Pittier8160d312017-04-18 11:52:23 +020029 cls.client = cls.os_admin.aggregates_client
zhufl88c7ea82018-03-21 10:05:22 +080030 cls.hyper_client = cls.os_admin.hypervisor_client
Rohan Kanade60b73092015-02-04 17:58:19 +053031
32 @classmethod
33 def resource_setup(cls):
34 super(AggregatesAdminNegativeTestJSON, cls).resource_setup()
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000035 cls.aggregate_name_prefix = 'test_aggregate'
Lingxian Kongbf2d5172013-10-01 22:00:24 +080036
zhufl88c7ea82018-03-21 10:05:22 +080037 hyper_list = cls.hyper_client.list_hypervisors()['hypervisors']
38 cls.hosts = [v['hypervisor_hostname'] for v in hyper_list
39 if v['status'] == 'enabled' and v['state'] == 'up']
Lingxian Kongbf2d5172013-10-01 22:00:24 +080040
zhufl08737dc2016-11-16 11:18:55 +080041 def _create_test_aggregate(self):
42 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
43 aggregate = (self.client.create_aggregate(name=aggregate_name)
44 ['aggregate'])
45 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
46 return aggregate
47
Jordan Pittier3b46d272017-04-12 16:17:28 +020048 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080049 @decorators.idempotent_id('86a1cb14-da37-4a70-b056-903fd56dfe29')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080050 def test_aggregate_create_as_user(self):
51 # Regular user is not allowed to create an aggregate.
52 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
Masayuki Igawa6b1cd292015-02-16 11:11:55 +090053 self.assertRaises(lib_exc.Forbidden,
zhuflb61942d2017-10-13 09:59:44 +080054 self.aggregates_client.create_aggregate,
Yuiko Takadaf93d2482014-01-30 16:25:08 +000055 name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +080056
Jordan Pittier3b46d272017-04-12 16:17:28 +020057 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080058 @decorators.idempotent_id('3b8a1929-3793-4e92-bcb4-dfa572ee6c1d')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080059 def test_aggregate_create_aggregate_name_length_less_than_1(self):
60 # the length of aggregate name should >= 1 and <=255
Masayuki Igawa4b29e472015-02-16 10:41:54 +090061 self.assertRaises(lib_exc.BadRequest,
Lingxian Kongbf2d5172013-10-01 22:00:24 +080062 self.client.create_aggregate,
Yuiko Takadaf93d2482014-01-30 16:25:08 +000063 name='')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080064
Jordan Pittier3b46d272017-04-12 16:17:28 +020065 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080066 @decorators.idempotent_id('4c194563-543b-4e70-a719-557bbe947fac')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080067 def test_aggregate_create_aggregate_name_length_exceeds_255(self):
68 # the length of aggregate name should >= 1 and <=255
69 aggregate_name = 'a' * 256
Masayuki Igawa4b29e472015-02-16 10:41:54 +090070 self.assertRaises(lib_exc.BadRequest,
Lingxian Kongbf2d5172013-10-01 22:00:24 +080071 self.client.create_aggregate,
Yuiko Takadaf93d2482014-01-30 16:25:08 +000072 name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +080073
Jordan Pittier3b46d272017-04-12 16:17:28 +020074 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080075 @decorators.idempotent_id('9c23a291-b0b1-487b-b464-132e061151b3')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080076 def test_aggregate_create_with_existent_aggregate_name(self):
77 # creating an aggregate with existent aggregate name is forbidden
zhufl08737dc2016-11-16 11:18:55 +080078 aggregate = self._create_test_aggregate()
Masayuki Igawad9388762015-01-20 14:56:42 +090079 self.assertRaises(lib_exc.Conflict,
Lingxian Kongbf2d5172013-10-01 22:00:24 +080080 self.client.create_aggregate,
zhufl08737dc2016-11-16 11:18:55 +080081 name=aggregate['name'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +080082
Jordan Pittier3b46d272017-04-12 16:17:28 +020083 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080084 @decorators.idempotent_id('cd6de795-c15d-45f1-8d9e-813c6bb72a3d')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080085 def test_aggregate_delete_as_user(self):
86 # Regular user is not allowed to delete an aggregate.
zhufl08737dc2016-11-16 11:18:55 +080087 aggregate = self._create_test_aggregate()
Masayuki Igawa6b1cd292015-02-16 11:11:55 +090088 self.assertRaises(lib_exc.Forbidden,
zhuflb61942d2017-10-13 09:59:44 +080089 self.aggregates_client.delete_aggregate,
Lingxian Kongbf2d5172013-10-01 22:00:24 +080090 aggregate['id'])
91
Jordan Pittier3b46d272017-04-12 16:17:28 +020092 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080093 @decorators.idempotent_id('b7d475a6-5dcd-4ff4-b70a-cd9de66a6672')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080094 def test_aggregate_list_as_user(self):
95 # Regular user is not allowed to list aggregates.
Masayuki Igawa6b1cd292015-02-16 11:11:55 +090096 self.assertRaises(lib_exc.Forbidden,
zhuflb61942d2017-10-13 09:59:44 +080097 self.aggregates_client.list_aggregates)
Lingxian Kongbf2d5172013-10-01 22:00:24 +080098
Jordan Pittier3b46d272017-04-12 16:17:28 +020099 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800100 @decorators.idempotent_id('557cad12-34c9-4ff4-95f0-22f0dfbaf7dc')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800101 def test_aggregate_get_details_as_user(self):
102 # Regular user is not allowed to get aggregate details.
zhufl08737dc2016-11-16 11:18:55 +0800103 aggregate = self._create_test_aggregate()
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900104 self.assertRaises(lib_exc.Forbidden,
zhuflb61942d2017-10-13 09:59:44 +0800105 self.aggregates_client.show_aggregate,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800106 aggregate['id'])
107
Jordan Pittier3b46d272017-04-12 16:17:28 +0200108 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800109 @decorators.idempotent_id('c74f4bf1-4708-4ff2-95a0-f49eaca951bd')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800110 def test_aggregate_delete_with_invalid_id(self):
111 # Delete an aggregate with invalid id should raise exceptions.
Masayuki Igawabfa07602015-01-20 18:47:17 +0900112 self.assertRaises(lib_exc.NotFound,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800113 self.client.delete_aggregate, -1)
114
Jordan Pittier3b46d272017-04-12 16:17:28 +0200115 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800116 @decorators.idempotent_id('3c916244-2c46-49a4-9b55-b20bb0ae512c')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800117 def test_aggregate_get_details_with_invalid_id(self):
118 # Get aggregate details with invalid id should raise exceptions.
Masayuki Igawabfa07602015-01-20 18:47:17 +0900119 self.assertRaises(lib_exc.NotFound,
Ken'ichi Ohmichi3de6d982015-04-13 00:20:41 +0000120 self.client.show_aggregate, -1)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800121
Jordan Pittier3b46d272017-04-12 16:17:28 +0200122 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800123 @decorators.idempotent_id('0ef07828-12b4-45ba-87cc-41425faf5711')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800124 def test_aggregate_add_non_exist_host(self):
125 # Adding a non-exist host to an aggregate should raise exceptions.
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800126 while True:
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +0000127 non_exist_host = data_utils.rand_name('nonexist_host')
zhufl88c7ea82018-03-21 10:05:22 +0800128 if non_exist_host not in self.hosts:
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800129 break
zhufl08737dc2016-11-16 11:18:55 +0800130 aggregate = self._create_test_aggregate()
Masayuki Igawabfa07602015-01-20 18:47:17 +0900131 self.assertRaises(lib_exc.NotFound, self.client.add_host,
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +0000132 aggregate['id'], host=non_exist_host)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800133
Jordan Pittier3b46d272017-04-12 16:17:28 +0200134 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800135 @decorators.idempotent_id('7324c334-bd13-4c93-8521-5877322c3d51')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800136 def test_aggregate_add_host_as_user(self):
137 # Regular user is not allowed to add a host to an aggregate.
zhufl08737dc2016-11-16 11:18:55 +0800138 aggregate = self._create_test_aggregate()
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900139 self.assertRaises(lib_exc.Forbidden,
zhuflb61942d2017-10-13 09:59:44 +0800140 self.aggregates_client.add_host,
zhufl88c7ea82018-03-21 10:05:22 +0800141 aggregate['id'], host=self.hosts[0])
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800142
Jordan Pittier3b46d272017-04-12 16:17:28 +0200143 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800144 @decorators.idempotent_id('19dd44e1-c435-4ee1-a402-88c4f90b5950')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800145 def test_aggregate_add_existent_host(self):
146 self.useFixture(fixtures.LockFixture('availability_zone'))
zhufl08737dc2016-11-16 11:18:55 +0800147 aggregate = self._create_test_aggregate()
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800148
zhufl88c7ea82018-03-21 10:05:22 +0800149 self.client.add_host(aggregate['id'], host=self.hosts[0])
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +0000150 self.addCleanup(self.client.remove_host, aggregate['id'],
zhufl88c7ea82018-03-21 10:05:22 +0800151 host=self.hosts[0])
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800152
Masayuki Igawad9388762015-01-20 14:56:42 +0900153 self.assertRaises(lib_exc.Conflict, self.client.add_host,
zhufl88c7ea82018-03-21 10:05:22 +0800154 aggregate['id'], host=self.hosts[0])
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800155
Jordan Pittier3b46d272017-04-12 16:17:28 +0200156 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800157 @decorators.idempotent_id('7a53af20-137a-4e44-a4ae-e19260e626d9')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800158 def test_aggregate_remove_host_as_user(self):
159 # Regular user is not allowed to remove a host from an aggregate.
160 self.useFixture(fixtures.LockFixture('availability_zone'))
zhufl08737dc2016-11-16 11:18:55 +0800161 aggregate = self._create_test_aggregate()
162
zhufl88c7ea82018-03-21 10:05:22 +0800163 self.client.add_host(aggregate['id'], host=self.hosts[0])
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +0000164 self.addCleanup(self.client.remove_host, aggregate['id'],
zhufl88c7ea82018-03-21 10:05:22 +0800165 host=self.hosts[0])
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800166
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900167 self.assertRaises(lib_exc.Forbidden,
zhuflb61942d2017-10-13 09:59:44 +0800168 self.aggregates_client.remove_host,
zhufl88c7ea82018-03-21 10:05:22 +0800169 aggregate['id'], host=self.hosts[0])
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800170
Jordan Pittier3b46d272017-04-12 16:17:28 +0200171 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800172 @decorators.idempotent_id('95d6a6fa-8da9-4426-84d0-eec0329f2e4d')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800173 def test_aggregate_remove_nonexistent_host(self):
zhufl08737dc2016-11-16 11:18:55 +0800174 aggregate = self._create_test_aggregate()
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800175
Masayuki Igawabfa07602015-01-20 18:47:17 +0900176 self.assertRaises(lib_exc.NotFound, self.client.remove_host,
zhufl6f80dc72016-11-22 17:55:57 +0800177 aggregate['id'], host='nonexist_host')