blob: e9436bc33070a0c314d65d23ad35c9b283798b15 [file] [log] [blame]
Lingxian Kong4b398fd2013-10-04 17:14:14 +08001# 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
15from tempest.api.compute import base
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080016from tempest.lib import decorators
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050017from tempest.lib import exceptions as lib_exc
Lingxian Kong4b398fd2013-10-04 17:14:14 +080018
19
Mate Lakat1e89a1b2013-10-26 11:19:13 +010020class HostsAdminNegativeTestJSON(base.BaseV2ComputeAdminTest):
Ken'ichi Ohmichi88363cb2015-11-19 08:00:54 +000021 """Tests hosts API using admin privileges."""
Lingxian Kong4b398fd2013-10-04 17:14:14 +080022
zhufle7398042018-03-13 16:20:18 +080023 max_microversion = '2.42'
24
Lingxian Kong4b398fd2013-10-04 17:14:14 +080025 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053026 def setup_clients(cls):
27 super(HostsAdminNegativeTestJSON, cls).setup_clients()
Jordan Pittier8160d312017-04-18 11:52:23 +020028 cls.client = cls.os_admin.hosts_client
29 cls.non_admin_client = cls.os_primary.hosts_client
Lingxian Kong4b398fd2013-10-04 17:14:14 +080030
zhufl63617972016-11-16 16:59:41 +080031 @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 Kong4b398fd2013-10-04 17:14:14 +080038
Jordan Pittier3b46d272017-04-12 16:17:28 +020039 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080040 @decorators.idempotent_id('dd032027-0210-4d9c-860e-69b1b8deed5f')
Lingxian Kong4b398fd2013-10-04 17:14:14 +080041 def test_list_hosts_with_non_admin_user(self):
zhufla0e87dc2020-05-13 15:52:15 +080042 """Non admin user is not allowed to list hosts"""
Masayuki Igawa6b1cd292015-02-16 11:11:55 +090043 self.assertRaises(lib_exc.Forbidden,
Lingxian Kong4b398fd2013-10-04 17:14:14 +080044 self.non_admin_client.list_hosts)
45
Jordan Pittier3b46d272017-04-12 16:17:28 +020046 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080047 @decorators.idempotent_id('e75b0a1a-041f-47a1-8b4a-b72a6ff36d3f')
Lingxian Kong4b398fd2013-10-04 17:14:14 +080048 def test_show_host_detail_with_nonexistent_hostname(self):
zhufla0e87dc2020-05-13 15:52:15 +080049 """Showing host detail with not existing hostname should fail"""
Masayuki Igawabfa07602015-01-20 18:47:17 +090050 self.assertRaises(lib_exc.NotFound,
zhufl63617972016-11-16 16:59:41 +080051 self.client.show_host, 'nonexistent_hostname')
Lingxian Kong4b398fd2013-10-04 17:14:14 +080052
Jordan Pittier3b46d272017-04-12 16:17:28 +020053 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080054 @decorators.idempotent_id('19ebe09c-bfd4-4b7c-81a2-e2e0710f59cc')
Lingxian Kong4b398fd2013-10-04 17:14:14 +080055 def test_show_host_detail_with_non_admin_user(self):
zhufla0e87dc2020-05-13 15:52:15 +080056 """Non admin user is not allowed to show host details"""
Masayuki Igawa6b1cd292015-02-16 11:11:55 +090057 self.assertRaises(lib_exc.Forbidden,
Ken'ichi Ohmichi394e6e42015-06-11 04:20:37 +000058 self.non_admin_client.show_host,
zhufl63617972016-11-16 16:59:41 +080059 self.hostname)
Lingxian Kong4b398fd2013-10-04 17:14:14 +080060
Jordan Pittier3b46d272017-04-12 16:17:28 +020061 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080062 @decorators.idempotent_id('e40c72b1-0239-4ed6-ba21-81a184df1f7c')
Lingxian Kong4b398fd2013-10-04 17:14:14 +080063 def test_update_host_with_non_admin_user(self):
zhufla0e87dc2020-05-13 15:52:15 +080064 """Non admin user is not allowed to update host"""
Masayuki Igawa6b1cd292015-02-16 11:11:55 +090065 self.assertRaises(lib_exc.Forbidden,
Lingxian Kong4b398fd2013-10-04 17:14:14 +080066 self.non_admin_client.update_host,
zhufl63617972016-11-16 16:59:41 +080067 self.hostname,
Haiwei Xu0c1ca792014-01-15 22:49:24 +090068 status='enable',
69 maintenance_mode='enable')
Lingxian Kong4b398fd2013-10-04 17:14:14 +080070
Jordan Pittier3b46d272017-04-12 16:17:28 +020071 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080072 @decorators.idempotent_id('fbe2bf3e-3246-4a95-a59f-94e4e298ec77')
Lingxian Kong4b398fd2013-10-04 17:14:14 +080073 def test_update_host_with_invalid_status(self):
zhufla0e87dc2020-05-13 15:52:15 +080074 """Updating host to invalid status should fail
75
76 'status' can only be 'enable' or 'disable'.
77 """
Masayuki Igawa4b29e472015-02-16 10:41:54 +090078 self.assertRaises(lib_exc.BadRequest,
Lingxian Kong4b398fd2013-10-04 17:14:14 +080079 self.client.update_host,
zhufl63617972016-11-16 16:59:41 +080080 self.hostname,
Lingxian Kong4b398fd2013-10-04 17:14:14 +080081 status='invalid',
82 maintenance_mode='enable')
83
Jordan Pittier3b46d272017-04-12 16:17:28 +020084 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080085 @decorators.idempotent_id('ab1e230e-5e22-41a9-8699-82b9947915d4')
Lingxian Kong4b398fd2013-10-04 17:14:14 +080086 def test_update_host_with_invalid_maintenance_mode(self):
zhufla0e87dc2020-05-13 15:52:15 +080087 """Updating host to invalid maintenance mode should fail
88
89 'maintenance_mode' can only be 'enable' or 'disable'.
90 """
Masayuki Igawa4b29e472015-02-16 10:41:54 +090091 self.assertRaises(lib_exc.BadRequest,
Lingxian Kong4b398fd2013-10-04 17:14:14 +080092 self.client.update_host,
zhufl63617972016-11-16 16:59:41 +080093 self.hostname,
Lingxian Kong4b398fd2013-10-04 17:14:14 +080094 status='enable',
95 maintenance_mode='invalid')
96
Jordan Pittier3b46d272017-04-12 16:17:28 +020097 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080098 @decorators.idempotent_id('0cd85f75-6992-4a4a-b1bd-d11e37fd0eee')
Lingxian Kong4b398fd2013-10-04 17:14:14 +080099 def test_update_host_without_param(self):
zhufla0e87dc2020-05-13 15:52:15 +0800100 """Updating host without param should fail
101
102 'status' or 'maintenance_mode' is needed for host update
103 """
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900104 self.assertRaises(lib_exc.BadRequest,
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800105 self.client.update_host,
zhufl63617972016-11-16 16:59:41 +0800106 self.hostname)
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800107
Jordan Pittier3b46d272017-04-12 16:17:28 +0200108 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800109 @decorators.idempotent_id('23c92146-2100-4d68-b2d6-c7ade970c9c1')
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800110 def test_update_nonexistent_host(self):
zhufla0e87dc2020-05-13 15:52:15 +0800111 """Updating not existing host should fail"""
Masayuki Igawabfa07602015-01-20 18:47:17 +0900112 self.assertRaises(lib_exc.NotFound,
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800113 self.client.update_host,
zhufl63617972016-11-16 16:59:41 +0800114 'nonexistent_hostname',
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800115 status='enable',
116 maintenance_mode='enable')
117
Jordan Pittier3b46d272017-04-12 16:17:28 +0200118 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800119 @decorators.idempotent_id('0d981ac3-4320-4898-b674-82b61fbb60e4')
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800120 def test_startup_nonexistent_host(self):
zhufla0e87dc2020-05-13 15:52:15 +0800121 """Starting up not existing host should fail"""
Masayuki Igawabfa07602015-01-20 18:47:17 +0900122 self.assertRaises(lib_exc.NotFound,
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800123 self.client.startup_host,
zhufl63617972016-11-16 16:59:41 +0800124 'nonexistent_hostname')
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800125
Jordan Pittier3b46d272017-04-12 16:17:28 +0200126 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800127 @decorators.idempotent_id('9f4ebb7e-b2ae-4e5b-a38f-0fd1bb0ddfca')
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800128 def test_startup_host_with_non_admin_user(self):
zhufla0e87dc2020-05-13 15:52:15 +0800129 """Non admin user is not allowed to startup host"""
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900130 self.assertRaises(lib_exc.Forbidden,
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800131 self.non_admin_client.startup_host,
zhufl63617972016-11-16 16:59:41 +0800132 self.hostname)
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800133
Jordan Pittier3b46d272017-04-12 16:17:28 +0200134 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800135 @decorators.idempotent_id('9e637444-29cf-4244-88c8-831ae82c31b6')
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800136 def test_shutdown_nonexistent_host(self):
zhufla0e87dc2020-05-13 15:52:15 +0800137 """Shutting down not existing host should fail"""
Masayuki Igawabfa07602015-01-20 18:47:17 +0900138 self.assertRaises(lib_exc.NotFound,
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800139 self.client.shutdown_host,
zhufl63617972016-11-16 16:59:41 +0800140 'nonexistent_hostname')
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800141
Jordan Pittier3b46d272017-04-12 16:17:28 +0200142 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800143 @decorators.idempotent_id('a803529c-7e3f-4d3c-a7d6-8e1c203d27f6')
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800144 def test_shutdown_host_with_non_admin_user(self):
zhufla0e87dc2020-05-13 15:52:15 +0800145 """Non admin user is not allowed to shutdown host"""
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900146 self.assertRaises(lib_exc.Forbidden,
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800147 self.non_admin_client.shutdown_host,
zhufl63617972016-11-16 16:59:41 +0800148 self.hostname)
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800149
Jordan Pittier3b46d272017-04-12 16:17:28 +0200150 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800151 @decorators.idempotent_id('f86bfd7b-0b13-4849-ae29-0322e83ee58b')
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800152 def test_reboot_nonexistent_host(self):
zhufla0e87dc2020-05-13 15:52:15 +0800153 """Rebooting not existing host should fail"""
Masayuki Igawabfa07602015-01-20 18:47:17 +0900154 self.assertRaises(lib_exc.NotFound,
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800155 self.client.reboot_host,
zhufl63617972016-11-16 16:59:41 +0800156 'nonexistent_hostname')
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800157
Jordan Pittier3b46d272017-04-12 16:17:28 +0200158 @decorators.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800159 @decorators.idempotent_id('02d79bb9-eb57-4612-abf6-2cb38897d2f8')
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800160 def test_reboot_host_with_non_admin_user(self):
zhufla0e87dc2020-05-13 15:52:15 +0800161 """Non admin user is not allowed to reboot host"""
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900162 self.assertRaises(lib_exc.Forbidden,
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800163 self.non_admin_client.reboot_host,
zhufl63617972016-11-16 16:59:41 +0800164 self.hostname)