'Waits for a Resource to reach a given status.'

def _wait_for_resource_status(self, stack_identifier, resource_name, status, failure_pattern='^.*_FAILED$', success_on_not_found=False):

    fail_regexp = re.compile(failure_pattern)
    build_timeout = self.conf.build_timeout
    build_interval = self.conf.build_interval
    start = timeutils.utcnow()
    while (timeutils.delta_seconds(start, timeutils.utcnow()) < build_timeout):
        try:
            res = self.client.resources.get(stack_identifier, resource_name)
        except heat_exceptions.HTTPNotFound:
            if success_on_not_found:
                return
        else:
            if (res.resource_status == status):
                return
            wait_for_action = status.split('_')[0]
            resource_action = res.resource_status.split('_')[0]
            if ((resource_action == wait_for_action) and fail_regexp.search(res.resource_status)):
                raise exceptions.StackResourceBuildErrorException(resource_name=res.resource_name, stack_identifier=stack_identifier, resource_status=res.resource_status, resource_status_reason=res.resource_status_reason)
        time.sleep(build_interval)
    message = ('Resource    %s    failed    to    reach    %s    status    within    the    required    time    (%s    s).' % (resource_name, status, build_timeout))
    raise exceptions.TimeoutException(message)
