blob: 4168fb4affedba616cf5f793180c04595968bf5f [file] [log] [blame]
Steve Baker450aa7f2014-08-25 10:37:27 +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 Baker450aa7f2014-08-25 10:37:27 +120013import os
14import random
15import re
Steve Baker450aa7f2014-08-25 10:37:27 +120016import subprocess
Steve Baker450aa7f2014-08-25 10:37:27 +120017import time
18
Pavlo Shchelokovskyy60e0ecd2014-12-14 22:17:21 +020019import fixtures
Steve Baker450aa7f2014-08-25 10:37:27 +120020from heatclient import exc as heat_exceptions
Steve Baker24641292015-03-13 10:47:50 +130021from oslo_log import log as logging
Jens Rosenboom4f069fb2015-02-18 14:19:07 +010022from oslo_utils import timeutils
Pavlo Shchelokovskyy60e0ecd2014-12-14 22:17:21 +020023import six
Sirushti Murugesan4920fda2015-04-22 00:35:26 +053024from six.moves import urllib
Pavlo Shchelokovskyy60e0ecd2014-12-14 22:17:21 +020025import testscenarios
26import testtools
Steve Baker450aa7f2014-08-25 10:37:27 +120027
Steve Baker450aa7f2014-08-25 10:37:27 +120028from heat_integrationtests.common import clients
29from heat_integrationtests.common import config
30from heat_integrationtests.common import exceptions
31from heat_integrationtests.common import remote_client
32
33LOG = logging.getLogger(__name__)
Angus Salkeld24043702014-11-21 08:49:26 +100034_LOG_FORMAT = "%(levelname)8s [%(name)s] %(message)s"
Steve Baker450aa7f2014-08-25 10:37:27 +120035
36
Angus Salkeld08514ad2015-02-06 10:08:31 +100037def call_until_true(duration, sleep_for, func, *args, **kwargs):
Steve Baker450aa7f2014-08-25 10:37:27 +120038 """
39 Call the given function until it returns True (and return True) or
40 until the specified duration (in seconds) elapses (and return
41 False).
42
43 :param func: A zero argument callable that returns True on success.
44 :param duration: The number of seconds for which to attempt a
45 successful call of the function.
46 :param sleep_for: The number of seconds to sleep after an unsuccessful
47 invocation of the function.
48 """
49 now = time.time()
50 timeout = now + duration
51 while now < timeout:
Angus Salkeld08514ad2015-02-06 10:08:31 +100052 if func(*args, **kwargs):
Steve Baker450aa7f2014-08-25 10:37:27 +120053 return True
54 LOG.debug("Sleeping for %d seconds", sleep_for)
55 time.sleep(sleep_for)
56 now = time.time()
57 return False
58
59
60def rand_name(name=''):
61 randbits = str(random.randint(1, 0x7fffffff))
62 if name:
63 return name + '-' + randbits
64 else:
65 return randbits
66
67
Angus Salkeld95f65a22014-11-24 12:38:30 +100068class HeatIntegrationTest(testscenarios.WithScenarios,
69 testtools.TestCase):
Steve Baker450aa7f2014-08-25 10:37:27 +120070
71 def setUp(self):
72 super(HeatIntegrationTest, self).setUp()
73
74 self.conf = config.init_conf()
75
76 self.assertIsNotNone(self.conf.auth_url,
77 'No auth_url configured')
78 self.assertIsNotNone(self.conf.username,
79 'No username configured')
80 self.assertIsNotNone(self.conf.password,
81 'No password configured')
82
83 self.manager = clients.ClientManager(self.conf)
84 self.identity_client = self.manager.identity_client
85 self.orchestration_client = self.manager.orchestration_client
86 self.compute_client = self.manager.compute_client
87 self.network_client = self.manager.network_client
88 self.volume_client = self.manager.volume_client
Angus Salkeld4408da32015-02-03 18:53:30 +100089 self.object_client = self.manager.object_client
Angus Salkeld406bbd52015-05-13 14:24:04 +100090 self.metering_client = self.manager.metering_client
Angus Salkeld24043702014-11-21 08:49:26 +100091 self.useFixture(fixtures.FakeLogger(format=_LOG_FORMAT))
Sirushti Murugesan13a8a172015-04-14 00:30:05 +053092 self.updated_time = {}
Steve Baker450aa7f2014-08-25 10:37:27 +120093
Steve Baker450aa7f2014-08-25 10:37:27 +120094 def get_remote_client(self, server_or_ip, username, private_key=None):
95 if isinstance(server_or_ip, six.string_types):
96 ip = server_or_ip
97 else:
98 network_name_for_ssh = self.conf.network_for_ssh
99 ip = server_or_ip.networks[network_name_for_ssh][0]
100 if private_key is None:
101 private_key = self.keypair.private_key
102 linux_client = remote_client.RemoteClient(ip, username,
103 pkey=private_key,
104 conf=self.conf)
105 try:
106 linux_client.validate_authentication()
107 except exceptions.SSHTimeout:
108 LOG.exception('ssh connection to %s failed' % ip)
109 raise
110
111 return linux_client
112
Anastasia Kuznetsova3e0ab4d2015-03-06 18:10:13 +0400113 def check_connectivity(self, check_ip):
114 def try_connect(ip):
115 try:
Sirushti Murugesan4920fda2015-04-22 00:35:26 +0530116 urllib.request.urlopen('http://%s/' % ip)
Anastasia Kuznetsova3e0ab4d2015-03-06 18:10:13 +0400117 return True
118 except IOError:
119 return False
120
121 timeout = self.conf.connectivity_timeout
122 elapsed_time = 0
123 while not try_connect(check_ip):
124 time.sleep(10)
125 elapsed_time += 10
126 if elapsed_time > timeout:
127 raise exceptions.TimeoutException()
128
Steve Baker450aa7f2014-08-25 10:37:27 +1200129 def _log_console_output(self, servers=None):
130 if not servers:
131 servers = self.compute_client.servers.list()
132 for server in servers:
Steve Baker24641292015-03-13 10:47:50 +1300133 LOG.info('Console output for %s', server.id)
134 LOG.info(server.get_console_output())
Steve Baker450aa7f2014-08-25 10:37:27 +1200135
Sergey Kraynevd6fa5c02015-02-13 03:03:55 -0500136 def _load_template(self, base_file, file_name, sub_dir=None):
137 sub_dir = sub_dir or ''
Steve Baker450aa7f2014-08-25 10:37:27 +1200138 filepath = os.path.join(os.path.dirname(os.path.realpath(base_file)),
Sergey Kraynevd6fa5c02015-02-13 03:03:55 -0500139 sub_dir, file_name)
Steve Baker450aa7f2014-08-25 10:37:27 +1200140 with open(filepath) as f:
141 return f.read()
142
143 def create_keypair(self, client=None, name=None):
144 if client is None:
145 client = self.compute_client
146 if name is None:
147 name = rand_name('heat-keypair')
148 keypair = client.keypairs.create(name)
149 self.assertEqual(keypair.name, name)
150
151 def delete_keypair():
152 keypair.delete()
153
154 self.addCleanup(delete_keypair)
155 return keypair
156
Sergey Krayneva265c132015-02-13 03:51:03 -0500157 def assign_keypair(self):
158 if self.conf.keypair_name:
159 self.keypair = None
160 self.keypair_name = self.conf.keypair_name
161 else:
162 self.keypair = self.create_keypair()
163 self.keypair_name = self.keypair.id
164
Steve Baker450aa7f2014-08-25 10:37:27 +1200165 @classmethod
166 def _stack_rand_name(cls):
167 return rand_name(cls.__name__)
168
Anastasia Kuznetsova673fc432015-03-12 16:41:36 +0400169 def _get_network(self, net_name=None):
170 if net_name is None:
171 net_name = self.conf.fixed_network_name
Steve Baker450aa7f2014-08-25 10:37:27 +1200172 networks = self.network_client.list_networks()
173 for net in networks['networks']:
Anastasia Kuznetsova673fc432015-03-12 16:41:36 +0400174 if net['name'] == net_name:
Steve Baker450aa7f2014-08-25 10:37:27 +1200175 return net
176
Sergey Kraynev83ef84d2015-04-29 05:31:54 -0400177 def _get_subnet_by_version(self, network, ip_version=4):
178 for subnet_id in self.net['subnets']:
179 subnet_info = self.network_client.show_subnet(subnet_id)
180 if subnet_info['subnet']['ip_version'] == ip_version:
181 return subnet_id
182
Rabi Mishra95ac9aa2015-04-30 10:40:43 +0530183 def _get_server_ip_by_version(self, addresses, ip_version=4):
184 for address in addresses:
185 if address['version'] == ip_version:
186 return address['addr']
187
Steve Baker450aa7f2014-08-25 10:37:27 +1200188 @staticmethod
189 def _stack_output(stack, output_key):
190 """Return a stack output value for a given key."""
191 return next((o['output_value'] for o in stack.outputs
192 if o['output_key'] == output_key), None)
193
194 def _ping_ip_address(self, ip_address, should_succeed=True):
195 cmd = ['ping', '-c1', '-w1', ip_address]
196
197 def ping():
198 proc = subprocess.Popen(cmd,
199 stdout=subprocess.PIPE,
200 stderr=subprocess.PIPE)
201 proc.wait()
202 return (proc.returncode == 0) == should_succeed
203
204 return call_until_true(
Angus Salkeld08514ad2015-02-06 10:08:31 +1000205 self.conf.build_timeout, 1, ping)
Steve Baker450aa7f2014-08-25 10:37:27 +1200206
Angus Salkelda7500d12015-04-10 15:44:07 +1000207 def _wait_for_all_resource_status(self, stack_identifier,
208 status, failure_pattern='^.*_FAILED$',
209 success_on_not_found=False):
210 for res in self.client.resources.list(stack_identifier):
211 self._wait_for_resource_status(
212 stack_identifier, res.resource_name,
213 status, failure_pattern=failure_pattern,
214 success_on_not_found=success_on_not_found)
215
Steve Baker450aa7f2014-08-25 10:37:27 +1200216 def _wait_for_resource_status(self, stack_identifier, resource_name,
217 status, failure_pattern='^.*_FAILED$',
218 success_on_not_found=False):
219 """Waits for a Resource to reach a given status."""
220 fail_regexp = re.compile(failure_pattern)
221 build_timeout = self.conf.build_timeout
222 build_interval = self.conf.build_interval
223
224 start = timeutils.utcnow()
225 while timeutils.delta_seconds(start,
226 timeutils.utcnow()) < build_timeout:
227 try:
228 res = self.client.resources.get(
229 stack_identifier, resource_name)
230 except heat_exceptions.HTTPNotFound:
231 if success_on_not_found:
232 return
233 # ignore this, as the resource may not have
234 # been created yet
235 else:
236 if res.resource_status == status:
237 return
Sirushti Murugesane5ad25b2015-04-18 23:30:59 +0530238 wait_for_action = status.split('_')[0]
239 resource_action = res.resource_status.split('_')[0]
240 if (resource_action == wait_for_action and
241 fail_regexp.search(res.resource_status)):
Steve Baker450aa7f2014-08-25 10:37:27 +1200242 raise exceptions.StackResourceBuildErrorException(
243 resource_name=res.resource_name,
244 stack_identifier=stack_identifier,
245 resource_status=res.resource_status,
246 resource_status_reason=res.resource_status_reason)
247 time.sleep(build_interval)
248
249 message = ('Resource %s failed to reach %s status within '
250 'the required time (%s s).' %
Anastasia Kuznetsova9a745572015-03-04 13:19:15 +0400251 (resource_name, status, build_timeout))
Steve Baker450aa7f2014-08-25 10:37:27 +1200252 raise exceptions.TimeoutException(message)
253
Sirushti Murugesan13a8a172015-04-14 00:30:05 +0530254 def _verify_status(self, stack, stack_identifier, status, fail_regexp):
255 if stack.stack_status == status:
256 # Handle UPDATE_COMPLETE case: Make sure we don't
257 # wait for a stale UPDATE_COMPLETE status.
258 if status == 'UPDATE_COMPLETE':
259 if self.updated_time.get(
260 stack_identifier) != stack.updated_time:
261 self.updated_time[stack_identifier] = stack.updated_time
262 return True
263 else:
264 return True
265
Sirushti Murugesane5ad25b2015-04-18 23:30:59 +0530266 wait_for_action = status.split('_')[0]
267 if (stack.action == wait_for_action and
268 fail_regexp.search(stack.stack_status)):
Sirushti Murugesan13a8a172015-04-14 00:30:05 +0530269 # Handle UPDATE_FAILED case.
270 if status == 'UPDATE_FAILED':
271 if self.updated_time.get(
272 stack_identifier) != stack.updated_time:
273 self.updated_time[stack_identifier] = stack.updated_time
274 raise exceptions.StackBuildErrorException(
275 stack_identifier=stack_identifier,
276 stack_status=stack.stack_status,
277 stack_status_reason=stack.stack_status_reason)
278 else:
279 raise exceptions.StackBuildErrorException(
280 stack_identifier=stack_identifier,
281 stack_status=stack.stack_status,
282 stack_status_reason=stack.stack_status_reason)
283
Steve Baker450aa7f2014-08-25 10:37:27 +1200284 def _wait_for_stack_status(self, stack_identifier, status,
285 failure_pattern='^.*_FAILED$',
286 success_on_not_found=False):
287 """
288 Waits for a Stack to reach a given status.
289
290 Note this compares the full $action_$status, e.g
291 CREATE_COMPLETE, not just COMPLETE which is exposed
292 via the status property of Stack in heatclient
293 """
294 fail_regexp = re.compile(failure_pattern)
295 build_timeout = self.conf.build_timeout
296 build_interval = self.conf.build_interval
297
298 start = timeutils.utcnow()
299 while timeutils.delta_seconds(start,
300 timeutils.utcnow()) < build_timeout:
301 try:
302 stack = self.client.stacks.get(stack_identifier)
303 except heat_exceptions.HTTPNotFound:
304 if success_on_not_found:
305 return
306 # ignore this, as the resource may not have
307 # been created yet
308 else:
Sirushti Murugesan13a8a172015-04-14 00:30:05 +0530309 if self._verify_status(stack, stack_identifier, status,
310 fail_regexp):
Steve Baker450aa7f2014-08-25 10:37:27 +1200311 return
Sirushti Murugesan13a8a172015-04-14 00:30:05 +0530312
Steve Baker450aa7f2014-08-25 10:37:27 +1200313 time.sleep(build_interval)
314
315 message = ('Stack %s failed to reach %s status within '
316 'the required time (%s s).' %
Anastasia Kuznetsova9a745572015-03-04 13:19:15 +0400317 (stack_identifier, status, build_timeout))
Steve Baker450aa7f2014-08-25 10:37:27 +1200318 raise exceptions.TimeoutException(message)
319
320 def _stack_delete(self, stack_identifier):
321 try:
322 self.client.stacks.delete(stack_identifier)
323 except heat_exceptions.HTTPNotFound:
324 pass
325 self._wait_for_stack_status(
326 stack_identifier, 'DELETE_COMPLETE',
327 success_on_not_found=True)
Steven Hardyc9efd972014-11-20 11:31:55 +0000328
329 def update_stack(self, stack_identifier, template, environment=None,
Sabeen Syed277ea692015-02-04 23:30:02 +0000330 files=None, parameters=None, tags=None,
Rakesh H Sa3325d62015-04-04 19:42:29 +0530331 expected_status='UPDATE_COMPLETE',
332 disable_rollback=True):
Steven Hardyc9efd972014-11-20 11:31:55 +0000333 env = environment or {}
334 env_files = files or {}
Sergey Kraynevbcc78df2015-02-27 04:34:32 -0500335 parameters = parameters or {}
Steven Hardyc9efd972014-11-20 11:31:55 +0000336 stack_name = stack_identifier.split('/')[0]
Sirushti Murugesan3a195a52015-05-01 09:47:09 +0530337
338 build_timeout = self.conf.build_timeout
339 build_interval = self.conf.build_interval
340 start = timeutils.utcnow()
341 while timeutils.delta_seconds(start,
342 timeutils.utcnow()) < build_timeout:
343 try:
344 self.client.stacks.update(
345 stack_id=stack_identifier,
346 stack_name=stack_name,
347 template=template,
348 files=env_files,
349 disable_rollback=disable_rollback,
350 parameters=parameters,
Sabeen Syed277ea692015-02-04 23:30:02 +0000351 environment=env,
352 tags=tags
Sirushti Murugesan3a195a52015-05-01 09:47:09 +0530353 )
354 except heat_exceptions.HTTPConflict as ex:
355 # FIXME(sirushtim): Wait a little for the stack lock to be
356 # released and hopefully, the stack should be updatable again.
357 if ex.error['error']['type'] != 'ActionInProgress':
358 raise ex
359
360 time.sleep(build_interval)
361 else:
362 break
363
Rakesh H Sa3325d62015-04-04 19:42:29 +0530364 kwargs = {'stack_identifier': stack_identifier,
365 'status': expected_status}
366 if expected_status in ['ROLLBACK_COMPLETE']:
Rakesh H Sa3325d62015-04-04 19:42:29 +0530367 # To trigger rollback you would intentionally fail the stack
368 # Hence check for rollback failures
369 kwargs['failure_pattern'] = '^ROLLBACK_FAILED$'
370
371 self._wait_for_stack_status(**kwargs)
Steven Hardyc9efd972014-11-20 11:31:55 +0000372
Steven Hardy03da0742015-03-19 00:13:17 -0400373 def assert_resource_is_a_stack(self, stack_identifier, res_name,
374 wait=False):
375 build_timeout = self.conf.build_timeout
376 build_interval = self.conf.build_interval
377 start = timeutils.utcnow()
378 while timeutils.delta_seconds(start,
379 timeutils.utcnow()) < build_timeout:
380 time.sleep(build_interval)
381 try:
382 nested_identifier = self._get_nested_identifier(
383 stack_identifier, res_name)
384 except Exception:
385 # We may have to wait, if the create is in-progress
386 if wait:
387 time.sleep(build_interval)
388 else:
389 raise
390 else:
391 return nested_identifier
392
393 def _get_nested_identifier(self, stack_identifier, res_name):
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000394 rsrc = self.client.resources.get(stack_identifier, res_name)
395 nested_link = [l for l in rsrc.links if l['rel'] == 'nested']
396 nested_href = nested_link[0]['href']
397 nested_id = nested_href.split('/')[-1]
398 nested_identifier = '/'.join(nested_href.split('/')[-2:])
399 self.assertEqual(rsrc.physical_resource_id, nested_id)
400
401 nested_stack = self.client.stacks.get(nested_id)
402 nested_identifier2 = '%s/%s' % (nested_stack.stack_name,
403 nested_stack.id)
404 self.assertEqual(nested_identifier, nested_identifier2)
405 parent_id = stack_identifier.split("/")[-1]
406 self.assertEqual(parent_id, nested_stack.parent)
407 return nested_identifier
408
Steven Hardyc9efd972014-11-20 11:31:55 +0000409 def list_resources(self, stack_identifier):
410 resources = self.client.resources.list(stack_identifier)
411 return dict((r.resource_name, r.resource_type) for r in resources)
Steven Hardyf2c82c02014-11-20 14:02:17 +0000412
413 def stack_create(self, stack_name=None, template=None, files=None,
Sabeen Syed277ea692015-02-04 23:30:02 +0000414 parameters=None, environment=None, tags=None,
415 expected_status='CREATE_COMPLETE',
416 disable_rollback=True, enable_cleanup=True):
Steven Hardyf2c82c02014-11-20 14:02:17 +0000417 name = stack_name or self._stack_rand_name()
418 templ = template or self.template
419 templ_files = files or {}
420 params = parameters or {}
421 env = environment or {}
422 self.client.stacks.create(
423 stack_name=name,
424 template=templ,
425 files=templ_files,
Rakesh H Sa3325d62015-04-04 19:42:29 +0530426 disable_rollback=disable_rollback,
Steven Hardyf2c82c02014-11-20 14:02:17 +0000427 parameters=params,
Sabeen Syed277ea692015-02-04 23:30:02 +0000428 environment=env,
429 tags=tags
Steven Hardyf2c82c02014-11-20 14:02:17 +0000430 )
Sergey Kraynevbf67ce32015-04-17 10:54:20 -0400431 if expected_status not in ['ROLLBACK_COMPLETE'] and enable_cleanup:
Rakesh H Sa3325d62015-04-04 19:42:29 +0530432 self.addCleanup(self.client.stacks.delete, name)
Steven Hardyf2c82c02014-11-20 14:02:17 +0000433
434 stack = self.client.stacks.get(name)
435 stack_identifier = '%s/%s' % (name, stack.id)
Rakesh H Sa3325d62015-04-04 19:42:29 +0530436 kwargs = {'stack_identifier': stack_identifier,
437 'status': expected_status}
Steve Bakerf6c8f122015-02-10 13:54:46 +1300438 if expected_status:
Rakesh H Sa3325d62015-04-04 19:42:29 +0530439 if expected_status in ['ROLLBACK_COMPLETE']:
440 # To trigger rollback you would intentionally fail the stack
441 # Hence check for rollback failures
442 kwargs['failure_pattern'] = '^ROLLBACK_FAILED$'
443 self._wait_for_stack_status(**kwargs)
Steven Hardyf2c82c02014-11-20 14:02:17 +0000444 return stack_identifier
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000445
446 def stack_adopt(self, stack_name=None, files=None,
447 parameters=None, environment=None, adopt_data=None,
448 wait_for_status='ADOPT_COMPLETE'):
Sirushti Murugesan04ee8022015-02-02 23:00:23 +0530449 if self.conf.skip_stack_adopt_tests:
450 self.skipTest('Testing Stack adopt disabled in conf, skipping')
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000451 name = stack_name or self._stack_rand_name()
452 templ_files = files or {}
453 params = parameters or {}
454 env = environment or {}
455 self.client.stacks.create(
456 stack_name=name,
457 files=templ_files,
458 disable_rollback=True,
459 parameters=params,
460 environment=env,
461 adopt_stack_data=adopt_data,
462 )
463 self.addCleanup(self.client.stacks.delete, name)
464
465 stack = self.client.stacks.get(name)
466 stack_identifier = '%s/%s' % (name, stack.id)
467 self._wait_for_stack_status(stack_identifier, wait_for_status)
468 return stack_identifier
Sirushti Murugesan04ee8022015-02-02 23:00:23 +0530469
470 def stack_abandon(self, stack_id):
471 if self.conf.skip_stack_abandon_tests:
472 self.addCleanup(self.client.stacks.delete, stack_id)
473 self.skipTest('Testing Stack abandon disabled in conf, skipping')
474 info = self.client.stacks.abandon(stack_id=stack_id)
475 return info
Oleksii Chuprykovd9cd9dc2015-02-03 10:34:55 -0500476
477 def stack_suspend(self, stack_identifier):
478 stack_name = stack_identifier.split('/')[0]
479 self.client.actions.suspend(stack_name)
Angus Salkelda7500d12015-04-10 15:44:07 +1000480
481 # improve debugging by first checking the resource's state.
482 self._wait_for_all_resource_status(stack_identifier,
483 'SUSPEND_COMPLETE')
Oleksii Chuprykovd9cd9dc2015-02-03 10:34:55 -0500484 self._wait_for_stack_status(stack_identifier, 'SUSPEND_COMPLETE')
485
486 def stack_resume(self, stack_identifier):
487 stack_name = stack_identifier.split('/')[0]
488 self.client.actions.resume(stack_name)
Angus Salkelda7500d12015-04-10 15:44:07 +1000489
490 # improve debugging by first checking the resource's state.
491 self._wait_for_all_resource_status(stack_identifier,
492 'RESUME_COMPLETE')
Oleksii Chuprykovd9cd9dc2015-02-03 10:34:55 -0500493 self._wait_for_stack_status(stack_identifier, 'RESUME_COMPLETE')
Steven Hardy03da0742015-03-19 00:13:17 -0400494
495 def wait_for_event_with_reason(self, stack_identifier, reason,
496 rsrc_name=None, num_expected=1):
497 build_timeout = self.conf.build_timeout
498 build_interval = self.conf.build_interval
499 start = timeutils.utcnow()
500 while timeutils.delta_seconds(start,
501 timeutils.utcnow()) < build_timeout:
502 try:
503 rsrc_events = self.client.events.list(stack_identifier,
504 resource_name=rsrc_name)
505 except heat_exceptions.HTTPNotFound:
506 LOG.debug("No events yet found for %s" % rsrc_name)
507 else:
508 matched = [e for e in rsrc_events
509 if e.resource_status_reason == reason]
510 if len(matched) == num_expected:
511 return matched
512 time.sleep(build_interval)