blob: 6d3c4a31fdce2f8c84de3de7456cadac57693699 [file] [log] [blame]
huangtianhua5232b662013-10-11 10:21:58 +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
15import uuid
16
Masayuki Igawa90c914e2015-01-20 14:48:16 +090017from tempest_lib import exceptions as lib_exc
Matt Riedemann7051d622014-03-23 18:36:17 -070018import testtools
19
huangtianhua5232b662013-10-11 10:21:58 +080020from tempest.api.compute import base
Matt Riedemannce6b14e2014-09-23 09:46:50 -070021from tempest.common import tempest_fixtures as fixtures
Fei Long Wangd39431f2015-05-14 11:30:48 +120022from tempest.common.utils import data_utils
Matt Riedemann7051d622014-03-23 18:36:17 -070023from tempest import config
Masayuki Igawa394d8d92014-03-04 17:21:56 +090024from tempest import test
huangtianhua5232b662013-10-11 10:21:58 +080025
Matt Riedemann7051d622014-03-23 18:36:17 -070026CONF = config.CONF
27
huangtianhua5232b662013-10-11 10:21:58 +080028
29class ServersAdminNegativeTestJSON(base.BaseV2ComputeAdminTest):
30
31 """
32 Tests Servers API using admin privileges
33 """
34
huangtianhua5232b662013-10-11 10:21:58 +080035 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053036 def setup_clients(cls):
37 super(ServersAdminNegativeTestJSON, cls).setup_clients()
huangtianhua5232b662013-10-11 10:21:58 +080038 cls.client = cls.os_adm.servers_client
39 cls.non_adm_client = cls.servers_client
40 cls.flavors_client = cls.os_adm.flavors_client
Rohan Kanade60b73092015-02-04 17:58:19 +053041
42 @classmethod
43 def resource_setup(cls):
44 super(ServersAdminNegativeTestJSON, cls).resource_setup()
Andrea Frittoli9612e812014-03-13 10:57:26 +000045 cls.tenant_id = cls.client.tenant_id
huangtianhua5232b662013-10-11 10:21:58 +080046
47 cls.s1_name = data_utils.rand_name('server')
David Kranz0fb14292015-02-11 15:55:20 -050048 server = cls.create_test_server(name=cls.s1_name,
49 wait_until='ACTIVE')
huangtianhua5232b662013-10-11 10:21:58 +080050 cls.s1_id = server['id']
51
52 def _get_unused_flavor_id(self):
53 flavor_id = data_utils.rand_int_id(start=1000)
54 while True:
55 try:
Ken'ichi Ohmichi5628f3f2015-05-22 20:17:56 +000056 self.flavors_client.show_flavor(flavor_id)
Masayuki Igawabfa07602015-01-20 18:47:17 +090057 except lib_exc.NotFound:
huangtianhua5232b662013-10-11 10:21:58 +080058 break
59 flavor_id = data_utils.rand_int_id(start=1000)
60 return flavor_id
61
Chris Hoge7579c1a2015-02-26 14:12:15 -080062 @test.idempotent_id('28dcec23-f807-49da-822c-56a92ea3c687')
Joseph Lanouxb3d956f2014-06-25 14:45:24 +000063 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
64 'Resize not available.')
Sean Dague639f2fa2015-04-27 09:00:33 -040065 @test.attr(type=['negative'])
huangtianhua5232b662013-10-11 10:21:58 +080066 def test_resize_server_using_overlimit_ram(self):
Matt Riedemannce6b14e2014-09-23 09:46:50 -070067 # NOTE(mriedem): Avoid conflicts with os-quota-class-sets tests.
68 self.useFixture(fixtures.LockFixture('compute_quotas'))
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000069 flavor_name = data_utils.rand_name("flavor")
huangtianhua5232b662013-10-11 10:21:58 +080070 flavor_id = self._get_unused_flavor_id()
Ken'ichi Ohmichif9868fc2015-06-17 02:36:06 +000071 quota_set = self.quotas_client.show_default_quota_set(self.tenant_id)
huangtianhua5232b662013-10-11 10:21:58 +080072 ram = int(quota_set['ram']) + 1
73 vcpus = 8
74 disk = 10
David Kranz2fa77b22015-02-09 11:39:50 -050075 flavor_ref = self.flavors_client.create_flavor(flavor_name,
76 ram, vcpus, disk,
77 flavor_id)
huangtianhua5232b662013-10-11 10:21:58 +080078 self.addCleanup(self.flavors_client.delete_flavor, flavor_id)
Masayuki Igawa6b1cd292015-02-16 11:11:55 +090079 self.assertRaises((lib_exc.Forbidden, lib_exc.OverLimit),
huangtianhua5232b662013-10-11 10:21:58 +080080 self.client.resize,
81 self.servers[0]['id'],
82 flavor_ref['id'])
83
Chris Hoge7579c1a2015-02-26 14:12:15 -080084 @test.idempotent_id('7368a427-2f26-4ad9-9ba9-911a0ec2b0db')
Joseph Lanouxb3d956f2014-06-25 14:45:24 +000085 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
86 'Resize not available.')
Sean Dague639f2fa2015-04-27 09:00:33 -040087 @test.attr(type=['negative'])
huangtianhua5232b662013-10-11 10:21:58 +080088 def test_resize_server_using_overlimit_vcpus(self):
Matt Riedemannce6b14e2014-09-23 09:46:50 -070089 # NOTE(mriedem): Avoid conflicts with os-quota-class-sets tests.
90 self.useFixture(fixtures.LockFixture('compute_quotas'))
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000091 flavor_name = data_utils.rand_name("flavor")
huangtianhua5232b662013-10-11 10:21:58 +080092 flavor_id = self._get_unused_flavor_id()
93 ram = 512
Ken'ichi Ohmichif9868fc2015-06-17 02:36:06 +000094 quota_set = self.quotas_client.show_default_quota_set(self.tenant_id)
huangtianhua5232b662013-10-11 10:21:58 +080095 vcpus = int(quota_set['cores']) + 1
96 disk = 10
David Kranz2fa77b22015-02-09 11:39:50 -050097 flavor_ref = self.flavors_client.create_flavor(flavor_name,
98 ram, vcpus, disk,
99 flavor_id)
huangtianhua5232b662013-10-11 10:21:58 +0800100 self.addCleanup(self.flavors_client.delete_flavor, flavor_id)
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900101 self.assertRaises((lib_exc.Forbidden, lib_exc.OverLimit),
huangtianhua5232b662013-10-11 10:21:58 +0800102 self.client.resize,
103 self.servers[0]['id'],
104 flavor_ref['id'])
105
Sean Dague639f2fa2015-04-27 09:00:33 -0400106 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800107 @test.idempotent_id('b0b4d8af-1256-41ef-9ee7-25f1c19dde80')
huangtianhua5232b662013-10-11 10:21:58 +0800108 def test_reset_state_server_invalid_state(self):
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900109 self.assertRaises(lib_exc.BadRequest,
huangtianhua5232b662013-10-11 10:21:58 +0800110 self.client.reset_state, self.s1_id,
111 state='invalid')
112
Sean Dague639f2fa2015-04-27 09:00:33 -0400113 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800114 @test.idempotent_id('4cdcc984-fab0-4577-9a9d-6d558527ee9d')
huangtianhua5232b662013-10-11 10:21:58 +0800115 def test_reset_state_server_invalid_type(self):
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900116 self.assertRaises(lib_exc.BadRequest,
huangtianhua5232b662013-10-11 10:21:58 +0800117 self.client.reset_state, self.s1_id,
118 state=1)
119
Sean Dague639f2fa2015-04-27 09:00:33 -0400120 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800121 @test.idempotent_id('e741298b-8df2-46f0-81cb-8f814ff2504c')
huangtianhua5232b662013-10-11 10:21:58 +0800122 def test_reset_state_server_nonexistent_server(self):
Masayuki Igawabfa07602015-01-20 18:47:17 +0900123 self.assertRaises(lib_exc.NotFound,
huangtianhua5232b662013-10-11 10:21:58 +0800124 self.client.reset_state, '999')
125
Sean Dague639f2fa2015-04-27 09:00:33 -0400126 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800127 @test.idempotent_id('e84e2234-60d2-42fa-8b30-e2d3049724ac')
huangtianhua5232b662013-10-11 10:21:58 +0800128 def test_get_server_diagnostics_by_non_admin(self):
129 # Non-admin user can not view server diagnostics according to policy
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900130 self.assertRaises(lib_exc.Forbidden,
huangtianhua5232b662013-10-11 10:21:58 +0800131 self.non_adm_client.get_server_diagnostics,
132 self.s1_id)
133
Sean Dague639f2fa2015-04-27 09:00:33 -0400134 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800135 @test.idempotent_id('46a4e1ca-87ae-4d28-987a-1b6b136a0221')
huangtianhua5232b662013-10-11 10:21:58 +0800136 def test_migrate_non_existent_server(self):
137 # migrate a non existent server
Masayuki Igawabfa07602015-01-20 18:47:17 +0900138 self.assertRaises(lib_exc.NotFound,
huangtianhua5232b662013-10-11 10:21:58 +0800139 self.client.migrate_server,
140 str(uuid.uuid4()))
141
Chris Hoge7579c1a2015-02-26 14:12:15 -0800142 @test.idempotent_id('b0b17f83-d14e-4fc4-8f31-bcc9f3cfa629')
Andrea Rosa3df237c2014-07-18 14:22:53 +0100143 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
144 'Resize not available.')
Matt Riedemann7051d622014-03-23 18:36:17 -0700145 @testtools.skipUnless(CONF.compute_feature_enabled.suspend,
146 'Suspend is not available.')
Sean Dague639f2fa2015-04-27 09:00:33 -0400147 @test.attr(type=['negative'])
huangtianhua5232b662013-10-11 10:21:58 +0800148 def test_migrate_server_invalid_state(self):
149 # create server.
David Kranz0fb14292015-02-11 15:55:20 -0500150 server = self.create_test_server(wait_until='ACTIVE')
huangtianhua5232b662013-10-11 10:21:58 +0800151 server_id = server['id']
152 # suspend the server.
David Kranzae99b9a2015-02-16 13:37:01 -0500153 self.client.suspend_server(server_id)
huangtianhua5232b662013-10-11 10:21:58 +0800154 self.client.wait_for_server_status(server_id, 'SUSPENDED')
155 # migrate an suspended server should fail
Masayuki Igawad9388762015-01-20 14:56:42 +0900156 self.assertRaises(lib_exc.Conflict,
huangtianhua5232b662013-10-11 10:21:58 +0800157 self.client.migrate_server,
158 server_id)