blob: 23b16e7611e41cbdf8755d19dd7702bea7901df5 [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
Matt Riedemann7051d622014-03-23 18:36:17 -070015import testtools
16
huangtianhua5232b662013-10-11 10:21:58 +080017from tempest.api.compute import base
Matt Riedemannce6b14e2014-09-23 09:46:50 -070018from tempest.common import tempest_fixtures as fixtures
Fei Long Wangd39431f2015-05-14 11:30:48 +120019from tempest.common.utils import data_utils
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000020from tempest.common import waiters
Matt Riedemann7051d622014-03-23 18:36:17 -070021from tempest import config
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050022from tempest.lib import exceptions as lib_exc
Masayuki Igawa394d8d92014-03-04 17:21:56 +090023from tempest import test
huangtianhua5232b662013-10-11 10:21:58 +080024
Matt Riedemann7051d622014-03-23 18:36:17 -070025CONF = config.CONF
26
huangtianhua5232b662013-10-11 10:21:58 +080027
28class ServersAdminNegativeTestJSON(base.BaseV2ComputeAdminTest):
Ken'ichi Ohmichi88363cb2015-11-19 08:00:54 +000029 """Tests Servers API using admin privileges"""
huangtianhua5232b662013-10-11 10:21:58 +080030
huangtianhua5232b662013-10-11 10:21:58 +080031 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053032 def setup_clients(cls):
33 super(ServersAdminNegativeTestJSON, cls).setup_clients()
huangtianhua5232b662013-10-11 10:21:58 +080034 cls.client = cls.os_adm.servers_client
35 cls.non_adm_client = cls.servers_client
36 cls.flavors_client = cls.os_adm.flavors_client
zhuflfbb29cd2016-08-29 17:38:07 +080037 cls.quotas_client = cls.os_adm.quotas_client
Rohan Kanade60b73092015-02-04 17:58:19 +053038
39 @classmethod
40 def resource_setup(cls):
41 super(ServersAdminNegativeTestJSON, cls).resource_setup()
Andrea Frittoli9612e812014-03-13 10:57:26 +000042 cls.tenant_id = cls.client.tenant_id
huangtianhua5232b662013-10-11 10:21:58 +080043
zhuflc6ce5392016-08-17 14:34:37 +080044 cls.s1_name = data_utils.rand_name(cls.__name__ + '-server')
David Kranz0fb14292015-02-11 15:55:20 -050045 server = cls.create_test_server(name=cls.s1_name,
46 wait_until='ACTIVE')
huangtianhua5232b662013-10-11 10:21:58 +080047 cls.s1_id = server['id']
48
49 def _get_unused_flavor_id(self):
50 flavor_id = data_utils.rand_int_id(start=1000)
51 while True:
52 try:
Ken'ichi Ohmichi5628f3f2015-05-22 20:17:56 +000053 self.flavors_client.show_flavor(flavor_id)
Masayuki Igawabfa07602015-01-20 18:47:17 +090054 except lib_exc.NotFound:
huangtianhua5232b662013-10-11 10:21:58 +080055 break
56 flavor_id = data_utils.rand_int_id(start=1000)
57 return flavor_id
58
Chris Hoge7579c1a2015-02-26 14:12:15 -080059 @test.idempotent_id('28dcec23-f807-49da-822c-56a92ea3c687')
Joseph Lanouxb3d956f2014-06-25 14:45:24 +000060 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
61 'Resize not available.')
Sean Dague639f2fa2015-04-27 09:00:33 -040062 @test.attr(type=['negative'])
huangtianhua5232b662013-10-11 10:21:58 +080063 def test_resize_server_using_overlimit_ram(self):
Matt Riedemannce6b14e2014-09-23 09:46:50 -070064 # NOTE(mriedem): Avoid conflicts with os-quota-class-sets tests.
65 self.useFixture(fixtures.LockFixture('compute_quotas'))
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000066 flavor_name = data_utils.rand_name("flavor")
huangtianhua5232b662013-10-11 10:21:58 +080067 flavor_id = self._get_unused_flavor_id()
zhuflfbb29cd2016-08-29 17:38:07 +080068 quota_set = self.quotas_client.show_quota_set(
69 self.tenant_id)['quota_set']
zhuflbe67e2d2016-02-02 16:18:22 +080070 ram = int(quota_set['ram'])
71 if ram == -1:
zhuflf7f3ab42016-09-14 17:36:32 +080072 raise self.skipException("ram quota set is -1,"
zhuflbe67e2d2016-02-02 16:18:22 +080073 " cannot test overlimit")
74 ram += 1
huangtianhua5232b662013-10-11 10:21:58 +080075 vcpus = 8
76 disk = 10
Ken'ichi Ohmichi96338c42015-07-17 06:25:14 +000077 flavor_ref = self.flavors_client.create_flavor(name=flavor_name,
78 ram=ram, vcpus=vcpus,
ghanshyam19973be2015-08-18 15:46:42 +090079 disk=disk,
80 id=flavor_id)['flavor']
huangtianhua5232b662013-10-11 10:21:58 +080081 self.addCleanup(self.flavors_client.delete_flavor, flavor_id)
Masayuki Igawa6b1cd292015-02-16 11:11:55 +090082 self.assertRaises((lib_exc.Forbidden, lib_exc.OverLimit),
Ken'ichi Ohmichi5271b0f2015-08-10 07:53:27 +000083 self.client.resize_server,
huangtianhua5232b662013-10-11 10:21:58 +080084 self.servers[0]['id'],
85 flavor_ref['id'])
86
Chris Hoge7579c1a2015-02-26 14:12:15 -080087 @test.idempotent_id('7368a427-2f26-4ad9-9ba9-911a0ec2b0db')
Joseph Lanouxb3d956f2014-06-25 14:45:24 +000088 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
89 'Resize not available.')
Sean Dague639f2fa2015-04-27 09:00:33 -040090 @test.attr(type=['negative'])
huangtianhua5232b662013-10-11 10:21:58 +080091 def test_resize_server_using_overlimit_vcpus(self):
Matt Riedemannce6b14e2014-09-23 09:46:50 -070092 # NOTE(mriedem): Avoid conflicts with os-quota-class-sets tests.
93 self.useFixture(fixtures.LockFixture('compute_quotas'))
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000094 flavor_name = data_utils.rand_name("flavor")
huangtianhua5232b662013-10-11 10:21:58 +080095 flavor_id = self._get_unused_flavor_id()
96 ram = 512
zhuflfbb29cd2016-08-29 17:38:07 +080097 quota_set = self.quotas_client.show_quota_set(
98 self.tenant_id)['quota_set']
zhuflbe67e2d2016-02-02 16:18:22 +080099 vcpus = int(quota_set['cores'])
100 if vcpus == -1:
zhuflf7f3ab42016-09-14 17:36:32 +0800101 raise self.skipException("cores quota set is -1,"
zhuflbe67e2d2016-02-02 16:18:22 +0800102 " cannot test overlimit")
103 vcpus += 1
huangtianhua5232b662013-10-11 10:21:58 +0800104 disk = 10
Ken'ichi Ohmichi96338c42015-07-17 06:25:14 +0000105 flavor_ref = self.flavors_client.create_flavor(name=flavor_name,
106 ram=ram, vcpus=vcpus,
ghanshyam19973be2015-08-18 15:46:42 +0900107 disk=disk,
108 id=flavor_id)['flavor']
huangtianhua5232b662013-10-11 10:21:58 +0800109 self.addCleanup(self.flavors_client.delete_flavor, flavor_id)
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900110 self.assertRaises((lib_exc.Forbidden, lib_exc.OverLimit),
Ken'ichi Ohmichi5271b0f2015-08-10 07:53:27 +0000111 self.client.resize_server,
huangtianhua5232b662013-10-11 10:21:58 +0800112 self.servers[0]['id'],
113 flavor_ref['id'])
114
Sean Dague639f2fa2015-04-27 09:00:33 -0400115 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800116 @test.idempotent_id('b0b4d8af-1256-41ef-9ee7-25f1c19dde80')
huangtianhua5232b662013-10-11 10:21:58 +0800117 def test_reset_state_server_invalid_state(self):
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900118 self.assertRaises(lib_exc.BadRequest,
huangtianhua5232b662013-10-11 10:21:58 +0800119 self.client.reset_state, self.s1_id,
120 state='invalid')
121
Sean Dague639f2fa2015-04-27 09:00:33 -0400122 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800123 @test.idempotent_id('4cdcc984-fab0-4577-9a9d-6d558527ee9d')
huangtianhua5232b662013-10-11 10:21:58 +0800124 def test_reset_state_server_invalid_type(self):
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900125 self.assertRaises(lib_exc.BadRequest,
huangtianhua5232b662013-10-11 10:21:58 +0800126 self.client.reset_state, self.s1_id,
127 state=1)
128
Sean Dague639f2fa2015-04-27 09:00:33 -0400129 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800130 @test.idempotent_id('e741298b-8df2-46f0-81cb-8f814ff2504c')
huangtianhua5232b662013-10-11 10:21:58 +0800131 def test_reset_state_server_nonexistent_server(self):
Masayuki Igawabfa07602015-01-20 18:47:17 +0900132 self.assertRaises(lib_exc.NotFound,
Ken'ichi Ohmichi36b714c2015-12-09 08:12:47 +0000133 self.client.reset_state, '999', state='error')
huangtianhua5232b662013-10-11 10:21:58 +0800134
Sean Dague639f2fa2015-04-27 09:00:33 -0400135 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800136 @test.idempotent_id('e84e2234-60d2-42fa-8b30-e2d3049724ac')
huangtianhua5232b662013-10-11 10:21:58 +0800137 def test_get_server_diagnostics_by_non_admin(self):
138 # Non-admin user can not view server diagnostics according to policy
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900139 self.assertRaises(lib_exc.Forbidden,
Ken'ichi Ohmichi277d1882015-11-20 00:44:06 +0000140 self.non_adm_client.show_server_diagnostics,
huangtianhua5232b662013-10-11 10:21:58 +0800141 self.s1_id)
142
Sean Dague639f2fa2015-04-27 09:00:33 -0400143 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800144 @test.idempotent_id('46a4e1ca-87ae-4d28-987a-1b6b136a0221')
huangtianhua5232b662013-10-11 10:21:58 +0800145 def test_migrate_non_existent_server(self):
146 # migrate a non existent server
Masayuki Igawabfa07602015-01-20 18:47:17 +0900147 self.assertRaises(lib_exc.NotFound,
huangtianhua5232b662013-10-11 10:21:58 +0800148 self.client.migrate_server,
Ken'ichi Ohmichid079c892016-04-19 11:23:36 -0700149 data_utils.rand_uuid())
huangtianhua5232b662013-10-11 10:21:58 +0800150
Chris Hoge7579c1a2015-02-26 14:12:15 -0800151 @test.idempotent_id('b0b17f83-d14e-4fc4-8f31-bcc9f3cfa629')
Andrea Rosa3df237c2014-07-18 14:22:53 +0100152 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
153 'Resize not available.')
Matt Riedemann7051d622014-03-23 18:36:17 -0700154 @testtools.skipUnless(CONF.compute_feature_enabled.suspend,
155 'Suspend is not available.')
Sean Dague639f2fa2015-04-27 09:00:33 -0400156 @test.attr(type=['negative'])
huangtianhua5232b662013-10-11 10:21:58 +0800157 def test_migrate_server_invalid_state(self):
158 # create server.
David Kranz0fb14292015-02-11 15:55:20 -0500159 server = self.create_test_server(wait_until='ACTIVE')
huangtianhua5232b662013-10-11 10:21:58 +0800160 server_id = server['id']
161 # suspend the server.
David Kranzae99b9a2015-02-16 13:37:01 -0500162 self.client.suspend_server(server_id)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000163 waiters.wait_for_server_status(self.client,
164 server_id, 'SUSPENDED')
hgangwx4ccc4a72015-12-28 21:19:50 +0800165 # migrate a suspended server should fail
Masayuki Igawad9388762015-01-20 14:56:42 +0900166 self.assertRaises(lib_exc.Conflict,
huangtianhua5232b662013-10-11 10:21:58 +0800167 self.client.migrate_server,
168 server_id)