blob: 6cc463df584133782774dcdc2139cec53cd97be1 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Jay Pipes13b479b2012-06-11 14:52:27 -04002# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
Daryl Wallecked8bef32011-12-05 23:02:08 -060016import base64
Daryl Wallecked8bef32011-12-05 23:02:08 -060017
Sean Dague1937d092013-05-17 16:36:38 -040018from tempest.api.compute import base
Matthew Treinisha83a16e2012-12-07 13:44:02 -050019from tempest import exceptions
Yuiko Takadae9999d62014-03-06 09:22:54 +000020from tempest import test
Jay Pipes13b479b2012-06-11 14:52:27 -040021
Daryl Wallecked8bef32011-12-05 23:02:08 -060022
ivan-zhuf2b00502013-10-18 10:06:52 +080023class ServerPersonalityTestJSON(base.BaseV2ComputeTest):
Attila Fazekas19044d52013-02-16 07:35:06 +010024
25 @classmethod
26 def setUpClass(cls):
27 super(ServerPersonalityTestJSON, cls).setUpClass()
28 cls.client = cls.servers_client
29 cls.user_client = cls.limits_client
Daryl Wallecked8bef32011-12-05 23:02:08 -060030
Yuiko Takadae9999d62014-03-06 09:22:54 +000031 @test.attr(type='gate')
Daryl Wallecked8bef32011-12-05 23:02:08 -060032 def test_personality_files_exceed_limit(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050033 # Server creation should fail if greater than the maximum allowed
34 # number of files are injected into the server.
Daryl Wallecked8bef32011-12-05 23:02:08 -060035 file_contents = 'This is a test file.'
36 personality = []
rajalakshmi-ganesana4ab0072012-08-07 19:48:56 +053037 max_file_limit = \
38 self.user_client.get_specific_absolute_limit("maxPersonality")
39 for i in range(0, int(max_file_limit) + 1):
Daryl Wallecked8bef32011-12-05 23:02:08 -060040 path = 'etc/test' + str(i) + '.txt'
41 personality.append({'path': path,
42 'contents': base64.b64encode(file_contents)})
Ken'ichi Ohmichi20f43ed2014-08-05 00:33:42 +000043 # A 403 Forbidden or 413 Overlimit (old behaviour) exception
44 # will be raised when out of quota
45 self.assertRaises((exceptions.Unauthorized, exceptions.OverLimit),
46 self.create_test_server, personality=personality)
Daryl Wallecked8bef32011-12-05 23:02:08 -060047
Yuiko Takadae9999d62014-03-06 09:22:54 +000048 @test.attr(type='gate')
Daryl Wallecked8bef32011-12-05 23:02:08 -060049 def test_can_create_server_with_max_number_personality_files(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050050 # Server should be created successfully if maximum allowed number of
51 # files is injected into the server during creation.
saradpatele6062f62013-03-11 01:17:32 -070052 file_contents = 'This is a test file.'
53 max_file_limit = \
54 self.user_client.get_specific_absolute_limit("maxPersonality")
55 person = []
56 for i in range(0, int(max_file_limit)):
57 path = 'etc/test' + str(i) + '.txt'
58 person.append({
59 'path': path,
60 'contents': base64.b64encode(file_contents),
61 })
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +090062 resp, server = self.create_test_server(personality=person)
saradpatele6062f62013-03-11 01:17:32 -070063 self.assertEqual('202', resp['status'])
Matthew Treinisha6f0b222012-08-16 17:07:32 -040064
65
Attila Fazekas19044d52013-02-16 07:35:06 +010066class ServerPersonalityTestXML(ServerPersonalityTestJSON):
67 _interface = "xml"