blob: df350423238cbd99ce4deeedcb82d171e91cb677 [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
rabic333f762016-09-29 08:34:03 +053045 def setUp(self):
46 super(SoftwareConfigIntegrationTest, self).setUp()
47 if not self.conf.image_ref:
48 raise self.skipException("No image configured to test")
49 if not self.conf.instance_type:
50 raise self.skipException("No flavor configured to test")
51
Steve Baker8c9aee12015-03-10 16:17:45 +130052 def check_stack(self):
53 sid = self.stack_identifier
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +040054 # Check that all stack resources were created
Steve Bakerf6c8f122015-02-10 13:54:46 +130055 for res in ('cfg2a', 'cfg2b', 'cfg1', 'cfg3', 'server'):
56 self._wait_for_resource_status(
57 sid, res, 'CREATE_COMPLETE')
58
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)
62
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +040063 # Waiting for each deployment to contribute their
64 # config to resource
Steve Bakerf6c8f122015-02-10 13:54:46 +130065 try:
Steve Bakerf6c8f122015-02-10 13:54:46 +130066 for res in ('dep2b', 'dep1', 'dep3'):
67 self._wait_for_resource_status(
68 sid, res, 'CREATE_IN_PROGRESS')
69
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +040070 server_metadata = self.client.resources.metadata(
71 sid, 'server')
Steve Bakerf6c8f122015-02-10 13:54:46 +130072 deployments = dict((d['name'], d) for d in
73 server_metadata['deployments'])
74
75 for res in ('dep2a', 'dep2b', 'dep1', 'dep3'):
76 self._wait_for_resource_status(
77 sid, res, 'CREATE_COMPLETE')
Steve Baker803f1502015-03-11 13:47:08 +130078 finally:
79 # attempt to log the server console regardless of deployments
80 # going to complete. This allows successful and failed boot
81 # logs to be compared
82 self._log_console_output(servers=[server])
Steve Bakerf6c8f122015-02-10 13:54:46 +130083
Steve Bakerf6c8f122015-02-10 13:54:46 +130084 complete_server_metadata = self.client.resources.metadata(
85 sid, 'server')
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +040086
87 # Ensure any previously available deployments haven't changed so
Steve Bakerf6c8f122015-02-10 13:54:46 +130088 # config isn't re-triggered
89 complete_deployments = dict((d['name'], d) for d in
90 complete_server_metadata['deployments'])
91 for k, v in six.iteritems(deployments):
92 self.assertEqual(v, complete_deployments[k])
93
94 stack = self.client.stacks.get(sid)
95
96 res1 = self._stack_output(stack, 'res1')
97 self.assertEqual(
98 'The file %s contains %s for server %s during %s' % (
99 '/tmp/baaaaa', 'fooooo', server_id, 'CREATE'),
100 res1['result'])
101 self.assertEqual(0, res1['status_code'])
102 self.assertEqual('Output to stderr\n', res1['stderr'])
103 self.assertTrue(len(res1['stdout']) > 0)
104
105 res2 = self._stack_output(stack, 'res2')
106 self.assertEqual(
107 'The file %s contains %s for server %s during %s' % (
108 '/tmp/cfn-init-foo', 'barrr', server_id, 'CREATE'),
109 res2['result'])
110 self.assertEqual(0, res2['status_code'])
111 self.assertEqual('', res2['stderr'])
112 self.assertEqual('', res2['stdout'])
113
114 res3 = self._stack_output(stack, 'res3')
115 self.assertEqual(
116 'The file %s contains %s for server %s during %s' % (
117 '/tmp/ba', 'fo', server_id, 'CREATE'),
118 res3['result'])
119 self.assertEqual(0, res3['status_code'])
120 self.assertEqual('', res3['stderr'])
121 self.assertTrue(len(res1['stdout']) > 0)
122
123 dep1_resource = self.client.resources.get(sid, 'dep1')
124 dep1_id = dep1_resource.physical_resource_id
125 dep1_dep = self.client.software_deployments.get(dep1_id)
Steve Baker8c9aee12015-03-10 16:17:45 +1300126 if hasattr(dep1_dep, 'updated_time'):
127 # Only check updated_time if the attribute exists.
128 # This allows latest heat agent code to be tested with
129 # Juno heat (which doesn't expose updated_time)
130 self.assertIsNotNone(dep1_dep.updated_time)
131 self.assertNotEqual(
132 dep1_dep.updated_time,
133 dep1_dep.creation_time)
Steve Bakerf6c8f122015-02-10 13:54:46 +1300134
135 def test_server_software_config(self):
Peter Razumovskyf0ac9582015-09-24 16:49:03 +0300136 """Check that passed files with scripts are executed on created server.
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +0400137
138 The alternative scenario is the following:
139 1. Create a stack and pass files with scripts.
140 2. Check that all stack resources are created successfully.
141 3. Wait for all deployments.
142 4. Check that stack was created.
143 5. Check stack outputs.
144 """
145
146 parameters = {
147 'key_name': self.keypair_name,
148 'flavor': self.conf.instance_type,
149 'image': self.conf.image_ref,
150 'network': self.net['id']
151 }
152
153 files = {
154 'cfg1.sh': CFG1_SH,
155 'cfg3.pp': CFG3_PP
156 }
157
Steve Baker0b679bb2015-03-11 13:46:42 +1300158 env_files, env = template_utils.process_environment_and_files(
159 self.conf.boot_config_env)
160
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +0400161 # Launch stack
Steve Baker8c9aee12015-03-10 16:17:45 +1300162 self.stack_identifier = self.launch_stack(
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +0400163 template_name='test_server_software_config.yaml',
164 parameters=parameters,
Steve Baker0b679bb2015-03-11 13:46:42 +1300165 files=dict(list(files.items()) + list(env_files.items())),
166 expected_status=None,
167 environment=env
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +0400168 )
169
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +0400170 # Check stack
Steve Baker8c9aee12015-03-10 16:17:45 +1300171 self.check_stack()