blob: 07c8c4e8a02a335f9ca098aa7f8957b9fc916561 [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
Matthew Treinish01472ff2015-02-20 17:26:52 -050016from tempest_lib.common.utils import data_utils
Masayuki Igawad9388762015-01-20 14:56:42 +090017from tempest_lib import exceptions as lib_exc
18
Lingxian Kongbf2d5172013-10-01 22:00:24 +080019from tempest.api.compute import base
20from tempest.common import tempest_fixtures as fixtures
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
Rohan Kanade60b73092015-02-04 17:58:19 +053031 def setup_clients(cls):
32 super(AggregatesAdminNegativeTestJSON, cls).setup_clients()
Lingxian Kongbf2d5172013-10-01 22:00:24 +080033 cls.client = cls.os_adm.aggregates_client
34 cls.user_client = cls.aggregates_client
Rohan Kanade60b73092015-02-04 17:58:19 +053035
36 @classmethod
37 def resource_setup(cls):
38 super(AggregatesAdminNegativeTestJSON, cls).resource_setup()
Lingxian Kongbf2d5172013-10-01 22:00:24 +080039 cls.aggregate_name_prefix = 'test_aggregate_'
40 cls.az_name_prefix = 'test_az_'
41
David Kranz0a735172015-01-16 10:51:18 -050042 hosts_all = cls.os_adm.hosts_client.list_hosts()
Lingxian Kongbf2d5172013-10-01 22:00:24 +080043 hosts = map(lambda x: x['host_name'],
44 filter(lambda y: y['service'] == 'compute', hosts_all))
45 cls.host = hosts[0]
46
Masayuki Igawa394d8d92014-03-04 17:21:56 +090047 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080048 @test.idempotent_id('86a1cb14-da37-4a70-b056-903fd56dfe29')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080049 def test_aggregate_create_as_user(self):
50 # Regular user is not allowed to create an aggregate.
51 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
Masayuki Igawa6b1cd292015-02-16 11:11:55 +090052 self.assertRaises(lib_exc.Forbidden,
Lingxian Kongbf2d5172013-10-01 22:00:24 +080053 self.user_client.create_aggregate,
Yuiko Takadaf93d2482014-01-30 16:25:08 +000054 name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +080055
Masayuki Igawa394d8d92014-03-04 17:21:56 +090056 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080057 @test.idempotent_id('3b8a1929-3793-4e92-bcb4-dfa572ee6c1d')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080058 def test_aggregate_create_aggregate_name_length_less_than_1(self):
59 # the length of aggregate name should >= 1 and <=255
Masayuki Igawa4b29e472015-02-16 10:41:54 +090060 self.assertRaises(lib_exc.BadRequest,
Lingxian Kongbf2d5172013-10-01 22:00:24 +080061 self.client.create_aggregate,
Yuiko Takadaf93d2482014-01-30 16:25:08 +000062 name='')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080063
Masayuki Igawa394d8d92014-03-04 17:21:56 +090064 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080065 @test.idempotent_id('4c194563-543b-4e70-a719-557bbe947fac')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080066 def test_aggregate_create_aggregate_name_length_exceeds_255(self):
67 # the length of aggregate name should >= 1 and <=255
68 aggregate_name = 'a' * 256
Masayuki Igawa4b29e472015-02-16 10:41:54 +090069 self.assertRaises(lib_exc.BadRequest,
Lingxian Kongbf2d5172013-10-01 22:00:24 +080070 self.client.create_aggregate,
Yuiko Takadaf93d2482014-01-30 16:25:08 +000071 name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +080072
Masayuki Igawa394d8d92014-03-04 17:21:56 +090073 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080074 @test.idempotent_id('9c23a291-b0b1-487b-b464-132e061151b3')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080075 def test_aggregate_create_with_existent_aggregate_name(self):
76 # creating an aggregate with existent aggregate name is forbidden
77 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -050078 aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +080079 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
80
Masayuki Igawad9388762015-01-20 14:56:42 +090081 self.assertRaises(lib_exc.Conflict,
Lingxian Kongbf2d5172013-10-01 22:00:24 +080082 self.client.create_aggregate,
Yuiko Takadaf93d2482014-01-30 16:25:08 +000083 name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +080084
Masayuki Igawa394d8d92014-03-04 17:21:56 +090085 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080086 @test.idempotent_id('cd6de795-c15d-45f1-8d9e-813c6bb72a3d')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080087 def test_aggregate_delete_as_user(self):
88 # Regular user is not allowed to delete an aggregate.
89 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -050090 aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +080091 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
92
Masayuki Igawa6b1cd292015-02-16 11:11:55 +090093 self.assertRaises(lib_exc.Forbidden,
Lingxian Kongbf2d5172013-10-01 22:00:24 +080094 self.user_client.delete_aggregate,
95 aggregate['id'])
96
Masayuki Igawa394d8d92014-03-04 17:21:56 +090097 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080098 @test.idempotent_id('b7d475a6-5dcd-4ff4-b70a-cd9de66a6672')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080099 def test_aggregate_list_as_user(self):
100 # Regular user is not allowed to list aggregates.
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900101 self.assertRaises(lib_exc.Forbidden,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800102 self.user_client.list_aggregates)
103
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900104 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800105 @test.idempotent_id('557cad12-34c9-4ff4-95f0-22f0dfbaf7dc')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800106 def test_aggregate_get_details_as_user(self):
107 # Regular user is not allowed to get aggregate details.
108 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -0500109 aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800110 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
111
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900112 self.assertRaises(lib_exc.Forbidden,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800113 self.user_client.get_aggregate,
114 aggregate['id'])
115
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900116 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800117 @test.idempotent_id('c74f4bf1-4708-4ff2-95a0-f49eaca951bd')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800118 def test_aggregate_delete_with_invalid_id(self):
119 # Delete an aggregate with invalid id should raise exceptions.
Masayuki Igawabfa07602015-01-20 18:47:17 +0900120 self.assertRaises(lib_exc.NotFound,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800121 self.client.delete_aggregate, -1)
122
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900123 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800124 @test.idempotent_id('3c916244-2c46-49a4-9b55-b20bb0ae512c')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800125 def test_aggregate_get_details_with_invalid_id(self):
126 # Get aggregate details with invalid id should raise exceptions.
Masayuki Igawabfa07602015-01-20 18:47:17 +0900127 self.assertRaises(lib_exc.NotFound,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800128 self.client.get_aggregate, -1)
129
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900130 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800131 @test.idempotent_id('0ef07828-12b4-45ba-87cc-41425faf5711')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800132 def test_aggregate_add_non_exist_host(self):
133 # Adding a non-exist host to an aggregate should raise exceptions.
David Kranz0a735172015-01-16 10:51:18 -0500134 hosts_all = self.os_adm.hosts_client.list_hosts()
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800135 hosts = map(lambda x: x['host_name'], hosts_all)
136 while True:
137 non_exist_host = data_utils.rand_name('nonexist_host_')
138 if non_exist_host not in hosts:
139 break
140
141 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -0500142 aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800143 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
144
Masayuki Igawabfa07602015-01-20 18:47:17 +0900145 self.assertRaises(lib_exc.NotFound, self.client.add_host,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800146 aggregate['id'], non_exist_host)
147
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900148 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800149 @test.idempotent_id('7324c334-bd13-4c93-8521-5877322c3d51')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800150 def test_aggregate_add_host_as_user(self):
151 # Regular user is not allowed to add a host to an aggregate.
152 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -0500153 aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800154 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
155
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900156 self.assertRaises(lib_exc.Forbidden,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800157 self.user_client.add_host,
158 aggregate['id'], self.host)
159
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900160 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800161 @test.idempotent_id('19dd44e1-c435-4ee1-a402-88c4f90b5950')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800162 def test_aggregate_add_existent_host(self):
163 self.useFixture(fixtures.LockFixture('availability_zone'))
164 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -0500165 aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800166 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
167
David Kranz0a735172015-01-16 10:51:18 -0500168 self.client.add_host(aggregate['id'], self.host)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800169 self.addCleanup(self.client.remove_host, aggregate['id'], self.host)
170
Masayuki Igawad9388762015-01-20 14:56:42 +0900171 self.assertRaises(lib_exc.Conflict, self.client.add_host,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800172 aggregate['id'], self.host)
173
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900174 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800175 @test.idempotent_id('7a53af20-137a-4e44-a4ae-e19260e626d9')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800176 def test_aggregate_remove_host_as_user(self):
177 # Regular user is not allowed to remove a host from an aggregate.
178 self.useFixture(fixtures.LockFixture('availability_zone'))
179 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -0500180 aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800181 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
David Kranz0a735172015-01-16 10:51:18 -0500182 self.client.add_host(aggregate['id'], self.host)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800183 self.addCleanup(self.client.remove_host, aggregate['id'], self.host)
184
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900185 self.assertRaises(lib_exc.Forbidden,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800186 self.user_client.remove_host,
187 aggregate['id'], self.host)
188
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900189 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800190 @test.idempotent_id('95d6a6fa-8da9-4426-84d0-eec0329f2e4d')
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800191 def test_aggregate_remove_nonexistent_host(self):
192 non_exist_host = data_utils.rand_name('nonexist_host_')
193 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -0500194 aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800195 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
196
Masayuki Igawabfa07602015-01-20 18:47:17 +0900197 self.assertRaises(lib_exc.NotFound, self.client.remove_host,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800198 aggregate['id'], non_exist_host)