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 |
| 21 | from tempest import exceptions |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 22 | from tempest import test |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 23 | |
| 24 | |
| 25 | class AggregatesAdminNegativeTestJSON(base.BaseV2ComputeAdminTest): |
| 26 | |
| 27 | """ |
| 28 | Tests Aggregates API that require admin privileges |
| 29 | """ |
| 30 | |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 31 | @classmethod |
Andrea Frittoli | 50bb80d | 2014-09-15 12:34:27 +0100 | [diff] [blame] | 32 | def resource_setup(cls): |
| 33 | super(AggregatesAdminNegativeTestJSON, cls).resource_setup() |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 34 | cls.client = cls.os_adm.aggregates_client |
| 35 | cls.user_client = cls.aggregates_client |
| 36 | cls.aggregate_name_prefix = 'test_aggregate_' |
| 37 | cls.az_name_prefix = 'test_az_' |
| 38 | |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 39 | hosts_all = cls.os_adm.hosts_client.list_hosts() |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 40 | hosts = map(lambda x: x['host_name'], |
| 41 | filter(lambda y: y['service'] == 'compute', hosts_all)) |
| 42 | cls.host = hosts[0] |
| 43 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 44 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 45 | 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) |
| 48 | self.assertRaises(exceptions.Unauthorized, |
| 49 | self.user_client.create_aggregate, |
Yuiko Takada | f93d248 | 2014-01-30 16:25:08 +0000 | [diff] [blame] | 50 | name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 51 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 52 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 53 | def test_aggregate_create_aggregate_name_length_less_than_1(self): |
| 54 | # the length of aggregate name should >= 1 and <=255 |
| 55 | self.assertRaises(exceptions.BadRequest, |
| 56 | self.client.create_aggregate, |
Yuiko Takada | f93d248 | 2014-01-30 16:25:08 +0000 | [diff] [blame] | 57 | name='') |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 58 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 59 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 60 | def test_aggregate_create_aggregate_name_length_exceeds_255(self): |
| 61 | # the length of aggregate name should >= 1 and <=255 |
| 62 | aggregate_name = 'a' * 256 |
| 63 | self.assertRaises(exceptions.BadRequest, |
| 64 | self.client.create_aggregate, |
Yuiko Takada | f93d248 | 2014-01-30 16:25:08 +0000 | [diff] [blame] | 65 | name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 66 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 67 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 68 | def test_aggregate_create_with_existent_aggregate_name(self): |
| 69 | # creating an aggregate with existent aggregate name is forbidden |
| 70 | aggregate_name = data_utils.rand_name(self.aggregate_name_prefix) |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 71 | aggregate = self.client.create_aggregate(name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 72 | self.addCleanup(self.client.delete_aggregate, aggregate['id']) |
| 73 | |
Masayuki Igawa | d938876 | 2015-01-20 14:56:42 +0900 | [diff] [blame^] | 74 | self.assertRaises(lib_exc.Conflict, |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 75 | self.client.create_aggregate, |
Yuiko Takada | f93d248 | 2014-01-30 16:25:08 +0000 | [diff] [blame] | 76 | name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 77 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 78 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 79 | def test_aggregate_delete_as_user(self): |
| 80 | # Regular user is not allowed to delete an aggregate. |
| 81 | aggregate_name = data_utils.rand_name(self.aggregate_name_prefix) |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 82 | aggregate = self.client.create_aggregate(name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 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 Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 89 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 90 | 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 Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 95 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 96 | 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) |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 99 | aggregate = self.client.create_aggregate(name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 100 | self.addCleanup(self.client.delete_aggregate, aggregate['id']) |
| 101 | |
| 102 | self.assertRaises(exceptions.Unauthorized, |
| 103 | self.user_client.get_aggregate, |
| 104 | aggregate['id']) |
| 105 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 106 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 107 | def test_aggregate_delete_with_invalid_id(self): |
| 108 | # Delete an aggregate with invalid id should raise exceptions. |
| 109 | self.assertRaises(exceptions.NotFound, |
| 110 | self.client.delete_aggregate, -1) |
| 111 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 112 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 113 | def test_aggregate_get_details_with_invalid_id(self): |
| 114 | # Get aggregate details with invalid id should raise exceptions. |
| 115 | self.assertRaises(exceptions.NotFound, |
| 116 | self.client.get_aggregate, -1) |
| 117 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 118 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 119 | def test_aggregate_add_non_exist_host(self): |
| 120 | # Adding a non-exist host to an aggregate should raise exceptions. |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 121 | hosts_all = self.os_adm.hosts_client.list_hosts() |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 122 | hosts = map(lambda x: x['host_name'], hosts_all) |
| 123 | while True: |
| 124 | non_exist_host = data_utils.rand_name('nonexist_host_') |
| 125 | if non_exist_host not in hosts: |
| 126 | break |
| 127 | |
| 128 | aggregate_name = data_utils.rand_name(self.aggregate_name_prefix) |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 129 | aggregate = self.client.create_aggregate(name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 130 | self.addCleanup(self.client.delete_aggregate, aggregate['id']) |
| 131 | |
| 132 | self.assertRaises(exceptions.NotFound, self.client.add_host, |
| 133 | aggregate['id'], non_exist_host) |
| 134 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 135 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 136 | def test_aggregate_add_host_as_user(self): |
| 137 | # Regular user is not allowed to add a host to an aggregate. |
| 138 | aggregate_name = data_utils.rand_name(self.aggregate_name_prefix) |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 139 | aggregate = self.client.create_aggregate(name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 140 | self.addCleanup(self.client.delete_aggregate, aggregate['id']) |
| 141 | |
| 142 | self.assertRaises(exceptions.Unauthorized, |
| 143 | self.user_client.add_host, |
| 144 | aggregate['id'], self.host) |
| 145 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 146 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 147 | def test_aggregate_add_existent_host(self): |
| 148 | self.useFixture(fixtures.LockFixture('availability_zone')) |
| 149 | aggregate_name = data_utils.rand_name(self.aggregate_name_prefix) |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 150 | aggregate = self.client.create_aggregate(name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 151 | self.addCleanup(self.client.delete_aggregate, aggregate['id']) |
| 152 | |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 153 | self.client.add_host(aggregate['id'], self.host) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 154 | self.addCleanup(self.client.remove_host, aggregate['id'], self.host) |
| 155 | |
Masayuki Igawa | d938876 | 2015-01-20 14:56:42 +0900 | [diff] [blame^] | 156 | self.assertRaises(lib_exc.Conflict, self.client.add_host, |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 157 | aggregate['id'], self.host) |
| 158 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 159 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 160 | def test_aggregate_remove_host_as_user(self): |
| 161 | # Regular user is not allowed to remove a host from an aggregate. |
| 162 | self.useFixture(fixtures.LockFixture('availability_zone')) |
| 163 | aggregate_name = data_utils.rand_name(self.aggregate_name_prefix) |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 164 | aggregate = self.client.create_aggregate(name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 165 | self.addCleanup(self.client.delete_aggregate, aggregate['id']) |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 166 | self.client.add_host(aggregate['id'], self.host) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 167 | self.addCleanup(self.client.remove_host, aggregate['id'], self.host) |
| 168 | |
| 169 | self.assertRaises(exceptions.Unauthorized, |
| 170 | self.user_client.remove_host, |
| 171 | aggregate['id'], self.host) |
| 172 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 173 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 174 | def test_aggregate_remove_nonexistent_host(self): |
| 175 | non_exist_host = data_utils.rand_name('nonexist_host_') |
| 176 | aggregate_name = data_utils.rand_name(self.aggregate_name_prefix) |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 177 | aggregate = self.client.create_aggregate(name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 178 | self.addCleanup(self.client.delete_aggregate, aggregate['id']) |
| 179 | |
| 180 | self.assertRaises(exceptions.NotFound, self.client.remove_host, |
| 181 | aggregate['id'], non_exist_host) |