blob: 019e6c989da0698c321b7495dcd28bad04f54805 [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
Steve Baker9d3cd4f2015-08-07 10:45:26 +120013from oslo_utils import timeutils
14import requests
15import time
16import yaml
17
18from heat_integrationtests.common import exceptions
Rabi Mishra477efc92015-07-31 13:01:45 +053019from heat_integrationtests.functional import functional_base
Steve Baker10a4bc42015-07-23 10:21:02 +120020
21
Rabi Mishra477efc92015-07-31 13:01:45 +053022class ParallelDeploymentsTest(functional_base.FunctionalTestsBase):
Steve Baker9d3cd4f2015-08-07 10:45:26 +120023 server_template = '''
Steve Baker10a4bc42015-07-23 10:21:02 +120024heat_template_version: "2013-05-23"
25parameters:
26 flavor:
27 type: string
28 image:
29 type: string
30 network:
31 type: string
32resources:
33 server:
34 type: OS::Nova::Server
35 properties:
36 image: {get_param: image}
37 flavor: {get_param: flavor}
38 user_data_format: SOFTWARE_CONFIG
Steve Baker9d3cd4f2015-08-07 10:45:26 +120039 networks: [{network: {get_param: network}}]
40outputs:
41 server:
42 value: {get_resource: server}
43'''
44
45 config_template = '''
46heat_template_version: "2013-05-23"
47parameters:
48 server:
49 type: string
50resources:
Steve Baker10a4bc42015-07-23 10:21:02 +120051 config:
52 type: OS::Heat::SoftwareConfig
53 properties:
Steve Baker10a4bc42015-07-23 10:21:02 +120054'''
55
Steve Baker9d3cd4f2015-08-07 10:45:26 +120056 deployment_snippet = '''
57type: OS::Heat::SoftwareDeployments
58properties:
59 config: {get_resource: config}
60 servers: {'0': {get_param: server}}
61'''
Steve Baker10a4bc42015-07-23 10:21:02 +120062
Steve Baker9d3cd4f2015-08-07 10:45:26 +120063 enable_cleanup = True
64
65 def test_deployments_metadata(self):
Steve Baker10a4bc42015-07-23 10:21:02 +120066 parms = {'flavor': self.conf.minimal_instance_type,
67 'network': self.conf.fixed_network_name,
68 'image': self.conf.minimal_image_ref}
69 stack_identifier = self.stack_create(
70 parameters=parms,
Steve Baker9d3cd4f2015-08-07 10:45:26 +120071 template=self.server_template,
72 enable_cleanup=self.enable_cleanup)
73 server_stack = self.client.stacks.get(stack_identifier)
74 server = server_stack.outputs[0]['output_value']
75
76 config_stacks = []
77 # add up to 3 stacks each with up to 3 deployments
78 deploy_count = 0
79 deploy_count = self.deploy_many_configs(
80 stack_identifier,
81 server,
82 config_stacks,
83 2,
84 5,
85 deploy_count)
86 deploy_count = self.deploy_many_configs(
87 stack_identifier,
88 server,
89 config_stacks,
90 3,
91 3,
92 deploy_count)
93
94 self.signal_deployments(stack_identifier)
95 for config_stack in config_stacks:
96 self._wait_for_stack_status(config_stack, 'CREATE_COMPLETE')
97
98 def deploy_many_configs(self, stack_identifier, server, config_stacks,
99 stack_count, deploys_per_stack,
100 deploy_count_start):
101 for a in range(stack_count):
102 config_stacks.append(
103 self.deploy_config(server, deploys_per_stack))
104
105 for config_stack in config_stacks:
106 self.wait_for_deploy_physical_id(config_stack)
107
108 new_count = deploy_count_start + stack_count * deploys_per_stack
109 server_metadata = self.client.resources.metadata(
110 stack_identifier, 'server')
111 self.assertEqual(
112 new_count,
113 len(server_metadata['deployments']),
114 '%s stacks with %s deployments' % (stack_count, deploys_per_stack)
115 )
116 return new_count
117
118 def deploy_config(self, server, deploy_count):
119 parms = {'server': server}
120 template = yaml.safe_load(self.config_template)
121 resources = template['resources']
122 resources['config']['properties'] = {'config': 'x' * 10000}
123 for a in range(deploy_count):
124 resources['dep_%s' % a] = yaml.safe_load(self.deployment_snippet)
125 return self.stack_create(
126 parameters=parms,
127 template=template,
128 enable_cleanup=self.enable_cleanup,
129 expected_status=None)
130
131 def wait_for_deploy_physical_id(self, stack):
132 build_timeout = self.conf.build_timeout
133 build_interval = self.conf.build_interval
134
135 start = timeutils.utcnow()
136 while timeutils.delta_seconds(start,
137 timeutils.utcnow()) < build_timeout:
138 created = True
139 for res in self.client.resources.list(stack, nested_depth='2'):
140 if not res.physical_resource_id:
141 created = False
142 break
143 if created:
144 return
145 time.sleep(build_interval)
146
147 message = ('Deployment resources failed to be created within '
148 'the required time (%s s).' %
149 (build_timeout))
150 raise exceptions.TimeoutException(message)
151
152 def signal_deployments(self, stack_identifier):
153 server_metadata = self.client.resources.metadata(
154 stack_identifier, 'server')
155 for dep in server_metadata['deployments']:
156 iv = dict((i['name'], i['value']) for i in dep['inputs'])
157 sigurl = iv.get('deploy_signal_id')
158 requests.post(sigurl, data='{}',
159 headers={'content-type': None})