blob: 2f0af726ab234212179990e1f3f954d1ebc5dccc [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
Matt Riedemann7051d622014-03-23 18:36:17 -070017import testtools
18
huangtianhua5232b662013-10-11 10:21:58 +080019from tempest.api.compute import base
Matt Riedemannce6b14e2014-09-23 09:46:50 -070020from tempest.common import tempest_fixtures as fixtures
huangtianhua5232b662013-10-11 10:21:58 +080021from tempest.common.utils import data_utils
Matt Riedemann7051d622014-03-23 18:36:17 -070022from tempest import config
huangtianhua5232b662013-10-11 10:21:58 +080023from tempest import exceptions
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):
30
31 """
32 Tests Servers API using admin privileges
33 """
34
huangtianhua5232b662013-10-11 10:21:58 +080035 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010036 def resource_setup(cls):
37 super(ServersAdminNegativeTestJSON, cls).resource_setup()
huangtianhua5232b662013-10-11 10:21:58 +080038 cls.client = cls.os_adm.servers_client
39 cls.non_adm_client = cls.servers_client
40 cls.flavors_client = cls.os_adm.flavors_client
Andrea Frittoli9612e812014-03-13 10:57:26 +000041 cls.tenant_id = cls.client.tenant_id
huangtianhua5232b662013-10-11 10:21:58 +080042
43 cls.s1_name = data_utils.rand_name('server')
44 resp, server = cls.create_test_server(name=cls.s1_name,
45 wait_until='ACTIVE')
46 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:
52 resp, body = self.flavors_client.get_flavor_details(flavor_id)
53 except exceptions.NotFound:
54 break
55 flavor_id = data_utils.rand_int_id(start=1000)
56 return flavor_id
57
Joseph Lanouxb3d956f2014-06-25 14:45:24 +000058 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
59 'Resize not available.')
Masayuki Igawa394d8d92014-03-04 17:21:56 +090060 @test.attr(type=['negative', 'gate'])
huangtianhua5232b662013-10-11 10:21:58 +080061 def test_resize_server_using_overlimit_ram(self):
Matt Riedemannce6b14e2014-09-23 09:46:50 -070062 # NOTE(mriedem): Avoid conflicts with os-quota-class-sets tests.
63 self.useFixture(fixtures.LockFixture('compute_quotas'))
huangtianhua5232b662013-10-11 10:21:58 +080064 flavor_name = data_utils.rand_name("flavor-")
65 flavor_id = self._get_unused_flavor_id()
66 resp, quota_set = self.quotas_client.get_default_quota_set(
67 self.tenant_id)
68 ram = int(quota_set['ram']) + 1
69 vcpus = 8
70 disk = 10
71 resp, flavor_ref = self.flavors_client.create_flavor(flavor_name,
72 ram, vcpus, disk,
73 flavor_id)
74 self.addCleanup(self.flavors_client.delete_flavor, flavor_id)
ZHU ZHU35762542014-09-01 01:58:49 -050075 self.assertRaises((exceptions.Unauthorized, exceptions.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
89 resp, quota_set = self.quotas_client.get_default_quota_set(
90 self.tenant_id)
91 vcpus = int(quota_set['cores']) + 1
92 disk = 10
93 resp, flavor_ref = self.flavors_client.create_flavor(flavor_name,
94 ram, vcpus, disk,
95 flavor_id)
96 self.addCleanup(self.flavors_client.delete_flavor, flavor_id)
ZHU ZHU35762542014-09-01 01:58:49 -050097 self.assertRaises((exceptions.Unauthorized, exceptions.OverLimit),
huangtianhua5232b662013-10-11 10:21:58 +080098 self.client.resize,
99 self.servers[0]['id'],
100 flavor_ref['id'])
101
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900102 @test.attr(type=['negative', 'gate'])
huangtianhua5232b662013-10-11 10:21:58 +0800103 def test_reset_state_server_invalid_state(self):
104 self.assertRaises(exceptions.BadRequest,
105 self.client.reset_state, self.s1_id,
106 state='invalid')
107
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900108 @test.attr(type=['negative', 'gate'])
huangtianhua5232b662013-10-11 10:21:58 +0800109 def test_reset_state_server_invalid_type(self):
110 self.assertRaises(exceptions.BadRequest,
111 self.client.reset_state, self.s1_id,
112 state=1)
113
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900114 @test.attr(type=['negative', 'gate'])
huangtianhua5232b662013-10-11 10:21:58 +0800115 def test_reset_state_server_nonexistent_server(self):
116 self.assertRaises(exceptions.NotFound,
117 self.client.reset_state, '999')
118
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900119 @test.attr(type=['negative', 'gate'])
huangtianhua5232b662013-10-11 10:21:58 +0800120 def test_get_server_diagnostics_by_non_admin(self):
121 # Non-admin user can not view server diagnostics according to policy
122 self.assertRaises(exceptions.Unauthorized,
123 self.non_adm_client.get_server_diagnostics,
124 self.s1_id)
125
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900126 @test.attr(type=['negative', 'gate'])
huangtianhua5232b662013-10-11 10:21:58 +0800127 def test_migrate_non_existent_server(self):
128 # migrate a non existent server
129 self.assertRaises(exceptions.NotFound,
130 self.client.migrate_server,
131 str(uuid.uuid4()))
132
Andrea Rosa3df237c2014-07-18 14:22:53 +0100133 @testtools.skipUnless(CONF.compute_feature_enabled.resize,
134 'Resize not available.')
Matt Riedemann7051d622014-03-23 18:36:17 -0700135 @testtools.skipUnless(CONF.compute_feature_enabled.suspend,
136 'Suspend is not available.')
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900137 @test.attr(type=['negative', 'gate'])
huangtianhua5232b662013-10-11 10:21:58 +0800138 def test_migrate_server_invalid_state(self):
139 # create server.
140 resp, server = self.create_test_server(wait_until='ACTIVE')
141 self.assertEqual(202, resp.status)
142 server_id = server['id']
143 # suspend the server.
144 resp, _ = self.client.suspend_server(server_id)
145 self.assertEqual(202, resp.status)
146 self.client.wait_for_server_status(server_id, 'SUSPENDED')
147 # migrate an suspended server should fail
148 self.assertRaises(exceptions.Conflict,
149 self.client.migrate_server,
150 server_id)