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 | |
| 16 | from tempest.api.compute import base |
| 17 | from tempest.common import tempest_fixtures as fixtures |
| 18 | from tempest.common.utils import data_utils |
| 19 | from tempest import exceptions |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 20 | from tempest import test |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 21 | |
| 22 | |
| 23 | class AggregatesAdminNegativeTestJSON(base.BaseV2ComputeAdminTest): |
| 24 | |
| 25 | """ |
| 26 | Tests Aggregates API that require admin privileges |
| 27 | """ |
| 28 | |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 29 | @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 Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 42 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 43 | 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 Takada | f93d248 | 2014-01-30 16:25:08 +0000 | [diff] [blame] | 48 | name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 49 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 50 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 51 | 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 Takada | f93d248 | 2014-01-30 16:25:08 +0000 | [diff] [blame] | 55 | name='') |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 56 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 57 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 58 | 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 Takada | f93d248 | 2014-01-30 16:25:08 +0000 | [diff] [blame] | 63 | name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 64 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 65 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 66 | 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 Takada | f93d248 | 2014-01-30 16:25:08 +0000 | [diff] [blame] | 69 | resp, aggregate = self.client.create_aggregate(name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 70 | 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 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) |
Yuiko Takada | f93d248 | 2014-01-30 16:25:08 +0000 | [diff] [blame] | 81 | resp, aggregate = self.client.create_aggregate(name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 82 | 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 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) |
Yuiko Takada | f93d248 | 2014-01-30 16:25:08 +0000 | [diff] [blame] | 99 | resp, aggregate = self.client.create_aggregate(name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 100 | 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 Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 107 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 108 | 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 Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 113 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 114 | 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 Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 119 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 120 | 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 Takada | f93d248 | 2014-01-30 16:25:08 +0000 | [diff] [blame] | 130 | resp, aggregate = self.client.create_aggregate(name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 131 | 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 Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 136 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 137 | 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 Takada | f93d248 | 2014-01-30 16:25:08 +0000 | [diff] [blame] | 140 | resp, aggregate = self.client.create_aggregate(name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 141 | 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 Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 148 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 149 | 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 Takada | f93d248 | 2014-01-30 16:25:08 +0000 | [diff] [blame] | 152 | resp, aggregate = self.client.create_aggregate(name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 153 | 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 Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 163 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 164 | 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 Takada | f93d248 | 2014-01-30 16:25:08 +0000 | [diff] [blame] | 168 | resp, aggregate = self.client.create_aggregate(name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 169 | 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 Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 179 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 180 | 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 Takada | f93d248 | 2014-01-30 16:25:08 +0000 | [diff] [blame] | 183 | resp, aggregate = self.client.create_aggregate(name=aggregate_name) |
Lingxian Kong | bf2d517 | 2013-10-01 22:00:24 +0800 | [diff] [blame] | 184 | 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 | |
| 191 | class AggregatesAdminNegativeTestXML(AggregatesAdminNegativeTestJSON): |
| 192 | _interface = 'xml' |