Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [diff] [blame] | 1 | # 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 Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 18 | import base64 |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 19 | |
Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [diff] [blame] | 20 | from nose.plugins.attrib import attr |
| 21 | |
| 22 | from tempest import exceptions |
| 23 | from tempest.common.utils.data_utils import rand_name |
Matthew Treinish | a6f0b22 | 2012-08-16 17:07:32 -0400 | [diff] [blame] | 24 | from tempest.tests.compute import base |
Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [diff] [blame] | 25 | |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 26 | |
Matthew Treinish | a6f0b22 | 2012-08-16 17:07:32 -0400 | [diff] [blame] | 27 | class ServerPersonalityTestBase(object): |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 28 | |
| 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-ganesan | a4ab007 | 2012-08-07 19:48:56 +0530 | [diff] [blame] | 37 | max_file_limit = \ |
| 38 | self.user_client.get_specific_absolute_limit("maxPersonality") |
| 39 | for i in range(0, int(max_file_limit) + 1): |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 40 | path = 'etc/test' + str(i) + '.txt' |
| 41 | personality.append({'path': path, |
| 42 | 'contents': base64.b64encode(file_contents)}) |
| 43 | try: |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 44 | self.client.create_server(name, self.image_ref, self.flavor_ref, |
| 45 | personality=personality) |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 46 | 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 | """ |
saradpatel | 26bf032 | 2012-05-02 23:20:17 -0700 | [diff] [blame] | 57 | try: |
| 58 | name = rand_name('server') |
| 59 | file_contents = 'This is a test file.' |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 60 | |
rajalakshmi-ganesan | a4ab007 | 2012-08-07 19:48:56 +0530 | [diff] [blame] | 61 | max_file_limit = \ |
| 62 | self.user_client.get_specific_absolute_limit("maxPersonality") |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 63 | |
saradpatel | 26bf032 | 2012-05-02 23:20:17 -0700 | [diff] [blame] | 64 | personality = [] |
rajalakshmi-ganesan | a4ab007 | 2012-08-07 19:48:56 +0530 | [diff] [blame] | 65 | for i in range(0, int(max_file_limit)): |
saradpatel | 26bf032 | 2012-05-02 23:20:17 -0700 | [diff] [blame] | 66 | path = 'etc/test' + str(i) + '.txt' |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 67 | personality.append({ |
| 68 | 'path': path, |
| 69 | 'contents': base64.b64encode(file_contents), |
| 70 | }) |
saradpatel | 26bf032 | 2012-05-02 23:20:17 -0700 | [diff] [blame] | 71 | resp, server = self.client.create_server(name, self.image_ref, |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 72 | self.flavor_ref, |
| 73 | personality=personality) |
saradpatel | 26bf032 | 2012-05-02 23:20:17 -0700 | [diff] [blame] | 74 | self.assertEqual('202', resp['status']) |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 75 | |
Matthew Treinish | a6f0b22 | 2012-08-16 17:07:32 -0400 | [diff] [blame] | 76 | except Exception: |
| 77 | raise Error(resp['message']) |
| 78 | |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 79 | #Teardown |
saradpatel | 26bf032 | 2012-05-02 23:20:17 -0700 | [diff] [blame] | 80 | finally: |
| 81 | self.client.delete_server(server['id']) |
Matthew Treinish | a6f0b22 | 2012-08-16 17:07:32 -0400 | [diff] [blame] | 82 | |
| 83 | |
| 84 | class ServerPersonalityTestXML(base.BaseComputeTestXML, |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 85 | ServerPersonalityTestBase): |
Matthew Treinish | a6f0b22 | 2012-08-16 17:07:32 -0400 | [diff] [blame] | 86 | @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 | |
| 94 | class ServerPersonalityTestJSON(base.BaseComputeTestJSON, |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 95 | ServerPersonalityTestBase): |
Matthew Treinish | a6f0b22 | 2012-08-16 17:07:32 -0400 | [diff] [blame] | 96 | @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 |