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