blob: 4744bf520b35e2d6a7f40f34ff20fc1562aba9e9 [file] [log] [blame]
Jay Pipes13b479b2012-06-11 14:52:27 -04001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2012 OpenStack, LLC
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
Daryl Wallecked8bef32011-12-05 23:02:08 -060018import base64
Daryl Wallecked8bef32011-12-05 23:02:08 -060019
Sean Dague1937d092013-05-17 16:36:38 -040020from tempest.api.compute import base
Matthew Treinisha83a16e2012-12-07 13:44:02 -050021from tempest import exceptions
Chris Yeoh9465b0b2013-02-09 22:19:15 +103022from tempest.test import attr
Jay Pipes13b479b2012-06-11 14:52:27 -040023
Daryl Wallecked8bef32011-12-05 23:02:08 -060024
Attila Fazekas19044d52013-02-16 07:35:06 +010025class ServerPersonalityTestJSON(base.BaseComputeTest):
26 _interface = 'json'
27
28 @classmethod
29 def setUpClass(cls):
30 super(ServerPersonalityTestJSON, cls).setUpClass()
31 cls.client = cls.servers_client
32 cls.user_client = cls.limits_client
Daryl Wallecked8bef32011-12-05 23:02:08 -060033
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040034 @attr(type='gate')
Daryl Wallecked8bef32011-12-05 23:02:08 -060035 def test_personality_files_exceed_limit(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050036 # Server creation should fail if greater than the maximum allowed
37 # number of files are injected into the server.
Daryl Wallecked8bef32011-12-05 23:02:08 -060038 file_contents = 'This is a test file.'
39 personality = []
rajalakshmi-ganesana4ab0072012-08-07 19:48:56 +053040 max_file_limit = \
41 self.user_client.get_specific_absolute_limit("maxPersonality")
42 for i in range(0, int(max_file_limit) + 1):
Daryl Wallecked8bef32011-12-05 23:02:08 -060043 path = 'etc/test' + str(i) + '.txt'
44 personality.append({'path': path,
45 'contents': base64.b64encode(file_contents)})
saradpatele6062f62013-03-11 01:17:32 -070046 self.assertRaises(exceptions.OverLimit, self.create_server,
47 personality=personality)
Daryl Wallecked8bef32011-12-05 23:02:08 -060048
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040049 @attr(type=['positive', 'gate'])
Daryl Wallecked8bef32011-12-05 23:02:08 -060050 def test_can_create_server_with_max_number_personality_files(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050051 # Server should be created successfully if maximum allowed number of
52 # files is injected into the server during creation.
saradpatele6062f62013-03-11 01:17:32 -070053 file_contents = 'This is a test file.'
54 max_file_limit = \
55 self.user_client.get_specific_absolute_limit("maxPersonality")
56 person = []
57 for i in range(0, int(max_file_limit)):
58 path = 'etc/test' + str(i) + '.txt'
59 person.append({
60 'path': path,
61 'contents': base64.b64encode(file_contents),
62 })
63 resp, server = self.create_server(personality=person)
64 self.addCleanup(self.client.delete_server, server['id'])
65 self.assertEqual('202', resp['status'])
Matthew Treinisha6f0b222012-08-16 17:07:32 -040066
67
Attila Fazekas19044d52013-02-16 07:35:06 +010068class ServerPersonalityTestXML(ServerPersonalityTestJSON):
69 _interface = "xml"