3 # Copyright (c) 2017 Huawei Technologies Co., Ltd. All Rights Reserved.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Echo text to the log file, summary log file and stdout
18 # echo_summary "something to say"
19 function echo_summary {
29 which curl >/dev/null || {
30 echo_summary "curl must be installed"
35 for i in $(seq 1 "$times"); do
37 if out=$(curl --max-time 1 -gkfs "$url" 2>/dev/null); then
38 echo_summary "On try ${i}, ${prefix}: ${out}"
43 echo_summary "Timed out waiting for ${prefix} to answer at ${url}; tried ${times} waiting ${wait} between each"
47 # Prints line number and "message" in error format
48 # err $LINENO "message"
52 xtrace=$(set +o | grep xtrace)
54 local msg="[ERROR] ${BASH_SOURCE[2]}:$1 $2"
60 # Prints line number and "message" then exits
61 # die $LINENO "message"
66 if [ $exitcode == 0 ]; then
70 # Give buffers a second to flush
75 get_default_host_ip() {
78 # Search for an IP unless an explicit is set by ``HOST_IP`` environment variable
79 if [ -z "$host_ip" ]; then
81 # Find the interface used for the default route
82 host_ip_iface=${host_ip_iface:-$(ip -f "$af" route | awk '/default/ {print $5}' | head -1)}
84 host_ips=$(LC_ALL=C ip -f "$af" addr show "${host_ip_iface}" | sed /temporary/d |awk /$af'/ {split($2,parts,"/"); print parts[1]}')
86 for ip in $host_ips; do