blob: fc918a3cb34f10d5a3a4b38fecccf5a1d8a3e733 [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
16from tempest.common.utils import data_utils
17from tempest import exceptions
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +090018from tempest import test
Lingxian Kong4b398fd2013-10-04 17:14:14 +080019
20
Mate Lakat1e89a1b2013-10-26 11:19:13 +010021class HostsAdminNegativeTestJSON(base.BaseV2ComputeAdminTest):
Lingxian Kong4b398fd2013-10-04 17:14:14 +080022
23 """
24 Tests hosts API using admin privileges.
25 """
26
Lingxian Kong4b398fd2013-10-04 17:14:14 +080027 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010028 def resource_setup(cls):
29 super(HostsAdminNegativeTestJSON, cls).resource_setup()
Lingxian Kong4b398fd2013-10-04 17:14:14 +080030 cls.client = cls.os_adm.hosts_client
31 cls.non_admin_client = cls.os.hosts_client
32
33 def _get_host_name(self):
David Kranz0a735172015-01-16 10:51:18 -050034 hosts = self.client.list_hosts()
Lingxian Kong4b398fd2013-10-04 17:14:14 +080035 self.assertTrue(len(hosts) >= 1)
36 hostname = hosts[0]['host_name']
37 return hostname
38
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +090039 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +080040 def test_list_hosts_with_non_admin_user(self):
41 self.assertRaises(exceptions.Unauthorized,
42 self.non_admin_client.list_hosts)
43
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +090044 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +080045 def test_show_host_detail_with_nonexistent_hostname(self):
46 nonexitent_hostname = data_utils.rand_name('rand_hostname')
47 self.assertRaises(exceptions.NotFound,
48 self.client.show_host_detail, nonexitent_hostname)
49
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +090050 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +080051 def test_show_host_detail_with_non_admin_user(self):
52 hostname = self._get_host_name()
53
54 self.assertRaises(exceptions.Unauthorized,
55 self.non_admin_client.show_host_detail,
56 hostname)
57
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +090058 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +080059 def test_update_host_with_non_admin_user(self):
60 hostname = self._get_host_name()
61
62 self.assertRaises(exceptions.Unauthorized,
63 self.non_admin_client.update_host,
Haiwei Xu0c1ca792014-01-15 22:49:24 +090064 hostname,
65 status='enable',
66 maintenance_mode='enable')
Lingxian Kong4b398fd2013-10-04 17:14:14 +080067
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +090068 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +080069 def test_update_host_with_extra_param(self):
70 # only 'status' and 'maintenance_mode' are the valid params.
71 hostname = self._get_host_name()
72
73 self.assertRaises(exceptions.BadRequest,
74 self.client.update_host,
75 hostname,
76 status='enable',
77 maintenance_mode='enable',
78 param='XXX')
79
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +090080 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +080081 def test_update_host_with_invalid_status(self):
82 # 'status' can only be 'enable' or 'disable'
83 hostname = self._get_host_name()
84
85 self.assertRaises(exceptions.BadRequest,
86 self.client.update_host,
87 hostname,
88 status='invalid',
89 maintenance_mode='enable')
90
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +090091 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +080092 def test_update_host_with_invalid_maintenance_mode(self):
93 # 'maintenance_mode' can only be 'enable' or 'disable'
94 hostname = self._get_host_name()
95
96 self.assertRaises(exceptions.BadRequest,
97 self.client.update_host,
98 hostname,
99 status='enable',
100 maintenance_mode='invalid')
101
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +0900102 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800103 def test_update_host_without_param(self):
104 # 'status' or 'maintenance_mode' needed for host update
105 hostname = self._get_host_name()
106
107 self.assertRaises(exceptions.BadRequest,
108 self.client.update_host,
109 hostname)
110
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +0900111 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800112 def test_update_nonexistent_host(self):
113 nonexitent_hostname = data_utils.rand_name('rand_hostname')
114
115 self.assertRaises(exceptions.NotFound,
116 self.client.update_host,
117 nonexitent_hostname,
118 status='enable',
119 maintenance_mode='enable')
120
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +0900121 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800122 def test_startup_nonexistent_host(self):
123 nonexitent_hostname = data_utils.rand_name('rand_hostname')
124
125 self.assertRaises(exceptions.NotFound,
126 self.client.startup_host,
127 nonexitent_hostname)
128
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +0900129 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800130 def test_startup_host_with_non_admin_user(self):
131 hostname = self._get_host_name()
132
133 self.assertRaises(exceptions.Unauthorized,
134 self.non_admin_client.startup_host,
135 hostname)
136
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +0900137 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800138 def test_shutdown_nonexistent_host(self):
139 nonexitent_hostname = data_utils.rand_name('rand_hostname')
140
141 self.assertRaises(exceptions.NotFound,
142 self.client.shutdown_host,
143 nonexitent_hostname)
144
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +0900145 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800146 def test_shutdown_host_with_non_admin_user(self):
147 hostname = self._get_host_name()
148
149 self.assertRaises(exceptions.Unauthorized,
150 self.non_admin_client.shutdown_host,
151 hostname)
152
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +0900153 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800154 def test_reboot_nonexistent_host(self):
155 nonexitent_hostname = data_utils.rand_name('rand_hostname')
156
157 self.assertRaises(exceptions.NotFound,
158 self.client.reboot_host,
159 nonexitent_hostname)
160
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +0900161 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800162 def test_reboot_host_with_non_admin_user(self):
163 hostname = self._get_host_name()
164
165 self.assertRaises(exceptions.Unauthorized,
166 self.non_admin_client.reboot_host,
167 hostname)