blob: 860d6882663542e8498fc3a497e1ef2c9b1b372e [file] [log] [blame]
Steve Baker10a4bc42015-07-23 10:21:02 +12001# 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
Thomas Herve2ce4bda2016-01-22 17:55:55 +010013import json
14import os
Steve Baker9d3cd4f2015-08-07 10:45:26 +120015import requests
Thomas Herve2ce4bda2016-01-22 17:55:55 +010016import subprocess
17import tempfile
Steve Baker9d3cd4f2015-08-07 10:45:26 +120018import time
19import yaml
20
Thomas Herve2ce4bda2016-01-22 17:55:55 +010021from oslo_utils import timeutils
22
Steve Baker9d3cd4f2015-08-07 10:45:26 +120023from heat_integrationtests.common import exceptions
Rabi Mishra477efc92015-07-31 13:01:45 +053024from heat_integrationtests.functional import functional_base
Steve Baker10a4bc42015-07-23 10:21:02 +120025
26
Rabi Mishra477efc92015-07-31 13:01:45 +053027class ParallelDeploymentsTest(functional_base.FunctionalTestsBase):
Steve Baker9d3cd4f2015-08-07 10:45:26 +120028 server_template = '''
Steve Baker10a4bc42015-07-23 10:21:02 +120029heat_template_version: "2013-05-23"
30parameters:
31 flavor:
32 type: string
33 image:
34 type: string
35 network:
36 type: string
37resources:
38 server:
39 type: OS::Nova::Server
40 properties:
41 image: {get_param: image}
42 flavor: {get_param: flavor}
43 user_data_format: SOFTWARE_CONFIG
Steve Baker9d3cd4f2015-08-07 10:45:26 +120044 networks: [{network: {get_param: network}}]
45outputs:
46 server:
47 value: {get_resource: server}
48'''
49
50 config_template = '''
51heat_template_version: "2013-05-23"
52parameters:
53 server:
54 type: string
55resources:
Steve Baker10a4bc42015-07-23 10:21:02 +120056 config:
57 type: OS::Heat::SoftwareConfig
58 properties:
Steve Baker10a4bc42015-07-23 10:21:02 +120059'''
60
Steve Baker9d3cd4f2015-08-07 10:45:26 +120061 deployment_snippet = '''
62type: OS::Heat::SoftwareDeployments
63properties:
64 config: {get_resource: config}
65 servers: {'0': {get_param: server}}
66'''
Steve Baker10a4bc42015-07-23 10:21:02 +120067
Steve Baker9d3cd4f2015-08-07 10:45:26 +120068 enable_cleanup = True
69
70 def test_deployments_metadata(self):
Steve Baker10a4bc42015-07-23 10:21:02 +120071 parms = {'flavor': self.conf.minimal_instance_type,
72 'network': self.conf.fixed_network_name,
73 'image': self.conf.minimal_image_ref}
74 stack_identifier = self.stack_create(
75 parameters=parms,
Steve Baker9d3cd4f2015-08-07 10:45:26 +120076 template=self.server_template,
77 enable_cleanup=self.enable_cleanup)
78 server_stack = self.client.stacks.get(stack_identifier)
79 server = server_stack.outputs[0]['output_value']
80
81 config_stacks = []
82 # add up to 3 stacks each with up to 3 deployments
83 deploy_count = 0
84 deploy_count = self.deploy_many_configs(
85 stack_identifier,
86 server,
87 config_stacks,
88 2,
89 5,
90 deploy_count)
Oleksii Chuprykova064e282015-08-30 09:05:32 +030091 self.deploy_many_configs(
Steve Baker9d3cd4f2015-08-07 10:45:26 +120092 stack_identifier,
93 server,
94 config_stacks,
95 3,
96 3,
97 deploy_count)
98
99 self.signal_deployments(stack_identifier)
100 for config_stack in config_stacks:
101 self._wait_for_stack_status(config_stack, 'CREATE_COMPLETE')
102
Oleksii Chuprykova064e282015-08-30 09:05:32 +0300103 def deploy_many_configs(self, stack, server, config_stacks,
Steve Baker9d3cd4f2015-08-07 10:45:26 +1200104 stack_count, deploys_per_stack,
105 deploy_count_start):
106 for a in range(stack_count):
107 config_stacks.append(
108 self.deploy_config(server, deploys_per_stack))
109
Steve Baker9d3cd4f2015-08-07 10:45:26 +1200110 new_count = deploy_count_start + stack_count * deploys_per_stack
Oleksii Chuprykova064e282015-08-30 09:05:32 +0300111 self.wait_for_deploy_metadata_set(stack, new_count)
Steve Baker9d3cd4f2015-08-07 10:45:26 +1200112 return new_count
113
114 def deploy_config(self, server, deploy_count):
115 parms = {'server': server}
116 template = yaml.safe_load(self.config_template)
117 resources = template['resources']
118 resources['config']['properties'] = {'config': 'x' * 10000}
119 for a in range(deploy_count):
120 resources['dep_%s' % a] = yaml.safe_load(self.deployment_snippet)
121 return self.stack_create(
122 parameters=parms,
123 template=template,
124 enable_cleanup=self.enable_cleanup,
125 expected_status=None)
126
Oleksii Chuprykova064e282015-08-30 09:05:32 +0300127 def wait_for_deploy_metadata_set(self, stack, deploy_count):
Steve Baker9d3cd4f2015-08-07 10:45:26 +1200128 build_timeout = self.conf.build_timeout
129 build_interval = self.conf.build_interval
130
131 start = timeutils.utcnow()
132 while timeutils.delta_seconds(start,
133 timeutils.utcnow()) < build_timeout:
Oleksii Chuprykova064e282015-08-30 09:05:32 +0300134 server_metadata = self.client.resources.metadata(
135 stack, 'server')
136 if len(server_metadata['deployments']) == deploy_count:
Steve Baker9d3cd4f2015-08-07 10:45:26 +1200137 return
138 time.sleep(build_interval)
139
140 message = ('Deployment resources failed to be created within '
141 'the required time (%s s).' %
142 (build_timeout))
143 raise exceptions.TimeoutException(message)
144
145 def signal_deployments(self, stack_identifier):
146 server_metadata = self.client.resources.metadata(
147 stack_identifier, 'server')
148 for dep in server_metadata['deployments']:
149 iv = dict((i['name'], i['value']) for i in dep['inputs'])
150 sigurl = iv.get('deploy_signal_id')
151 requests.post(sigurl, data='{}',
tyagi39aa11a2016-03-07 04:47:00 -0800152 headers={'content-type': None},
153 verify=self.verify_cert)
Thomas Herve2ce4bda2016-01-22 17:55:55 +0100154
155
156class ZaqarSignalTransportTest(functional_base.FunctionalTestsBase):
157 server_template = '''
158heat_template_version: "2013-05-23"
159
160parameters:
161 flavor:
162 type: string
163 image:
164 type: string
165 network:
166 type: string
167
168resources:
169 server:
170 type: OS::Nova::Server
171 properties:
172 image: {get_param: image}
173 flavor: {get_param: flavor}
174 user_data_format: SOFTWARE_CONFIG
175 software_config_transport: ZAQAR_MESSAGE
176 networks: [{network: {get_param: network}}]
177 config:
178 type: OS::Heat::SoftwareConfig
179 properties:
180 config: echo 'foo'
181 deployment:
182 type: OS::Heat::SoftwareDeployment
183 properties:
184 config: {get_resource: config}
185 server: {get_resource: server}
186 signal_transport: ZAQAR_SIGNAL
187
188outputs:
189 data:
190 value: {get_attr: [deployment, deploy_stdout]}
191'''
192
193 conf_template = '''
194[zaqar]
195user_id = %(user_id)s
196password = %(password)s
197project_id = %(project_id)s
198auth_url = %(auth_url)s
199queue_id = %(queue_id)s
200 '''
201
202 def test_signal_queues(self):
203 parms = {'flavor': self.conf.minimal_instance_type,
204 'network': self.conf.fixed_network_name,
205 'image': self.conf.minimal_image_ref}
206 stack_identifier = self.stack_create(
207 parameters=parms,
208 template=self.server_template,
209 expected_status=None)
210 metadata = self.wait_for_deploy_metadata_set(stack_identifier)
211 config = metadata['os-collect-config']['zaqar']
212 conf_content = self.conf_template % config
213 fd, temp_path = tempfile.mkstemp()
214 os.write(fd, conf_content)
215 os.close(fd)
216 cmd = ['os-collect-config', '--one-time',
217 '--config-file=%s' % temp_path, 'zaqar']
218 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
219 stdout_value = proc.communicate()[0]
220 data = json.loads(stdout_value)
221 self.assertEqual(config, data['zaqar']['os-collect-config']['zaqar'])
222 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
223 stdout_value = proc.communicate()[0]
224 data = json.loads(stdout_value)
225
226 fd, temp_path = tempfile.mkstemp()
227 os.write(fd, json.dumps(data['zaqar']['deployments'][0]))
228 os.close(fd)
229 cmd = ['python', self.conf.heat_config_notify_script, temp_path]
230 proc = subprocess.Popen(cmd,
231 stderr=subprocess.PIPE,
232 stdin=subprocess.PIPE)
233 proc.communicate(json.dumps({'deploy_stdout': 'here!'}))
234 self._wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE')
235 stack = self.client.stacks.get(stack_identifier)
236 self.assertEqual('here!', stack.outputs[0]['output_value'])
237
238 def wait_for_deploy_metadata_set(self, stack):
239 build_timeout = self.conf.build_timeout
240 build_interval = self.conf.build_interval
241
242 start = timeutils.utcnow()
243 while timeutils.delta_seconds(start,
244 timeutils.utcnow()) < build_timeout:
245 server_metadata = self.client.resources.metadata(
246 stack, 'server')
247 if server_metadata.get('deployments'):
248 return server_metadata
249 time.sleep(build_interval)
250
251 message = ('Deployment resources failed to be created within '
252 'the required time (%s s).' %
253 (build_timeout))
254 raise exceptions.TimeoutException(message)