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 | |
Sirushti Murugesan | 12dc973 | 2016-07-13 22:49:17 +0530 | [diff] [blame] | 16 | from oslo_serialization 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 |
Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 23 | from tempest.lib import decorators |
Andrea Frittoli (andreaf) | db9672e | 2016-02-23 14:07:24 -0500 | [diff] [blame] | 24 | from tempest.lib import exceptions as lib_exc |
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 | |
Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 53 | @decorators.idempotent_id('3cfe87fd-115b-4a02-b942-7dc36a337fdf') |
Takeaki Matsumoto | d7e04b2 | 2015-09-04 15:13:38 +0900 | [diff] [blame] | 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, |
Sirushti Murugesan | 12dc973 | 2016-07-13 22:49:17 +0530 | [diff] [blame] | 58 | 'contents': base64.encode_as_text(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, |
Andrea Frittoli (andreaf) | 2a70a61 | 2016-04-29 16:09:13 -0500 | [diff] [blame] | 69 | self.validation_resources['keypair']['private_key'], |
| 70 | server=server, |
| 71 | servers_client=self.client) |
Matthew Treinish | f06ceb7 | 2015-12-14 12:09:30 -0500 | [diff] [blame] | 72 | self.assertEqual(file_contents, |
| 73 | linux_client.exec_command( |
| 74 | 'sudo cat %s' % file_path)) |
Takeaki Matsumoto | d7e04b2 | 2015-09-04 15:13:38 +0900 | [diff] [blame] | 75 | |
Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 76 | @decorators.idempotent_id('128966d8-71fc-443c-8cab-08e24114ecc9') |
Takeaki Matsumoto | d7e04b2 | 2015-09-04 15:13:38 +0900 | [diff] [blame] | 77 | def test_rebuild_server_with_personality(self): |
Matthew Treinish | f06ceb7 | 2015-12-14 12:09:30 -0500 | [diff] [blame] | 78 | server = self.create_test_server(wait_until='ACTIVE', validatable=True) |
| 79 | server_id = server['id'] |
Takeaki Matsumoto | d7e04b2 | 2015-09-04 15:13:38 +0900 | [diff] [blame] | 80 | file_contents = 'Test server rebuild.' |
| 81 | personality = [{'path': 'rebuild.txt', |
Sirushti Murugesan | 12dc973 | 2016-07-13 22:49:17 +0530 | [diff] [blame] | 82 | 'contents': base64.encode_as_text(file_contents)}] |
Matthew Treinish | f06ceb7 | 2015-12-14 12:09:30 -0500 | [diff] [blame] | 83 | rebuilt_server = self.client.rebuild_server(server_id, |
| 84 | self.image_ref_alt, |
| 85 | personality=personality) |
| 86 | waiters.wait_for_server_status(self.client, server_id, 'ACTIVE') |
| 87 | self.assertEqual(self.image_ref_alt, |
| 88 | rebuilt_server['server']['image']['id']) |
Takeaki Matsumoto | d7e04b2 | 2015-09-04 15:13:38 +0900 | [diff] [blame] | 89 | |
Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 90 | @decorators.idempotent_id('176cd8c9-b9e8-48ee-a480-180beab292bf') |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 91 | def test_personality_files_exceed_limit(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 92 | # Server creation should fail if greater than the maximum allowed |
| 93 | # number of files are injected into the server. |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 94 | file_contents = 'This is a test file.' |
| 95 | personality = [] |
ghanshyam | 8a59949 | 2015-08-24 15:55:59 +0900 | [diff] [blame] | 96 | limits = self.user_client.show_limits()['limits'] |
Ken'ichi Ohmichi | b93e676 | 2015-06-15 07:11:29 +0000 | [diff] [blame] | 97 | max_file_limit = limits['absolute']['maxPersonality'] |
ghanshyam | aae0781 | 2014-12-17 11:38:06 +0900 | [diff] [blame] | 98 | if max_file_limit == -1: |
| 99 | raise self.skipException("No limit for personality files") |
rajalakshmi-ganesan | a4ab007 | 2012-08-07 19:48:56 +0530 | [diff] [blame] | 100 | for i in range(0, int(max_file_limit) + 1): |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 101 | path = 'etc/test' + str(i) + '.txt' |
| 102 | personality.append({'path': path, |
Sirushti Murugesan | 12dc973 | 2016-07-13 22:49:17 +0530 | [diff] [blame] | 103 | 'contents': base64.encode_as_text( |
| 104 | file_contents)}) |
Ken'ichi Ohmichi | 20f43ed | 2014-08-05 00:33:42 +0000 | [diff] [blame] | 105 | # A 403 Forbidden or 413 Overlimit (old behaviour) exception |
| 106 | # will be raised when out of quota |
Masayuki Igawa | 6b1cd29 | 2015-02-16 11:11:55 +0900 | [diff] [blame] | 107 | self.assertRaises((lib_exc.Forbidden, lib_exc.OverLimit), |
Ken'ichi Ohmichi | 20f43ed | 2014-08-05 00:33:42 +0000 | [diff] [blame] | 108 | self.create_test_server, personality=personality) |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 109 | |
Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 110 | @decorators.idempotent_id('52f12ee8-5180-40cc-b417-31572ea3d555') |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 111 | def test_can_create_server_with_max_number_personality_files(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 112 | # Server should be created successfully if maximum allowed number of |
| 113 | # files is injected into the server during creation. |
saradpatel | e6062f6 | 2013-03-11 01:17:32 -0700 | [diff] [blame] | 114 | file_contents = 'This is a test file.' |
ghanshyam | 8a59949 | 2015-08-24 15:55:59 +0900 | [diff] [blame] | 115 | limits = self.user_client.show_limits()['limits'] |
Ken'ichi Ohmichi | b93e676 | 2015-06-15 07:11:29 +0000 | [diff] [blame] | 116 | max_file_limit = limits['absolute']['maxPersonality'] |
ghanshyam | aae0781 | 2014-12-17 11:38:06 +0900 | [diff] [blame] | 117 | if max_file_limit == -1: |
| 118 | raise self.skipException("No limit for personality files") |
saradpatel | e6062f6 | 2013-03-11 01:17:32 -0700 | [diff] [blame] | 119 | person = [] |
| 120 | for i in range(0, int(max_file_limit)): |
Andrea Frittoli | 9fb9d55 | 2016-12-05 12:22:25 +0000 | [diff] [blame] | 121 | # NOTE(andreaf) The cirros disk image is blank before boot |
| 122 | # so we can only inject safely to / |
| 123 | path = '/test' + str(i) + '.txt' |
saradpatel | e6062f6 | 2013-03-11 01:17:32 -0700 | [diff] [blame] | 124 | person.append({ |
| 125 | 'path': path, |
zhufl | 552608a | 2016-12-05 14:13:58 +0800 | [diff] [blame] | 126 | 'contents': base64.encode_as_text(file_contents + str(i)), |
saradpatel | e6062f6 | 2013-03-11 01:17:32 -0700 | [diff] [blame] | 127 | }) |
Ghanshyam | 3390d9f | 2015-12-25 12:48:02 +0900 | [diff] [blame] | 128 | password = data_utils.rand_password() |
Yaroslav Lobankov | 77946eb | 2015-12-21 21:25:18 +0300 | [diff] [blame] | 129 | created_server = self.create_test_server(personality=person, |
Ghanshyam | 3390d9f | 2015-12-25 12:48:02 +0900 | [diff] [blame] | 130 | adminPass=password, |
Yaroslav Lobankov | 77946eb | 2015-12-21 21:25:18 +0300 | [diff] [blame] | 131 | wait_until='ACTIVE', |
| 132 | validatable=True) |
| 133 | server = self.client.show_server(created_server['id'])['server'] |
Matthew Treinish | f06ceb7 | 2015-12-14 12:09:30 -0500 | [diff] [blame] | 134 | if CONF.validation.run_validation: |
| 135 | linux_client = remote_client.RemoteClient( |
| 136 | self.get_server_ip(server), |
Ghanshyam | 3390d9f | 2015-12-25 12:48:02 +0900 | [diff] [blame] | 137 | self.ssh_user, password, |
Andrea Frittoli (andreaf) | 2a70a61 | 2016-04-29 16:09:13 -0500 | [diff] [blame] | 138 | self.validation_resources['keypair']['private_key'], |
| 139 | server=server, |
| 140 | servers_client=self.client) |
Matthew Treinish | f06ceb7 | 2015-12-14 12:09:30 -0500 | [diff] [blame] | 141 | for i in person: |
Anna Babich | 0e40821 | 2016-09-19 12:30:56 +0300 | [diff] [blame] | 142 | self.assertEqual(base64.decode_as_text(i['contents']), |
Matthew Treinish | f06ceb7 | 2015-12-14 12:09:30 -0500 | [diff] [blame] | 143 | linux_client.exec_command( |
| 144 | 'sudo cat %s' % i['path'])) |