blob: cb034c94fdede936be261291ad420be9171e8fd0 [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
27 _interface = 'json'
28
29 @classmethod
30 def setUpClass(cls):
31 super(HostsAdminNegativeTestJSON, cls).setUpClass()
32 cls.client = cls.os_adm.hosts_client
33 cls.non_admin_client = cls.os.hosts_client
34
35 def _get_host_name(self):
36 resp, hosts = self.client.list_hosts()
37 self.assertEqual(200, resp.status)
38 self.assertTrue(len(hosts) >= 1)
39 hostname = hosts[0]['host_name']
40 return hostname
41
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +090042 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +080043 def test_list_hosts_with_non_admin_user(self):
44 self.assertRaises(exceptions.Unauthorized,
45 self.non_admin_client.list_hosts)
46
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +090047 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +080048 def test_show_host_detail_with_nonexistent_hostname(self):
49 nonexitent_hostname = data_utils.rand_name('rand_hostname')
50 self.assertRaises(exceptions.NotFound,
51 self.client.show_host_detail, nonexitent_hostname)
52
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +090053 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +080054 def test_show_host_detail_with_non_admin_user(self):
55 hostname = self._get_host_name()
56
57 self.assertRaises(exceptions.Unauthorized,
58 self.non_admin_client.show_host_detail,
59 hostname)
60
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +090061 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +080062 def test_update_host_with_non_admin_user(self):
63 hostname = self._get_host_name()
64
65 self.assertRaises(exceptions.Unauthorized,
66 self.non_admin_client.update_host,
Haiwei Xu0c1ca792014-01-15 22:49:24 +090067 hostname,
68 status='enable',
69 maintenance_mode='enable')
Lingxian Kong4b398fd2013-10-04 17:14:14 +080070
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +090071 @test.skip_because(bug="1261964", interface="xml")
72 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +080073 def test_update_host_with_extra_param(self):
74 # only 'status' and 'maintenance_mode' are the valid params.
75 hostname = self._get_host_name()
76
77 self.assertRaises(exceptions.BadRequest,
78 self.client.update_host,
79 hostname,
80 status='enable',
81 maintenance_mode='enable',
82 param='XXX')
83
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +090084 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +080085 def test_update_host_with_invalid_status(self):
86 # 'status' can only be 'enable' or 'disable'
87 hostname = self._get_host_name()
88
89 self.assertRaises(exceptions.BadRequest,
90 self.client.update_host,
91 hostname,
92 status='invalid',
93 maintenance_mode='enable')
94
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +090095 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +080096 def test_update_host_with_invalid_maintenance_mode(self):
97 # 'maintenance_mode' can only be 'enable' or 'disable'
98 hostname = self._get_host_name()
99
100 self.assertRaises(exceptions.BadRequest,
101 self.client.update_host,
102 hostname,
103 status='enable',
104 maintenance_mode='invalid')
105
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +0900106 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800107 def test_update_host_without_param(self):
108 # 'status' or 'maintenance_mode' needed for host update
109 hostname = self._get_host_name()
110
111 self.assertRaises(exceptions.BadRequest,
112 self.client.update_host,
113 hostname)
114
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +0900115 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800116 def test_update_nonexistent_host(self):
117 nonexitent_hostname = data_utils.rand_name('rand_hostname')
118
119 self.assertRaises(exceptions.NotFound,
120 self.client.update_host,
121 nonexitent_hostname,
122 status='enable',
123 maintenance_mode='enable')
124
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +0900125 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800126 def test_startup_nonexistent_host(self):
127 nonexitent_hostname = data_utils.rand_name('rand_hostname')
128
129 self.assertRaises(exceptions.NotFound,
130 self.client.startup_host,
131 nonexitent_hostname)
132
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +0900133 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800134 def test_startup_host_with_non_admin_user(self):
135 hostname = self._get_host_name()
136
137 self.assertRaises(exceptions.Unauthorized,
138 self.non_admin_client.startup_host,
139 hostname)
140
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +0900141 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800142 def test_shutdown_nonexistent_host(self):
143 nonexitent_hostname = data_utils.rand_name('rand_hostname')
144
145 self.assertRaises(exceptions.NotFound,
146 self.client.shutdown_host,
147 nonexitent_hostname)
148
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +0900149 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800150 def test_shutdown_host_with_non_admin_user(self):
151 hostname = self._get_host_name()
152
153 self.assertRaises(exceptions.Unauthorized,
154 self.non_admin_client.shutdown_host,
155 hostname)
156
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +0900157 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800158 def test_reboot_nonexistent_host(self):
159 nonexitent_hostname = data_utils.rand_name('rand_hostname')
160
161 self.assertRaises(exceptions.NotFound,
162 self.client.reboot_host,
163 nonexitent_hostname)
164
Ken'ichi Ohmichia1aa44c2013-12-06 20:48:24 +0900165 @test.attr(type=['negative', 'gate'])
Lingxian Kong4b398fd2013-10-04 17:14:14 +0800166 def test_reboot_host_with_non_admin_user(self):
167 hostname = self._get_host_name()
168
169 self.assertRaises(exceptions.Unauthorized,
170 self.non_admin_client.reboot_host,
171 hostname)
172
173
174class HostsAdminNegativeTestXML(HostsAdminNegativeTestJSON):
175 _interface = 'xml'