Liu, Zhi Kun | b0ac0b8 | 2013-06-20 16:20:21 +0800 | [diff] [blame] | 1 | # 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 | |
| 15 | from tempest.api.compute import base |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 16 | from tempest.common.utils import data_utils |
ChenZheng | d4acec4 | 2014-01-03 15:22:31 +0800 | [diff] [blame] | 17 | from tempest import test |
Liu, Zhi Kun | b0ac0b8 | 2013-06-20 16:20:21 +0800 | [diff] [blame] | 18 | |
| 19 | |
ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 20 | class ServersAdminTestJSON(base.BaseV2ComputeAdminTest): |
Liu, Zhi Kun | b0ac0b8 | 2013-06-20 16:20:21 +0800 | [diff] [blame] | 21 | |
| 22 | """ |
| 23 | Tests Servers API using admin privileges |
| 24 | """ |
| 25 | |
ChenZheng | d4acec4 | 2014-01-03 15:22:31 +0800 | [diff] [blame] | 26 | _host_key = 'OS-EXT-SRV-ATTR:host' |
Liu, Zhi Kun | b0ac0b8 | 2013-06-20 16:20:21 +0800 | [diff] [blame] | 27 | |
| 28 | @classmethod |
Masayuki Igawa | 67b827f | 2014-03-17 18:44:57 +0900 | [diff] [blame] | 29 | @test.safe_setup |
Liu, Zhi Kun | b0ac0b8 | 2013-06-20 16:20:21 +0800 | [diff] [blame] | 30 | def setUpClass(cls): |
| 31 | super(ServersAdminTestJSON, cls).setUpClass() |
| 32 | cls.client = cls.os_adm.servers_client |
Zhi Kun Liu | e540176 | 2013-09-11 20:45:48 +0800 | [diff] [blame] | 33 | cls.non_admin_client = cls.servers_client |
Zhu Zhu | da07085 | 2013-09-25 08:07:57 -0500 | [diff] [blame] | 34 | cls.flavors_client = cls.os_adm.flavors_client |
Liu, Zhi Kun | b0ac0b8 | 2013-06-20 16:20:21 +0800 | [diff] [blame] | 35 | |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 36 | cls.s1_name = data_utils.rand_name('server') |
Ken'ichi Ohmichi | cfc052e | 2013-10-23 11:50:04 +0900 | [diff] [blame] | 37 | resp, server = cls.create_test_server(name=cls.s1_name, |
| 38 | wait_until='ACTIVE') |
LingxianKong | c26e607 | 2013-09-28 21:16:52 +0800 | [diff] [blame] | 39 | cls.s1_id = server['id'] |
| 40 | |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 41 | cls.s2_name = data_utils.rand_name('server') |
Ken'ichi Ohmichi | cfc052e | 2013-10-23 11:50:04 +0900 | [diff] [blame] | 42 | resp, server = cls.create_test_server(name=cls.s2_name, |
| 43 | wait_until='ACTIVE') |
ChenZheng | 5b62f65 | 2014-01-03 15:03:33 +0800 | [diff] [blame] | 44 | cls.s2_id = server['id'] |
Liu, Zhi Kun | b0ac0b8 | 2013-06-20 16:20:21 +0800 | [diff] [blame] | 45 | |
ChenZheng | d4acec4 | 2014-01-03 15:22:31 +0800 | [diff] [blame] | 46 | @test.attr(type='gate') |
Liu, Zhi Kun | b0ac0b8 | 2013-06-20 16:20:21 +0800 | [diff] [blame] | 47 | 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 | |
ChenZheng | d4acec4 | 2014-01-03 15:22:31 +0800 | [diff] [blame] | 54 | @test.attr(type='gate') |
ChenZheng | 5b62f65 | 2014-01-03 15:03:33 +0800 | [diff] [blame] | 55 | 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 | |
ChenZheng | d4acec4 | 2014-01-03 15:22:31 +0800 | [diff] [blame] | 70 | @test.attr(type='gate') |
Liu, Zhi Kun | b0ac0b8 | 2013-06-20 16:20:21 +0800 | [diff] [blame] | 71 | 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 | |
ChenZheng | d4acec4 | 2014-01-03 15:22:31 +0800 | [diff] [blame] | 82 | @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') |
LingxianKong | c26e607 | 2013-09-28 21:16:52 +0800 | [diff] [blame] | 110 | 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 | |
ChenZheng | d4acec4 | 2014-01-03 15:22:31 +0800 | [diff] [blame] | 127 | @test.attr(type='gate') |
| 128 | @test.skip_because(bug="1240043") |
Zhu Zhu | da07085 | 2013-09-25 08:07:57 -0500 | [diff] [blame] | 129 | 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 | |
ChenZheng | d4acec4 | 2014-01-03 15:22:31 +0800 | [diff] [blame] | 139 | @test.attr(type='gate') |
Zhi Kun Liu | e540176 | 2013-09-11 20:45:48 +0800 | [diff] [blame] | 140 | 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 Solanas | b15d8b6 | 2014-02-07 00:04:15 -0800 | [diff] [blame] | 144 | # resetting vm state require admin privilege |
Zhi Kun Liu | e540176 | 2013-09-11 20:45:48 +0800 | [diff] [blame] | 145 | 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 Mann | 79f4a09 | 2014-02-27 21:01:31 +0900 | [diff] [blame] | 167 | @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 | |
raiesmh08 | cbe21b0 | 2014-03-12 17:04:44 +0530 | [diff] [blame] | 177 | @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 Kun | b0ac0b8 | 2013-06-20 16:20:21 +0800 | [diff] [blame] | 187 | |
| 188 | class ServersAdminTestXML(ServersAdminTestJSON): |
ChenZheng | d4acec4 | 2014-01-03 15:22:31 +0800 | [diff] [blame] | 189 | _host_key = ( |
| 190 | '{http://docs.openstack.org/compute/ext/extended_status/api/v1.1}host') |
Liu, Zhi Kun | b0ac0b8 | 2013-06-20 16:20:21 +0800 | [diff] [blame] | 191 | _interface = 'xml' |