blob: 9800bb41be168eb1a431dc8d41421b0b8d0905c2 [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
huangtianhua5232b662013-10-11 10:21:58 +080022from tempest.common.utils import data_utils
Matt Riedemann7051d622014-03-23 18:36:17 -070023from tempest import config
huangtianhua5232b662013-10-11 10:21:58 +080024from tempest import exceptions
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
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010037 def resource_setup(cls):
38 super(ServersAdminNegativeTestJSON, cls).resource_setup()
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
Andrea Frittoli9612e812014-03-13 10:57:26 +000042 cls.tenant_id = cls.client.tenant_id
huangtianhua5232b662013-10-11 10:21:58 +080043
44 cls.s1_name = data_utils.rand_name('server')
45 resp, server = cls.create_test_server(name=cls.s1_name,
46 wait_until='ACTIVE')
47 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:
David Kranz2fa77b22015-02-09 11:39:50 -050053 self.flavors_client.get_flavor_details(flavor_id)
huangtianhua5232b662013-10-11 10:21:58 +080054 except exceptions.NotFound:
55 break
56 flavor_id = data_utils.rand_int_id(start=1000)
57 return flavor_id
58
Joseph Lanouxb3d956f2014-06-25 14:45:24 +000059 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
60 'Resize not available.')
Masayuki Igawa394d8d92014-03-04 17:21:56 +090061 @test.attr(type=['negative', 'gate'])
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'))
huangtianhua5232b662013-10-11 10:21:58 +080065 flavor_name = data_utils.rand_name("flavor-")
66 flavor_id = self._get_unused_flavor_id()
David Kranz3e4c28b2015-02-09 12:35:18 -050067 quota_set = self.quotas_client.get_default_quota_set(self.tenant_id)
huangtianhua5232b662013-10-11 10:21:58 +080068 ram = int(quota_set['ram']) + 1
69 vcpus = 8
70 disk = 10
David Kranz2fa77b22015-02-09 11:39:50 -050071 flavor_ref = self.flavors_client.create_flavor(flavor_name,
72 ram, vcpus, disk,
73 flavor_id)
huangtianhua5232b662013-10-11 10:21:58 +080074 self.addCleanup(self.flavors_client.delete_flavor, flavor_id)
Masayuki Igawa90c914e2015-01-20 14:48:16 +090075 self.assertRaises((exceptions.Unauthorized, lib_exc.OverLimit),
huangtianhua5232b662013-10-11 10:21:58 +080076 self.client.resize,
77 self.servers[0]['id'],
78 flavor_ref['id'])
79
Joseph Lanouxb3d956f2014-06-25 14:45:24 +000080 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
81 'Resize not available.')
Masayuki Igawa394d8d92014-03-04 17:21:56 +090082 @test.attr(type=['negative', 'gate'])
huangtianhua5232b662013-10-11 10:21:58 +080083 def test_resize_server_using_overlimit_vcpus(self):
Matt Riedemannce6b14e2014-09-23 09:46:50 -070084 # NOTE(mriedem): Avoid conflicts with os-quota-class-sets tests.
85 self.useFixture(fixtures.LockFixture('compute_quotas'))
huangtianhua5232b662013-10-11 10:21:58 +080086 flavor_name = data_utils.rand_name("flavor-")
87 flavor_id = self._get_unused_flavor_id()
88 ram = 512
David Kranz3e4c28b2015-02-09 12:35:18 -050089 quota_set = self.quotas_client.get_default_quota_set(self.tenant_id)
huangtianhua5232b662013-10-11 10:21:58 +080090 vcpus = int(quota_set['cores']) + 1
91 disk = 10
David Kranz2fa77b22015-02-09 11:39:50 -050092 flavor_ref = self.flavors_client.create_flavor(flavor_name,
93 ram, vcpus, disk,
94 flavor_id)
huangtianhua5232b662013-10-11 10:21:58 +080095 self.addCleanup(self.flavors_client.delete_flavor, flavor_id)
Masayuki Igawa90c914e2015-01-20 14:48:16 +090096 self.assertRaises((exceptions.Unauthorized, lib_exc.OverLimit),
huangtianhua5232b662013-10-11 10:21:58 +080097 self.client.resize,
98 self.servers[0]['id'],
99 flavor_ref['id'])
100
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900101 @test.attr(type=['negative', 'gate'])
huangtianhua5232b662013-10-11 10:21:58 +0800102 def test_reset_state_server_invalid_state(self):
103 self.assertRaises(exceptions.BadRequest,
104 self.client.reset_state, self.s1_id,
105 state='invalid')
106
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900107 @test.attr(type=['negative', 'gate'])
huangtianhua5232b662013-10-11 10:21:58 +0800108 def test_reset_state_server_invalid_type(self):
109 self.assertRaises(exceptions.BadRequest,
110 self.client.reset_state, self.s1_id,
111 state=1)
112
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900113 @test.attr(type=['negative', 'gate'])
huangtianhua5232b662013-10-11 10:21:58 +0800114 def test_reset_state_server_nonexistent_server(self):
115 self.assertRaises(exceptions.NotFound,
116 self.client.reset_state, '999')
117
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900118 @test.attr(type=['negative', 'gate'])
huangtianhua5232b662013-10-11 10:21:58 +0800119 def test_get_server_diagnostics_by_non_admin(self):
120 # Non-admin user can not view server diagnostics according to policy
121 self.assertRaises(exceptions.Unauthorized,
122 self.non_adm_client.get_server_diagnostics,
123 self.s1_id)
124
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900125 @test.attr(type=['negative', 'gate'])
huangtianhua5232b662013-10-11 10:21:58 +0800126 def test_migrate_non_existent_server(self):
127 # migrate a non existent server
128 self.assertRaises(exceptions.NotFound,
129 self.client.migrate_server,
130 str(uuid.uuid4()))
131
Andrea Rosa3df237c2014-07-18 14:22:53 +0100132 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
133 'Resize not available.')
Matt Riedemann7051d622014-03-23 18:36:17 -0700134 @testtools.skipUnless(CONF.compute_feature_enabled.suspend,
135 'Suspend is not available.')
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900136 @test.attr(type=['negative', 'gate'])
huangtianhua5232b662013-10-11 10:21:58 +0800137 def test_migrate_server_invalid_state(self):
138 # create server.
139 resp, server = self.create_test_server(wait_until='ACTIVE')
140 self.assertEqual(202, resp.status)
141 server_id = server['id']
142 # suspend the server.
143 resp, _ = self.client.suspend_server(server_id)
144 self.assertEqual(202, resp.status)
145 self.client.wait_for_server_status(server_id, 'SUSPENDED')
146 # migrate an suspended server should fail
147 self.assertRaises(exceptions.Conflict,
148 self.client.migrate_server,
149 server_id)