blob: 690f2abc30a6aee6f3da0670ba7dfa3ebc42a8e5 [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
18from tempest.common.utils import data_utils
19from tempest import exceptions
Masayuki Igawa394d8d92014-03-04 17:21:56 +090020from tempest import test
Lingxian Kongbf2d5172013-10-01 22:00:24 +080021
22
23class AggregatesAdminNegativeTestJSON(base.BaseV2ComputeAdminTest):
24
25 """
26 Tests Aggregates API that require admin privileges
27 """
28
Lingxian Kongbf2d5172013-10-01 22:00:24 +080029 @classmethod
30 def setUpClass(cls):
31 super(AggregatesAdminNegativeTestJSON, cls).setUpClass()
32 cls.client = cls.os_adm.aggregates_client
33 cls.user_client = cls.aggregates_client
34 cls.aggregate_name_prefix = 'test_aggregate_'
35 cls.az_name_prefix = 'test_az_'
36
37 resp, hosts_all = cls.os_adm.hosts_client.list_hosts()
38 hosts = map(lambda x: x['host_name'],
39 filter(lambda y: y['service'] == 'compute', hosts_all))
40 cls.host = hosts[0]
41
Masayuki Igawa394d8d92014-03-04 17:21:56 +090042 @test.attr(type=['negative', 'gate'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +080043 def test_aggregate_create_as_user(self):
44 # Regular user is not allowed to create an aggregate.
45 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
46 self.assertRaises(exceptions.Unauthorized,
47 self.user_client.create_aggregate,
Yuiko Takadaf93d2482014-01-30 16:25:08 +000048 name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +080049
Masayuki Igawa394d8d92014-03-04 17:21:56 +090050 @test.attr(type=['negative', 'gate'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +080051 def test_aggregate_create_aggregate_name_length_less_than_1(self):
52 # the length of aggregate name should >= 1 and <=255
53 self.assertRaises(exceptions.BadRequest,
54 self.client.create_aggregate,
Yuiko Takadaf93d2482014-01-30 16:25:08 +000055 name='')
Lingxian Kongbf2d5172013-10-01 22:00:24 +080056
Masayuki Igawa394d8d92014-03-04 17:21:56 +090057 @test.attr(type=['negative', 'gate'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +080058 def test_aggregate_create_aggregate_name_length_exceeds_255(self):
59 # the length of aggregate name should >= 1 and <=255
60 aggregate_name = 'a' * 256
61 self.assertRaises(exceptions.BadRequest,
62 self.client.create_aggregate,
Yuiko Takadaf93d2482014-01-30 16:25:08 +000063 name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +080064
Masayuki Igawa394d8d92014-03-04 17:21:56 +090065 @test.attr(type=['negative', 'gate'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +080066 def test_aggregate_create_with_existent_aggregate_name(self):
67 # creating an aggregate with existent aggregate name is forbidden
68 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
Yuiko Takadaf93d2482014-01-30 16:25:08 +000069 resp, aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +080070 self.assertEqual(200, resp.status)
71 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
72
73 self.assertRaises(exceptions.Conflict,
74 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)
Yuiko Takadaf93d2482014-01-30 16:25:08 +000081 resp, aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +080082 self.assertEqual(200, resp.status)
83 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
84
85 self.assertRaises(exceptions.Unauthorized,
86 self.user_client.delete_aggregate,
87 aggregate['id'])
88
Masayuki Igawa394d8d92014-03-04 17:21:56 +090089 @test.attr(type=['negative', 'gate'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +080090 def test_aggregate_list_as_user(self):
91 # Regular user is not allowed to list aggregates.
92 self.assertRaises(exceptions.Unauthorized,
93 self.user_client.list_aggregates)
94
Masayuki Igawa394d8d92014-03-04 17:21:56 +090095 @test.attr(type=['negative', 'gate'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +080096 def test_aggregate_get_details_as_user(self):
97 # Regular user is not allowed to get aggregate details.
98 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
Yuiko Takadaf93d2482014-01-30 16:25:08 +000099 resp, aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800100 self.assertEqual(200, resp.status)
101 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
102
103 self.assertRaises(exceptions.Unauthorized,
104 self.user_client.get_aggregate,
105 aggregate['id'])
106
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900107 @test.attr(type=['negative', 'gate'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800108 def test_aggregate_delete_with_invalid_id(self):
109 # Delete an aggregate with invalid id should raise exceptions.
110 self.assertRaises(exceptions.NotFound,
111 self.client.delete_aggregate, -1)
112
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900113 @test.attr(type=['negative', 'gate'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800114 def test_aggregate_get_details_with_invalid_id(self):
115 # Get aggregate details with invalid id should raise exceptions.
116 self.assertRaises(exceptions.NotFound,
117 self.client.get_aggregate, -1)
118
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900119 @test.attr(type=['negative', 'gate'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800120 def test_aggregate_add_non_exist_host(self):
121 # Adding a non-exist host to an aggregate should raise exceptions.
122 resp, hosts_all = self.os_adm.hosts_client.list_hosts()
123 hosts = map(lambda x: x['host_name'], hosts_all)
124 while True:
125 non_exist_host = data_utils.rand_name('nonexist_host_')
126 if non_exist_host not in hosts:
127 break
128
129 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
Yuiko Takadaf93d2482014-01-30 16:25:08 +0000130 resp, aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800131 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
132
133 self.assertRaises(exceptions.NotFound, self.client.add_host,
134 aggregate['id'], non_exist_host)
135
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900136 @test.attr(type=['negative', 'gate'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800137 def test_aggregate_add_host_as_user(self):
138 # Regular user is not allowed to add a host to an aggregate.
139 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
Yuiko Takadaf93d2482014-01-30 16:25:08 +0000140 resp, aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800141 self.assertEqual(200, resp.status)
142 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
143
144 self.assertRaises(exceptions.Unauthorized,
145 self.user_client.add_host,
146 aggregate['id'], self.host)
147
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900148 @test.attr(type=['negative', 'gate'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800149 def test_aggregate_add_existent_host(self):
150 self.useFixture(fixtures.LockFixture('availability_zone'))
151 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
Yuiko Takadaf93d2482014-01-30 16:25:08 +0000152 resp, aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800153 self.assertEqual(200, resp.status)
154 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
155
156 resp, body = self.client.add_host(aggregate['id'], self.host)
157 self.assertEqual(200, resp.status)
158 self.addCleanup(self.client.remove_host, aggregate['id'], self.host)
159
160 self.assertRaises(exceptions.Conflict, self.client.add_host,
161 aggregate['id'], self.host)
162
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900163 @test.attr(type=['negative', 'gate'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800164 def test_aggregate_remove_host_as_user(self):
165 # Regular user is not allowed to remove a host from an aggregate.
166 self.useFixture(fixtures.LockFixture('availability_zone'))
167 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
Yuiko Takadaf93d2482014-01-30 16:25:08 +0000168 resp, aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800169 self.assertEqual(200, resp.status)
170 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
171 resp, body = self.client.add_host(aggregate['id'], self.host)
172 self.assertEqual(200, resp.status)
173 self.addCleanup(self.client.remove_host, aggregate['id'], self.host)
174
175 self.assertRaises(exceptions.Unauthorized,
176 self.user_client.remove_host,
177 aggregate['id'], self.host)
178
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900179 @test.attr(type=['negative', 'gate'])
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800180 def test_aggregate_remove_nonexistent_host(self):
181 non_exist_host = data_utils.rand_name('nonexist_host_')
182 aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
Yuiko Takadaf93d2482014-01-30 16:25:08 +0000183 resp, aggregate = self.client.create_aggregate(name=aggregate_name)
Lingxian Kongbf2d5172013-10-01 22:00:24 +0800184 self.assertEqual(200, resp.status)
185 self.addCleanup(self.client.delete_aggregate, aggregate['id'])
186
187 self.assertRaises(exceptions.NotFound, self.client.remove_host,
188 aggregate['id'], non_exist_host)
189
190
191class AggregatesAdminNegativeTestXML(AggregatesAdminNegativeTestJSON):
192 _interface = 'xml'