blob: 41be620d4e466bd3362ad4d880cc5f2145d826e6 [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
Lingxian Kongbf2d5172013-10-01 22:00:24 +080030 cls.user_client = cls.aggregates_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
Jordan Pittier8160d312017-04-18 11:52:23 +020037 hosts_all = cls.os_admin.hosts_client.list_hosts()['hosts']
Sirushti Murugesan935f2cc2016-07-12 19:48:24 +053038 hosts = ([host['host_name']
39 for host in hosts_all if host['service'] == 'compute'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +080040 cls.host = hosts[0]
41
zhufl08737dc2016-11-16 11:18:55 +080042 def _create_test_aggregate(self):
43 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
44 aggregate = (self.client.create_aggregate(name=aggregate_name)
45 ['aggregate'])
46 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
47 return aggregate
48
Jordan Pittier3b46d272017-04-12 16:17:28 +020049 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080050 @decorators.idempotent_id('86a1cb14-da37-4a70-b056-903fd56dfe29')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080051 def test_aggregate_create_as_user(self):
52 # Regular user is not allowed to create an aggregate.
53 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
Masayuki Igawa6b1cd292015-02-16 11:11:55 +090054 self.assertRaises(lib_exc.Forbidden,
Lingxian Kongbf2d5172013-10-01 22:00:24 +080055 self.user_client.create_aggregate,
Yuiko Takadaf93d2482014-01-30 16:25:08 +000056 name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +080057
Jordan Pittier3b46d272017-04-12 16:17:28 +020058 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080059 @decorators.idempotent_id('3b8a1929-3793-4e92-bcb4-dfa572ee6c1d')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080060 def test_aggregate_create_aggregate_name_length_less_than_1(self):
61 # the length of aggregate name should >= 1 and <=255
Masayuki Igawa4b29e472015-02-16 10:41:54 +090062 self.assertRaises(lib_exc.BadRequest,
Lingxian Kongbf2d5172013-10-01 22:00:24 +080063 self.client.create_aggregate,
Yuiko Takadaf93d2482014-01-30 16:25:08 +000064 name='')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080065
Jordan Pittier3b46d272017-04-12 16:17:28 +020066 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080067 @decorators.idempotent_id('4c194563-543b-4e70-a719-557bbe947fac')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080068 def test_aggregate_create_aggregate_name_length_exceeds_255(self):
69 # the length of aggregate name should >= 1 and <=255
70 aggregate_name = 'a' * 256
Masayuki Igawa4b29e472015-02-16 10:41:54 +090071 self.assertRaises(lib_exc.BadRequest,
Lingxian Kongbf2d5172013-10-01 22:00:24 +080072 self.client.create_aggregate,
Yuiko Takadaf93d2482014-01-30 16:25:08 +000073 name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +080074
Jordan Pittier3b46d272017-04-12 16:17:28 +020075 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080076 @decorators.idempotent_id('9c23a291-b0b1-487b-b464-132e061151b3')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080077 def test_aggregate_create_with_existent_aggregate_name(self):
78 # creating an aggregate with existent aggregate name is forbidden
zhufl08737dc2016-11-16 11:18:55 +080079 aggregate = self._create_test_aggregate()
Masayuki Igawad9388762015-01-20 14:56:42 +090080 self.assertRaises(lib_exc.Conflict,
Lingxian Kongbf2d5172013-10-01 22:00:24 +080081 self.client.create_aggregate,
zhufl08737dc2016-11-16 11:18:55 +080082 name=aggregate['name'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +080083
Jordan Pittier3b46d272017-04-12 16:17:28 +020084 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080085 @decorators.idempotent_id('cd6de795-c15d-45f1-8d9e-813c6bb72a3d')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080086 def test_aggregate_delete_as_user(self):
87 # Regular user is not allowed to delete an aggregate.
zhufl08737dc2016-11-16 11:18:55 +080088 aggregate = self._create_test_aggregate()
Masayuki Igawa6b1cd292015-02-16 11:11:55 +090089 self.assertRaises(lib_exc.Forbidden,
Lingxian Kongbf2d5172013-10-01 22:00:24 +080090 self.user_client.delete_aggregate,
91 aggregate['id'])
92
Jordan Pittier3b46d272017-04-12 16:17:28 +020093 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080094 @decorators.idempotent_id('b7d475a6-5dcd-4ff4-b70a-cd9de66a6672')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080095 def test_aggregate_list_as_user(self):
96 # Regular user is not allowed to list aggregates.
Masayuki Igawa6b1cd292015-02-16 11:11:55 +090097 self.assertRaises(lib_exc.Forbidden,
Lingxian Kongbf2d5172013-10-01 22:00:24 +080098 self.user_client.list_aggregates)
99
Jordan Pittier3b46d272017-04-12 16:17:28 +0200100 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800101 @decorators.idempotent_id('557cad12-34c9-4ff4-95f0-22f0dfbaf7dc')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800102 def test_aggregate_get_details_as_user(self):
103 # Regular user is not allowed to get aggregate details.
zhufl08737dc2016-11-16 11:18:55 +0800104 aggregate = self._create_test_aggregate()
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900105 self.assertRaises(lib_exc.Forbidden,
Ken'ichi Ohmichi3de6d982015-04-13 00:20:41 +0000106 self.user_client.show_aggregate,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800107 aggregate['id'])
108
Jordan Pittier3b46d272017-04-12 16:17:28 +0200109 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800110 @decorators.idempotent_id('c74f4bf1-4708-4ff2-95a0-f49eaca951bd')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800111 def test_aggregate_delete_with_invalid_id(self):
112 # Delete an aggregate with invalid id should raise exceptions.
Masayuki Igawabfa07602015-01-20 18:47:17 +0900113 self.assertRaises(lib_exc.NotFound,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800114 self.client.delete_aggregate, -1)
115
Jordan Pittier3b46d272017-04-12 16:17:28 +0200116 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800117 @decorators.idempotent_id('3c916244-2c46-49a4-9b55-b20bb0ae512c')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800118 def test_aggregate_get_details_with_invalid_id(self):
119 # Get aggregate details with invalid id should raise exceptions.
Masayuki Igawabfa07602015-01-20 18:47:17 +0900120 self.assertRaises(lib_exc.NotFound,
Ken'ichi Ohmichi3de6d982015-04-13 00:20:41 +0000121 self.client.show_aggregate, -1)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800122
Jordan Pittier3b46d272017-04-12 16:17:28 +0200123 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800124 @decorators.idempotent_id('0ef07828-12b4-45ba-87cc-41425faf5711')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800125 def test_aggregate_add_non_exist_host(self):
126 # Adding a non-exist host to an aggregate should raise exceptions.
Jordan Pittier8160d312017-04-18 11:52:23 +0200127 hosts_all = self.os_admin.hosts_client.list_hosts()['hosts']
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800128 hosts = map(lambda x: x['host_name'], hosts_all)
129 while True:
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +0000130 non_exist_host = data_utils.rand_name('nonexist_host')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800131 if non_exist_host not in hosts:
132 break
zhufl08737dc2016-11-16 11:18:55 +0800133 aggregate = self._create_test_aggregate()
Masayuki Igawabfa07602015-01-20 18:47:17 +0900134 self.assertRaises(lib_exc.NotFound, self.client.add_host,
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +0000135 aggregate['id'], host=non_exist_host)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800136
Jordan Pittier3b46d272017-04-12 16:17:28 +0200137 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800138 @decorators.idempotent_id('7324c334-bd13-4c93-8521-5877322c3d51')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800139 def test_aggregate_add_host_as_user(self):
140 # Regular user is not allowed to add a host to an aggregate.
zhufl08737dc2016-11-16 11:18:55 +0800141 aggregate = self._create_test_aggregate()
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900142 self.assertRaises(lib_exc.Forbidden,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800143 self.user_client.add_host,
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +0000144 aggregate['id'], host=self.host)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800145
Jordan Pittier3b46d272017-04-12 16:17:28 +0200146 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800147 @decorators.idempotent_id('19dd44e1-c435-4ee1-a402-88c4f90b5950')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800148 def test_aggregate_add_existent_host(self):
149 self.useFixture(fixtures.LockFixture('availability_zone'))
zhufl08737dc2016-11-16 11:18:55 +0800150 aggregate = self._create_test_aggregate()
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800151
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +0000152 self.client.add_host(aggregate['id'], host=self.host)
153 self.addCleanup(self.client.remove_host, aggregate['id'],
154 host=self.host)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800155
Masayuki Igawad9388762015-01-20 14:56:42 +0900156 self.assertRaises(lib_exc.Conflict, self.client.add_host,
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +0000157 aggregate['id'], host=self.host)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800158
Jordan Pittier3b46d272017-04-12 16:17:28 +0200159 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800160 @decorators.idempotent_id('7a53af20-137a-4e44-a4ae-e19260e626d9')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800161 def test_aggregate_remove_host_as_user(self):
162 # Regular user is not allowed to remove a host from an aggregate.
163 self.useFixture(fixtures.LockFixture('availability_zone'))
zhufl08737dc2016-11-16 11:18:55 +0800164 aggregate = self._create_test_aggregate()
165
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +0000166 self.client.add_host(aggregate['id'], host=self.host)
167 self.addCleanup(self.client.remove_host, aggregate['id'],
168 host=self.host)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800169
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900170 self.assertRaises(lib_exc.Forbidden,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800171 self.user_client.remove_host,
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +0000172 aggregate['id'], host=self.host)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800173
Jordan Pittier3b46d272017-04-12 16:17:28 +0200174 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800175 @decorators.idempotent_id('95d6a6fa-8da9-4426-84d0-eec0329f2e4d')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800176 def test_aggregate_remove_nonexistent_host(self):
zhufl08737dc2016-11-16 11:18:55 +0800177 aggregate = self._create_test_aggregate()
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800178
Masayuki Igawabfa07602015-01-20 18:47:17 +0900179 self.assertRaises(lib_exc.NotFound, self.client.remove_host,
zhufl6f80dc72016-11-22 17:55:57 +0800180 aggregate['id'], host='nonexist_host')