blob: 4f484e2c2637247a2394f353fe184ab842654071 [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):
Attila Fazekas19044d52013-02-16 07:35:06 +010031
32 @classmethod
Matthew Treinishf06ceb72015-12-14 12:09:30 -050033 def setup_credentials(cls):
34 cls.prepare_instance_network()
35 super(ServerPersonalityTestJSON, cls).setup_credentials()
36
37 @classmethod
Takeaki Matsumotod7e04b22015-09-04 15:13:38 +090038 def skip_checks(cls):
39 super(ServerPersonalityTestJSON, cls).skip_checks()
40 if not CONF.compute_feature_enabled.personality:
41 raise cls.skipException("Nova personality feature disabled")
42
43 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053044 def setup_clients(cls):
45 super(ServerPersonalityTestJSON, cls).setup_clients()
Attila Fazekas19044d52013-02-16 07:35:06 +010046 cls.client = cls.servers_client
Daryl Wallecked8bef32011-12-05 23:02:08 -060047
Matt Riedemannb5720532018-09-19 16:02:05 -040048 # NOTE(mriedem): Marked as slow because personality (file injection) is
49 # deprecated in nova so we don't care as much about running this all the
50 # time (and it's slow).
51 @decorators.attr(type='slow')
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080052 @decorators.idempotent_id('3cfe87fd-115b-4a02-b942-7dc36a337fdf')
Takeaki Matsumotod7e04b22015-09-04 15:13:38 +090053 def test_create_server_with_personality(self):
54 file_contents = 'This is a test file.'
Matthew Treinishf06ceb72015-12-14 12:09:30 -050055 file_path = '/test.txt'
56 personality = [{'path': file_path,
Sirushti Murugesan12dc9732016-07-13 22:49:17 +053057 'contents': base64.encode_as_text(file_contents)}]
Ghanshyam3390d9f2015-12-25 12:48:02 +090058 password = data_utils.rand_password()
Andrea Frittoli9f416dd2017-08-10 15:38:00 +010059 validation_resources = self.get_test_validation_resources(
60 self.os_primary)
61 created_server = self.create_test_server(
62 personality=personality, adminPass=password, wait_until='ACTIVE',
63 validatable=True,
64 validation_resources=validation_resources)
65 self.addCleanup(waiters.wait_for_server_termination,
66 self.servers_client, created_server['id'])
67 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
68 self.servers_client.delete_server,
69 created_server['id'])
Yaroslav Lobankov77946eb2015-12-21 21:25:18 +030070 server = self.client.show_server(created_server['id'])['server']
Matthew Treinishf06ceb72015-12-14 12:09:30 -050071 if CONF.validation.run_validation:
72 linux_client = remote_client.RemoteClient(
Andrea Frittoli9f416dd2017-08-10 15:38:00 +010073 self.get_server_ip(server, validation_resources),
Ghanshyam3390d9f2015-12-25 12:48:02 +090074 self.ssh_user, password,
Andrea Frittoli9f416dd2017-08-10 15:38:00 +010075 validation_resources['keypair']['private_key'],
Andrea Frittoli (andreaf)2a70a612016-04-29 16:09:13 -050076 server=server,
77 servers_client=self.client)
Matthew Treinishf06ceb72015-12-14 12:09:30 -050078 self.assertEqual(file_contents,
79 linux_client.exec_command(
80 'sudo cat %s' % file_path))
Takeaki Matsumotod7e04b22015-09-04 15:13:38 +090081
Matt Riedemannb5720532018-09-19 16:02:05 -040082 # NOTE(mriedem): Marked as slow because personality (file injection) is
83 # deprecated in nova so we don't care as much about running this all the
84 # time (and it's slow).
85 @decorators.attr(type='slow')
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080086 @decorators.idempotent_id('128966d8-71fc-443c-8cab-08e24114ecc9')
Takeaki Matsumotod7e04b22015-09-04 15:13:38 +090087 def test_rebuild_server_with_personality(self):
Andrea Frittoli9f416dd2017-08-10 15:38:00 +010088 validation_resources = self.get_test_validation_resources(
89 self.os_primary)
90 server = self.create_test_server(
91 wait_until='ACTIVE', validatable=True,
92 validation_resources=validation_resources)
Matthew Treinishf06ceb72015-12-14 12:09:30 -050093 server_id = server['id']
Andrea Frittoli9f416dd2017-08-10 15:38:00 +010094 self.addCleanup(waiters.wait_for_server_termination,
95 self.servers_client, server_id)
96 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
97 self.servers_client.delete_server, server_id)
Takeaki Matsumotod7e04b22015-09-04 15:13:38 +090098 file_contents = 'Test server rebuild.'
99 personality = [{'path': 'rebuild.txt',
Sirushti Murugesan12dc9732016-07-13 22:49:17 +0530100 'contents': base64.encode_as_text(file_contents)}]
Matthew Treinishf06ceb72015-12-14 12:09:30 -0500101 rebuilt_server = self.client.rebuild_server(server_id,
102 self.image_ref_alt,
103 personality=personality)
104 waiters.wait_for_server_status(self.client, server_id, 'ACTIVE')
105 self.assertEqual(self.image_ref_alt,
106 rebuilt_server['server']['image']['id'])
Takeaki Matsumotod7e04b22015-09-04 15:13:38 +0900107
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -0800108 @decorators.idempotent_id('176cd8c9-b9e8-48ee-a480-180beab292bf')
Daryl Wallecked8bef32011-12-05 23:02:08 -0600109 def test_personality_files_exceed_limit(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500110 # Server creation should fail if greater than the maximum allowed
111 # number of files are injected into the server.
Daryl Wallecked8bef32011-12-05 23:02:08 -0600112 file_contents = 'This is a test file.'
113 personality = []
zhuflb61942d2017-10-13 09:59:44 +0800114 limits = self.limits_client.show_limits()['limits']
Ken'ichi Ohmichib93e6762015-06-15 07:11:29 +0000115 max_file_limit = limits['absolute']['maxPersonality']
ghanshyamaae07812014-12-17 11:38:06 +0900116 if max_file_limit == -1:
117 raise self.skipException("No limit for personality files")
zhufl44cdf152017-02-21 11:21:57 +0800118 for i in range(0, max_file_limit + 1):
Daryl Wallecked8bef32011-12-05 23:02:08 -0600119 path = 'etc/test' + str(i) + '.txt'
120 personality.append({'path': path,
Sirushti Murugesan12dc9732016-07-13 22:49:17 +0530121 'contents': base64.encode_as_text(
122 file_contents)})
Ken'ichi Ohmichi20f43ed2014-08-05 00:33:42 +0000123 # A 403 Forbidden or 413 Overlimit (old behaviour) exception
124 # will be raised when out of quota
Masayuki Igawa6b1cd292015-02-16 11:11:55 +0900125 self.assertRaises((lib_exc.Forbidden, lib_exc.OverLimit),
Ken'ichi Ohmichi20f43ed2014-08-05 00:33:42 +0000126 self.create_test_server, personality=personality)
Daryl Wallecked8bef32011-12-05 23:02:08 -0600127
Matt Riedemannb5720532018-09-19 16:02:05 -0400128 # NOTE(mriedem): Marked as slow because personality (file injection) is
129 # deprecated in nova so we don't care as much about running this all the
130 # time (and it's slow).
131 @decorators.attr(type='slow')
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -0800132 @decorators.idempotent_id('52f12ee8-5180-40cc-b417-31572ea3d555')
Daryl Wallecked8bef32011-12-05 23:02:08 -0600133 def test_can_create_server_with_max_number_personality_files(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500134 # Server should be created successfully if maximum allowed number of
135 # files is injected into the server during creation.
saradpatele6062f62013-03-11 01:17:32 -0700136 file_contents = 'This is a test file.'
zhuflb61942d2017-10-13 09:59:44 +0800137 limits = self.limits_client.show_limits()['limits']
Ken'ichi Ohmichib93e6762015-06-15 07:11:29 +0000138 max_file_limit = limits['absolute']['maxPersonality']
ghanshyamaae07812014-12-17 11:38:06 +0900139 if max_file_limit == -1:
140 raise self.skipException("No limit for personality files")
saradpatele6062f62013-03-11 01:17:32 -0700141 person = []
zhufl44cdf152017-02-21 11:21:57 +0800142 for i in range(0, max_file_limit):
Andrea Frittoli9fb9d552016-12-05 12:22:25 +0000143 # NOTE(andreaf) The cirros disk image is blank before boot
144 # so we can only inject safely to /
145 path = '/test' + str(i) + '.txt'
saradpatele6062f62013-03-11 01:17:32 -0700146 person.append({
147 'path': path,
zhufl552608a2016-12-05 14:13:58 +0800148 'contents': base64.encode_as_text(file_contents + str(i)),
saradpatele6062f62013-03-11 01:17:32 -0700149 })
Ghanshyam3390d9f2015-12-25 12:48:02 +0900150 password = data_utils.rand_password()
Andrea Frittoli9f416dd2017-08-10 15:38:00 +0100151 validation_resources = self.get_test_validation_resources(
152 self.os_primary)
153 created_server = self.create_test_server(
154 personality=person, adminPass=password, wait_until='ACTIVE',
155 validatable=True, validation_resources=validation_resources)
156 self.addCleanup(waiters.wait_for_server_termination,
157 self.servers_client, created_server['id'])
158 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
159 self.servers_client.delete_server,
160 created_server['id'])
Yaroslav Lobankov77946eb2015-12-21 21:25:18 +0300161 server = self.client.show_server(created_server['id'])['server']
Matthew Treinishf06ceb72015-12-14 12:09:30 -0500162 if CONF.validation.run_validation:
163 linux_client = remote_client.RemoteClient(
Andrea Frittoli9f416dd2017-08-10 15:38:00 +0100164 self.get_server_ip(server, validation_resources),
Ghanshyam3390d9f2015-12-25 12:48:02 +0900165 self.ssh_user, password,
Andrea Frittoli9f416dd2017-08-10 15:38:00 +0100166 validation_resources['keypair']['private_key'],
Andrea Frittoli (andreaf)2a70a612016-04-29 16:09:13 -0500167 server=server,
168 servers_client=self.client)
Matthew Treinishf06ceb72015-12-14 12:09:30 -0500169 for i in person:
Anna Babich0e408212016-09-19 12:30:56 +0300170 self.assertEqual(base64.decode_as_text(i['contents']),
Matthew Treinishf06ceb72015-12-14 12:09:30 -0500171 linux_client.exec_command(
172 'sudo cat %s' % i['path']))