blob: bd5d18bd5fb6f701f23f3543b25b86749aa04a33 [file] [log] [blame]
Steve Bakerf6c8f122015-02-10 13:54:46 +13001# 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
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
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
11# under the License.
12
13import six
14
15from heat_integrationtests.common import exceptions
16from heat_integrationtests.common import test
17
18CFG1_SH = '''#!/bin/sh
19echo "Writing to /tmp/$bar"
20echo $foo > /tmp/$bar
21echo -n "The file /tmp/$bar contains `cat /tmp/$bar` for server \
22$deploy_server_id during $deploy_action" > $heat_outputs_path.result
23echo "Written to /tmp/$bar"
24echo "Output to stderr" 1>&2
25'''
26
27CFG3_PP = '''file {'barfile':
28 ensure => file,
29 mode => 0644,
30 path => "/tmp/$::bar",
31 content => "$::foo",
32}
33file {'output_result':
34 ensure => file,
35 path => "$::heat_outputs_path.result",
36 mode => 0644,
37 content => "The file /tmp/$::bar contains $::foo for server \
38$::deploy_server_id during $::deploy_action",
39}'''
40
41
42class SoftwareConfigIntegrationTest(test.HeatIntegrationTest):
43
44 def setUp(self):
45 super(SoftwareConfigIntegrationTest, self).setUp()
46 if self.conf.skip_software_config_tests:
47 self.skipTest('Testing software config disabled in conf, '
48 'skipping')
49 self.client = self.orchestration_client
50 self.template_name = 'test_server_software_config.yaml'
51 self.sub_dir = 'templates'
52 self.stack_name = self._stack_rand_name()
53 self.maxDiff = None
54
55 def launch_stack(self):
56 net = self._get_default_network()
57 self.parameters = {
58 'key_name': self.keypair_name,
59 'flavor': self.conf.instance_type,
60 'image': self.conf.image_ref,
61 'network': net['id']
62 }
63
64 # create the stack
65 self.template = self._load_template(__file__, self.template_name,
66 self.sub_dir)
67 self.stack_create(
68 stack_name=self.stack_name,
69 template=self.template,
70 parameters=self.parameters,
71 files={
72 'cfg1.sh': CFG1_SH,
73 'cfg3.pp': CFG3_PP
74 },
75 expected_status=None)
76
77 self.stack = self.client.stacks.get(self.stack_name)
78 self.stack_identifier = '%s/%s' % (self.stack_name, self.stack.id)
79
80 def check_stack(self):
81 sid = self.stack_identifier
82 for res in ('cfg2a', 'cfg2b', 'cfg1', 'cfg3', 'server'):
83 self._wait_for_resource_status(
84 sid, res, 'CREATE_COMPLETE')
85
86 server_resource = self.client.resources.get(sid, 'server')
87 server_id = server_resource.physical_resource_id
88 server = self.compute_client.servers.get(server_id)
89
90 try:
91 # wait for each deployment to contribute their
92 # config to resource
93 for res in ('dep2b', 'dep1', 'dep3'):
94 self._wait_for_resource_status(
95 sid, res, 'CREATE_IN_PROGRESS')
96
97 server_metadata = self.client.resources.metadata(sid, 'server')
98 deployments = dict((d['name'], d) for d in
99 server_metadata['deployments'])
100
101 for res in ('dep2a', 'dep2b', 'dep1', 'dep3'):
102 self._wait_for_resource_status(
103 sid, res, 'CREATE_COMPLETE')
104 except (exceptions.StackResourceBuildErrorException,
105 exceptions.TimeoutException) as e:
106 self._log_console_output(servers=[server])
107 raise e
108
109 self._wait_for_stack_status(sid, 'CREATE_COMPLETE')
110
111 complete_server_metadata = self.client.resources.metadata(
112 sid, 'server')
113 # ensure any previously available deployments haven't changed so
114 # config isn't re-triggered
115 complete_deployments = dict((d['name'], d) for d in
116 complete_server_metadata['deployments'])
117 for k, v in six.iteritems(deployments):
118 self.assertEqual(v, complete_deployments[k])
119
120 stack = self.client.stacks.get(sid)
121
122 res1 = self._stack_output(stack, 'res1')
123 self.assertEqual(
124 'The file %s contains %s for server %s during %s' % (
125 '/tmp/baaaaa', 'fooooo', server_id, 'CREATE'),
126 res1['result'])
127 self.assertEqual(0, res1['status_code'])
128 self.assertEqual('Output to stderr\n', res1['stderr'])
129 self.assertTrue(len(res1['stdout']) > 0)
130
131 res2 = self._stack_output(stack, 'res2')
132 self.assertEqual(
133 'The file %s contains %s for server %s during %s' % (
134 '/tmp/cfn-init-foo', 'barrr', server_id, 'CREATE'),
135 res2['result'])
136 self.assertEqual(0, res2['status_code'])
137 self.assertEqual('', res2['stderr'])
138 self.assertEqual('', res2['stdout'])
139
140 res3 = self._stack_output(stack, 'res3')
141 self.assertEqual(
142 'The file %s contains %s for server %s during %s' % (
143 '/tmp/ba', 'fo', server_id, 'CREATE'),
144 res3['result'])
145 self.assertEqual(0, res3['status_code'])
146 self.assertEqual('', res3['stderr'])
147 self.assertTrue(len(res1['stdout']) > 0)
148
149 dep1_resource = self.client.resources.get(sid, 'dep1')
150 dep1_id = dep1_resource.physical_resource_id
151 dep1_dep = self.client.software_deployments.get(dep1_id)
152 self.assertIsNotNone(dep1_dep.updated_time)
153 self.assertNotEqual(dep1_dep.updated_time, dep1_dep.creation_time)
154
155 def test_server_software_config(self):
156 self.assign_keypair()
157 self.launch_stack()
158 self.check_stack()