blob: ba2adbb4e659e40a2e6608a7fe063273a6e6c379 [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
Andrea Frittoli9f416dd2017-08-10 15:38:00 +010023from tempest.lib.common.utils import test_utils
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080024from tempest.lib import decorators
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050025from tempest.lib import exceptions as lib_exc
Jay Pipes13b479b2012-06-11 14:52:27 -040026
Takeaki Matsumotod7e04b22015-09-04 15:13:38 +090027CONF = config.CONF
28
Daryl Wallecked8bef32011-12-05 23:02:08 -060029
ivan-zhuf2b00502013-10-18 10:06:52 +080030class ServerPersonalityTestJSON(base.BaseV2ComputeTest):
zhufl67b3d382020-05-25 13:35:12 +080031 """Test servers with injected files"""
Attila Fazekas19044d52013-02-16 07:35:06 +010032
33 @classmethod
Matthew Treinishf06ceb72015-12-14 12:09:30 -050034 def setup_credentials(cls):
35 cls.prepare_instance_network()
36 super(ServerPersonalityTestJSON, cls).setup_credentials()
37
38 @classmethod
Takeaki Matsumotod7e04b22015-09-04 15:13:38 +090039 def skip_checks(cls):
40 super(ServerPersonalityTestJSON, cls).skip_checks()
41 if not CONF.compute_feature_enabled.personality:
42 raise cls.skipException("Nova personality feature disabled")
43
44 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053045 def setup_clients(cls):
46 super(ServerPersonalityTestJSON, cls).setup_clients()
Attila Fazekas19044d52013-02-16 07:35:06 +010047 cls.client = cls.servers_client
Daryl Wallecked8bef32011-12-05 23:02:08 -060048
Matt Riedemannb5720532018-09-19 16:02:05 -040049 # NOTE(mriedem): Marked as slow because personality (file injection) is
50 # deprecated in nova so we don't care as much about running this all the
51 # time (and it's slow).
52 @decorators.attr(type='slow')
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):
zhufl67b3d382020-05-25 13:35:12 +080055 """Test creating server with file injection"""
Takeaki Matsumotod7e04b22015-09-04 15:13:38 +090056 file_contents = 'This is a test file.'
Matthew Treinishf06ceb72015-12-14 12:09:30 -050057 file_path = '/test.txt'
58 personality = [{'path': file_path,
Sirushti Murugesan12dc9732016-07-13 22:49:17 +053059 'contents': base64.encode_as_text(file_contents)}]
Ghanshyam3390d9f2015-12-25 12:48:02 +090060 password = data_utils.rand_password()
Andrea Frittoli9f416dd2017-08-10 15:38:00 +010061 validation_resources = self.get_test_validation_resources(
62 self.os_primary)
63 created_server = self.create_test_server(
64 personality=personality, adminPass=password, wait_until='ACTIVE',
65 validatable=True,
66 validation_resources=validation_resources)
67 self.addCleanup(waiters.wait_for_server_termination,
68 self.servers_client, created_server['id'])
69 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
70 self.servers_client.delete_server,
71 created_server['id'])
Yaroslav Lobankov77946eb2015-12-21 21:25:18 +030072 server = self.client.show_server(created_server['id'])['server']
Matthew Treinishf06ceb72015-12-14 12:09:30 -050073 if CONF.validation.run_validation:
74 linux_client = remote_client.RemoteClient(
Andrea Frittoli9f416dd2017-08-10 15:38:00 +010075 self.get_server_ip(server, validation_resources),
Ghanshyam3390d9f2015-12-25 12:48:02 +090076 self.ssh_user, password,
Andrea Frittoli9f416dd2017-08-10 15:38:00 +010077 validation_resources['keypair']['private_key'],
Andrea Frittoli (andreaf)2a70a612016-04-29 16:09:13 -050078 server=server,
79 servers_client=self.client)
Matthew Treinishf06ceb72015-12-14 12:09:30 -050080 self.assertEqual(file_contents,
81 linux_client.exec_command(
82 'sudo cat %s' % file_path))
Takeaki Matsumotod7e04b22015-09-04 15:13:38 +090083
Matt Riedemannb5720532018-09-19 16:02:05 -040084 # NOTE(mriedem): Marked as slow because personality (file injection) is
85 # deprecated in nova so we don't care as much about running this all the
86 # time (and it's slow).
87 @decorators.attr(type='slow')
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080088 @decorators.idempotent_id('128966d8-71fc-443c-8cab-08e24114ecc9')
Takeaki Matsumotod7e04b22015-09-04 15:13:38 +090089 def test_rebuild_server_with_personality(self):
zhufl67b3d382020-05-25 13:35:12 +080090 """Test injecting file when rebuilding server"""
Andrea Frittoli9f416dd2017-08-10 15:38:00 +010091 validation_resources = self.get_test_validation_resources(
92 self.os_primary)
93 server = self.create_test_server(
94 wait_until='ACTIVE', validatable=True,
95 validation_resources=validation_resources)
Matthew Treinishf06ceb72015-12-14 12:09:30 -050096 server_id = server['id']
Andrea Frittoli9f416dd2017-08-10 15:38:00 +010097 self.addCleanup(waiters.wait_for_server_termination,
98 self.servers_client, server_id)
99 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
100 self.servers_client.delete_server, server_id)
Takeaki Matsumotod7e04b22015-09-04 15:13:38 +0900101 file_contents = 'Test server rebuild.'
102 personality = [{'path': 'rebuild.txt',
Sirushti Murugesan12dc9732016-07-13 22:49:17 +0530103 'contents': base64.encode_as_text(file_contents)}]
Matthew Treinishf06ceb72015-12-14 12:09:30 -0500104 rebuilt_server = self.client.rebuild_server(server_id,
105 self.image_ref_alt,
106 personality=personality)
107 waiters.wait_for_server_status(self.client, server_id, 'ACTIVE')
108 self.assertEqual(self.image_ref_alt,
109 rebuilt_server['server']['image']['id'])
Takeaki Matsumotod7e04b22015-09-04 15:13:38 +0900110
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -0800111 @decorators.idempotent_id('176cd8c9-b9e8-48ee-a480-180beab292bf')
Daryl Wallecked8bef32011-12-05 23:02:08 -0600112 def test_personality_files_exceed_limit(self):
zhufl67b3d382020-05-25 13:35:12 +0800113 """Test creating server with injected files over limitation
114
115 Server creation should fail if greater than the maximum allowed
116 number of files are injected into the server.
117 """
Daryl Wallecked8bef32011-12-05 23:02:08 -0600118 file_contents = 'This is a test file.'
119 personality = []
zhuflb61942d2017-10-13 09:59:44 +0800120 limits = self.limits_client.show_limits()['limits']
Ken'ichi Ohmichib93e6762015-06-15 07:11:29 +0000121 max_file_limit = limits['absolute']['maxPersonality']
ghanshyamaae07812014-12-17 11:38:06 +0900122 if max_file_limit == -1:
123 raise self.skipException("No limit for personality files")
zhufl44cdf152017-02-21 11:21:57 +0800124 for i in range(0, max_file_limit + 1):
Daryl Wallecked8bef32011-12-05 23:02:08 -0600125 path = 'etc/test' + str(i) + '.txt'
126 personality.append({'path': path,
Sirushti Murugesan12dc9732016-07-13 22:49:17 +0530127 'contents': base64.encode_as_text(
128 file_contents)})
Ken'ichi Ohmichi20f43ed2014-08-05 00:33:42 +0000129 # A 403 Forbidden or 413 Overlimit (old behaviour) exception
130 # will be raised when out of quota
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900131 self.assertRaises((lib_exc.Forbidden, lib_exc.OverLimit),
Ken'ichi Ohmichi20f43ed2014-08-05 00:33:42 +0000132 self.create_test_server, personality=personality)
Daryl Wallecked8bef32011-12-05 23:02:08 -0600133
Matt Riedemannb5720532018-09-19 16:02:05 -0400134 # NOTE(mriedem): Marked as slow because personality (file injection) is
135 # deprecated in nova so we don't care as much about running this all the
136 # time (and it's slow).
137 @decorators.attr(type='slow')
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -0800138 @decorators.idempotent_id('52f12ee8-5180-40cc-b417-31572ea3d555')
Daryl Wallecked8bef32011-12-05 23:02:08 -0600139 def test_can_create_server_with_max_number_personality_files(self):
zhufl67b3d382020-05-25 13:35:12 +0800140 """Test creating server with maximum allowed number of injected files
141
142 Server should be created successfully if maximum allowed number of
143 files is injected into the server during creation.
144 """
saradpatele6062f62013-03-11 01:17:32 -0700145 file_contents = 'This is a test file.'
zhuflb61942d2017-10-13 09:59:44 +0800146 limits = self.limits_client.show_limits()['limits']
Ken'ichi Ohmichib93e6762015-06-15 07:11:29 +0000147 max_file_limit = limits['absolute']['maxPersonality']
ghanshyamaae07812014-12-17 11:38:06 +0900148 if max_file_limit == -1:
149 raise self.skipException("No limit for personality files")
saradpatele6062f62013-03-11 01:17:32 -0700150 person = []
zhufl44cdf152017-02-21 11:21:57 +0800151 for i in range(0, max_file_limit):
Andrea Frittoli9fb9d552016-12-05 12:22:25 +0000152 # NOTE(andreaf) The cirros disk image is blank before boot
153 # so we can only inject safely to /
154 path = '/test' + str(i) + '.txt'
saradpatele6062f62013-03-11 01:17:32 -0700155 person.append({
156 'path': path,
zhufl552608a2016-12-05 14:13:58 +0800157 'contents': base64.encode_as_text(file_contents + str(i)),
saradpatele6062f62013-03-11 01:17:32 -0700158 })
Ghanshyam3390d9f2015-12-25 12:48:02 +0900159 password = data_utils.rand_password()
Andrea Frittoli9f416dd2017-08-10 15:38:00 +0100160 validation_resources = self.get_test_validation_resources(
161 self.os_primary)
162 created_server = self.create_test_server(
163 personality=person, adminPass=password, wait_until='ACTIVE',
164 validatable=True, validation_resources=validation_resources)
165 self.addCleanup(waiters.wait_for_server_termination,
166 self.servers_client, created_server['id'])
167 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
168 self.servers_client.delete_server,
169 created_server['id'])
Yaroslav Lobankov77946eb2015-12-21 21:25:18 +0300170 server = self.client.show_server(created_server['id'])['server']
Matthew Treinishf06ceb72015-12-14 12:09:30 -0500171 if CONF.validation.run_validation:
172 linux_client = remote_client.RemoteClient(
Andrea Frittoli9f416dd2017-08-10 15:38:00 +0100173 self.get_server_ip(server, validation_resources),
Ghanshyam3390d9f2015-12-25 12:48:02 +0900174 self.ssh_user, password,
Andrea Frittoli9f416dd2017-08-10 15:38:00 +0100175 validation_resources['keypair']['private_key'],
Andrea Frittoli (andreaf)2a70a612016-04-29 16:09:13 -0500176 server=server,
177 servers_client=self.client)
Matthew Treinishf06ceb72015-12-14 12:09:30 -0500178 for i in person:
Anna Babich0e408212016-09-19 12:30:56 +0300179 self.assertEqual(base64.decode_as_text(i['contents']),
Matthew Treinishf06ceb72015-12-14 12:09:30 -0500180 linux_client.exec_command(
181 'sudo cat %s' % i['path']))