ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [diff] [blame] | 2 | # 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 Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 16 | import base64 |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 17 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 18 | from tempest.api.compute import base |
Matthew Treinish | a83a16e | 2012-12-07 13:44:02 -0500 | [diff] [blame] | 19 | from tempest import exceptions |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 20 | from tempest import test |
Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [diff] [blame] | 21 | |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 22 | |
ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 23 | class ServerPersonalityTestJSON(base.BaseV2ComputeTest): |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 24 | |
| 25 | @classmethod |
Andrea Frittoli | 50bb80d | 2014-09-15 12:34:27 +0100 | [diff] [blame] | 26 | def resource_setup(cls): |
| 27 | super(ServerPersonalityTestJSON, cls).resource_setup() |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 28 | cls.client = cls.servers_client |
| 29 | cls.user_client = cls.limits_client |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 30 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 31 | @test.attr(type='gate') |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 32 | def test_personality_files_exceed_limit(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 33 | # Server creation should fail if greater than the maximum allowed |
| 34 | # number of files are injected into the server. |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 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") |
ghanshyam | aae0781 | 2014-12-17 11:38:06 +0900 | [diff] [blame^] | 39 | if max_file_limit == -1: |
| 40 | raise self.skipException("No limit for personality files") |
rajalakshmi-ganesan | a4ab007 | 2012-08-07 19:48:56 +0530 | [diff] [blame] | 41 | for i in range(0, int(max_file_limit) + 1): |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 42 | path = 'etc/test' + str(i) + '.txt' |
| 43 | personality.append({'path': path, |
| 44 | 'contents': base64.b64encode(file_contents)}) |
Ken'ichi Ohmichi | 20f43ed | 2014-08-05 00:33:42 +0000 | [diff] [blame] | 45 | # A 403 Forbidden or 413 Overlimit (old behaviour) exception |
| 46 | # will be raised when out of quota |
| 47 | self.assertRaises((exceptions.Unauthorized, exceptions.OverLimit), |
| 48 | self.create_test_server, personality=personality) |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 49 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 50 | @test.attr(type='gate') |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 51 | def test_can_create_server_with_max_number_personality_files(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 52 | # Server should be created successfully if maximum allowed number of |
| 53 | # files is injected into the server during creation. |
saradpatel | e6062f6 | 2013-03-11 01:17:32 -0700 | [diff] [blame] | 54 | file_contents = 'This is a test file.' |
| 55 | max_file_limit = \ |
| 56 | self.user_client.get_specific_absolute_limit("maxPersonality") |
ghanshyam | aae0781 | 2014-12-17 11:38:06 +0900 | [diff] [blame^] | 57 | if max_file_limit == -1: |
| 58 | raise self.skipException("No limit for personality files") |
saradpatel | e6062f6 | 2013-03-11 01:17:32 -0700 | [diff] [blame] | 59 | person = [] |
| 60 | for i in range(0, int(max_file_limit)): |
| 61 | path = 'etc/test' + str(i) + '.txt' |
| 62 | person.append({ |
| 63 | 'path': path, |
| 64 | 'contents': base64.b64encode(file_contents), |
| 65 | }) |
Ken'ichi Ohmichi | cfc052e | 2013-10-23 11:50:04 +0900 | [diff] [blame] | 66 | resp, server = self.create_test_server(personality=person) |
saradpatel | e6062f6 | 2013-03-11 01:17:32 -0700 | [diff] [blame] | 67 | self.assertEqual('202', resp['status']) |