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 | |
Thomas Herve | 2ce4bda | 2016-01-22 17:55:55 +0100 | [diff] [blame] | 13 | import json |
| 14 | import os |
Steve Baker | 9d3cd4f | 2015-08-07 10:45:26 +1200 | [diff] [blame] | 15 | import requests |
Thomas Herve | 2ce4bda | 2016-01-22 17:55:55 +0100 | [diff] [blame] | 16 | import subprocess |
Thomas Herve | 4d1362b | 2017-03-24 10:33:01 +0100 | [diff] [blame^] | 17 | import sys |
Thomas Herve | 2ce4bda | 2016-01-22 17:55:55 +0100 | [diff] [blame] | 18 | import tempfile |
Steve Baker | 9d3cd4f | 2015-08-07 10:45:26 +1200 | [diff] [blame] | 19 | import time |
| 20 | import yaml |
| 21 | |
Thomas Herve | 2ce4bda | 2016-01-22 17:55:55 +0100 | [diff] [blame] | 22 | from oslo_utils import timeutils |
| 23 | |
Steve Baker | 9d3cd4f | 2015-08-07 10:45:26 +1200 | [diff] [blame] | 24 | from heat_integrationtests.common import exceptions |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 25 | from heat_integrationtests.functional import functional_base |
Steve Baker | 10a4bc4 | 2015-07-23 10:21:02 +1200 | [diff] [blame] | 26 | |
| 27 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 28 | class ParallelDeploymentsTest(functional_base.FunctionalTestsBase): |
Steve Baker | 9d3cd4f | 2015-08-07 10:45:26 +1200 | [diff] [blame] | 29 | server_template = ''' |
Steve Baker | 10a4bc4 | 2015-07-23 10:21:02 +1200 | [diff] [blame] | 30 | heat_template_version: "2013-05-23" |
| 31 | parameters: |
| 32 | flavor: |
| 33 | type: string |
| 34 | image: |
| 35 | type: string |
| 36 | network: |
| 37 | type: string |
| 38 | resources: |
| 39 | server: |
| 40 | type: OS::Nova::Server |
| 41 | properties: |
| 42 | image: {get_param: image} |
| 43 | flavor: {get_param: flavor} |
| 44 | user_data_format: SOFTWARE_CONFIG |
Steve Baker | 9d3cd4f | 2015-08-07 10:45:26 +1200 | [diff] [blame] | 45 | networks: [{network: {get_param: network}}] |
| 46 | outputs: |
| 47 | server: |
| 48 | value: {get_resource: server} |
| 49 | ''' |
| 50 | |
| 51 | config_template = ''' |
| 52 | heat_template_version: "2013-05-23" |
| 53 | parameters: |
| 54 | server: |
| 55 | type: string |
| 56 | resources: |
Steve Baker | 10a4bc4 | 2015-07-23 10:21:02 +1200 | [diff] [blame] | 57 | config: |
| 58 | type: OS::Heat::SoftwareConfig |
| 59 | properties: |
Steve Baker | 10a4bc4 | 2015-07-23 10:21:02 +1200 | [diff] [blame] | 60 | ''' |
| 61 | |
Steve Baker | 9d3cd4f | 2015-08-07 10:45:26 +1200 | [diff] [blame] | 62 | deployment_snippet = ''' |
| 63 | type: OS::Heat::SoftwareDeployments |
| 64 | properties: |
| 65 | config: {get_resource: config} |
| 66 | servers: {'0': {get_param: server}} |
| 67 | ''' |
Steve Baker | 10a4bc4 | 2015-07-23 10:21:02 +1200 | [diff] [blame] | 68 | |
Steve Baker | 9d3cd4f | 2015-08-07 10:45:26 +1200 | [diff] [blame] | 69 | enable_cleanup = True |
| 70 | |
| 71 | def test_deployments_metadata(self): |
Steve Baker | 10a4bc4 | 2015-07-23 10:21:02 +1200 | [diff] [blame] | 72 | parms = {'flavor': self.conf.minimal_instance_type, |
| 73 | 'network': self.conf.fixed_network_name, |
| 74 | 'image': self.conf.minimal_image_ref} |
| 75 | stack_identifier = self.stack_create( |
| 76 | parameters=parms, |
Steve Baker | 9d3cd4f | 2015-08-07 10:45:26 +1200 | [diff] [blame] | 77 | template=self.server_template, |
| 78 | enable_cleanup=self.enable_cleanup) |
| 79 | server_stack = self.client.stacks.get(stack_identifier) |
| 80 | server = server_stack.outputs[0]['output_value'] |
| 81 | |
| 82 | config_stacks = [] |
| 83 | # add up to 3 stacks each with up to 3 deployments |
| 84 | deploy_count = 0 |
| 85 | deploy_count = self.deploy_many_configs( |
| 86 | stack_identifier, |
| 87 | server, |
| 88 | config_stacks, |
| 89 | 2, |
| 90 | 5, |
| 91 | deploy_count) |
Oleksii Chuprykov | a064e28 | 2015-08-30 09:05:32 +0300 | [diff] [blame] | 92 | self.deploy_many_configs( |
Steve Baker | 9d3cd4f | 2015-08-07 10:45:26 +1200 | [diff] [blame] | 93 | stack_identifier, |
| 94 | server, |
| 95 | config_stacks, |
| 96 | 3, |
| 97 | 3, |
| 98 | deploy_count) |
| 99 | |
| 100 | self.signal_deployments(stack_identifier) |
| 101 | for config_stack in config_stacks: |
| 102 | self._wait_for_stack_status(config_stack, 'CREATE_COMPLETE') |
| 103 | |
Oleksii Chuprykov | a064e28 | 2015-08-30 09:05:32 +0300 | [diff] [blame] | 104 | def deploy_many_configs(self, stack, server, config_stacks, |
Steve Baker | 9d3cd4f | 2015-08-07 10:45:26 +1200 | [diff] [blame] | 105 | stack_count, deploys_per_stack, |
| 106 | deploy_count_start): |
| 107 | for a in range(stack_count): |
| 108 | config_stacks.append( |
| 109 | self.deploy_config(server, deploys_per_stack)) |
| 110 | |
Steve Baker | 9d3cd4f | 2015-08-07 10:45:26 +1200 | [diff] [blame] | 111 | new_count = deploy_count_start + stack_count * deploys_per_stack |
Oleksii Chuprykov | a064e28 | 2015-08-30 09:05:32 +0300 | [diff] [blame] | 112 | self.wait_for_deploy_metadata_set(stack, new_count) |
Steve Baker | 9d3cd4f | 2015-08-07 10:45:26 +1200 | [diff] [blame] | 113 | return new_count |
| 114 | |
| 115 | def deploy_config(self, server, deploy_count): |
| 116 | parms = {'server': server} |
| 117 | template = yaml.safe_load(self.config_template) |
| 118 | resources = template['resources'] |
| 119 | resources['config']['properties'] = {'config': 'x' * 10000} |
| 120 | for a in range(deploy_count): |
| 121 | resources['dep_%s' % a] = yaml.safe_load(self.deployment_snippet) |
| 122 | return self.stack_create( |
| 123 | parameters=parms, |
| 124 | template=template, |
| 125 | enable_cleanup=self.enable_cleanup, |
| 126 | expected_status=None) |
| 127 | |
Oleksii Chuprykov | a064e28 | 2015-08-30 09:05:32 +0300 | [diff] [blame] | 128 | def wait_for_deploy_metadata_set(self, stack, deploy_count): |
Steve Baker | 9d3cd4f | 2015-08-07 10:45:26 +1200 | [diff] [blame] | 129 | build_timeout = self.conf.build_timeout |
| 130 | build_interval = self.conf.build_interval |
| 131 | |
| 132 | start = timeutils.utcnow() |
| 133 | while timeutils.delta_seconds(start, |
| 134 | timeutils.utcnow()) < build_timeout: |
Oleksii Chuprykov | a064e28 | 2015-08-30 09:05:32 +0300 | [diff] [blame] | 135 | server_metadata = self.client.resources.metadata( |
| 136 | stack, 'server') |
| 137 | if len(server_metadata['deployments']) == deploy_count: |
Steve Baker | 9d3cd4f | 2015-08-07 10:45:26 +1200 | [diff] [blame] | 138 | return |
| 139 | time.sleep(build_interval) |
| 140 | |
| 141 | message = ('Deployment resources failed to be created within ' |
| 142 | 'the required time (%s s).' % |
| 143 | (build_timeout)) |
| 144 | raise exceptions.TimeoutException(message) |
| 145 | |
| 146 | def signal_deployments(self, stack_identifier): |
| 147 | server_metadata = self.client.resources.metadata( |
| 148 | stack_identifier, 'server') |
| 149 | for dep in server_metadata['deployments']: |
| 150 | iv = dict((i['name'], i['value']) for i in dep['inputs']) |
| 151 | sigurl = iv.get('deploy_signal_id') |
| 152 | requests.post(sigurl, data='{}', |
rabi | 10a9b10 | 2017-01-12 08:09:11 +0530 | [diff] [blame] | 153 | headers={'content-type': 'application/json'}, |
tyagi | 39aa11a | 2016-03-07 04:47:00 -0800 | [diff] [blame] | 154 | verify=self.verify_cert) |
Thomas Herve | 2ce4bda | 2016-01-22 17:55:55 +0100 | [diff] [blame] | 155 | |
| 156 | |
| 157 | class ZaqarSignalTransportTest(functional_base.FunctionalTestsBase): |
| 158 | server_template = ''' |
| 159 | heat_template_version: "2013-05-23" |
| 160 | |
| 161 | parameters: |
| 162 | flavor: |
| 163 | type: string |
| 164 | image: |
| 165 | type: string |
| 166 | network: |
| 167 | type: string |
| 168 | |
| 169 | resources: |
| 170 | server: |
| 171 | type: OS::Nova::Server |
| 172 | properties: |
| 173 | image: {get_param: image} |
| 174 | flavor: {get_param: flavor} |
| 175 | user_data_format: SOFTWARE_CONFIG |
| 176 | software_config_transport: ZAQAR_MESSAGE |
| 177 | networks: [{network: {get_param: network}}] |
| 178 | config: |
| 179 | type: OS::Heat::SoftwareConfig |
| 180 | properties: |
| 181 | config: echo 'foo' |
| 182 | deployment: |
| 183 | type: OS::Heat::SoftwareDeployment |
| 184 | properties: |
| 185 | config: {get_resource: config} |
| 186 | server: {get_resource: server} |
| 187 | signal_transport: ZAQAR_SIGNAL |
| 188 | |
| 189 | outputs: |
| 190 | data: |
| 191 | value: {get_attr: [deployment, deploy_stdout]} |
| 192 | ''' |
| 193 | |
| 194 | conf_template = ''' |
| 195 | [zaqar] |
| 196 | user_id = %(user_id)s |
| 197 | password = %(password)s |
| 198 | project_id = %(project_id)s |
| 199 | auth_url = %(auth_url)s |
| 200 | queue_id = %(queue_id)s |
| 201 | ''' |
| 202 | |
| 203 | def test_signal_queues(self): |
| 204 | parms = {'flavor': self.conf.minimal_instance_type, |
| 205 | 'network': self.conf.fixed_network_name, |
| 206 | 'image': self.conf.minimal_image_ref} |
| 207 | stack_identifier = self.stack_create( |
| 208 | parameters=parms, |
| 209 | template=self.server_template, |
| 210 | expected_status=None) |
| 211 | metadata = self.wait_for_deploy_metadata_set(stack_identifier) |
| 212 | config = metadata['os-collect-config']['zaqar'] |
| 213 | conf_content = self.conf_template % config |
| 214 | fd, temp_path = tempfile.mkstemp() |
Thomas Herve | 4d1362b | 2017-03-24 10:33:01 +0100 | [diff] [blame^] | 215 | os.write(fd, conf_content.encode('utf-8')) |
Thomas Herve | 2ce4bda | 2016-01-22 17:55:55 +0100 | [diff] [blame] | 216 | os.close(fd) |
| 217 | cmd = ['os-collect-config', '--one-time', |
| 218 | '--config-file=%s' % temp_path, 'zaqar'] |
| 219 | proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) |
| 220 | stdout_value = proc.communicate()[0] |
Thomas Herve | 4d1362b | 2017-03-24 10:33:01 +0100 | [diff] [blame^] | 221 | data = json.loads(stdout_value.decode('utf-8')) |
Thomas Herve | 2ce4bda | 2016-01-22 17:55:55 +0100 | [diff] [blame] | 222 | self.assertEqual(config, data['zaqar']['os-collect-config']['zaqar']) |
| 223 | proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) |
| 224 | stdout_value = proc.communicate()[0] |
Thomas Herve | 4d1362b | 2017-03-24 10:33:01 +0100 | [diff] [blame^] | 225 | data = json.loads(stdout_value.decode('utf-8')) |
Thomas Herve | 2ce4bda | 2016-01-22 17:55:55 +0100 | [diff] [blame] | 226 | |
| 227 | fd, temp_path = tempfile.mkstemp() |
Thomas Herve | 4d1362b | 2017-03-24 10:33:01 +0100 | [diff] [blame^] | 228 | os.write(fd, |
| 229 | json.dumps(data['zaqar']['deployments'][0]).encode('utf-8')) |
Thomas Herve | 2ce4bda | 2016-01-22 17:55:55 +0100 | [diff] [blame] | 230 | os.close(fd) |
Thomas Herve | 4d1362b | 2017-03-24 10:33:01 +0100 | [diff] [blame^] | 231 | cmd = [sys.executable, self.conf.heat_config_notify_script, temp_path] |
Thomas Herve | 2ce4bda | 2016-01-22 17:55:55 +0100 | [diff] [blame] | 232 | proc = subprocess.Popen(cmd, |
| 233 | stderr=subprocess.PIPE, |
| 234 | stdin=subprocess.PIPE) |
Thomas Herve | 4d1362b | 2017-03-24 10:33:01 +0100 | [diff] [blame^] | 235 | proc.communicate( |
| 236 | json.dumps({'deploy_stdout': 'here!'}).encode('utf-8')) |
Thomas Herve | 2ce4bda | 2016-01-22 17:55:55 +0100 | [diff] [blame] | 237 | self._wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE') |
| 238 | stack = self.client.stacks.get(stack_identifier) |
| 239 | self.assertEqual('here!', stack.outputs[0]['output_value']) |
| 240 | |
| 241 | def wait_for_deploy_metadata_set(self, stack): |
| 242 | build_timeout = self.conf.build_timeout |
| 243 | build_interval = self.conf.build_interval |
| 244 | |
| 245 | start = timeutils.utcnow() |
| 246 | while timeutils.delta_seconds(start, |
| 247 | timeutils.utcnow()) < build_timeout: |
| 248 | server_metadata = self.client.resources.metadata( |
| 249 | stack, 'server') |
| 250 | if server_metadata.get('deployments'): |
| 251 | return server_metadata |
| 252 | time.sleep(build_interval) |
| 253 | |
| 254 | message = ('Deployment resources failed to be created within ' |
| 255 | 'the required time (%s s).' % |
| 256 | (build_timeout)) |
| 257 | raise exceptions.TimeoutException(message) |