blob: fd44f7ffcfdb4ff27fa243fb4b16443182779392 [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'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +080044 def test_aggregate_create_as_user(self):
45 # Regular user is not allowed to create an aggregate.
46 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
Masayuki Igawa29d554f2015-01-20 12:36:42 +090047 self.assertRaises(lib_exc.Unauthorized,
Lingxian Kongbf2d5172013-10-01 22:00:24 +080048 self.user_client.create_aggregate,
Yuiko Takadaf93d2482014-01-30 16:25:08 +000049 name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +080050
Masayuki Igawa394d8d92014-03-04 17:21:56 +090051 @test.attr(type=['negative', 'gate'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +080052 def test_aggregate_create_aggregate_name_length_less_than_1(self):
53 # the length of aggregate name should >= 1 and <=255
Masayuki Igawa4b29e472015-02-16 10:41:54 +090054 self.assertRaises(lib_exc.BadRequest,
Lingxian Kongbf2d5172013-10-01 22:00:24 +080055 self.client.create_aggregate,
Yuiko Takadaf93d2482014-01-30 16:25:08 +000056 name='')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080057
Masayuki Igawa394d8d92014-03-04 17:21:56 +090058 @test.attr(type=['negative', 'gate'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +080059 def test_aggregate_create_aggregate_name_length_exceeds_255(self):
60 # the length of aggregate name should >= 1 and <=255
61 aggregate_name = 'a' * 256
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=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +080065
Masayuki Igawa394d8d92014-03-04 17:21:56 +090066 @test.attr(type=['negative', 'gate'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +080067 def test_aggregate_create_with_existent_aggregate_name(self):
68 # creating an aggregate with existent aggregate name is forbidden
69 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -050070 aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +080071 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
72
Masayuki Igawad9388762015-01-20 14:56:42 +090073 self.assertRaises(lib_exc.Conflict,
Lingxian Kongbf2d5172013-10-01 22:00:24 +080074 self.client.create_aggregate,
Yuiko Takadaf93d2482014-01-30 16:25:08 +000075 name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +080076
Masayuki Igawa394d8d92014-03-04 17:21:56 +090077 @test.attr(type=['negative', 'gate'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +080078 def test_aggregate_delete_as_user(self):
79 # Regular user is not allowed to delete an aggregate.
80 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -050081 aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +080082 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
83
Masayuki Igawa29d554f2015-01-20 12:36:42 +090084 self.assertRaises(lib_exc.Unauthorized,
Lingxian Kongbf2d5172013-10-01 22:00:24 +080085 self.user_client.delete_aggregate,
86 aggregate['id'])
87
Masayuki Igawa394d8d92014-03-04 17:21:56 +090088 @test.attr(type=['negative', 'gate'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +080089 def test_aggregate_list_as_user(self):
90 # Regular user is not allowed to list aggregates.
Masayuki Igawa29d554f2015-01-20 12:36:42 +090091 self.assertRaises(lib_exc.Unauthorized,
Lingxian Kongbf2d5172013-10-01 22:00:24 +080092 self.user_client.list_aggregates)
93
Masayuki Igawa394d8d92014-03-04 17:21:56 +090094 @test.attr(type=['negative', 'gate'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +080095 def test_aggregate_get_details_as_user(self):
96 # Regular user is not allowed to get aggregate details.
97 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -050098 aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +080099 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
100
Masayuki Igawa29d554f2015-01-20 12:36:42 +0900101 self.assertRaises(lib_exc.Unauthorized,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800102 self.user_client.get_aggregate,
103 aggregate['id'])
104
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900105 @test.attr(type=['negative', 'gate'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800106 def test_aggregate_delete_with_invalid_id(self):
107 # Delete an aggregate with invalid id should raise exceptions.
Masayuki Igawabfa07602015-01-20 18:47:17 +0900108 self.assertRaises(lib_exc.NotFound,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800109 self.client.delete_aggregate, -1)
110
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900111 @test.attr(type=['negative', 'gate'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800112 def test_aggregate_get_details_with_invalid_id(self):
113 # Get aggregate details with invalid id should raise exceptions.
Masayuki Igawabfa07602015-01-20 18:47:17 +0900114 self.assertRaises(lib_exc.NotFound,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800115 self.client.get_aggregate, -1)
116
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900117 @test.attr(type=['negative', 'gate'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800118 def test_aggregate_add_non_exist_host(self):
119 # Adding a non-exist host to an aggregate should raise exceptions.
David Kranz0a735172015-01-16 10:51:18 -0500120 hosts_all = self.os_adm.hosts_client.list_hosts()
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800121 hosts = map(lambda x: x['host_name'], hosts_all)
122 while True:
123 non_exist_host = data_utils.rand_name('nonexist_host_')
124 if non_exist_host not in hosts:
125 break
126
127 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -0500128 aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800129 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
130
Masayuki Igawabfa07602015-01-20 18:47:17 +0900131 self.assertRaises(lib_exc.NotFound, self.client.add_host,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800132 aggregate['id'], non_exist_host)
133
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900134 @test.attr(type=['negative', 'gate'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800135 def test_aggregate_add_host_as_user(self):
136 # Regular user is not allowed to add a host to an aggregate.
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 Igawa29d554f2015-01-20 12:36:42 +0900141 self.assertRaises(lib_exc.Unauthorized,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800142 self.user_client.add_host,
143 aggregate['id'], self.host)
144
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900145 @test.attr(type=['negative', 'gate'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800146 def test_aggregate_add_existent_host(self):
147 self.useFixture(fixtures.LockFixture('availability_zone'))
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
David Kranz0a735172015-01-16 10:51:18 -0500152 self.client.add_host(aggregate['id'], self.host)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800153 self.addCleanup(self.client.remove_host, aggregate['id'], self.host)
154
Masayuki Igawad9388762015-01-20 14:56:42 +0900155 self.assertRaises(lib_exc.Conflict, self.client.add_host,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800156 aggregate['id'], self.host)
157
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900158 @test.attr(type=['negative', 'gate'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800159 def test_aggregate_remove_host_as_user(self):
160 # Regular user is not allowed to remove a host from an aggregate.
161 self.useFixture(fixtures.LockFixture('availability_zone'))
162 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
David Kranz0a735172015-01-16 10:51:18 -0500163 aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800164 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
David Kranz0a735172015-01-16 10:51:18 -0500165 self.client.add_host(aggregate['id'], self.host)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800166 self.addCleanup(self.client.remove_host, aggregate['id'], self.host)
167
Masayuki Igawa29d554f2015-01-20 12:36:42 +0900168 self.assertRaises(lib_exc.Unauthorized,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800169 self.user_client.remove_host,
170 aggregate['id'], self.host)
171
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900172 @test.attr(type=['negative', 'gate'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800173 def test_aggregate_remove_nonexistent_host(self):
174 non_exist_host = data_utils.rand_name('nonexist_host_')
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'])
178
Masayuki Igawabfa07602015-01-20 18:47:17 +0900179 self.assertRaises(lib_exc.NotFound, self.client.remove_host,
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800180 aggregate['id'], non_exist_host)