blob: 0241e701d9ef3282ebff598e504fe588f90c32cc [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
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000023from tempest.common import waiters
Matt Riedemann7051d622014-03-23 18:36:17 -070024from tempest import config
Masayuki Igawa394d8d92014-03-04 17:21:56 +090025from tempest import test
huangtianhua5232b662013-10-11 10:21:58 +080026
Matt Riedemann7051d622014-03-23 18:36:17 -070027CONF = config.CONF
28
huangtianhua5232b662013-10-11 10:21:58 +080029
30class ServersAdminNegativeTestJSON(base.BaseV2ComputeAdminTest):
31
32 """
33 Tests Servers API using admin privileges
34 """
35
huangtianhua5232b662013-10-11 10:21:58 +080036 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053037 def setup_clients(cls):
38 super(ServersAdminNegativeTestJSON, cls).setup_clients()
huangtianhua5232b662013-10-11 10:21:58 +080039 cls.client = cls.os_adm.servers_client
40 cls.non_adm_client = cls.servers_client
41 cls.flavors_client = cls.os_adm.flavors_client
Rohan Kanade60b73092015-02-04 17:58:19 +053042
43 @classmethod
44 def resource_setup(cls):
45 super(ServersAdminNegativeTestJSON, cls).resource_setup()
Andrea Frittoli9612e812014-03-13 10:57:26 +000046 cls.tenant_id = cls.client.tenant_id
huangtianhua5232b662013-10-11 10:21:58 +080047
48 cls.s1_name = data_utils.rand_name('server')
David Kranz0fb14292015-02-11 15:55:20 -050049 server = cls.create_test_server(name=cls.s1_name,
50 wait_until='ACTIVE')
huangtianhua5232b662013-10-11 10:21:58 +080051 cls.s1_id = server['id']
52
53 def _get_unused_flavor_id(self):
54 flavor_id = data_utils.rand_int_id(start=1000)
55 while True:
56 try:
Ken'ichi Ohmichi5628f3f2015-05-22 20:17:56 +000057 self.flavors_client.show_flavor(flavor_id)
Masayuki Igawabfa07602015-01-20 18:47:17 +090058 except lib_exc.NotFound:
huangtianhua5232b662013-10-11 10:21:58 +080059 break
60 flavor_id = data_utils.rand_int_id(start=1000)
61 return flavor_id
62
Chris Hoge7579c1a2015-02-26 14:12:15 -080063 @test.idempotent_id('28dcec23-f807-49da-822c-56a92ea3c687')
Joseph Lanouxb3d956f2014-06-25 14:45:24 +000064 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
65 'Resize not available.')
Sean Dague639f2fa2015-04-27 09:00:33 -040066 @test.attr(type=['negative'])
huangtianhua5232b662013-10-11 10:21:58 +080067 def test_resize_server_using_overlimit_ram(self):
Matt Riedemannce6b14e2014-09-23 09:46:50 -070068 # NOTE(mriedem): Avoid conflicts with os-quota-class-sets tests.
69 self.useFixture(fixtures.LockFixture('compute_quotas'))
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000070 flavor_name = data_utils.rand_name("flavor")
huangtianhua5232b662013-10-11 10:21:58 +080071 flavor_id = self._get_unused_flavor_id()
Ken'ichi Ohmichif9868fc2015-06-17 02:36:06 +000072 quota_set = self.quotas_client.show_default_quota_set(self.tenant_id)
huangtianhua5232b662013-10-11 10:21:58 +080073 ram = int(quota_set['ram']) + 1
74 vcpus = 8
75 disk = 10
Ken'ichi Ohmichi96338c42015-07-17 06:25:14 +000076 flavor_ref = self.flavors_client.create_flavor(name=flavor_name,
77 ram=ram, vcpus=vcpus,
78 disk=disk, id=flavor_id)
huangtianhua5232b662013-10-11 10:21:58 +080079 self.addCleanup(self.flavors_client.delete_flavor, flavor_id)
Masayuki Igawa6b1cd292015-02-16 11:11:55 +090080 self.assertRaises((lib_exc.Forbidden, lib_exc.OverLimit),
huangtianhua5232b662013-10-11 10:21:58 +080081 self.client.resize,
82 self.servers[0]['id'],
83 flavor_ref['id'])
84
Chris Hoge7579c1a2015-02-26 14:12:15 -080085 @test.idempotent_id('7368a427-2f26-4ad9-9ba9-911a0ec2b0db')
Joseph Lanouxb3d956f2014-06-25 14:45:24 +000086 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
87 'Resize not available.')
Sean Dague639f2fa2015-04-27 09:00:33 -040088 @test.attr(type=['negative'])
huangtianhua5232b662013-10-11 10:21:58 +080089 def test_resize_server_using_overlimit_vcpus(self):
Matt Riedemannce6b14e2014-09-23 09:46:50 -070090 # NOTE(mriedem): Avoid conflicts with os-quota-class-sets tests.
91 self.useFixture(fixtures.LockFixture('compute_quotas'))
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000092 flavor_name = data_utils.rand_name("flavor")
huangtianhua5232b662013-10-11 10:21:58 +080093 flavor_id = self._get_unused_flavor_id()
94 ram = 512
Ken'ichi Ohmichif9868fc2015-06-17 02:36:06 +000095 quota_set = self.quotas_client.show_default_quota_set(self.tenant_id)
huangtianhua5232b662013-10-11 10:21:58 +080096 vcpus = int(quota_set['cores']) + 1
97 disk = 10
Ken'ichi Ohmichi96338c42015-07-17 06:25:14 +000098 flavor_ref = self.flavors_client.create_flavor(name=flavor_name,
99 ram=ram, vcpus=vcpus,
100 disk=disk, id=flavor_id)
huangtianhua5232b662013-10-11 10:21:58 +0800101 self.addCleanup(self.flavors_client.delete_flavor, flavor_id)
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900102 self.assertRaises((lib_exc.Forbidden, lib_exc.OverLimit),
huangtianhua5232b662013-10-11 10:21:58 +0800103 self.client.resize,
104 self.servers[0]['id'],
105 flavor_ref['id'])
106
Sean Dague639f2fa2015-04-27 09:00:33 -0400107 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800108 @test.idempotent_id('b0b4d8af-1256-41ef-9ee7-25f1c19dde80')
huangtianhua5232b662013-10-11 10:21:58 +0800109 def test_reset_state_server_invalid_state(self):
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900110 self.assertRaises(lib_exc.BadRequest,
huangtianhua5232b662013-10-11 10:21:58 +0800111 self.client.reset_state, self.s1_id,
112 state='invalid')
113
Sean Dague639f2fa2015-04-27 09:00:33 -0400114 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800115 @test.idempotent_id('4cdcc984-fab0-4577-9a9d-6d558527ee9d')
huangtianhua5232b662013-10-11 10:21:58 +0800116 def test_reset_state_server_invalid_type(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=1)
120
Sean Dague639f2fa2015-04-27 09:00:33 -0400121 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800122 @test.idempotent_id('e741298b-8df2-46f0-81cb-8f814ff2504c')
huangtianhua5232b662013-10-11 10:21:58 +0800123 def test_reset_state_server_nonexistent_server(self):
Masayuki Igawabfa07602015-01-20 18:47:17 +0900124 self.assertRaises(lib_exc.NotFound,
huangtianhua5232b662013-10-11 10:21:58 +0800125 self.client.reset_state, '999')
126
Sean Dague639f2fa2015-04-27 09:00:33 -0400127 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800128 @test.idempotent_id('e84e2234-60d2-42fa-8b30-e2d3049724ac')
huangtianhua5232b662013-10-11 10:21:58 +0800129 def test_get_server_diagnostics_by_non_admin(self):
130 # Non-admin user can not view server diagnostics according to policy
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900131 self.assertRaises(lib_exc.Forbidden,
huangtianhua5232b662013-10-11 10:21:58 +0800132 self.non_adm_client.get_server_diagnostics,
133 self.s1_id)
134
Sean Dague639f2fa2015-04-27 09:00:33 -0400135 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800136 @test.idempotent_id('46a4e1ca-87ae-4d28-987a-1b6b136a0221')
huangtianhua5232b662013-10-11 10:21:58 +0800137 def test_migrate_non_existent_server(self):
138 # migrate a non existent server
Masayuki Igawabfa07602015-01-20 18:47:17 +0900139 self.assertRaises(lib_exc.NotFound,
huangtianhua5232b662013-10-11 10:21:58 +0800140 self.client.migrate_server,
141 str(uuid.uuid4()))
142
Chris Hoge7579c1a2015-02-26 14:12:15 -0800143 @test.idempotent_id('b0b17f83-d14e-4fc4-8f31-bcc9f3cfa629')
Andrea Rosa3df237c2014-07-18 14:22:53 +0100144 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
145 'Resize not available.')
Matt Riedemann7051d622014-03-23 18:36:17 -0700146 @testtools.skipUnless(CONF.compute_feature_enabled.suspend,
147 'Suspend is not available.')
Sean Dague639f2fa2015-04-27 09:00:33 -0400148 @test.attr(type=['negative'])
huangtianhua5232b662013-10-11 10:21:58 +0800149 def test_migrate_server_invalid_state(self):
150 # create server.
David Kranz0fb14292015-02-11 15:55:20 -0500151 server = self.create_test_server(wait_until='ACTIVE')
huangtianhua5232b662013-10-11 10:21:58 +0800152 server_id = server['id']
153 # suspend the server.
David Kranzae99b9a2015-02-16 13:37:01 -0500154 self.client.suspend_server(server_id)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000155 waiters.wait_for_server_status(self.client,
156 server_id, 'SUSPENDED')
huangtianhua5232b662013-10-11 10:21:58 +0800157 # migrate an suspended server should fail
Masayuki Igawad9388762015-01-20 14:56:42 +0900158 self.assertRaises(lib_exc.Conflict,
huangtianhua5232b662013-10-11 10:21:58 +0800159 self.client.migrate_server,
160 server_id)