Steve Baker | 10a4bc4 | 2015-07-23 10:21:02 +1200 | [diff] [blame] | 1 | # 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 Baker | 9d3cd4f | 2015-08-07 10:45:26 +1200 | [diff] [blame] | 13 | from oslo_utils import timeutils |
| 14 | import requests |
| 15 | import time |
| 16 | import yaml |
| 17 | |
| 18 | from heat_integrationtests.common import exceptions |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 19 | from heat_integrationtests.functional import functional_base |
Steve Baker | 10a4bc4 | 2015-07-23 10:21:02 +1200 | [diff] [blame] | 20 | |
| 21 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 22 | class ParallelDeploymentsTest(functional_base.FunctionalTestsBase): |
Steve Baker | 9d3cd4f | 2015-08-07 10:45:26 +1200 | [diff] [blame] | 23 | server_template = ''' |
Steve Baker | 10a4bc4 | 2015-07-23 10:21:02 +1200 | [diff] [blame] | 24 | heat_template_version: "2013-05-23" |
| 25 | parameters: |
| 26 | flavor: |
| 27 | type: string |
| 28 | image: |
| 29 | type: string |
| 30 | network: |
| 31 | type: string |
| 32 | resources: |
| 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 Baker | 9d3cd4f | 2015-08-07 10:45:26 +1200 | [diff] [blame] | 39 | networks: [{network: {get_param: network}}] |
| 40 | outputs: |
| 41 | server: |
| 42 | value: {get_resource: server} |
| 43 | ''' |
| 44 | |
| 45 | config_template = ''' |
| 46 | heat_template_version: "2013-05-23" |
| 47 | parameters: |
| 48 | server: |
| 49 | type: string |
| 50 | resources: |
Steve Baker | 10a4bc4 | 2015-07-23 10:21:02 +1200 | [diff] [blame] | 51 | config: |
| 52 | type: OS::Heat::SoftwareConfig |
| 53 | properties: |
Steve Baker | 10a4bc4 | 2015-07-23 10:21:02 +1200 | [diff] [blame] | 54 | ''' |
| 55 | |
Steve Baker | 9d3cd4f | 2015-08-07 10:45:26 +1200 | [diff] [blame] | 56 | deployment_snippet = ''' |
| 57 | type: OS::Heat::SoftwareDeployments |
| 58 | properties: |
| 59 | config: {get_resource: config} |
| 60 | servers: {'0': {get_param: server}} |
| 61 | ''' |
Steve Baker | 10a4bc4 | 2015-07-23 10:21:02 +1200 | [diff] [blame] | 62 | |
Steve Baker | 9d3cd4f | 2015-08-07 10:45:26 +1200 | [diff] [blame] | 63 | enable_cleanup = True |
| 64 | |
| 65 | def test_deployments_metadata(self): |
Steve Baker | 10a4bc4 | 2015-07-23 10:21:02 +1200 | [diff] [blame] | 66 | 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 Baker | 9d3cd4f | 2015-08-07 10:45:26 +1200 | [diff] [blame] | 71 | 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 Chuprykov | a064e28 | 2015-08-30 09:05:32 +0300 | [diff] [blame] | 86 | self.deploy_many_configs( |
Steve Baker | 9d3cd4f | 2015-08-07 10:45:26 +1200 | [diff] [blame] | 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 | |
Oleksii Chuprykov | a064e28 | 2015-08-30 09:05:32 +0300 | [diff] [blame] | 98 | def deploy_many_configs(self, stack, server, config_stacks, |
Steve Baker | 9d3cd4f | 2015-08-07 10:45:26 +1200 | [diff] [blame] | 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 | |
Steve Baker | 9d3cd4f | 2015-08-07 10:45:26 +1200 | [diff] [blame] | 105 | new_count = deploy_count_start + stack_count * deploys_per_stack |
Oleksii Chuprykov | a064e28 | 2015-08-30 09:05:32 +0300 | [diff] [blame] | 106 | self.wait_for_deploy_metadata_set(stack, new_count) |
Steve Baker | 9d3cd4f | 2015-08-07 10:45:26 +1200 | [diff] [blame] | 107 | 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 Chuprykov | a064e28 | 2015-08-30 09:05:32 +0300 | [diff] [blame] | 122 | def wait_for_deploy_metadata_set(self, stack, deploy_count): |
Steve Baker | 9d3cd4f | 2015-08-07 10:45:26 +1200 | [diff] [blame] | 123 | 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 Chuprykov | a064e28 | 2015-08-30 09:05:32 +0300 | [diff] [blame] | 129 | server_metadata = self.client.resources.metadata( |
| 130 | stack, 'server') |
| 131 | if len(server_metadata['deployments']) == deploy_count: |
Steve Baker | 9d3cd4f | 2015-08-07 10:45:26 +1200 | [diff] [blame] | 132 | 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}) |