blob: ebdceefacbc376ef5b44b331949ca199c3e53c6e [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
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000019from tempest.common import waiters
Matt Riedemann7051d622014-03-23 18:36:17 -070020from tempest import config
Ken'ichi Ohmichi757833a2017-03-10 10:30:30 -080021from tempest.lib.common.utils import data_utils
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
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
zhufl8bd576f2017-02-16 11:37:38 +080044 server = cls.create_test_server(wait_until='ACTIVE')
huangtianhua5232b662013-10-11 10:21:58 +080045 cls.s1_id = server['id']
46
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080047 @decorators.idempotent_id('28dcec23-f807-49da-822c-56a92ea3c687')
Joseph Lanouxb3d956f2014-06-25 14:45:24 +000048 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
49 'Resize not available.')
Sean Dague639f2fa2015-04-27 09:00:33 -040050 @test.attr(type=['negative'])
huangtianhua5232b662013-10-11 10:21:58 +080051 def test_resize_server_using_overlimit_ram(self):
Matt Riedemannce6b14e2014-09-23 09:46:50 -070052 # NOTE(mriedem): Avoid conflicts with os-quota-class-sets tests.
53 self.useFixture(fixtures.LockFixture('compute_quotas'))
zhuflfbb29cd2016-08-29 17:38:07 +080054 quota_set = self.quotas_client.show_quota_set(
55 self.tenant_id)['quota_set']
zhufl44cdf152017-02-21 11:21:57 +080056 ram = quota_set['ram']
zhuflbe67e2d2016-02-02 16:18:22 +080057 if ram == -1:
zhuflf7f3ab42016-09-14 17:36:32 +080058 raise self.skipException("ram quota set is -1,"
zhuflbe67e2d2016-02-02 16:18:22 +080059 " cannot test overlimit")
60 ram += 1
zhufl854acc02016-12-20 15:47:04 +080061 vcpus = 1
62 disk = 5
zhufl94cb0542017-02-13 17:51:47 +080063 flavor_ref = self.create_flavor(ram=ram, vcpus=vcpus, disk=disk)
Masayuki Igawa6b1cd292015-02-16 11:11:55 +090064 self.assertRaises((lib_exc.Forbidden, lib_exc.OverLimit),
Ken'ichi Ohmichi5271b0f2015-08-10 07:53:27 +000065 self.client.resize_server,
huangtianhua5232b662013-10-11 10:21:58 +080066 self.servers[0]['id'],
67 flavor_ref['id'])
68
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080069 @decorators.idempotent_id('7368a427-2f26-4ad9-9ba9-911a0ec2b0db')
Joseph Lanouxb3d956f2014-06-25 14:45:24 +000070 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
71 'Resize not available.')
Sean Dague639f2fa2015-04-27 09:00:33 -040072 @test.attr(type=['negative'])
huangtianhua5232b662013-10-11 10:21:58 +080073 def test_resize_server_using_overlimit_vcpus(self):
Matt Riedemannce6b14e2014-09-23 09:46:50 -070074 # NOTE(mriedem): Avoid conflicts with os-quota-class-sets tests.
75 self.useFixture(fixtures.LockFixture('compute_quotas'))
zhuflfbb29cd2016-08-29 17:38:07 +080076 quota_set = self.quotas_client.show_quota_set(
77 self.tenant_id)['quota_set']
zhufl44cdf152017-02-21 11:21:57 +080078 vcpus = quota_set['cores']
zhuflbe67e2d2016-02-02 16:18:22 +080079 if vcpus == -1:
zhuflf7f3ab42016-09-14 17:36:32 +080080 raise self.skipException("cores quota set is -1,"
zhuflbe67e2d2016-02-02 16:18:22 +080081 " cannot test overlimit")
82 vcpus += 1
zhufl854acc02016-12-20 15:47:04 +080083 ram = 512
84 disk = 5
zhufl94cb0542017-02-13 17:51:47 +080085 flavor_ref = self.create_flavor(ram=ram, vcpus=vcpus, disk=disk)
Masayuki Igawa6b1cd292015-02-16 11:11:55 +090086 self.assertRaises((lib_exc.Forbidden, lib_exc.OverLimit),
Ken'ichi Ohmichi5271b0f2015-08-10 07:53:27 +000087 self.client.resize_server,
huangtianhua5232b662013-10-11 10:21:58 +080088 self.servers[0]['id'],
89 flavor_ref['id'])
90
Sean Dague639f2fa2015-04-27 09:00:33 -040091 @test.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080092 @decorators.idempotent_id('b0b4d8af-1256-41ef-9ee7-25f1c19dde80')
huangtianhua5232b662013-10-11 10:21:58 +080093 def test_reset_state_server_invalid_state(self):
Masayuki Igawa4b29e472015-02-16 10:41:54 +090094 self.assertRaises(lib_exc.BadRequest,
huangtianhua5232b662013-10-11 10:21:58 +080095 self.client.reset_state, self.s1_id,
96 state='invalid')
97
Sean Dague639f2fa2015-04-27 09:00:33 -040098 @test.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080099 @decorators.idempotent_id('4cdcc984-fab0-4577-9a9d-6d558527ee9d')
huangtianhua5232b662013-10-11 10:21:58 +0800100 def test_reset_state_server_invalid_type(self):
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900101 self.assertRaises(lib_exc.BadRequest,
huangtianhua5232b662013-10-11 10:21:58 +0800102 self.client.reset_state, self.s1_id,
103 state=1)
104
Sean Dague639f2fa2015-04-27 09:00:33 -0400105 @test.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800106 @decorators.idempotent_id('e741298b-8df2-46f0-81cb-8f814ff2504c')
huangtianhua5232b662013-10-11 10:21:58 +0800107 def test_reset_state_server_nonexistent_server(self):
Masayuki Igawabfa07602015-01-20 18:47:17 +0900108 self.assertRaises(lib_exc.NotFound,
Ken'ichi Ohmichi36b714c2015-12-09 08:12:47 +0000109 self.client.reset_state, '999', state='error')
huangtianhua5232b662013-10-11 10:21:58 +0800110
Sean Dague639f2fa2015-04-27 09:00:33 -0400111 @test.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800112 @decorators.idempotent_id('e84e2234-60d2-42fa-8b30-e2d3049724ac')
huangtianhua5232b662013-10-11 10:21:58 +0800113 def test_get_server_diagnostics_by_non_admin(self):
114 # Non-admin user can not view server diagnostics according to policy
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900115 self.assertRaises(lib_exc.Forbidden,
Ken'ichi Ohmichi277d1882015-11-20 00:44:06 +0000116 self.non_adm_client.show_server_diagnostics,
huangtianhua5232b662013-10-11 10:21:58 +0800117 self.s1_id)
118
Sean Dague639f2fa2015-04-27 09:00:33 -0400119 @test.attr(type=['negative'])
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800120 @decorators.idempotent_id('46a4e1ca-87ae-4d28-987a-1b6b136a0221')
huangtianhua5232b662013-10-11 10:21:58 +0800121 def test_migrate_non_existent_server(self):
122 # migrate a non existent server
Masayuki Igawabfa07602015-01-20 18:47:17 +0900123 self.assertRaises(lib_exc.NotFound,
huangtianhua5232b662013-10-11 10:21:58 +0800124 self.client.migrate_server,
Ken'ichi Ohmichid079c892016-04-19 11:23:36 -0700125 data_utils.rand_uuid())
huangtianhua5232b662013-10-11 10:21:58 +0800126
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800127 @decorators.idempotent_id('b0b17f83-d14e-4fc4-8f31-bcc9f3cfa629')
Andrea Rosa3df237c2014-07-18 14:22:53 +0100128 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
129 'Resize not available.')
Matt Riedemann7051d622014-03-23 18:36:17 -0700130 @testtools.skipUnless(CONF.compute_feature_enabled.suspend,
131 'Suspend is not available.')
Sean Dague639f2fa2015-04-27 09:00:33 -0400132 @test.attr(type=['negative'])
huangtianhua5232b662013-10-11 10:21:58 +0800133 def test_migrate_server_invalid_state(self):
134 # create server.
David Kranz0fb14292015-02-11 15:55:20 -0500135 server = self.create_test_server(wait_until='ACTIVE')
huangtianhua5232b662013-10-11 10:21:58 +0800136 server_id = server['id']
137 # suspend the server.
David Kranzae99b9a2015-02-16 13:37:01 -0500138 self.client.suspend_server(server_id)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000139 waiters.wait_for_server_status(self.client,
140 server_id, 'SUSPENDED')
hgangwx4ccc4a72015-12-28 21:19:50 +0800141 # migrate a suspended server should fail
Masayuki Igawad9388762015-01-20 14:56:42 +0900142 self.assertRaises(lib_exc.Conflict,
huangtianhua5232b662013-10-11 10:21:58 +0800143 self.client.migrate_server,
144 server_id)