blob: bc00f8cc66b8059aba5e3e29d9aeeb77543806cd [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
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000016from tempest.common import waiters
Stephen Finucane39fa9c12020-09-03 17:47:19 +010017from tempest import config
Ken'ichi Ohmichi757833a2017-03-10 10:30:30 -080018from tempest.lib.common.utils import data_utils
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050019from tempest.lib import decorators
zhufl34b55032018-03-29 17:07:32 +080020from tempest.lib import exceptions as lib_exc
Liu, Zhi Kunb0ac0b82013-06-20 16:20:21 +080021
Stephen Finucane39fa9c12020-09-03 17:47:19 +010022CONF = config.CONF
23
Liu, Zhi Kunb0ac0b82013-06-20 16:20:21 +080024
ivan-zhuf2b00502013-10-18 10:06:52 +080025class ServersAdminTestJSON(base.BaseV2ComputeAdminTest):
Ken'ichi Ohmichi9e3dac02015-11-19 07:01:07 +000026 """Tests Servers API using admin privileges"""
Liu, Zhi Kunb0ac0b82013-06-20 16:20:21 +080027
Liu, Zhi Kunb0ac0b82013-06-20 16:20:21 +080028 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053029 def setup_clients(cls):
30 super(ServersAdminTestJSON, cls).setup_clients()
Jordan Pittier8160d312017-04-18 11:52:23 +020031 cls.client = cls.os_admin.servers_client
Zhi Kun Liue5401762013-09-11 20:45:48 +080032 cls.non_admin_client = cls.servers_client
Liu, Zhi Kunb0ac0b82013-06-20 16:20:21 +080033
Rohan Kanade60b73092015-02-04 17:58:19 +053034 @classmethod
35 def resource_setup(cls):
36 super(ServersAdminTestJSON, cls).resource_setup()
37
zhuflc6ce5392016-08-17 14:34:37 +080038 cls.s1_name = data_utils.rand_name(cls.__name__ + '-server')
zhuflb4c484e2017-04-05 15:05:15 +080039 server = cls.create_test_server(name=cls.s1_name)
LingxianKongc26e6072013-09-28 21:16:52 +080040 cls.s1_id = server['id']
41
zhuflc6ce5392016-08-17 14:34:37 +080042 cls.s2_name = data_utils.rand_name(cls.__name__ + '-server')
David Kranz0fb14292015-02-11 15:55:20 -050043 server = cls.create_test_server(name=cls.s2_name,
44 wait_until='ACTIVE')
ChenZheng5b62f652014-01-03 15:03:33 +080045 cls.s2_id = server['id']
zhuflb4c484e2017-04-05 15:05:15 +080046 waiters.wait_for_server_status(cls.non_admin_client,
47 cls.s1_id, 'ACTIVE')
Liu, Zhi Kunb0ac0b82013-06-20 16:20:21 +080048
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080049 @decorators.idempotent_id('06f960bb-15bb-48dc-873d-f96e89be7870')
ChenZheng5b62f652014-01-03 15:03:33 +080050 def test_list_servers_filter_by_error_status(self):
zhufl4e726a62020-08-10 16:30:28 +080051 """Test filtering the list of servers by server error status"""
ChenZheng5b62f652014-01-03 15:03:33 +080052 params = {'status': 'error'}
David Kranzae99b9a2015-02-16 13:37:01 -050053 self.client.reset_state(self.s1_id, state='error')
Ken'ichi Ohmichicbc26a82015-07-03 08:18:04 +000054 body = self.non_admin_client.list_servers(**params)
ChenZheng5b62f652014-01-03 15:03:33 +080055 # Reset server's state to 'active'
David Kranzae99b9a2015-02-16 13:37:01 -050056 self.client.reset_state(self.s1_id, state='active')
ChenZheng5b62f652014-01-03 15:03:33 +080057 # Verify server's state
ghanshyam0f825252015-08-25 16:02:50 +090058 server = self.client.show_server(self.s1_id)['server']
ChenZheng5b62f652014-01-03 15:03:33 +080059 self.assertEqual(server['status'], 'ACTIVE')
60 servers = body['servers']
61 # Verify error server in list result
62 self.assertIn(self.s1_id, map(lambda x: x['id'], servers))
63 self.assertNotIn(self.s2_id, map(lambda x: x['id'], servers))
64
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080065 @decorators.idempotent_id('d56e9540-73ed-45e0-9b88-98fc419087eb')
Ken'ichi Ohmichi68be16f2016-06-03 13:19:26 -070066 def test_list_servers_detailed_filter_by_invalid_status(self):
zhufl4e726a62020-08-10 16:30:28 +080067 """Test filtering the list of servers by invalid server status"""
Ken'ichi Ohmichi68be16f2016-06-03 13:19:26 -070068 params = {'status': 'invalid_status'}
zhufl34b55032018-03-29 17:07:32 +080069 if self.is_requested_microversion_compatible('2.37'):
70 body = self.client.list_servers(detail=True, **params)
71 servers = body['servers']
72 self.assertEmpty(servers)
73 else:
74 self.assertRaises(lib_exc.BadRequest, self.client.list_servers,
75 detail=True, **params)
Ken'ichi Ohmichi68be16f2016-06-03 13:19:26 -070076
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080077 @decorators.idempotent_id('51717b38-bdc1-458b-b636-1cf82d99f62f')
Ken'ichi Ohmichi3f9cd0c2016-09-01 14:52:03 -070078 def test_list_servers_by_admin(self):
zhufl4e726a62020-08-10 16:30:28 +080079 """Test listing servers by admin without other projects
80
81 Listing servers by admin user returns a list which doesn't
82 contain the other projects' server by default.
83 """
Ken'ichi Ohmichi3f9cd0c2016-09-01 14:52:03 -070084 body = self.client.list_servers(detail=True)
85 servers = body['servers']
86
87 # This case is for the test environments which contain
88 # the existing servers before testing
89 servers_name = [server['name'] for server in servers]
90 self.assertNotIn(self.s1_name, servers_name)
91 self.assertNotIn(self.s2_name, servers_name)
92
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080093 @decorators.idempotent_id('9f5579ae-19b4-4985-a091-2a5d56106580')
Liu, Zhi Kunb0ac0b82013-06-20 16:20:21 +080094 def test_list_servers_by_admin_with_all_tenants(self):
zhufl4e726a62020-08-10 16:30:28 +080095 """Test listing servers by admin with all tenants
96
97 Listing servers by admin user with all tenants parameter,
98 all servers should be listed.
99 """
Liu, Zhi Kunb0ac0b82013-06-20 16:20:21 +0800100 params = {'all_tenants': ''}
Ken'ichi Ohmichicbc26a82015-07-03 08:18:04 +0000101 body = self.client.list_servers(detail=True, **params)
Liu, Zhi Kunb0ac0b82013-06-20 16:20:21 +0800102 servers = body['servers']
Sirushti Murugesan935f2cc2016-07-12 19:48:24 +0530103 servers_name = [server['name'] for server in servers]
Liu, Zhi Kunb0ac0b82013-06-20 16:20:21 +0800104
105 self.assertIn(self.s1_name, servers_name)
106 self.assertIn(self.s2_name, servers_name)
107
Jordan Pittierc5665a62017-04-12 16:42:53 +0200108 @decorators.related_bug('1659811')
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800109 @decorators.idempotent_id('7e5d6b8f-454a-4ba1-8ae2-da857af8338b')
David Kranzb28b4182015-01-05 16:07:19 -0500110 def test_list_servers_by_admin_with_specified_tenant(self):
zhufl4e726a62020-08-10 16:30:28 +0800111 """Test listing servers by admin with specified project
David Kranzb28b4182015-01-05 16:07:19 -0500112
zhufl4e726a62020-08-10 16:30:28 +0800113 In nova v2, tenant_id is ignored unless all_tenants is specified.
114 """
David Kranzb28b4182015-01-05 16:07:19 -0500115 # List the primary tenant but get nothing due to odd specified behavior
116 tenant_id = self.non_admin_client.tenant_id
117 params = {'tenant_id': tenant_id}
Ken'ichi Ohmichicbc26a82015-07-03 08:18:04 +0000118 body = self.client.list_servers(detail=True, **params)
David Kranzb28b4182015-01-05 16:07:19 -0500119 servers = body['servers']
Davanum Srinivas816607c2017-01-17 16:01:31 -0500120 servers_name = [x['name'] for x in servers]
zhufl80b8d0a2016-09-22 14:35:27 +0800121 self.assertNotIn(self.s1_name, servers_name)
122 self.assertNotIn(self.s2_name, servers_name)
David Kranzb28b4182015-01-05 16:07:19 -0500123
guo yunxian88a7e092016-09-28 17:36:57 +0800124 # List the primary tenant with all_tenants is specified
125 params = {'all_tenants': '', 'tenant_id': tenant_id}
126 body = self.client.list_servers(detail=True, **params)
127 servers = body['servers']
Davanum Srinivas816607c2017-01-17 16:01:31 -0500128 servers_name = [x['name'] for x in servers]
guo yunxian88a7e092016-09-28 17:36:57 +0800129 self.assertIn(self.s1_name, servers_name)
130 self.assertIn(self.s2_name, servers_name)
131
zhufl80b8d0a2016-09-22 14:35:27 +0800132 # List the admin tenant shouldn't get servers created by other tenants
David Kranzb28b4182015-01-05 16:07:19 -0500133 admin_tenant_id = self.client.tenant_id
134 params = {'all_tenants': '', 'tenant_id': admin_tenant_id}
Ken'ichi Ohmichicbc26a82015-07-03 08:18:04 +0000135 body = self.client.list_servers(detail=True, **params)
David Kranzb28b4182015-01-05 16:07:19 -0500136 servers = body['servers']
Davanum Srinivas816607c2017-01-17 16:01:31 -0500137 servers_name = [x['name'] for x in servers]
zhufl80b8d0a2016-09-22 14:35:27 +0800138 self.assertNotIn(self.s1_name, servers_name)
139 self.assertNotIn(self.s2_name, servers_name)
David Kranzb28b4182015-01-05 16:07:19 -0500140
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800141 @decorators.idempotent_id('86c7a8f7-50cf-43a9-9bac-5b985317134f')
ChenZhengd4acec42014-01-03 15:22:31 +0800142 def test_list_servers_filter_by_exist_host(self):
zhufl4e726a62020-08-10 16:30:28 +0800143 """Test filtering the list of servers by existent host"""
zhufl64917382017-08-11 13:55:25 +0800144 server = self.client.show_server(self.s1_id)['server']
Ken'ichi Ohmichi70456892016-08-12 14:31:19 -0700145 hostname = server['OS-EXT-SRV-ATTR:host']
zhufl64917382017-08-11 13:55:25 +0800146 params = {'host': hostname, 'all_tenants': '1'}
147 servers = self.client.list_servers(**params)['servers']
148 self.assertIn(server['id'], map(lambda x: x['id'], servers))
149
150 nonexistent_params = {'host': 'nonexistent_host',
151 'all_tenants': '1'}
Ken'ichi Ohmichicbc26a82015-07-03 08:18:04 +0000152 nonexistent_body = self.client.list_servers(**nonexistent_params)
ChenZhengd4acec42014-01-03 15:22:31 +0800153 nonexistent_servers = nonexistent_body['servers']
zhufl64917382017-08-11 13:55:25 +0800154 self.assertNotIn(server['id'],
ChenZhengd4acec42014-01-03 15:22:31 +0800155 map(lambda x: x['id'], nonexistent_servers))
156
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800157 @decorators.idempotent_id('ee8ae470-db70-474d-b752-690b7892cab1')
LingxianKongc26e6072013-09-28 21:16:52 +0800158 def test_reset_state_server(self):
zhufl4e726a62020-08-10 16:30:28 +0800159 """Test resetting server state to error/active"""
LingxianKongc26e6072013-09-28 21:16:52 +0800160 # Reset server's state to 'error'
Ken'ichi Ohmichi36b714c2015-12-09 08:12:47 +0000161 self.client.reset_state(self.s1_id, state='error')
LingxianKongc26e6072013-09-28 21:16:52 +0800162
163 # Verify server's state
ghanshyam0f825252015-08-25 16:02:50 +0900164 server = self.client.show_server(self.s1_id)['server']
LingxianKongc26e6072013-09-28 21:16:52 +0800165 self.assertEqual(server['status'], 'ERROR')
166
167 # Reset server's state to 'active'
David Kranzae99b9a2015-02-16 13:37:01 -0500168 self.client.reset_state(self.s1_id, state='active')
LingxianKongc26e6072013-09-28 21:16:52 +0800169
170 # Verify server's state
ghanshyam0f825252015-08-25 16:02:50 +0900171 server = self.client.show_server(self.s1_id)['server']
LingxianKongc26e6072013-09-28 21:16:52 +0800172 self.assertEqual(server['status'], 'ACTIVE')
173
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800174 @decorators.idempotent_id('682cb127-e5bb-4f53-87ce-cb9003604442')
Zhi Kun Liue5401762013-09-11 20:45:48 +0800175 def test_rebuild_server_in_error_state(self):
zhufl4e726a62020-08-10 16:30:28 +0800176 """Test rebuilding server in error state
Zhi Kun Liue5401762013-09-11 20:45:48 +0800177
zhufl4e726a62020-08-10 16:30:28 +0800178 The server in error state should be rebuilt using the provided
179 image and changed to ACTIVE state.
180 """
Marc Solanasb15d8b62014-02-07 00:04:15 -0800181 # resetting vm state require admin privilege
David Kranzae99b9a2015-02-16 13:37:01 -0500182 self.client.reset_state(self.s1_id, state='error')
Ken'ichi Ohmichi5271b0f2015-08-10 07:53:27 +0000183 rebuilt_server = self.non_admin_client.rebuild_server(
ghanshyam0f825252015-08-25 16:02:50 +0900184 self.s1_id, self.image_ref_alt)['server']
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000185 self.addCleanup(waiters.wait_for_server_status, self.non_admin_client,
Zhi Kun Liue5401762013-09-11 20:45:48 +0800186 self.s1_id, 'ACTIVE')
Ken'ichi Ohmichi5271b0f2015-08-10 07:53:27 +0000187 self.addCleanup(self.non_admin_client.rebuild_server, self.s1_id,
Zhi Kun Liue5401762013-09-11 20:45:48 +0800188 self.image_ref)
189
190 # Verify the properties in the initial response are correct
191 self.assertEqual(self.s1_id, rebuilt_server['id'])
192 rebuilt_image_id = rebuilt_server['image']['id']
193 self.assertEqual(self.image_ref_alt, rebuilt_image_id)
zhuflbcb71172018-03-29 13:49:31 +0800194 self.assert_flavor_equal(self.flavor_ref, rebuilt_server['flavor'])
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000195 waiters.wait_for_server_status(self.non_admin_client,
196 rebuilt_server['id'], 'ACTIVE',
197 raise_on_error=False)
Zhi Kun Liue5401762013-09-11 20:45:48 +0800198 # Verify the server properties after rebuilding
ghanshyam0f825252015-08-25 16:02:50 +0900199 server = (self.non_admin_client.show_server(rebuilt_server['id'])
200 ['server'])
Zhi Kun Liue5401762013-09-11 20:45:48 +0800201 rebuilt_image_id = server['image']['id']
202 self.assertEqual(self.image_ref_alt, rebuilt_image_id)
203
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800204 @decorators.idempotent_id('7a1323b4-a6a2-497a-96cb-76c07b945c71')
Ghanshyam Mann79f4a092014-02-27 21:01:31 +0900205 def test_reset_network_inject_network_info(self):
zhufl4e726a62020-08-10 16:30:28 +0800206 """Test resetting and injecting network info of a server"""
Stephen Finucane39fa9c12020-09-03 17:47:19 +0100207 if not CONF.compute_feature_enabled.xenapi_apis:
208 raise self.skipException(
209 'The resetNetwork server action is not supported.')
210
Ghanshyam Mann79f4a092014-02-27 21:01:31 +0900211 # Reset Network of a Server
David Kranz0fb14292015-02-11 15:55:20 -0500212 server = self.create_test_server(wait_until='ACTIVE')
David Kranzae99b9a2015-02-16 13:37:01 -0500213 self.client.reset_network(server['id'])
Ghanshyam Mann79f4a092014-02-27 21:01:31 +0900214 # Inject the Network Info into Server
David Kranzae99b9a2015-02-16 13:37:01 -0500215 self.client.inject_network_info(server['id'])
Ghanshyam Mann79f4a092014-02-27 21:01:31 +0900216
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800217 @decorators.idempotent_id('fdcd9b33-0903-4e00-a1f7-b5f6543068d6')
raiesmh08cbe21b02014-03-12 17:04:44 +0530218 def test_create_server_with_scheduling_hint(self):
zhufl4e726a62020-08-10 16:30:28 +0800219 """Test creating server with scheduling hint"""
raiesmh08cbe21b02014-03-12 17:04:44 +0530220 # Create a server with scheduler hints.
221 hints = {
222 'same_host': self.s1_id
223 }
Ken'ichi Ohmichif2d436e2015-09-03 01:13:16 +0000224 self.create_test_server(scheduler_hints=hints,
David Kranz0fb14292015-02-11 15:55:20 -0500225 wait_until='ACTIVE')
Ghanshyam Mann1a65c4f2022-03-03 22:03:26 -0600226
227
228class ServersAdmin275Test(base.BaseV2ComputeAdminTest):
229 """Test compute server with microversion greater than 2.75
230
231 # NOTE(gmann): This test tests the Server APIs response schema
232 # for 2.75 microversion. No specific assert or behaviour verification
233 # is needed.
234 """
235
236 min_microversion = '2.75'
237
238 @decorators.idempotent_id('bf2b4a00-73a3-4d53-81fa-acbcd97d6339')
239 def test_rebuild_update_server_275(self):
240 server = self.create_test_server()
241 # Checking update response schema.
242 self.servers_client.update_server(server['id'])
243 waiters.wait_for_server_status(self.servers_client, server['id'],
244 'ACTIVE')
245 # Checking rebuild API response schema
246 self.servers_client.rebuild_server(server['id'], self.image_ref_alt)
247 waiters.wait_for_server_status(self.servers_client,
248 server['id'], 'ACTIVE')
249 # Checking rebuild server with admin response schema.
250 self.os_admin.servers_client.rebuild_server(
251 server['id'], self.image_ref)
252 self.addCleanup(waiters.wait_for_server_status,
253 self.os_admin.servers_client,
254 server['id'], 'ACTIVE')