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 | f06ceb7 | 2015-12-14 12:09:30 -0500 | [diff] [blame] | 19 | from tempest.common.utils.linux import remote_client |
| 20 | from tempest.common import waiters |
Takeaki Matsumoto | d7e04b2 | 2015-09-04 15:13:38 +0900 | [diff] [blame] | 21 | from tempest import config |
Andrea Frittoli (andreaf) | db9672e | 2016-02-23 14:07:24 -0500 | [diff] [blame^] | 22 | from tempest.lib.common.utils import data_utils |
| 23 | from tempest.lib import exceptions as lib_exc |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 24 | from tempest import test |
Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [diff] [blame] | 25 | |
Takeaki Matsumoto | d7e04b2 | 2015-09-04 15:13:38 +0900 | [diff] [blame] | 26 | CONF = config.CONF |
| 27 | |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 28 | |
ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 29 | class ServerPersonalityTestJSON(base.BaseV2ComputeTest): |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 30 | |
| 31 | @classmethod |
Matthew Treinish | f06ceb7 | 2015-12-14 12:09:30 -0500 | [diff] [blame] | 32 | def setup_credentials(cls): |
| 33 | cls.prepare_instance_network() |
| 34 | super(ServerPersonalityTestJSON, cls).setup_credentials() |
| 35 | |
| 36 | @classmethod |
| 37 | def resource_setup(cls): |
| 38 | cls.set_validation_resources() |
| 39 | super(ServerPersonalityTestJSON, cls).resource_setup() |
| 40 | |
| 41 | @classmethod |
Takeaki Matsumoto | d7e04b2 | 2015-09-04 15:13:38 +0900 | [diff] [blame] | 42 | def skip_checks(cls): |
| 43 | super(ServerPersonalityTestJSON, cls).skip_checks() |
| 44 | if not CONF.compute_feature_enabled.personality: |
| 45 | raise cls.skipException("Nova personality feature disabled") |
| 46 | |
| 47 | @classmethod |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 48 | def setup_clients(cls): |
| 49 | super(ServerPersonalityTestJSON, cls).setup_clients() |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 50 | cls.client = cls.servers_client |
| 51 | cls.user_client = cls.limits_client |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 52 | |
Takeaki Matsumoto | d7e04b2 | 2015-09-04 15:13:38 +0900 | [diff] [blame] | 53 | @test.idempotent_id('3cfe87fd-115b-4a02-b942-7dc36a337fdf') |
| 54 | def test_create_server_with_personality(self): |
| 55 | file_contents = 'This is a test file.' |
Matthew Treinish | f06ceb7 | 2015-12-14 12:09:30 -0500 | [diff] [blame] | 56 | file_path = '/test.txt' |
| 57 | personality = [{'path': file_path, |
Takeaki Matsumoto | d7e04b2 | 2015-09-04 15:13:38 +0900 | [diff] [blame] | 58 | 'contents': base64.b64encode(file_contents)}] |
Ghanshyam | 3390d9f | 2015-12-25 12:48:02 +0900 | [diff] [blame] | 59 | password = data_utils.rand_password() |
Yaroslav Lobankov | 77946eb | 2015-12-21 21:25:18 +0300 | [diff] [blame] | 60 | created_server = self.create_test_server(personality=personality, |
Ghanshyam | 3390d9f | 2015-12-25 12:48:02 +0900 | [diff] [blame] | 61 | adminPass=password, |
Yaroslav Lobankov | 77946eb | 2015-12-21 21:25:18 +0300 | [diff] [blame] | 62 | wait_until='ACTIVE', |
| 63 | validatable=True) |
| 64 | server = self.client.show_server(created_server['id'])['server'] |
Matthew Treinish | f06ceb7 | 2015-12-14 12:09:30 -0500 | [diff] [blame] | 65 | if CONF.validation.run_validation: |
| 66 | linux_client = remote_client.RemoteClient( |
| 67 | self.get_server_ip(server), |
Ghanshyam | 3390d9f | 2015-12-25 12:48:02 +0900 | [diff] [blame] | 68 | self.ssh_user, password, |
Matthew Treinish | f06ceb7 | 2015-12-14 12:09:30 -0500 | [diff] [blame] | 69 | self.validation_resources['keypair']['private_key']) |
| 70 | self.assertEqual(file_contents, |
| 71 | linux_client.exec_command( |
| 72 | 'sudo cat %s' % file_path)) |
Takeaki Matsumoto | d7e04b2 | 2015-09-04 15:13:38 +0900 | [diff] [blame] | 73 | |
| 74 | @test.idempotent_id('128966d8-71fc-443c-8cab-08e24114ecc9') |
| 75 | def test_rebuild_server_with_personality(self): |
Matthew Treinish | f06ceb7 | 2015-12-14 12:09:30 -0500 | [diff] [blame] | 76 | server = self.create_test_server(wait_until='ACTIVE', validatable=True) |
| 77 | server_id = server['id'] |
Takeaki Matsumoto | d7e04b2 | 2015-09-04 15:13:38 +0900 | [diff] [blame] | 78 | file_contents = 'Test server rebuild.' |
| 79 | personality = [{'path': 'rebuild.txt', |
| 80 | 'contents': base64.b64encode(file_contents)}] |
Matthew Treinish | f06ceb7 | 2015-12-14 12:09:30 -0500 | [diff] [blame] | 81 | rebuilt_server = self.client.rebuild_server(server_id, |
| 82 | self.image_ref_alt, |
| 83 | personality=personality) |
| 84 | waiters.wait_for_server_status(self.client, server_id, 'ACTIVE') |
| 85 | self.assertEqual(self.image_ref_alt, |
| 86 | rebuilt_server['server']['image']['id']) |
Takeaki Matsumoto | d7e04b2 | 2015-09-04 15:13:38 +0900 | [diff] [blame] | 87 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 88 | @test.idempotent_id('176cd8c9-b9e8-48ee-a480-180beab292bf') |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 89 | def test_personality_files_exceed_limit(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 90 | # Server creation should fail if greater than the maximum allowed |
| 91 | # number of files are injected into the server. |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 92 | file_contents = 'This is a test file.' |
| 93 | personality = [] |
ghanshyam | 8a59949 | 2015-08-24 15:55:59 +0900 | [diff] [blame] | 94 | limits = self.user_client.show_limits()['limits'] |
Ken'ichi Ohmichi | b93e676 | 2015-06-15 07:11:29 +0000 | [diff] [blame] | 95 | max_file_limit = limits['absolute']['maxPersonality'] |
ghanshyam | aae0781 | 2014-12-17 11:38:06 +0900 | [diff] [blame] | 96 | if max_file_limit == -1: |
| 97 | raise self.skipException("No limit for personality files") |
rajalakshmi-ganesan | a4ab007 | 2012-08-07 19:48:56 +0530 | [diff] [blame] | 98 | for i in range(0, int(max_file_limit) + 1): |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 99 | path = 'etc/test' + str(i) + '.txt' |
| 100 | personality.append({'path': path, |
| 101 | 'contents': base64.b64encode(file_contents)}) |
Ken'ichi Ohmichi | 20f43ed | 2014-08-05 00:33:42 +0000 | [diff] [blame] | 102 | # A 403 Forbidden or 413 Overlimit (old behaviour) exception |
| 103 | # will be raised when out of quota |
Masayuki Igawa | 6b1cd29 | 2015-02-16 11:11:55 +0900 | [diff] [blame] | 104 | self.assertRaises((lib_exc.Forbidden, lib_exc.OverLimit), |
Ken'ichi Ohmichi | 20f43ed | 2014-08-05 00:33:42 +0000 | [diff] [blame] | 105 | self.create_test_server, personality=personality) |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 106 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 107 | @test.idempotent_id('52f12ee8-5180-40cc-b417-31572ea3d555') |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 108 | def test_can_create_server_with_max_number_personality_files(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 109 | # Server should be created successfully if maximum allowed number of |
| 110 | # files is injected into the server during creation. |
saradpatel | e6062f6 | 2013-03-11 01:17:32 -0700 | [diff] [blame] | 111 | file_contents = 'This is a test file.' |
ghanshyam | 8a59949 | 2015-08-24 15:55:59 +0900 | [diff] [blame] | 112 | limits = self.user_client.show_limits()['limits'] |
Ken'ichi Ohmichi | b93e676 | 2015-06-15 07:11:29 +0000 | [diff] [blame] | 113 | max_file_limit = limits['absolute']['maxPersonality'] |
ghanshyam | aae0781 | 2014-12-17 11:38:06 +0900 | [diff] [blame] | 114 | if max_file_limit == -1: |
| 115 | raise self.skipException("No limit for personality files") |
saradpatel | e6062f6 | 2013-03-11 01:17:32 -0700 | [diff] [blame] | 116 | person = [] |
| 117 | for i in range(0, int(max_file_limit)): |
Matthew Treinish | f06ceb7 | 2015-12-14 12:09:30 -0500 | [diff] [blame] | 118 | path = '/etc/test' + str(i) + '.txt' |
saradpatel | e6062f6 | 2013-03-11 01:17:32 -0700 | [diff] [blame] | 119 | person.append({ |
| 120 | 'path': path, |
| 121 | 'contents': base64.b64encode(file_contents), |
| 122 | }) |
Ghanshyam | 3390d9f | 2015-12-25 12:48:02 +0900 | [diff] [blame] | 123 | password = data_utils.rand_password() |
Yaroslav Lobankov | 77946eb | 2015-12-21 21:25:18 +0300 | [diff] [blame] | 124 | created_server = self.create_test_server(personality=person, |
Ghanshyam | 3390d9f | 2015-12-25 12:48:02 +0900 | [diff] [blame] | 125 | adminPass=password, |
Yaroslav Lobankov | 77946eb | 2015-12-21 21:25:18 +0300 | [diff] [blame] | 126 | wait_until='ACTIVE', |
| 127 | validatable=True) |
| 128 | server = self.client.show_server(created_server['id'])['server'] |
Matthew Treinish | f06ceb7 | 2015-12-14 12:09:30 -0500 | [diff] [blame] | 129 | if CONF.validation.run_validation: |
| 130 | linux_client = remote_client.RemoteClient( |
| 131 | self.get_server_ip(server), |
Ghanshyam | 3390d9f | 2015-12-25 12:48:02 +0900 | [diff] [blame] | 132 | self.ssh_user, password, |
Matthew Treinish | f06ceb7 | 2015-12-14 12:09:30 -0500 | [diff] [blame] | 133 | self.validation_resources['keypair']['private_key']) |
| 134 | for i in person: |
| 135 | self.assertEqual(base64.b64decode(i['contents']), |
| 136 | linux_client.exec_command( |
| 137 | 'sudo cat %s' % i['path'])) |