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 |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 16 | from tempest.lib import decorators |
Andrea Frittoli (andreaf) | db9672e | 2016-02-23 14:07:24 -0500 | [diff] [blame] | 17 | from tempest.lib import exceptions as lib_exc |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 18 | |
| 19 | |
Mate Lakat | 1e89a1b | 2013-10-26 11:19:13 +0100 | [diff] [blame] | 20 | class HostsAdminNegativeTestJSON(base.BaseV2ComputeAdminTest): |
Ken'ichi Ohmichi | 88363cb | 2015-11-19 08:00:54 +0000 | [diff] [blame] | 21 | """Tests hosts API using admin privileges.""" |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 22 | |
zhufl | e739804 | 2018-03-13 16:20:18 +0800 | [diff] [blame] | 23 | max_microversion = '2.42' |
| 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() |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 28 | cls.client = cls.os_admin.hosts_client |
| 29 | cls.non_admin_client = cls.os_primary.hosts_client |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 30 | |
zhufl | 6361797 | 2016-11-16 16:59:41 +0800 | [diff] [blame] | 31 | @classmethod |
| 32 | def resource_setup(cls): |
| 33 | super(HostsAdminNegativeTestJSON, cls).resource_setup() |
| 34 | hosts = cls.client.list_hosts()['hosts'] |
| 35 | if not hosts: |
| 36 | raise lib_exc.NotFound("no host found") |
| 37 | cls.hostname = hosts[0]['host_name'] |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 38 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 39 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 40 | @decorators.idempotent_id('dd032027-0210-4d9c-860e-69b1b8deed5f') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 41 | def test_list_hosts_with_non_admin_user(self): |
zhufl | a0e87dc | 2020-05-13 15:52:15 +0800 | [diff] [blame] | 42 | """Non admin user is not allowed to list hosts""" |
Masayuki Igawa | 6b1cd29 | 2015-02-16 11:11:55 +0900 | [diff] [blame] | 43 | self.assertRaises(lib_exc.Forbidden, |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 44 | self.non_admin_client.list_hosts) |
| 45 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 46 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 47 | @decorators.idempotent_id('e75b0a1a-041f-47a1-8b4a-b72a6ff36d3f') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 48 | def test_show_host_detail_with_nonexistent_hostname(self): |
zhufl | a0e87dc | 2020-05-13 15:52:15 +0800 | [diff] [blame] | 49 | """Showing host detail with not existing hostname should fail""" |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 50 | self.assertRaises(lib_exc.NotFound, |
zhufl | 6361797 | 2016-11-16 16:59:41 +0800 | [diff] [blame] | 51 | self.client.show_host, 'nonexistent_hostname') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 52 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 53 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 54 | @decorators.idempotent_id('19ebe09c-bfd4-4b7c-81a2-e2e0710f59cc') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 55 | def test_show_host_detail_with_non_admin_user(self): |
zhufl | a0e87dc | 2020-05-13 15:52:15 +0800 | [diff] [blame] | 56 | """Non admin user is not allowed to show host details""" |
Masayuki Igawa | 6b1cd29 | 2015-02-16 11:11:55 +0900 | [diff] [blame] | 57 | self.assertRaises(lib_exc.Forbidden, |
Ken'ichi Ohmichi | 394e6e4 | 2015-06-11 04:20:37 +0000 | [diff] [blame] | 58 | self.non_admin_client.show_host, |
zhufl | 6361797 | 2016-11-16 16:59:41 +0800 | [diff] [blame] | 59 | self.hostname) |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 60 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 61 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 62 | @decorators.idempotent_id('e40c72b1-0239-4ed6-ba21-81a184df1f7c') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 63 | def test_update_host_with_non_admin_user(self): |
zhufl | a0e87dc | 2020-05-13 15:52:15 +0800 | [diff] [blame] | 64 | """Non admin user is not allowed to update host""" |
Masayuki Igawa | 6b1cd29 | 2015-02-16 11:11:55 +0900 | [diff] [blame] | 65 | self.assertRaises(lib_exc.Forbidden, |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 66 | self.non_admin_client.update_host, |
zhufl | 6361797 | 2016-11-16 16:59:41 +0800 | [diff] [blame] | 67 | self.hostname, |
Haiwei Xu | 0c1ca79 | 2014-01-15 22:49:24 +0900 | [diff] [blame] | 68 | status='enable', |
| 69 | maintenance_mode='enable') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 70 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 71 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 72 | @decorators.idempotent_id('fbe2bf3e-3246-4a95-a59f-94e4e298ec77') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 73 | def test_update_host_with_invalid_status(self): |
zhufl | a0e87dc | 2020-05-13 15:52:15 +0800 | [diff] [blame] | 74 | """Updating host to invalid status should fail |
| 75 | |
| 76 | 'status' can only be 'enable' or 'disable'. |
| 77 | """ |
Masayuki Igawa | 4b29e47 | 2015-02-16 10:41:54 +0900 | [diff] [blame] | 78 | self.assertRaises(lib_exc.BadRequest, |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 79 | self.client.update_host, |
zhufl | 6361797 | 2016-11-16 16:59:41 +0800 | [diff] [blame] | 80 | self.hostname, |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 81 | status='invalid', |
| 82 | maintenance_mode='enable') |
| 83 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 84 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 85 | @decorators.idempotent_id('ab1e230e-5e22-41a9-8699-82b9947915d4') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 86 | def test_update_host_with_invalid_maintenance_mode(self): |
zhufl | a0e87dc | 2020-05-13 15:52:15 +0800 | [diff] [blame] | 87 | """Updating host to invalid maintenance mode should fail |
| 88 | |
| 89 | 'maintenance_mode' can only be 'enable' or 'disable'. |
| 90 | """ |
Masayuki Igawa | 4b29e47 | 2015-02-16 10:41:54 +0900 | [diff] [blame] | 91 | self.assertRaises(lib_exc.BadRequest, |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 92 | self.client.update_host, |
zhufl | 6361797 | 2016-11-16 16:59:41 +0800 | [diff] [blame] | 93 | self.hostname, |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 94 | status='enable', |
| 95 | maintenance_mode='invalid') |
| 96 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 97 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 98 | @decorators.idempotent_id('0cd85f75-6992-4a4a-b1bd-d11e37fd0eee') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 99 | def test_update_host_without_param(self): |
zhufl | a0e87dc | 2020-05-13 15:52:15 +0800 | [diff] [blame] | 100 | """Updating host without param should fail |
| 101 | |
| 102 | 'status' or 'maintenance_mode' is needed for host update |
| 103 | """ |
Masayuki Igawa | 4b29e47 | 2015-02-16 10:41:54 +0900 | [diff] [blame] | 104 | self.assertRaises(lib_exc.BadRequest, |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 105 | self.client.update_host, |
zhufl | 6361797 | 2016-11-16 16:59:41 +0800 | [diff] [blame] | 106 | self.hostname) |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 107 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 108 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 109 | @decorators.idempotent_id('23c92146-2100-4d68-b2d6-c7ade970c9c1') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 110 | def test_update_nonexistent_host(self): |
zhufl | a0e87dc | 2020-05-13 15:52:15 +0800 | [diff] [blame] | 111 | """Updating not existing host should fail""" |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 112 | self.assertRaises(lib_exc.NotFound, |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 113 | self.client.update_host, |
zhufl | 6361797 | 2016-11-16 16:59:41 +0800 | [diff] [blame] | 114 | 'nonexistent_hostname', |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 115 | status='enable', |
| 116 | maintenance_mode='enable') |
| 117 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 118 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 119 | @decorators.idempotent_id('0d981ac3-4320-4898-b674-82b61fbb60e4') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 120 | def test_startup_nonexistent_host(self): |
zhufl | a0e87dc | 2020-05-13 15:52:15 +0800 | [diff] [blame] | 121 | """Starting up not existing host should fail""" |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 122 | self.assertRaises(lib_exc.NotFound, |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 123 | self.client.startup_host, |
zhufl | 6361797 | 2016-11-16 16:59:41 +0800 | [diff] [blame] | 124 | 'nonexistent_hostname') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 125 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 126 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 127 | @decorators.idempotent_id('9f4ebb7e-b2ae-4e5b-a38f-0fd1bb0ddfca') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 128 | def test_startup_host_with_non_admin_user(self): |
zhufl | a0e87dc | 2020-05-13 15:52:15 +0800 | [diff] [blame] | 129 | """Non admin user is not allowed to startup host""" |
Masayuki Igawa | 6b1cd29 | 2015-02-16 11:11:55 +0900 | [diff] [blame] | 130 | self.assertRaises(lib_exc.Forbidden, |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 131 | self.non_admin_client.startup_host, |
zhufl | 6361797 | 2016-11-16 16:59:41 +0800 | [diff] [blame] | 132 | self.hostname) |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 133 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 134 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 135 | @decorators.idempotent_id('9e637444-29cf-4244-88c8-831ae82c31b6') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 136 | def test_shutdown_nonexistent_host(self): |
zhufl | a0e87dc | 2020-05-13 15:52:15 +0800 | [diff] [blame] | 137 | """Shutting down not existing host should fail""" |
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, |
zhufl | 6361797 | 2016-11-16 16:59:41 +0800 | [diff] [blame] | 140 | 'nonexistent_hostname') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 141 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 142 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 143 | @decorators.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): |
zhufl | a0e87dc | 2020-05-13 15:52:15 +0800 | [diff] [blame] | 145 | """Non admin user is not allowed to shutdown host""" |
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, |
zhufl | 6361797 | 2016-11-16 16:59:41 +0800 | [diff] [blame] | 148 | self.hostname) |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 149 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 150 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 151 | @decorators.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): |
zhufl | a0e87dc | 2020-05-13 15:52:15 +0800 | [diff] [blame] | 153 | """Rebooting not existing host should fail""" |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 154 | self.assertRaises(lib_exc.NotFound, |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 155 | self.client.reboot_host, |
zhufl | 6361797 | 2016-11-16 16:59:41 +0800 | [diff] [blame] | 156 | 'nonexistent_hostname') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 157 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 158 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 159 | @decorators.idempotent_id('02d79bb9-eb57-4612-abf6-2cb38897d2f8') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 160 | def test_reboot_host_with_non_admin_user(self): |
zhufl | a0e87dc | 2020-05-13 15:52:15 +0800 | [diff] [blame] | 161 | """Non admin user is not allowed to reboot host""" |
Masayuki Igawa | 6b1cd29 | 2015-02-16 11:11:55 +0900 | [diff] [blame] | 162 | self.assertRaises(lib_exc.Forbidden, |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 163 | self.non_admin_client.reboot_host, |
zhufl | 6361797 | 2016-11-16 16:59:41 +0800 | [diff] [blame] | 164 | self.hostname) |