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 | |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 15 | from tempest_lib import exceptions as lib_exc |
| 16 | |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 17 | from tempest.api.compute import base |
Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [diff] [blame] | 18 | from tempest.common.utils import data_utils |
Ken'ichi Ohmichi | a1aa44c | 2013-12-06 20:48:24 +0900 | [diff] [blame] | 19 | from tempest import test |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 20 | |
| 21 | |
Mate Lakat | 1e89a1b | 2013-10-26 11:19:13 +0100 | [diff] [blame] | 22 | class HostsAdminNegativeTestJSON(base.BaseV2ComputeAdminTest): |
Ken'ichi Ohmichi | 88363cb | 2015-11-19 08:00:54 +0000 | [diff] [blame] | 23 | """Tests hosts API using admin privileges.""" |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 24 | |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 25 | @classmethod |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 26 | def setup_clients(cls): |
| 27 | super(HostsAdminNegativeTestJSON, cls).setup_clients() |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 28 | cls.client = cls.os_adm.hosts_client |
| 29 | cls.non_admin_client = cls.os.hosts_client |
| 30 | |
| 31 | def _get_host_name(self): |
ghanshyam | e1bd29e | 2015-08-18 16:47:24 +0900 | [diff] [blame] | 32 | hosts = self.client.list_hosts()['hosts'] |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 33 | self.assertTrue(len(hosts) >= 1) |
| 34 | hostname = hosts[0]['host_name'] |
| 35 | return hostname |
| 36 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 37 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 38 | @test.idempotent_id('dd032027-0210-4d9c-860e-69b1b8deed5f') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 39 | def test_list_hosts_with_non_admin_user(self): |
Masayuki Igawa | 6b1cd29 | 2015-02-16 11:11:55 +0900 | [diff] [blame] | 40 | self.assertRaises(lib_exc.Forbidden, |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 41 | self.non_admin_client.list_hosts) |
| 42 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 43 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 44 | @test.idempotent_id('e75b0a1a-041f-47a1-8b4a-b72a6ff36d3f') |
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') |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 47 | self.assertRaises(lib_exc.NotFound, |
Ken'ichi Ohmichi | 394e6e4 | 2015-06-11 04:20:37 +0000 | [diff] [blame] | 48 | self.client.show_host, nonexitent_hostname) |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 49 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 50 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 51 | @test.idempotent_id('19ebe09c-bfd4-4b7c-81a2-e2e0710f59cc') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 52 | def test_show_host_detail_with_non_admin_user(self): |
| 53 | hostname = self._get_host_name() |
| 54 | |
Masayuki Igawa | 6b1cd29 | 2015-02-16 11:11:55 +0900 | [diff] [blame] | 55 | self.assertRaises(lib_exc.Forbidden, |
Ken'ichi Ohmichi | 394e6e4 | 2015-06-11 04:20:37 +0000 | [diff] [blame] | 56 | self.non_admin_client.show_host, |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 57 | hostname) |
| 58 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 59 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 60 | @test.idempotent_id('e40c72b1-0239-4ed6-ba21-81a184df1f7c') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 61 | def test_update_host_with_non_admin_user(self): |
| 62 | hostname = self._get_host_name() |
| 63 | |
Masayuki Igawa | 6b1cd29 | 2015-02-16 11:11:55 +0900 | [diff] [blame] | 64 | self.assertRaises(lib_exc.Forbidden, |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 65 | self.non_admin_client.update_host, |
Haiwei Xu | 0c1ca79 | 2014-01-15 22:49:24 +0900 | [diff] [blame] | 66 | hostname, |
| 67 | status='enable', |
| 68 | maintenance_mode='enable') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 69 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 70 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 71 | @test.idempotent_id('fbe2bf3e-3246-4a95-a59f-94e4e298ec77') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 72 | def test_update_host_with_invalid_status(self): |
| 73 | # 'status' can only be 'enable' or 'disable' |
| 74 | hostname = self._get_host_name() |
| 75 | |
Masayuki Igawa | 4b29e47 | 2015-02-16 10:41:54 +0900 | [diff] [blame] | 76 | self.assertRaises(lib_exc.BadRequest, |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 77 | self.client.update_host, |
| 78 | hostname, |
| 79 | status='invalid', |
| 80 | maintenance_mode='enable') |
| 81 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 82 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 83 | @test.idempotent_id('ab1e230e-5e22-41a9-8699-82b9947915d4') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 84 | def test_update_host_with_invalid_maintenance_mode(self): |
| 85 | # 'maintenance_mode' can only be 'enable' or 'disable' |
| 86 | hostname = self._get_host_name() |
| 87 | |
Masayuki Igawa | 4b29e47 | 2015-02-16 10:41:54 +0900 | [diff] [blame] | 88 | self.assertRaises(lib_exc.BadRequest, |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 89 | self.client.update_host, |
| 90 | hostname, |
| 91 | status='enable', |
| 92 | maintenance_mode='invalid') |
| 93 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 94 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 95 | @test.idempotent_id('0cd85f75-6992-4a4a-b1bd-d11e37fd0eee') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 96 | def test_update_host_without_param(self): |
| 97 | # 'status' or 'maintenance_mode' needed for host update |
| 98 | hostname = self._get_host_name() |
| 99 | |
Masayuki Igawa | 4b29e47 | 2015-02-16 10:41:54 +0900 | [diff] [blame] | 100 | self.assertRaises(lib_exc.BadRequest, |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 101 | self.client.update_host, |
| 102 | hostname) |
| 103 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 104 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 105 | @test.idempotent_id('23c92146-2100-4d68-b2d6-c7ade970c9c1') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 106 | def test_update_nonexistent_host(self): |
| 107 | nonexitent_hostname = data_utils.rand_name('rand_hostname') |
| 108 | |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 109 | self.assertRaises(lib_exc.NotFound, |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 110 | self.client.update_host, |
| 111 | nonexitent_hostname, |
| 112 | status='enable', |
| 113 | maintenance_mode='enable') |
| 114 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 115 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 116 | @test.idempotent_id('0d981ac3-4320-4898-b674-82b61fbb60e4') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 117 | def test_startup_nonexistent_host(self): |
| 118 | nonexitent_hostname = data_utils.rand_name('rand_hostname') |
| 119 | |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 120 | self.assertRaises(lib_exc.NotFound, |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 121 | self.client.startup_host, |
| 122 | nonexitent_hostname) |
| 123 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 124 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 125 | @test.idempotent_id('9f4ebb7e-b2ae-4e5b-a38f-0fd1bb0ddfca') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 126 | def test_startup_host_with_non_admin_user(self): |
| 127 | hostname = self._get_host_name() |
| 128 | |
Masayuki Igawa | 6b1cd29 | 2015-02-16 11:11:55 +0900 | [diff] [blame] | 129 | self.assertRaises(lib_exc.Forbidden, |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 130 | self.non_admin_client.startup_host, |
| 131 | hostname) |
| 132 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 133 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 134 | @test.idempotent_id('9e637444-29cf-4244-88c8-831ae82c31b6') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 135 | def test_shutdown_nonexistent_host(self): |
| 136 | nonexitent_hostname = data_utils.rand_name('rand_hostname') |
| 137 | |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 138 | self.assertRaises(lib_exc.NotFound, |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 139 | self.client.shutdown_host, |
| 140 | nonexitent_hostname) |
| 141 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 142 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 143 | @test.idempotent_id('a803529c-7e3f-4d3c-a7d6-8e1c203d27f6') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 144 | def test_shutdown_host_with_non_admin_user(self): |
| 145 | hostname = self._get_host_name() |
| 146 | |
Masayuki Igawa | 6b1cd29 | 2015-02-16 11:11:55 +0900 | [diff] [blame] | 147 | self.assertRaises(lib_exc.Forbidden, |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 148 | self.non_admin_client.shutdown_host, |
| 149 | hostname) |
| 150 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 151 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 152 | @test.idempotent_id('f86bfd7b-0b13-4849-ae29-0322e83ee58b') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 153 | def test_reboot_nonexistent_host(self): |
| 154 | nonexitent_hostname = data_utils.rand_name('rand_hostname') |
| 155 | |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 156 | self.assertRaises(lib_exc.NotFound, |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 157 | self.client.reboot_host, |
| 158 | nonexitent_hostname) |
| 159 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 160 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 161 | @test.idempotent_id('02d79bb9-eb57-4612-abf6-2cb38897d2f8') |
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 | |
Masayuki Igawa | 6b1cd29 | 2015-02-16 11:11:55 +0900 | [diff] [blame] | 165 | self.assertRaises(lib_exc.Forbidden, |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 166 | self.non_admin_client.reboot_host, |
| 167 | hostname) |