blob: 5220c97aaf48c7b1fe7b434e3c768b2556d9a8ea [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
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080022from tempest.lib import decorators
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050023from tempest.lib import exceptions as lib_exc
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):
Ken'ichi Ohmichi88363cb2015-11-19 08:00:54 +000030 """Tests Servers API using admin privileges"""
huangtianhua5232b662013-10-11 10:21:58 +080031
huangtianhua5232b662013-10-11 10:21:58 +080032 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053033 def setup_clients(cls):
34 super(ServersAdminNegativeTestJSON, cls).setup_clients()
huangtianhua5232b662013-10-11 10:21:58 +080035 cls.client = cls.os_adm.servers_client
36 cls.non_adm_client = cls.servers_client
37 cls.flavors_client = cls.os_adm.flavors_client
zhuflfbb29cd2016-08-29 17:38:07 +080038 cls.quotas_client = cls.os_adm.quotas_client
Rohan Kanade60b73092015-02-04 17:58:19 +053039
40 @classmethod
41 def resource_setup(cls):
42 super(ServersAdminNegativeTestJSON, cls).resource_setup()
Andrea Frittoli9612e812014-03-13 10:57:26 +000043 cls.tenant_id = cls.client.tenant_id
huangtianhua5232b662013-10-11 10:21:58 +080044
zhufl8bd576f2017-02-16 11:37:38 +080045 server = cls.create_test_server(wait_until='ACTIVE')
huangtianhua5232b662013-10-11 10:21:58 +080046 cls.s1_id = server['id']
47
48 def _get_unused_flavor_id(self):
49 flavor_id = data_utils.rand_int_id(start=1000)
50 while True:
51 try:
Ken'ichi Ohmichi5628f3f2015-05-22 20:17:56 +000052 self.flavors_client.show_flavor(flavor_id)
Masayuki Igawabfa07602015-01-20 18:47:17 +090053 except lib_exc.NotFound:
huangtianhua5232b662013-10-11 10:21:58 +080054 break
55 flavor_id = data_utils.rand_int_id(start=1000)
56 return flavor_id
57
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080058 @decorators.idempotent_id('28dcec23-f807-49da-822c-56a92ea3c687')
Joseph Lanouxb3d956f2014-06-25 14:45:24 +000059 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
60 'Resize not available.')
Sean Dague639f2fa2015-04-27 09:00:33 -040061 @test.attr(type=['negative'])
huangtianhua5232b662013-10-11 10:21:58 +080062 def test_resize_server_using_overlimit_ram(self):
Matt Riedemannce6b14e2014-09-23 09:46:50 -070063 # NOTE(mriedem): Avoid conflicts with os-quota-class-sets tests.
64 self.useFixture(fixtures.LockFixture('compute_quotas'))
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000065 flavor_name = data_utils.rand_name("flavor")
huangtianhua5232b662013-10-11 10:21:58 +080066 flavor_id = self._get_unused_flavor_id()
zhuflfbb29cd2016-08-29 17:38:07 +080067 quota_set = self.quotas_client.show_quota_set(
68 self.tenant_id)['quota_set']
zhufl44cdf152017-02-21 11:21:57 +080069 ram = quota_set['ram']
zhuflbe67e2d2016-02-02 16:18:22 +080070 if ram == -1:
zhuflf7f3ab42016-09-14 17:36:32 +080071 raise self.skipException("ram quota set is -1,"
zhuflbe67e2d2016-02-02 16:18:22 +080072 " cannot test overlimit")
73 ram += 1
zhufl854acc02016-12-20 15:47:04 +080074 vcpus = 1
75 disk = 5
Ken'ichi Ohmichi96338c42015-07-17 06:25:14 +000076 flavor_ref = self.flavors_client.create_flavor(name=flavor_name,
77 ram=ram, vcpus=vcpus,
ghanshyam19973be2015-08-18 15:46:42 +090078 disk=disk,
79 id=flavor_id)['flavor']
huangtianhua5232b662013-10-11 10:21:58 +080080 self.addCleanup(self.flavors_client.delete_flavor, flavor_id)
Masayuki Igawa6b1cd292015-02-16 11:11:55 +090081 self.assertRaises((lib_exc.Forbidden, lib_exc.OverLimit),
Ken'ichi Ohmichi5271b0f2015-08-10 07:53:27 +000082 self.client.resize_server,
huangtianhua5232b662013-10-11 10:21:58 +080083 self.servers[0]['id'],
84 flavor_ref['id'])
85
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080086 @decorators.idempotent_id('7368a427-2f26-4ad9-9ba9-911a0ec2b0db')
Joseph Lanouxb3d956f2014-06-25 14:45:24 +000087 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
88 'Resize not available.')
Sean Dague639f2fa2015-04-27 09:00:33 -040089 @test.attr(type=['negative'])
huangtianhua5232b662013-10-11 10:21:58 +080090 def test_resize_server_using_overlimit_vcpus(self):
Matt Riedemannce6b14e2014-09-23 09:46:50 -070091 # NOTE(mriedem): Avoid conflicts with os-quota-class-sets tests.
92 self.useFixture(fixtures.LockFixture('compute_quotas'))
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000093 flavor_name = data_utils.rand_name("flavor")
huangtianhua5232b662013-10-11 10:21:58 +080094 flavor_id = self._get_unused_flavor_id()
zhuflfbb29cd2016-08-29 17:38:07 +080095 quota_set = self.quotas_client.show_quota_set(
96 self.tenant_id)['quota_set']
zhufl44cdf152017-02-21 11:21:57 +080097 vcpus = quota_set['cores']
zhuflbe67e2d2016-02-02 16:18:22 +080098 if vcpus == -1:
zhuflf7f3ab42016-09-14 17:36:32 +080099 raise self.skipException("cores quota set is -1,"
zhuflbe67e2d2016-02-02 16:18:22 +0800100 " cannot test overlimit")
101 vcpus += 1
zhufl854acc02016-12-20 15:47:04 +0800102 ram = 512
103 disk = 5
Ken'ichi Ohmichi96338c42015-07-17 06:25:14 +0000104 flavor_ref = self.flavors_client.create_flavor(name=flavor_name,
105 ram=ram, vcpus=vcpus,
ghanshyam19973be2015-08-18 15:46:42 +0900106 disk=disk,
107 id=flavor_id)['flavor']
huangtianhua5232b662013-10-11 10:21:58 +0800108 self.addCleanup(self.flavors_client.delete_flavor, flavor_id)
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900109 self.assertRaises((lib_exc.Forbidden, lib_exc.OverLimit),
Ken'ichi Ohmichi5271b0f2015-08-10 07:53:27 +0000110 self.client.resize_server,
huangtianhua5232b662013-10-11 10:21:58 +0800111 self.servers[0]['id'],
112 flavor_ref['id'])
113
Sean Dague639f2fa2015-04-27 09:00:33 -0400114 @test.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800115 @decorators.idempotent_id('b0b4d8af-1256-41ef-9ee7-25f1c19dde80')
huangtianhua5232b662013-10-11 10:21:58 +0800116 def test_reset_state_server_invalid_state(self):
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900117 self.assertRaises(lib_exc.BadRequest,
huangtianhua5232b662013-10-11 10:21:58 +0800118 self.client.reset_state, self.s1_id,
119 state='invalid')
120
Sean Dague639f2fa2015-04-27 09:00:33 -0400121 @test.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800122 @decorators.idempotent_id('4cdcc984-fab0-4577-9a9d-6d558527ee9d')
huangtianhua5232b662013-10-11 10:21:58 +0800123 def test_reset_state_server_invalid_type(self):
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900124 self.assertRaises(lib_exc.BadRequest,
huangtianhua5232b662013-10-11 10:21:58 +0800125 self.client.reset_state, self.s1_id,
126 state=1)
127
Sean Dague639f2fa2015-04-27 09:00:33 -0400128 @test.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800129 @decorators.idempotent_id('e741298b-8df2-46f0-81cb-8f814ff2504c')
huangtianhua5232b662013-10-11 10:21:58 +0800130 def test_reset_state_server_nonexistent_server(self):
Masayuki Igawabfa07602015-01-20 18:47:17 +0900131 self.assertRaises(lib_exc.NotFound,
Ken'ichi Ohmichi36b714c2015-12-09 08:12:47 +0000132 self.client.reset_state, '999', state='error')
huangtianhua5232b662013-10-11 10:21:58 +0800133
Sean Dague639f2fa2015-04-27 09:00:33 -0400134 @test.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800135 @decorators.idempotent_id('e84e2234-60d2-42fa-8b30-e2d3049724ac')
huangtianhua5232b662013-10-11 10:21:58 +0800136 def test_get_server_diagnostics_by_non_admin(self):
137 # Non-admin user can not view server diagnostics according to policy
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900138 self.assertRaises(lib_exc.Forbidden,
Ken'ichi Ohmichi277d1882015-11-20 00:44:06 +0000139 self.non_adm_client.show_server_diagnostics,
huangtianhua5232b662013-10-11 10:21:58 +0800140 self.s1_id)
141
Sean Dague639f2fa2015-04-27 09:00:33 -0400142 @test.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800143 @decorators.idempotent_id('46a4e1ca-87ae-4d28-987a-1b6b136a0221')
huangtianhua5232b662013-10-11 10:21:58 +0800144 def test_migrate_non_existent_server(self):
145 # migrate a non existent server
Masayuki Igawabfa07602015-01-20 18:47:17 +0900146 self.assertRaises(lib_exc.NotFound,
huangtianhua5232b662013-10-11 10:21:58 +0800147 self.client.migrate_server,
Ken'ichi Ohmichid079c892016-04-19 11:23:36 -0700148 data_utils.rand_uuid())
huangtianhua5232b662013-10-11 10:21:58 +0800149
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800150 @decorators.idempotent_id('b0b17f83-d14e-4fc4-8f31-bcc9f3cfa629')
Andrea Rosa3df237c2014-07-18 14:22:53 +0100151 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
152 'Resize not available.')
Matt Riedemann7051d622014-03-23 18:36:17 -0700153 @testtools.skipUnless(CONF.compute_feature_enabled.suspend,
154 'Suspend is not available.')
Sean Dague639f2fa2015-04-27 09:00:33 -0400155 @test.attr(type=['negative'])
huangtianhua5232b662013-10-11 10:21:58 +0800156 def test_migrate_server_invalid_state(self):
157 # create server.
David Kranz0fb14292015-02-11 15:55:20 -0500158 server = self.create_test_server(wait_until='ACTIVE')
huangtianhua5232b662013-10-11 10:21:58 +0800159 server_id = server['id']
160 # suspend the server.
David Kranzae99b9a2015-02-16 13:37:01 -0500161 self.client.suspend_server(server_id)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000162 waiters.wait_for_server_status(self.client,
163 server_id, 'SUSPENDED')
hgangwx4ccc4a72015-12-28 21:19:50 +0800164 # migrate a suspended server should fail
Masayuki Igawad9388762015-01-20 14:56:42 +0900165 self.assertRaises(lib_exc.Conflict,
huangtianhua5232b662013-10-11 10:21:58 +0800166 self.client.migrate_server,
167 server_id)