blob: 49af645b67ef9be3f7355dd7350fc4d349364318 [file] [log] [blame]
Liu, Zhi Kunb0ac0b82013-06-20 16:20:21 +08001# Copyright 2013 IBM Corp.
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
Masayuki Igawa259c1132013-10-31 17:48:44 +090016from tempest.common.utils import data_utils
ChenZhengd4acec42014-01-03 15:22:31 +080017from tempest import test
Liu, Zhi Kunb0ac0b82013-06-20 16:20:21 +080018
19
ivan-zhuf2b00502013-10-18 10:06:52 +080020class ServersAdminTestJSON(base.BaseV2ComputeAdminTest):
Liu, Zhi Kunb0ac0b82013-06-20 16:20:21 +080021
22 """
23 Tests Servers API using admin privileges
24 """
25
ChenZhengd4acec42014-01-03 15:22:31 +080026 _host_key = 'OS-EXT-SRV-ATTR:host'
Liu, Zhi Kunb0ac0b82013-06-20 16:20:21 +080027
28 @classmethod
Masayuki Igawa67b827f2014-03-17 18:44:57 +090029 @test.safe_setup
Liu, Zhi Kunb0ac0b82013-06-20 16:20:21 +080030 def setUpClass(cls):
31 super(ServersAdminTestJSON, cls).setUpClass()
32 cls.client = cls.os_adm.servers_client
Zhi Kun Liue5401762013-09-11 20:45:48 +080033 cls.non_admin_client = cls.servers_client
Zhu Zhuda070852013-09-25 08:07:57 -050034 cls.flavors_client = cls.os_adm.flavors_client
Liu, Zhi Kunb0ac0b82013-06-20 16:20:21 +080035
Masayuki Igawa259c1132013-10-31 17:48:44 +090036 cls.s1_name = data_utils.rand_name('server')
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +090037 resp, server = cls.create_test_server(name=cls.s1_name,
38 wait_until='ACTIVE')
LingxianKongc26e6072013-09-28 21:16:52 +080039 cls.s1_id = server['id']
40
Masayuki Igawa259c1132013-10-31 17:48:44 +090041 cls.s2_name = data_utils.rand_name('server')
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +090042 resp, server = cls.create_test_server(name=cls.s2_name,
43 wait_until='ACTIVE')
ChenZheng5b62f652014-01-03 15:03:33 +080044 cls.s2_id = server['id']
Liu, Zhi Kunb0ac0b82013-06-20 16:20:21 +080045
ChenZhengd4acec42014-01-03 15:22:31 +080046 @test.attr(type='gate')
Liu, Zhi Kunb0ac0b82013-06-20 16:20:21 +080047 def test_list_servers_by_admin(self):
48 # Listing servers by admin user returns empty list by default
49 resp, body = self.client.list_servers_with_detail()
50 servers = body['servers']
51 self.assertEqual('200', resp['status'])
52 self.assertEqual([], servers)
53
ChenZhengd4acec42014-01-03 15:22:31 +080054 @test.attr(type='gate')
ChenZheng5b62f652014-01-03 15:03:33 +080055 def test_list_servers_filter_by_error_status(self):
56 # Filter the list of servers by server error status
57 params = {'status': 'error'}
58 resp, server = self.client.reset_state(self.s1_id, state='error')
59 resp, body = self.non_admin_client.list_servers(params)
60 # Reset server's state to 'active'
61 resp, server = self.client.reset_state(self.s1_id, state='active')
62 # Verify server's state
63 resp, server = self.client.get_server(self.s1_id)
64 self.assertEqual(server['status'], 'ACTIVE')
65 servers = body['servers']
66 # Verify error server in list result
67 self.assertIn(self.s1_id, map(lambda x: x['id'], servers))
68 self.assertNotIn(self.s2_id, map(lambda x: x['id'], servers))
69
ChenZhengd4acec42014-01-03 15:22:31 +080070 @test.attr(type='gate')
Liu, Zhi Kunb0ac0b82013-06-20 16:20:21 +080071 def test_list_servers_by_admin_with_all_tenants(self):
72 # Listing servers by admin user with all tenants parameter
73 # Here should be listed all servers
74 params = {'all_tenants': ''}
75 resp, body = self.client.list_servers_with_detail(params)
76 servers = body['servers']
77 servers_name = map(lambda x: x['name'], servers)
78
79 self.assertIn(self.s1_name, servers_name)
80 self.assertIn(self.s2_name, servers_name)
81
ChenZhengd4acec42014-01-03 15:22:31 +080082 @test.attr(type='gate')
83 def test_list_servers_filter_by_exist_host(self):
84 # Filter the list of servers by existent host
85 name = data_utils.rand_name('server')
86 flavor = self.flavor_ref
87 image_id = self.image_ref
88 resp, test_server = self.client.create_server(
89 name, image_id, flavor)
90 self.assertEqual('202', resp['status'])
91 self.addCleanup(self.client.delete_server, test_server['id'])
92 self.client.wait_for_server_status(test_server['id'], 'ACTIVE')
93 resp, server = self.client.get_server(test_server['id'])
94 self.assertEqual(server['status'], 'ACTIVE')
95 hostname = server[self._host_key]
96 params = {'host': hostname}
97 resp, body = self.client.list_servers(params)
98 self.assertEqual('200', resp['status'])
99 servers = body['servers']
100 nonexistent_params = {'host': 'nonexistent_host'}
101 resp, nonexistent_body = self.client.list_servers(
102 nonexistent_params)
103 self.assertEqual('200', resp['status'])
104 nonexistent_servers = nonexistent_body['servers']
105 self.assertIn(test_server['id'], map(lambda x: x['id'], servers))
106 self.assertNotIn(test_server['id'],
107 map(lambda x: x['id'], nonexistent_servers))
108
109 @test.attr(type='gate')
LingxianKongc26e6072013-09-28 21:16:52 +0800110 def test_reset_state_server(self):
111 # Reset server's state to 'error'
112 resp, server = self.client.reset_state(self.s1_id)
113 self.assertEqual(202, resp.status)
114
115 # Verify server's state
116 resp, server = self.client.get_server(self.s1_id)
117 self.assertEqual(server['status'], 'ERROR')
118
119 # Reset server's state to 'active'
120 resp, server = self.client.reset_state(self.s1_id, state='active')
121 self.assertEqual(202, resp.status)
122
123 # Verify server's state
124 resp, server = self.client.get_server(self.s1_id)
125 self.assertEqual(server['status'], 'ACTIVE')
126
ChenZhengd4acec42014-01-03 15:22:31 +0800127 @test.attr(type='gate')
128 @test.skip_because(bug="1240043")
Zhu Zhuda070852013-09-25 08:07:57 -0500129 def test_get_server_diagnostics_by_admin(self):
130 # Retrieve server diagnostics by admin user
131 resp, diagnostic = self.client.get_server_diagnostics(self.s1_id)
132 self.assertEqual(200, resp.status)
133 basic_attrs = ['rx_packets', 'rx_errors', 'rx_drop',
134 'tx_packets', 'tx_errors', 'tx_drop',
135 'read_req', 'write_req', 'cpu', 'memory']
136 for key in basic_attrs:
137 self.assertIn(key, str(diagnostic.keys()))
138
ChenZhengd4acec42014-01-03 15:22:31 +0800139 @test.attr(type='gate')
Zhi Kun Liue5401762013-09-11 20:45:48 +0800140 def test_rebuild_server_in_error_state(self):
141 # The server in error state should be rebuilt using the provided
142 # image and changed to ACTIVE state
143
Marc Solanasb15d8b62014-02-07 00:04:15 -0800144 # resetting vm state require admin privilege
Zhi Kun Liue5401762013-09-11 20:45:48 +0800145 resp, server = self.client.reset_state(self.s1_id, state='error')
146 self.assertEqual(202, resp.status)
147 resp, rebuilt_server = self.non_admin_client.rebuild(
148 self.s1_id, self.image_ref_alt)
149 self.addCleanup(self.non_admin_client.wait_for_server_status,
150 self.s1_id, 'ACTIVE')
151 self.addCleanup(self.non_admin_client.rebuild, self.s1_id,
152 self.image_ref)
153
154 # Verify the properties in the initial response are correct
155 self.assertEqual(self.s1_id, rebuilt_server['id'])
156 rebuilt_image_id = rebuilt_server['image']['id']
157 self.assertEqual(self.image_ref_alt, rebuilt_image_id)
158 self.assertEqual(self.flavor_ref, rebuilt_server['flavor']['id'])
159 self.non_admin_client.wait_for_server_status(rebuilt_server['id'],
160 'ACTIVE',
161 raise_on_error=False)
162 # Verify the server properties after rebuilding
163 resp, server = self.non_admin_client.get_server(rebuilt_server['id'])
164 rebuilt_image_id = server['image']['id']
165 self.assertEqual(self.image_ref_alt, rebuilt_image_id)
166
Ghanshyam Mann79f4a092014-02-27 21:01:31 +0900167 @test.attr(type='gate')
168 def test_reset_network_inject_network_info(self):
169 # Reset Network of a Server
170 resp, server = self.create_test_server(wait_until='ACTIVE')
171 resp, server_body = self.client.reset_network(server['id'])
172 self.assertEqual(202, resp.status)
173 # Inject the Network Info into Server
174 resp, server_body = self.client.inject_network_info(server['id'])
175 self.assertEqual(202, resp.status)
176
raiesmh08cbe21b02014-03-12 17:04:44 +0530177 @test.attr(type='gate')
178 def test_create_server_with_scheduling_hint(self):
179 # Create a server with scheduler hints.
180 hints = {
181 'same_host': self.s1_id
182 }
183 resp, server = self.create_test_server(sched_hints=hints,
184 wait_until='ACTIVE')
185 self.assertEqual('202', resp['status'])
186
Liu, Zhi Kunb0ac0b82013-06-20 16:20:21 +0800187
188class ServersAdminTestXML(ServersAdminTestJSON):
ChenZhengd4acec42014-01-03 15:22:31 +0800189 _host_key = (
190 '{http://docs.openstack.org/compute/ext/extended_status/api/v1.1}host')
Liu, Zhi Kunb0ac0b82013-06-20 16:20:21 +0800191 _interface = 'xml'