Merge "Wait for service to be listening before running tests"
[multicloud/k8s.git] / kud / tests / onap4k8s.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2018
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10 set -o errexit
11 set -o pipefail
12
13 source _functions.sh
14 set +e
15
16 master_ip=$(kubectl cluster-info | grep "Kubernetes master" | \
17     awk -F ":" '{print $2}' | awk -F "//" '{print $2}')
18 onap_svc_node_port=30498
19 declare -i timeout=18
20 declare -i interval=10
21
22 base_url="http://$master_ip:$onap_svc_node_port/v1"
23
24 function check_onap_svc {
25     while ((timeout > 0)); do
26         echo "try $timeout: Wait for $interval seconds to check for onap svc"
27         sleep $interval
28         call_api "$base_url/healthcheck"
29         call_api_ret=$?
30         if [[ $call_api_ret -eq 0 ]]; then
31             echo "onap svc health check is success"
32             exit 0
33         fi
34         ((timeout-=1))
35     done
36 }
37
38 check_onap_svc
39 echo "Failed to check for onap svc"
40 exit 1