blob: 957d24acb2b6140733496e53fd7a5e27dc720e81 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Jay Pipes13b479b2012-06-11 14:52:27 -04002# 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 Murugesan12dc9732016-07-13 22:49:17 +053016from oslo_serialization import base64
Daryl Wallecked8bef32011-12-05 23:02:08 -060017
Sean Dague1937d092013-05-17 16:36:38 -040018from tempest.api.compute import base
Matthew Treinishf06ceb72015-12-14 12:09:30 -050019from tempest.common.utils.linux import remote_client
20from tempest.common import waiters
Takeaki Matsumotod7e04b22015-09-04 15:13:38 +090021from tempest import config
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050022from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080023from tempest.lib import decorators
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050024from tempest.lib import exceptions as lib_exc
Jay Pipes13b479b2012-06-11 14:52:27 -040025
Takeaki Matsumotod7e04b22015-09-04 15:13:38 +090026CONF = config.CONF
27
Daryl Wallecked8bef32011-12-05 23:02:08 -060028
ivan-zhuf2b00502013-10-18 10:06:52 +080029class ServerPersonalityTestJSON(base.BaseV2ComputeTest):
Attila Fazekas19044d52013-02-16 07:35:06 +010030
31 @classmethod
Matthew Treinishf06ceb72015-12-14 12:09:30 -050032 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 Matsumotod7e04b22015-09-04 15:13:38 +090042 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 Kanade60b73092015-02-04 17:58:19 +053048 def setup_clients(cls):
49 super(ServerPersonalityTestJSON, cls).setup_clients()
Attila Fazekas19044d52013-02-16 07:35:06 +010050 cls.client = cls.servers_client
51 cls.user_client = cls.limits_client
Daryl Wallecked8bef32011-12-05 23:02:08 -060052
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080053 @decorators.idempotent_id('3cfe87fd-115b-4a02-b942-7dc36a337fdf')
Takeaki Matsumotod7e04b22015-09-04 15:13:38 +090054 def test_create_server_with_personality(self):
55 file_contents = 'This is a test file.'
Matthew Treinishf06ceb72015-12-14 12:09:30 -050056 file_path = '/test.txt'
57 personality = [{'path': file_path,
Sirushti Murugesan12dc9732016-07-13 22:49:17 +053058 'contents': base64.encode_as_text(file_contents)}]
Ghanshyam3390d9f2015-12-25 12:48:02 +090059 password = data_utils.rand_password()
Yaroslav Lobankov77946eb2015-12-21 21:25:18 +030060 created_server = self.create_test_server(personality=personality,
Ghanshyam3390d9f2015-12-25 12:48:02 +090061 adminPass=password,
Yaroslav Lobankov77946eb2015-12-21 21:25:18 +030062 wait_until='ACTIVE',
63 validatable=True)
64 server = self.client.show_server(created_server['id'])['server']
Matthew Treinishf06ceb72015-12-14 12:09:30 -050065 if CONF.validation.run_validation:
66 linux_client = remote_client.RemoteClient(
67 self.get_server_ip(server),
Ghanshyam3390d9f2015-12-25 12:48:02 +090068 self.ssh_user, password,
Andrea Frittoli (andreaf)2a70a612016-04-29 16:09:13 -050069 self.validation_resources['keypair']['private_key'],
70 server=server,
71 servers_client=self.client)
Matthew Treinishf06ceb72015-12-14 12:09:30 -050072 self.assertEqual(file_contents,
73 linux_client.exec_command(
74 'sudo cat %s' % file_path))
Takeaki Matsumotod7e04b22015-09-04 15:13:38 +090075
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080076 @decorators.idempotent_id('128966d8-71fc-443c-8cab-08e24114ecc9')
Takeaki Matsumotod7e04b22015-09-04 15:13:38 +090077 def test_rebuild_server_with_personality(self):
Matthew Treinishf06ceb72015-12-14 12:09:30 -050078 server = self.create_test_server(wait_until='ACTIVE', validatable=True)
79 server_id = server['id']
Takeaki Matsumotod7e04b22015-09-04 15:13:38 +090080 file_contents = 'Test server rebuild.'
81 personality = [{'path': 'rebuild.txt',
Sirushti Murugesan12dc9732016-07-13 22:49:17 +053082 'contents': base64.encode_as_text(file_contents)}]
Matthew Treinishf06ceb72015-12-14 12:09:30 -050083 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 Matsumotod7e04b22015-09-04 15:13:38 +090089
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080090 @decorators.idempotent_id('176cd8c9-b9e8-48ee-a480-180beab292bf')
Daryl Wallecked8bef32011-12-05 23:02:08 -060091 def test_personality_files_exceed_limit(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050092 # Server creation should fail if greater than the maximum allowed
93 # number of files are injected into the server.
Daryl Wallecked8bef32011-12-05 23:02:08 -060094 file_contents = 'This is a test file.'
95 personality = []
ghanshyam8a599492015-08-24 15:55:59 +090096 limits = self.user_client.show_limits()['limits']
Ken'ichi Ohmichib93e6762015-06-15 07:11:29 +000097 max_file_limit = limits['absolute']['maxPersonality']
ghanshyamaae07812014-12-17 11:38:06 +090098 if max_file_limit == -1:
99 raise self.skipException("No limit for personality files")
rajalakshmi-ganesana4ab0072012-08-07 19:48:56 +0530100 for i in range(0, int(max_file_limit) + 1):
Daryl Wallecked8bef32011-12-05 23:02:08 -0600101 path = 'etc/test' + str(i) + '.txt'
102 personality.append({'path': path,
Sirushti Murugesan12dc9732016-07-13 22:49:17 +0530103 'contents': base64.encode_as_text(
104 file_contents)})
Ken'ichi Ohmichi20f43ed2014-08-05 00:33:42 +0000105 # A 403 Forbidden or 413 Overlimit (old behaviour) exception
106 # will be raised when out of quota
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900107 self.assertRaises((lib_exc.Forbidden, lib_exc.OverLimit),
Ken'ichi Ohmichi20f43ed2014-08-05 00:33:42 +0000108 self.create_test_server, personality=personality)
Daryl Wallecked8bef32011-12-05 23:02:08 -0600109
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -0800110 @decorators.idempotent_id('52f12ee8-5180-40cc-b417-31572ea3d555')
Daryl Wallecked8bef32011-12-05 23:02:08 -0600111 def test_can_create_server_with_max_number_personality_files(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500112 # Server should be created successfully if maximum allowed number of
113 # files is injected into the server during creation.
saradpatele6062f62013-03-11 01:17:32 -0700114 file_contents = 'This is a test file.'
ghanshyam8a599492015-08-24 15:55:59 +0900115 limits = self.user_client.show_limits()['limits']
Ken'ichi Ohmichib93e6762015-06-15 07:11:29 +0000116 max_file_limit = limits['absolute']['maxPersonality']
ghanshyamaae07812014-12-17 11:38:06 +0900117 if max_file_limit == -1:
118 raise self.skipException("No limit for personality files")
saradpatele6062f62013-03-11 01:17:32 -0700119 person = []
120 for i in range(0, int(max_file_limit)):
Andrea Frittoli9fb9d552016-12-05 12:22:25 +0000121 # NOTE(andreaf) The cirros disk image is blank before boot
122 # so we can only inject safely to /
123 path = '/test' + str(i) + '.txt'
saradpatele6062f62013-03-11 01:17:32 -0700124 person.append({
125 'path': path,
zhufl552608a2016-12-05 14:13:58 +0800126 'contents': base64.encode_as_text(file_contents + str(i)),
saradpatele6062f62013-03-11 01:17:32 -0700127 })
Ghanshyam3390d9f2015-12-25 12:48:02 +0900128 password = data_utils.rand_password()
Yaroslav Lobankov77946eb2015-12-21 21:25:18 +0300129 created_server = self.create_test_server(personality=person,
Ghanshyam3390d9f2015-12-25 12:48:02 +0900130 adminPass=password,
Yaroslav Lobankov77946eb2015-12-21 21:25:18 +0300131 wait_until='ACTIVE',
132 validatable=True)
133 server = self.client.show_server(created_server['id'])['server']
Matthew Treinishf06ceb72015-12-14 12:09:30 -0500134 if CONF.validation.run_validation:
135 linux_client = remote_client.RemoteClient(
136 self.get_server_ip(server),
Ghanshyam3390d9f2015-12-25 12:48:02 +0900137 self.ssh_user, password,
Andrea Frittoli (andreaf)2a70a612016-04-29 16:09:13 -0500138 self.validation_resources['keypair']['private_key'],
139 server=server,
140 servers_client=self.client)
Matthew Treinishf06ceb72015-12-14 12:09:30 -0500141 for i in person:
Anna Babich0e408212016-09-19 12:30:56 +0300142 self.assertEqual(base64.decode_as_text(i['contents']),
Matthew Treinishf06ceb72015-12-14 12:09:30 -0500143 linux_client.exec_command(
144 'sudo cat %s' % i['path']))