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 | |
| 27 | _interface = 'json' |
| 28 | |
| 29 | @classmethod |
| 30 | def setUpClass(cls): |
| 31 | super(HostsAdminNegativeTestJSON, cls).setUpClass() |
| 32 | cls.client = cls.os_adm.hosts_client |
| 33 | cls.non_admin_client = cls.os.hosts_client |
| 34 | |
| 35 | def _get_host_name(self): |
| 36 | resp, hosts = self.client.list_hosts() |
| 37 | self.assertEqual(200, resp.status) |
| 38 | self.assertTrue(len(hosts) >= 1) |
| 39 | hostname = hosts[0]['host_name'] |
| 40 | return hostname |
| 41 | |
Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 42 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 43 | def test_list_hosts_with_non_admin_user(self): |
| 44 | self.assertRaises(exceptions.Unauthorized, |
| 45 | self.non_admin_client.list_hosts) |
| 46 | |
Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 47 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 48 | def test_show_host_detail_with_nonexistent_hostname(self): |
| 49 | nonexitent_hostname = data_utils.rand_name('rand_hostname') |
| 50 | self.assertRaises(exceptions.NotFound, |
| 51 | self.client.show_host_detail, nonexitent_hostname) |
| 52 | |
Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 53 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 54 | def test_show_host_detail_with_non_admin_user(self): |
| 55 | hostname = self._get_host_name() |
| 56 | |
| 57 | self.assertRaises(exceptions.Unauthorized, |
| 58 | self.non_admin_client.show_host_detail, |
| 59 | hostname) |
| 60 | |
Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 61 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 62 | def test_update_host_with_non_admin_user(self): |
| 63 | hostname = self._get_host_name() |
| 64 | |
| 65 | self.assertRaises(exceptions.Unauthorized, |
| 66 | self.non_admin_client.update_host, |
Haiwei Xu | 0c1ca79 | 2014-01-15 22:49:24 +0900 | [diff] [blame] | 67 | hostname, |
| 68 | status='enable', |
| 69 | maintenance_mode='enable') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 70 | |
Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 71 | @test.skip_because(bug="1261964", interface="xml") |
| 72 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 73 | def test_update_host_with_extra_param(self): |
| 74 | # only 'status' and 'maintenance_mode' are the valid params. |
| 75 | hostname = self._get_host_name() |
| 76 | |
| 77 | self.assertRaises(exceptions.BadRequest, |
| 78 | self.client.update_host, |
| 79 | hostname, |
| 80 | status='enable', |
| 81 | maintenance_mode='enable', |
| 82 | param='XXX') |
| 83 | |
Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 84 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 85 | def test_update_host_with_invalid_status(self): |
| 86 | # 'status' can only be 'enable' or 'disable' |
| 87 | hostname = self._get_host_name() |
| 88 | |
| 89 | self.assertRaises(exceptions.BadRequest, |
| 90 | self.client.update_host, |
| 91 | hostname, |
| 92 | status='invalid', |
| 93 | maintenance_mode='enable') |
| 94 | |
Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 95 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 96 | def test_update_host_with_invalid_maintenance_mode(self): |
| 97 | # 'maintenance_mode' can only be 'enable' or 'disable' |
| 98 | hostname = self._get_host_name() |
| 99 | |
| 100 | self.assertRaises(exceptions.BadRequest, |
| 101 | self.client.update_host, |
| 102 | hostname, |
| 103 | status='enable', |
| 104 | maintenance_mode='invalid') |
| 105 | |
Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 106 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 107 | def test_update_host_without_param(self): |
| 108 | # 'status' or 'maintenance_mode' needed for host update |
| 109 | hostname = self._get_host_name() |
| 110 | |
| 111 | self.assertRaises(exceptions.BadRequest, |
| 112 | self.client.update_host, |
| 113 | hostname) |
| 114 | |
Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 115 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 116 | def test_update_nonexistent_host(self): |
| 117 | nonexitent_hostname = data_utils.rand_name('rand_hostname') |
| 118 | |
| 119 | self.assertRaises(exceptions.NotFound, |
| 120 | self.client.update_host, |
| 121 | nonexitent_hostname, |
| 122 | status='enable', |
| 123 | maintenance_mode='enable') |
| 124 | |
Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 125 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 126 | def test_startup_nonexistent_host(self): |
| 127 | nonexitent_hostname = data_utils.rand_name('rand_hostname') |
| 128 | |
| 129 | self.assertRaises(exceptions.NotFound, |
| 130 | self.client.startup_host, |
| 131 | nonexitent_hostname) |
| 132 | |
Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 133 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 134 | def test_startup_host_with_non_admin_user(self): |
| 135 | hostname = self._get_host_name() |
| 136 | |
| 137 | self.assertRaises(exceptions.Unauthorized, |
| 138 | self.non_admin_client.startup_host, |
| 139 | hostname) |
| 140 | |
Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 141 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 142 | def test_shutdown_nonexistent_host(self): |
| 143 | nonexitent_hostname = data_utils.rand_name('rand_hostname') |
| 144 | |
| 145 | self.assertRaises(exceptions.NotFound, |
| 146 | self.client.shutdown_host, |
| 147 | nonexitent_hostname) |
| 148 | |
Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 149 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 150 | def test_shutdown_host_with_non_admin_user(self): |
| 151 | hostname = self._get_host_name() |
| 152 | |
| 153 | self.assertRaises(exceptions.Unauthorized, |
| 154 | self.non_admin_client.shutdown_host, |
| 155 | hostname) |
| 156 | |
Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 157 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 158 | def test_reboot_nonexistent_host(self): |
| 159 | nonexitent_hostname = data_utils.rand_name('rand_hostname') |
| 160 | |
| 161 | self.assertRaises(exceptions.NotFound, |
| 162 | self.client.reboot_host, |
| 163 | nonexitent_hostname) |
| 164 | |
Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 165 | @test.attr(type=['negative', 'gate']) |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 166 | def test_reboot_host_with_non_admin_user(self): |
| 167 | hostname = self._get_host_name() |
| 168 | |
| 169 | self.assertRaises(exceptions.Unauthorized, |
| 170 | self.non_admin_client.reboot_host, |
| 171 | hostname) |
| 172 | |
| 173 | |
| 174 | class HostsAdminNegativeTestXML(HostsAdminNegativeTestJSON): |
| 175 | _interface = 'xml' |