blob: a8f952a8058599a7a3e7daf52a23d46bce2967ee [file] [log] [blame]
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import time
from salt.exceptions import CommandExecutionError
from heatv1.common import send
@send('get')
def service_list(cloud_name):
"""Return list of Heat services."""
url = '/services'
return url, {}
def wait_for_service(cloud_name, host=None, binary=None, retries=18, timeout=10):
"""Ensure the service is up and running on specified host.
:param host: name of a host where service is running
:param binary: name of the service
:param timeout: number of seconds to wait before retries
:param retries: number of retries
"""
for _i in range(retries):
services = service_list(cloud_name=cloud_name)['body']['services']
down_services = [s for s in services if s['status'] == 'down']
# When Heat worker is reloaded, it creates new instance with different Engine ID.
# This is needed for checking that at least one instance on the host is running.
up_services_hosts = {s['host'] for s in services if s['status'] == 'up'}
if host:
down_services = [s for s in down_services if s['host'] == host \
and s['host'] not in up_services_hosts]
if binary:
down_services = [s for s in down_services if s['binary'] == binary \
and s['host'] not in up_services_hosts]
if not host and not binary:
down_services = [s for s in down_services if s['host'] not in up_services_hosts]
if not down_services:
return 'Heat services are running.'
time.sleep(timeout)
raise CommandExecutionError("Heat services {} are still down".format(down_services))