blob: 75457d1d1c97797f727c41b6b466f51cf54ffdd8 [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
Jay Pipes13b479b2012-06-11 14:52:27 -040020from nose.plugins.attrib import attr
21
22from tempest import exceptions
23from tempest.common.utils.data_utils import rand_name
Matthew Treinisha6f0b222012-08-16 17:07:32 -040024from tempest.tests.compute import base
Jay Pipes13b479b2012-06-11 14:52:27 -040025
Daryl Wallecked8bef32011-12-05 23:02:08 -060026
Matthew Treinisha6f0b222012-08-16 17:07:32 -040027class ServerPersonalityTestBase(object):
Daryl Wallecked8bef32011-12-05 23:02:08 -060028
29 def test_personality_files_exceed_limit(self):
30 """
31 Server creation should fail if greater than the maximum allowed
32 number of files are injected into the server.
33 """
34 name = rand_name('server')
35 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)})
43 try:
Zhongyue Luo79d8d362012-09-25 13:49:27 +080044 self.client.create_server(name, self.image_ref, self.flavor_ref,
45 personality=personality)
Daryl Wallecked8bef32011-12-05 23:02:08 -060046 except exceptions.OverLimit:
47 pass
48 else:
49 self.fail('This request did not fail as expected')
50
51 @attr(type='positive')
52 def test_can_create_server_with_max_number_personality_files(self):
53 """
54 Server should be created successfully if maximum allowed number of
55 files is injected into the server during creation.
56 """
saradpatel26bf0322012-05-02 23:20:17 -070057 try:
58 name = rand_name('server')
59 file_contents = 'This is a test file.'
Daryl Wallecked8bef32011-12-05 23:02:08 -060060
rajalakshmi-ganesana4ab0072012-08-07 19:48:56 +053061 max_file_limit = \
62 self.user_client.get_specific_absolute_limit("maxPersonality")
Daryl Wallecked8bef32011-12-05 23:02:08 -060063
saradpatel26bf0322012-05-02 23:20:17 -070064 personality = []
rajalakshmi-ganesana4ab0072012-08-07 19:48:56 +053065 for i in range(0, int(max_file_limit)):
saradpatel26bf0322012-05-02 23:20:17 -070066 path = 'etc/test' + str(i) + '.txt'
Zhongyue Luo79d8d362012-09-25 13:49:27 +080067 personality.append({
68 'path': path,
69 'contents': base64.b64encode(file_contents),
70 })
saradpatel26bf0322012-05-02 23:20:17 -070071 resp, server = self.client.create_server(name, self.image_ref,
Zhongyue Luo79d8d362012-09-25 13:49:27 +080072 self.flavor_ref,
73 personality=personality)
saradpatel26bf0322012-05-02 23:20:17 -070074 self.assertEqual('202', resp['status'])
Daryl Wallecked8bef32011-12-05 23:02:08 -060075
Matthew Treinisha6f0b222012-08-16 17:07:32 -040076 except Exception:
77 raise Error(resp['message'])
78
Daryl Wallecked8bef32011-12-05 23:02:08 -060079 #Teardown
saradpatel26bf0322012-05-02 23:20:17 -070080 finally:
81 self.client.delete_server(server['id'])
Matthew Treinisha6f0b222012-08-16 17:07:32 -040082
83
84class ServerPersonalityTestXML(base.BaseComputeTestXML,
Zhongyue Luoe0884a32012-09-25 17:24:17 +080085 ServerPersonalityTestBase):
Matthew Treinisha6f0b222012-08-16 17:07:32 -040086 @classmethod
87 def setUpClass(cls):
88 cls._interface = "xml"
89 super(ServerPersonalityTestXML, cls).setUpClass()
90 cls.client = cls.servers_client
91 cls.user_client = cls.limits_client
92
93
94class ServerPersonalityTestJSON(base.BaseComputeTestJSON,
Zhongyue Luo79d8d362012-09-25 13:49:27 +080095 ServerPersonalityTestBase):
Matthew Treinisha6f0b222012-08-16 17:07:32 -040096 @classmethod
97 def setUpClass(cls):
98 cls._interface = "json"
99 super(ServerPersonalityTestJSON, cls).setUpClass()
100 cls.client = cls.servers_client
101 cls.user_client = cls.limits_client