1
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2
# not use this file except in compliance with the License. You may obtain
3
# a copy of the License at
5
# http://www.apache.org/licenses/LICENSE-2.0
7
# Unless required by applicable law or agreed to in writing, software
8
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10
# License for the specific language governing permissions and limitations
13
from heatclient.common import template_utils
16
from heat_integrationtests.common import exceptions
17
from heat_integrationtests.scenario import scenario_base
19
CFG1_SH = '''#!/bin/sh
20
echo "Writing to /tmp/$bar"
22
echo -n "The file /tmp/$bar contains `cat /tmp/$bar` for server \
23
$deploy_server_id during $deploy_action" > $heat_outputs_path.result
24
echo "Written to /tmp/$bar"
25
echo "Output to stderr" 1>&2
28
CFG3_PP = '''file {'barfile':
31
path => "/tmp/$::bar",
34
file {'output_result':
36
path => "$::heat_outputs_path.result",
38
content => "The file /tmp/$::bar contains $::foo for server \
39
$::deploy_server_id during $::deploy_action",
43
class SoftwareConfigIntegrationTest(scenario_base.ScenarioTestsBase):
46
super(SoftwareConfigIntegrationTest, self).setUp()
47
if self.conf.skip_software_config_tests:
48
self.skipTest('Testing software config disabled in conf, '
50
self.stack_name = self._stack_rand_name()
52
def check_stack(self):
53
sid = self.stack_identifier
54
# Check that all stack resources were created
55
for res in ('cfg2a', 'cfg2b', 'cfg1', 'cfg3', 'server'):
56
self._wait_for_resource_status(
57
sid, res, 'CREATE_COMPLETE')
59
server_resource = self.client.resources.get(sid, 'server')
60
server_id = server_resource.physical_resource_id
61
server = self.compute_client.servers.get(server_id)
63
# Waiting for each deployment to contribute their
66
for res in ('dep2b', 'dep1', 'dep3'):
67
self._wait_for_resource_status(
68
sid, res, 'CREATE_IN_PROGRESS')
70
server_metadata = self.client.resources.metadata(
72
deployments = dict((d['name'], d) for d in
73
server_metadata['deployments'])
75
for res in ('dep2a', 'dep2b', 'dep1', 'dep3'):
76
self._wait_for_resource_status(
77
sid, res, 'CREATE_COMPLETE')
78
except (exceptions.StackResourceBuildErrorException,
79
exceptions.TimeoutException) as e:
80
self._log_console_output(servers=[server])
83
# Check that stack was fully created
84
self._wait_for_stack_status(sid, 'CREATE_COMPLETE')
86
complete_server_metadata = self.client.resources.metadata(
89
# Ensure any previously available deployments haven't changed so
90
# config isn't re-triggered
91
complete_deployments = dict((d['name'], d) for d in
92
complete_server_metadata['deployments'])
93
for k, v in six.iteritems(deployments):
94
self.assertEqual(v, complete_deployments[k])
96
stack = self.client.stacks.get(sid)
98
res1 = self._stack_output(stack, 'res1')
100
'The file %s contains %s for server %s during %s' % (
101
'/tmp/baaaaa', 'fooooo', server_id, 'CREATE'),
103
self.assertEqual(0, res1['status_code'])
104
self.assertEqual('Output to stderr\n', res1['stderr'])
105
self.assertTrue(len(res1['stdout']) > 0)
107
res2 = self._stack_output(stack, 'res2')
109
'The file %s contains %s for server %s during %s' % (
110
'/tmp/cfn-init-foo', 'barrr', server_id, 'CREATE'),
112
self.assertEqual(0, res2['status_code'])
113
self.assertEqual('', res2['stderr'])
114
self.assertEqual('', res2['stdout'])
116
res3 = self._stack_output(stack, 'res3')
118
'The file %s contains %s for server %s during %s' % (
119
'/tmp/ba', 'fo', server_id, 'CREATE'),
121
self.assertEqual(0, res3['status_code'])
122
self.assertEqual('', res3['stderr'])
123
self.assertTrue(len(res1['stdout']) > 0)
125
dep1_resource = self.client.resources.get(sid, 'dep1')
126
dep1_id = dep1_resource.physical_resource_id
127
dep1_dep = self.client.software_deployments.get(dep1_id)
128
if hasattr(dep1_dep, 'updated_time'):
129
# Only check updated_time if the attribute exists.
130
# This allows latest heat agent code to be tested with
131
# Juno heat (which doesn't expose updated_time)
132
self.assertIsNotNone(dep1_dep.updated_time)
134
dep1_dep.updated_time,
135
dep1_dep.creation_time)
137
def test_server_software_config(self):
139
Check that passed files with scripts are executed on created server.
141
The alternative scenario is the following:
142
1. Create a stack and pass files with scripts.
143
2. Check that all stack resources are created successfully.
144
3. Wait for all deployments.
145
4. Check that stack was created.
146
5. Check stack outputs.
150
'key_name': self.keypair_name,
151
'flavor': self.conf.instance_type,
152
'image': self.conf.image_ref,
153
'network': self.net['id']
161
env_files, env = template_utils.process_environment_and_files(
162
self.conf.boot_config_env)
165
self.stack_identifier = self.launch_stack(
166
stack_name=self.stack_name,
167
template_name='test_server_software_config.yaml',
168
parameters=parameters,
169
files=dict(list(files.items()) + list(env_files.items())),
170
expected_status=None,