| Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 1 | # Copyright 2013 Huawei Technologies Co.,LTD. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
| 15 | from tempest.api.compute import base |
| 16 | from tempest.common.utils import data_utils |
| 17 | from tempest import exceptions |
| Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 18 | from tempest import test |
| Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 19 | |
| 20 | |
| Mate Lakat | 1e89a1b | 2013-10-26 11:19:13 +0100 | [diff] [blame] | 21 | class HostsAdminNegativeTestJSON(base.BaseV2ComputeAdminTest): |
| Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 22 | |
| 23 | """ |
| 24 | Tests hosts API using admin privileges. |
| 25 | """ |
| 26 | |
| Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 27 | @classmethod |
| Andrea Frittoli | 50bb80d | 2014-09-15 12:34:27 +0100 | [diff] [blame] | 28 | def resource_setup(cls): |
| 29 | super(HostsAdminNegativeTestJSON, cls).resource_setup() |
| Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 30 | cls.client = cls.os_adm.hosts_client |
| 31 | cls.non_admin_client = cls.os.hosts_client |
| 32 | |
| 33 | def _get_host_name(self): |
| David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame^] | 34 | hosts = self.client.list_hosts() |
| Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 35 | self.assertTrue(len(hosts) >= 1) |
| 36 | hostname = hosts[0]['host_name'] |
| 37 | return hostname |
| 38 | |
| Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 39 | @test.attr(type=['negative', 'gate']) |
| Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 40 | def test_list_hosts_with_non_admin_user(self): |
| 41 | self.assertRaises(exceptions.Unauthorized, |
| 42 | self.non_admin_client.list_hosts) |
| 43 | |
| Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 44 | @test.attr(type=['negative', 'gate']) |
| Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 45 | def test_show_host_detail_with_nonexistent_hostname(self): |
| 46 | nonexitent_hostname = data_utils.rand_name('rand_hostname') |
| 47 | self.assertRaises(exceptions.NotFound, |
| 48 | self.client.show_host_detail, nonexitent_hostname) |
| 49 | |
| Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 50 | @test.attr(type=['negative', 'gate']) |
| Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 51 | def test_show_host_detail_with_non_admin_user(self): |
| 52 | hostname = self._get_host_name() |
| 53 | |
| 54 | self.assertRaises(exceptions.Unauthorized, |
| 55 | self.non_admin_client.show_host_detail, |
| 56 | hostname) |
| 57 | |
| Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 58 | @test.attr(type=['negative', 'gate']) |
| Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 59 | def test_update_host_with_non_admin_user(self): |
| 60 | hostname = self._get_host_name() |
| 61 | |
| 62 | self.assertRaises(exceptions.Unauthorized, |
| 63 | self.non_admin_client.update_host, |
| Haiwei Xu | 0c1ca79 | 2014-01-15 22:49:24 +0900 | [diff] [blame] | 64 | hostname, |
| 65 | status='enable', |
| 66 | maintenance_mode='enable') |
| Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 67 | |
| Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 68 | @test.attr(type=['negative', 'gate']) |
| Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 69 | def test_update_host_with_extra_param(self): |
| 70 | # only 'status' and 'maintenance_mode' are the valid params. |
| 71 | hostname = self._get_host_name() |
| 72 | |
| 73 | self.assertRaises(exceptions.BadRequest, |
| 74 | self.client.update_host, |
| 75 | hostname, |
| 76 | status='enable', |
| 77 | maintenance_mode='enable', |
| 78 | param='XXX') |
| 79 | |
| Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 80 | @test.attr(type=['negative', 'gate']) |
| Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 81 | def test_update_host_with_invalid_status(self): |
| 82 | # 'status' can only be 'enable' or 'disable' |
| 83 | hostname = self._get_host_name() |
| 84 | |
| 85 | self.assertRaises(exceptions.BadRequest, |
| 86 | self.client.update_host, |
| 87 | hostname, |
| 88 | status='invalid', |
| 89 | maintenance_mode='enable') |
| 90 | |
| Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 91 | @test.attr(type=['negative', 'gate']) |
| Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 92 | def test_update_host_with_invalid_maintenance_mode(self): |
| 93 | # 'maintenance_mode' can only be 'enable' or 'disable' |
| 94 | hostname = self._get_host_name() |
| 95 | |
| 96 | self.assertRaises(exceptions.BadRequest, |
| 97 | self.client.update_host, |
| 98 | hostname, |
| 99 | status='enable', |
| 100 | maintenance_mode='invalid') |
| 101 | |
| Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 102 | @test.attr(type=['negative', 'gate']) |
| Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 103 | def test_update_host_without_param(self): |
| 104 | # 'status' or 'maintenance_mode' needed for host update |
| 105 | hostname = self._get_host_name() |
| 106 | |
| 107 | self.assertRaises(exceptions.BadRequest, |
| 108 | self.client.update_host, |
| 109 | hostname) |
| 110 | |
| Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 111 | @test.attr(type=['negative', 'gate']) |
| Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 112 | def test_update_nonexistent_host(self): |
| 113 | nonexitent_hostname = data_utils.rand_name('rand_hostname') |
| 114 | |
| 115 | self.assertRaises(exceptions.NotFound, |
| 116 | self.client.update_host, |
| 117 | nonexitent_hostname, |
| 118 | status='enable', |
| 119 | maintenance_mode='enable') |
| 120 | |
| Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 121 | @test.attr(type=['negative', 'gate']) |
| Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 122 | def test_startup_nonexistent_host(self): |
| 123 | nonexitent_hostname = data_utils.rand_name('rand_hostname') |
| 124 | |
| 125 | self.assertRaises(exceptions.NotFound, |
| 126 | self.client.startup_host, |
| 127 | nonexitent_hostname) |
| 128 | |
| Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 129 | @test.attr(type=['negative', 'gate']) |
| Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 130 | def test_startup_host_with_non_admin_user(self): |
| 131 | hostname = self._get_host_name() |
| 132 | |
| 133 | self.assertRaises(exceptions.Unauthorized, |
| 134 | self.non_admin_client.startup_host, |
| 135 | hostname) |
| 136 | |
| Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 137 | @test.attr(type=['negative', 'gate']) |
| Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 138 | def test_shutdown_nonexistent_host(self): |
| 139 | nonexitent_hostname = data_utils.rand_name('rand_hostname') |
| 140 | |
| 141 | self.assertRaises(exceptions.NotFound, |
| 142 | self.client.shutdown_host, |
| 143 | nonexitent_hostname) |
| 144 | |
| Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 145 | @test.attr(type=['negative', 'gate']) |
| Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 146 | def test_shutdown_host_with_non_admin_user(self): |
| 147 | hostname = self._get_host_name() |
| 148 | |
| 149 | self.assertRaises(exceptions.Unauthorized, |
| 150 | self.non_admin_client.shutdown_host, |
| 151 | hostname) |
| 152 | |
| Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 153 | @test.attr(type=['negative', 'gate']) |
| Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 154 | def test_reboot_nonexistent_host(self): |
| 155 | nonexitent_hostname = data_utils.rand_name('rand_hostname') |
| 156 | |
| 157 | self.assertRaises(exceptions.NotFound, |
| 158 | self.client.reboot_host, |
| 159 | nonexitent_hostname) |
| 160 | |
| Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 161 | @test.attr(type=['negative', 'gate']) |
| Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 162 | def test_reboot_host_with_non_admin_user(self): |
| 163 | hostname = self._get_host_name() |
| 164 | |
| 165 | self.assertRaises(exceptions.Unauthorized, |
| 166 | self.non_admin_client.reboot_host, |
| 167 | hostname) |