blob: af7d671e295ab2a8935288375e10a9cc64e567dc [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)
Oleksii Chuprykova064e282015-08-30 09:05:32 +030086 self.deploy_many_configs(
Steve Baker9d3cd4f2015-08-07 10:45:26 +120087 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
Oleksii Chuprykova064e282015-08-30 09:05:32 +030098 def deploy_many_configs(self, stack, server, config_stacks,
Steve Baker9d3cd4f2015-08-07 10:45:26 +120099 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
Steve Baker9d3cd4f2015-08-07 10:45:26 +1200105 new_count = deploy_count_start + stack_count * deploys_per_stack
Oleksii Chuprykova064e282015-08-30 09:05:32 +0300106 self.wait_for_deploy_metadata_set(stack, new_count)
Steve Baker9d3cd4f2015-08-07 10:45:26 +1200107 return new_count
108
109 def deploy_config(self, server, deploy_count):
110 parms = {'server': server}
111 template = yaml.safe_load(self.config_template)
112 resources = template['resources']
113 resources['config']['properties'] = {'config': 'x' * 10000}
114 for a in range(deploy_count):
115 resources['dep_%s' % a] = yaml.safe_load(self.deployment_snippet)
116 return self.stack_create(
117 parameters=parms,
118 template=template,
119 enable_cleanup=self.enable_cleanup,
120 expected_status=None)
121
Oleksii Chuprykova064e282015-08-30 09:05:32 +0300122 def wait_for_deploy_metadata_set(self, stack, deploy_count):
Steve Baker9d3cd4f2015-08-07 10:45:26 +1200123 build_timeout = self.conf.build_timeout
124 build_interval = self.conf.build_interval
125
126 start = timeutils.utcnow()
127 while timeutils.delta_seconds(start,
128 timeutils.utcnow()) < build_timeout:
Oleksii Chuprykova064e282015-08-30 09:05:32 +0300129 server_metadata = self.client.resources.metadata(
130 stack, 'server')
131 if len(server_metadata['deployments']) == deploy_count:
Steve Baker9d3cd4f2015-08-07 10:45:26 +1200132 return
133 time.sleep(build_interval)
134
135 message = ('Deployment resources failed to be created within '
136 'the required time (%s s).' %
137 (build_timeout))
138 raise exceptions.TimeoutException(message)
139
140 def signal_deployments(self, stack_identifier):
141 server_metadata = self.client.resources.metadata(
142 stack_identifier, 'server')
143 for dep in server_metadata['deployments']:
144 iv = dict((i['name'], i['value']) for i in dep['inputs'])
145 sigurl = iv.get('deploy_signal_id')
146 requests.post(sigurl, data='{}',
147 headers={'content-type': None})