Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 1 | # 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 Igawa | d938876 | 2015-01-20 14:56:42 +0900 | [diff] [blame] | 16 | from tempest_lib import exceptions as lib_exc |
| 17 | |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 18 | from tempest.api.compute import base |
| 19 | from tempest.common import tempest_fixtures as fixtures |
| 20 | from tempest.common.utils import data_utils |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 21 | from tempest import test |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 22 | |
| 23 | |
| 24 | class AggregatesAdminNegativeTestJSON(base.BaseV2ComputeAdminTest): |
| 25 | |
| 26 | """ |
| 27 | Tests Aggregates API that require admin privileges |
| 28 | """ |
| 29 | |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 30 | @classmethod |
Andrea Frittoli | 50bb80d | 2014-09-15 12:34:27 +0100 | [diff] [blame] | 31 | def resource_setup(cls): |
| 32 | super(AggregatesAdminNegativeTestJSON, cls).resource_setup() |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 33 | 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 Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 38 | hosts_all = cls.os_adm.hosts_client.list_hosts() |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 39 | hosts = map(lambda x: x['host_name'], |
| 40 | filter(lambda y: y['service'] == 'compute', hosts_all)) |
| 41 | cls.host = hosts[0] |
| 42 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 43 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 44 | 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 Igawa | 29d554f | 2015-01-20 12:36:42 +0900 | [diff] [blame] | 47 | self.assertRaises(lib_exc.Unauthorized, |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 48 | self.user_client.create_aggregate, |
Yuiko Takada | f93d248 | 2014-01-30 16:25:08 +0000 | [diff] [blame] | 49 | name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 50 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 51 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 52 | def test_aggregate_create_aggregate_name_length_less_than_1(self): |
| 53 | # the length of aggregate name should >= 1 and <=255 |
Masayuki Igawa | 4b29e47 | 2015-02-16 10:41:54 +0900 | [diff] [blame] | 54 | self.assertRaises(lib_exc.BadRequest, |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 55 | self.client.create_aggregate, |
Yuiko Takada | f93d248 | 2014-01-30 16:25:08 +0000 | [diff] [blame] | 56 | name='') |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 57 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 58 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 59 | 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 Igawa | 4b29e47 | 2015-02-16 10:41:54 +0900 | [diff] [blame] | 62 | self.assertRaises(lib_exc.BadRequest, |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 63 | self.client.create_aggregate, |
Yuiko Takada | f93d248 | 2014-01-30 16:25:08 +0000 | [diff] [blame] | 64 | name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 65 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 66 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 67 | 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 Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 70 | aggregate = self.client.create_aggregate(name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 71 | self.addCleanup(self.client.delete_aggregate, aggregate['id']) |
| 72 | |
Masayuki Igawa | d938876 | 2015-01-20 14:56:42 +0900 | [diff] [blame] | 73 | self.assertRaises(lib_exc.Conflict, |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 74 | self.client.create_aggregate, |
Yuiko Takada | f93d248 | 2014-01-30 16:25:08 +0000 | [diff] [blame] | 75 | name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 76 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 77 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 78 | 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 Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 81 | aggregate = self.client.create_aggregate(name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 82 | self.addCleanup(self.client.delete_aggregate, aggregate['id']) |
| 83 | |
Masayuki Igawa | 29d554f | 2015-01-20 12:36:42 +0900 | [diff] [blame] | 84 | self.assertRaises(lib_exc.Unauthorized, |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 85 | self.user_client.delete_aggregate, |
| 86 | aggregate['id']) |
| 87 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 88 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 89 | def test_aggregate_list_as_user(self): |
| 90 | # Regular user is not allowed to list aggregates. |
Masayuki Igawa | 29d554f | 2015-01-20 12:36:42 +0900 | [diff] [blame] | 91 | self.assertRaises(lib_exc.Unauthorized, |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 92 | self.user_client.list_aggregates) |
| 93 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 94 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 95 | 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 Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 98 | aggregate = self.client.create_aggregate(name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 99 | self.addCleanup(self.client.delete_aggregate, aggregate['id']) |
| 100 | |
Masayuki Igawa | 29d554f | 2015-01-20 12:36:42 +0900 | [diff] [blame] | 101 | self.assertRaises(lib_exc.Unauthorized, |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 102 | self.user_client.get_aggregate, |
| 103 | aggregate['id']) |
| 104 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 105 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 106 | def test_aggregate_delete_with_invalid_id(self): |
| 107 | # Delete an aggregate with invalid id should raise exceptions. |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 108 | self.assertRaises(lib_exc.NotFound, |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 109 | self.client.delete_aggregate, -1) |
| 110 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 111 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 112 | def test_aggregate_get_details_with_invalid_id(self): |
| 113 | # Get aggregate details with invalid id should raise exceptions. |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 114 | self.assertRaises(lib_exc.NotFound, |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 115 | self.client.get_aggregate, -1) |
| 116 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 117 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 118 | def test_aggregate_add_non_exist_host(self): |
| 119 | # Adding a non-exist host to an aggregate should raise exceptions. |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 120 | hosts_all = self.os_adm.hosts_client.list_hosts() |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 121 | 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 Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 128 | aggregate = self.client.create_aggregate(name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 129 | self.addCleanup(self.client.delete_aggregate, aggregate['id']) |
| 130 | |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 131 | self.assertRaises(lib_exc.NotFound, self.client.add_host, |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 132 | aggregate['id'], non_exist_host) |
| 133 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 134 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 135 | 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 Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 138 | aggregate = self.client.create_aggregate(name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 139 | self.addCleanup(self.client.delete_aggregate, aggregate['id']) |
| 140 | |
Masayuki Igawa | 29d554f | 2015-01-20 12:36:42 +0900 | [diff] [blame] | 141 | self.assertRaises(lib_exc.Unauthorized, |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 142 | self.user_client.add_host, |
| 143 | aggregate['id'], self.host) |
| 144 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 145 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 146 | 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 Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 149 | aggregate = self.client.create_aggregate(name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 150 | self.addCleanup(self.client.delete_aggregate, aggregate['id']) |
| 151 | |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 152 | self.client.add_host(aggregate['id'], self.host) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 153 | self.addCleanup(self.client.remove_host, aggregate['id'], self.host) |
| 154 | |
Masayuki Igawa | d938876 | 2015-01-20 14:56:42 +0900 | [diff] [blame] | 155 | self.assertRaises(lib_exc.Conflict, self.client.add_host, |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 156 | aggregate['id'], self.host) |
| 157 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 158 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 159 | 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 Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 163 | aggregate = self.client.create_aggregate(name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 164 | self.addCleanup(self.client.delete_aggregate, aggregate['id']) |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 165 | self.client.add_host(aggregate['id'], self.host) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 166 | self.addCleanup(self.client.remove_host, aggregate['id'], self.host) |
| 167 | |
Masayuki Igawa | 29d554f | 2015-01-20 12:36:42 +0900 | [diff] [blame] | 168 | self.assertRaises(lib_exc.Unauthorized, |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 169 | self.user_client.remove_host, |
| 170 | aggregate['id'], self.host) |
| 171 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 172 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 173 | 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 Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 176 | aggregate = self.client.create_aggregate(name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 177 | self.addCleanup(self.client.delete_aggregate, aggregate['id']) |
| 178 | |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 179 | self.assertRaises(lib_exc.NotFound, self.client.remove_host, |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 180 | aggregate['id'], non_exist_host) |