blob: ec12fda17b4881881a3bf04704fb3b3f9841ef85 [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
Steve Baker0b679bb2015-03-11 13:46:42 +130013from heatclient.common import template_utils
Steve Bakerf6c8f122015-02-10 13:54:46 +130014import six
15
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +040016from heat_integrationtests.scenario import scenario_base
Steve Bakerf6c8f122015-02-10 13:54:46 +130017
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",
Oleg Khavroshin6c7211c2016-01-12 16:38:13 +030039}
40'''
Steve Bakerf6c8f122015-02-10 13:54:46 +130041
42
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +040043class SoftwareConfigIntegrationTest(scenario_base.ScenarioTestsBase):
Steve Bakerf6c8f122015-02-10 13:54:46 +130044
Steve Baker8c9aee12015-03-10 16:17:45 +130045 def check_stack(self):
46 sid = self.stack_identifier
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +040047 # Check that all stack resources were created
Steve Bakerf6c8f122015-02-10 13:54:46 +130048 for res in ('cfg2a', 'cfg2b', 'cfg1', 'cfg3', 'server'):
49 self._wait_for_resource_status(
50 sid, res, 'CREATE_COMPLETE')
51
52 server_resource = self.client.resources.get(sid, 'server')
53 server_id = server_resource.physical_resource_id
54 server = self.compute_client.servers.get(server_id)
55
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +040056 # Waiting for each deployment to contribute their
57 # config to resource
Steve Bakerf6c8f122015-02-10 13:54:46 +130058 try:
Steve Bakerf6c8f122015-02-10 13:54:46 +130059 for res in ('dep2b', 'dep1', 'dep3'):
60 self._wait_for_resource_status(
61 sid, res, 'CREATE_IN_PROGRESS')
62
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +040063 server_metadata = self.client.resources.metadata(
64 sid, 'server')
Steve Bakerf6c8f122015-02-10 13:54:46 +130065 deployments = dict((d['name'], d) for d in
66 server_metadata['deployments'])
67
68 for res in ('dep2a', 'dep2b', 'dep1', 'dep3'):
69 self._wait_for_resource_status(
70 sid, res, 'CREATE_COMPLETE')
Steve Baker803f1502015-03-11 13:47:08 +130071 finally:
72 # attempt to log the server console regardless of deployments
73 # going to complete. This allows successful and failed boot
74 # logs to be compared
75 self._log_console_output(servers=[server])
Steve Bakerf6c8f122015-02-10 13:54:46 +130076
Steve Bakerf6c8f122015-02-10 13:54:46 +130077 complete_server_metadata = self.client.resources.metadata(
78 sid, 'server')
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +040079
80 # Ensure any previously available deployments haven't changed so
Steve Bakerf6c8f122015-02-10 13:54:46 +130081 # config isn't re-triggered
82 complete_deployments = dict((d['name'], d) for d in
83 complete_server_metadata['deployments'])
84 for k, v in six.iteritems(deployments):
85 self.assertEqual(v, complete_deployments[k])
86
87 stack = self.client.stacks.get(sid)
88
89 res1 = self._stack_output(stack, 'res1')
90 self.assertEqual(
91 'The file %s contains %s for server %s during %s' % (
92 '/tmp/baaaaa', 'fooooo', server_id, 'CREATE'),
93 res1['result'])
94 self.assertEqual(0, res1['status_code'])
95 self.assertEqual('Output to stderr\n', res1['stderr'])
96 self.assertTrue(len(res1['stdout']) > 0)
97
98 res2 = self._stack_output(stack, 'res2')
99 self.assertEqual(
100 'The file %s contains %s for server %s during %s' % (
101 '/tmp/cfn-init-foo', 'barrr', server_id, 'CREATE'),
102 res2['result'])
103 self.assertEqual(0, res2['status_code'])
104 self.assertEqual('', res2['stderr'])
105 self.assertEqual('', res2['stdout'])
106
107 res3 = self._stack_output(stack, 'res3')
108 self.assertEqual(
109 'The file %s contains %s for server %s during %s' % (
110 '/tmp/ba', 'fo', server_id, 'CREATE'),
111 res3['result'])
112 self.assertEqual(0, res3['status_code'])
113 self.assertEqual('', res3['stderr'])
114 self.assertTrue(len(res1['stdout']) > 0)
115
116 dep1_resource = self.client.resources.get(sid, 'dep1')
117 dep1_id = dep1_resource.physical_resource_id
118 dep1_dep = self.client.software_deployments.get(dep1_id)
Steve Baker8c9aee12015-03-10 16:17:45 +1300119 if hasattr(dep1_dep, 'updated_time'):
120 # Only check updated_time if the attribute exists.
121 # This allows latest heat agent code to be tested with
122 # Juno heat (which doesn't expose updated_time)
123 self.assertIsNotNone(dep1_dep.updated_time)
124 self.assertNotEqual(
125 dep1_dep.updated_time,
126 dep1_dep.creation_time)
Steve Bakerf6c8f122015-02-10 13:54:46 +1300127
128 def test_server_software_config(self):
Peter Razumovskyf0ac9582015-09-24 16:49:03 +0300129 """Check that passed files with scripts are executed on created server.
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +0400130
131 The alternative scenario is the following:
132 1. Create a stack and pass files with scripts.
133 2. Check that all stack resources are created successfully.
134 3. Wait for all deployments.
135 4. Check that stack was created.
136 5. Check stack outputs.
137 """
138
139 parameters = {
140 'key_name': self.keypair_name,
141 'flavor': self.conf.instance_type,
142 'image': self.conf.image_ref,
143 'network': self.net['id']
144 }
145
146 files = {
147 'cfg1.sh': CFG1_SH,
148 'cfg3.pp': CFG3_PP
149 }
150
Steve Baker0b679bb2015-03-11 13:46:42 +1300151 env_files, env = template_utils.process_environment_and_files(
152 self.conf.boot_config_env)
153
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +0400154 # Launch stack
Steve Baker8c9aee12015-03-10 16:17:45 +1300155 self.stack_identifier = self.launch_stack(
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +0400156 template_name='test_server_software_config.yaml',
157 parameters=parameters,
Steve Baker0b679bb2015-03-11 13:46:42 +1300158 files=dict(list(files.items()) + list(env_files.items())),
159 expected_status=None,
160 environment=env
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +0400161 )
162
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +0400163 # Check stack
Steve Baker8c9aee12015-03-10 16:17:45 +1300164 self.check_stack()