blob: 02e2b0b7855e775cdd884e076fb64a4a0b6d8a80 [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
Masayuki Igawad9388762015-01-20 14:56:42 +090016from tempest_lib import exceptions as lib_exc
17
Lingxian Kongbf2d5172013-10-01 22:00:24 +080018from tempest.api.compute import base
19from tempest.common import tempest_fixtures as fixtures
20from tempest.common.utils import data_utils
Masayuki Igawa394d8d92014-03-04 17:21:56 +090021from tempest import test
Lingxian Kongbf2d5172013-10-01 22:00:24 +080022
23
24class AggregatesAdminNegativeTestJSON(base.BaseV2ComputeAdminTest):
25
26 """
27 Tests Aggregates API that require admin privileges
28 """
29
Lingxian Kongbf2d5172013-10-01 22:00:24 +080030 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010031 def resource_setup(cls):
32 super(AggregatesAdminNegativeTestJSON, cls).resource_setup()
Lingxian Kongbf2d5172013-10-01 22:00:24 +080033 cls.client = cls.os_adm.aggregates_client
34 cls.user_client = cls.aggregates_client
35 cls.aggregate_name_prefix = 'test_aggregate_'
36 cls.az_name_prefix = 'test_az_'
37
David Kranz0a735172015-01-16 10:51:18 -050038 hosts_all = cls.os_adm.hosts_client.list_hosts()
Lingxian Kongbf2d5172013-10-01 22:00:24 +080039 hosts = map(lambda x: x['host_name'],
40 filter(lambda y: y['service'] == 'compute', hosts_all))
41 cls.host = hosts[0]
42
Masayuki Igawa394d8d92014-03-04 17:21:56 +090043 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080044 @test.idempotent_id('86a1cb14-da37-4a70-b056-903fd56dfe29')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080045 def test_aggregate_create_as_user(self):
46 # Regular user is not allowed to create an aggregate.
47 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
Masayuki Igawa29d554f2015-01-20 12:36:42 +090048 self.assertRaises(lib_exc.Unauthorized,
Lingxian Kongbf2d5172013-10-01 22:00:24 +080049 self.user_client.create_aggregate,
Yuiko Takadaf93d2482014-01-30 16:25:08 +000050 name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +080051
Masayuki Igawa394d8d92014-03-04 17:21:56 +090052 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080053 @test.idempotent_id('3b8a1929-3793-4e92-bcb4-dfa572ee6c1d')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080054 def test_aggregate_create_aggregate_name_length_less_than_1(self):
55 # the length of aggregate name should >= 1 and <=255
Masayuki Igawa4b29e472015-02-16 10:41:54 +090056 self.assertRaises(lib_exc.BadRequest,
Lingxian Kongbf2d5172013-10-01 22:00:24 +080057 self.client.create_aggregate,
Yuiko Takadaf93d2482014-01-30 16:25:08 +000058 name='')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080059
Masayuki Igawa394d8d92014-03-04 17:21:56 +090060 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080061 @test.idempotent_id('4c194563-543b-4e70-a719-557bbe947fac')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080062 def test_aggregate_create_aggregate_name_length_exceeds_255(self):
63 # the length of aggregate name should >= 1 and <=255
64 aggregate_name = 'a' * 256
Masayuki Igawa4b29e472015-02-16 10:41:54 +090065 self.assertRaises(lib_exc.BadRequest,
Lingxian Kongbf2d5172013-10-01 22:00:24 +080066 self.client.create_aggregate,
Yuiko Takadaf93d2482014-01-30 16:25:08 +000067 name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +080068
Masayuki Igawa394d8d92014-03-04 17:21:56 +090069 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080070 @test.idempotent_id('9c23a291-b0b1-487b-b464-132e061151b3')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080071 def test_aggregate_create_with_existent_aggregate_name(self):
72 # creating an aggregate with existent aggregate name is forbidden
73 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -050074 aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +080075 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
76
Masayuki Igawad9388762015-01-20 14:56:42 +090077 self.assertRaises(lib_exc.Conflict,
Lingxian Kongbf2d5172013-10-01 22:00:24 +080078 self.client.create_aggregate,
Yuiko Takadaf93d2482014-01-30 16:25:08 +000079 name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +080080
Masayuki Igawa394d8d92014-03-04 17:21:56 +090081 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080082 @test.idempotent_id('cd6de795-c15d-45f1-8d9e-813c6bb72a3d')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080083 def test_aggregate_delete_as_user(self):
84 # Regular user is not allowed to delete an aggregate.
85 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)
Lingxian Kongbf2d5172013-10-01 22:00:24 +080087 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
88
Masayuki Igawa29d554f2015-01-20 12:36:42 +090089 self.assertRaises(lib_exc.Unauthorized,
Lingxian Kongbf2d5172013-10-01 22:00:24 +080090 self.user_client.delete_aggregate,
91 aggregate['id'])
92
Masayuki Igawa394d8d92014-03-04 17:21:56 +090093 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080094 @test.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 Igawa29d554f2015-01-20 12:36:42 +090097 self.assertRaises(lib_exc.Unauthorized,
Lingxian Kongbf2d5172013-10-01 22:00:24 +080098 self.user_client.list_aggregates)
99
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900100 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800101 @test.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.
104 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -0500105 aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800106 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
107
Masayuki Igawa29d554f2015-01-20 12:36:42 +0900108 self.assertRaises(lib_exc.Unauthorized,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800109 self.user_client.get_aggregate,
110 aggregate['id'])
111
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900112 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800113 @test.idempotent_id('c74f4bf1-4708-4ff2-95a0-f49eaca951bd')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800114 def test_aggregate_delete_with_invalid_id(self):
115 # Delete an aggregate with invalid id should raise exceptions.
Masayuki Igawabfa07602015-01-20 18:47:17 +0900116 self.assertRaises(lib_exc.NotFound,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800117 self.client.delete_aggregate, -1)
118
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900119 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800120 @test.idempotent_id('3c916244-2c46-49a4-9b55-b20bb0ae512c')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800121 def test_aggregate_get_details_with_invalid_id(self):
122 # Get aggregate details with invalid id should raise exceptions.
Masayuki Igawabfa07602015-01-20 18:47:17 +0900123 self.assertRaises(lib_exc.NotFound,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800124 self.client.get_aggregate, -1)
125
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900126 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800127 @test.idempotent_id('0ef07828-12b4-45ba-87cc-41425faf5711')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800128 def test_aggregate_add_non_exist_host(self):
129 # Adding a non-exist host to an aggregate should raise exceptions.
David Kranz0a735172015-01-16 10:51:18 -0500130 hosts_all = self.os_adm.hosts_client.list_hosts()
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800131 hosts = map(lambda x: x['host_name'], hosts_all)
132 while True:
133 non_exist_host = data_utils.rand_name('nonexist_host_')
134 if non_exist_host not in hosts:
135 break
136
137 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -0500138 aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800139 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
140
Masayuki Igawabfa07602015-01-20 18:47:17 +0900141 self.assertRaises(lib_exc.NotFound, self.client.add_host,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800142 aggregate['id'], non_exist_host)
143
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900144 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800145 @test.idempotent_id('7324c334-bd13-4c93-8521-5877322c3d51')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800146 def test_aggregate_add_host_as_user(self):
147 # Regular user is not allowed to add a host to an aggregate.
148 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -0500149 aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800150 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
151
Masayuki Igawa29d554f2015-01-20 12:36:42 +0900152 self.assertRaises(lib_exc.Unauthorized,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800153 self.user_client.add_host,
154 aggregate['id'], self.host)
155
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900156 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800157 @test.idempotent_id('19dd44e1-c435-4ee1-a402-88c4f90b5950')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800158 def test_aggregate_add_existent_host(self):
159 self.useFixture(fixtures.LockFixture('availability_zone'))
160 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -0500161 aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800162 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
163
David Kranz0a735172015-01-16 10:51:18 -0500164 self.client.add_host(aggregate['id'], self.host)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800165 self.addCleanup(self.client.remove_host, aggregate['id'], self.host)
166
Masayuki Igawad9388762015-01-20 14:56:42 +0900167 self.assertRaises(lib_exc.Conflict, self.client.add_host,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800168 aggregate['id'], self.host)
169
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900170 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800171 @test.idempotent_id('7a53af20-137a-4e44-a4ae-e19260e626d9')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800172 def test_aggregate_remove_host_as_user(self):
173 # Regular user is not allowed to remove a host from an aggregate.
174 self.useFixture(fixtures.LockFixture('availability_zone'))
175 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -0500176 aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800177 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
David Kranz0a735172015-01-16 10:51:18 -0500178 self.client.add_host(aggregate['id'], self.host)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800179 self.addCleanup(self.client.remove_host, aggregate['id'], self.host)
180
Masayuki Igawa29d554f2015-01-20 12:36:42 +0900181 self.assertRaises(lib_exc.Unauthorized,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800182 self.user_client.remove_host,
183 aggregate['id'], self.host)
184
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900185 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800186 @test.idempotent_id('95d6a6fa-8da9-4426-84d0-eec0329f2e4d')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800187 def test_aggregate_remove_nonexistent_host(self):
188 non_exist_host = data_utils.rand_name('nonexist_host_')
189 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -0500190 aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800191 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
192
Masayuki Igawabfa07602015-01-20 18:47:17 +0900193 self.assertRaises(lib_exc.NotFound, self.client.remove_host,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800194 aggregate['id'], non_exist_host)