aboutsummaryrefslogtreecommitdiffstats
path: root/docker/common.sh
blob: b81dedf7ed43c5c197688b34362e45fd121f6da5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash

#
# Author: Jose Lausuch (jose.lausuch@ericsson.com)
#
# Installs the Functest framework within the Docker container
# and run the tests automatically
#
# If config_functest.yaml is given by the docker run command,
# it must be run like this:
#
#   docker run -ti \
#      -e "INSTALLER_TYPE=<something>" \
#      -e "INSTALLER_IP=<ip>" \
#      -v $(pwd)/config_functest.yaml:/home/opnfv/functest/conf/config_functest.yaml \
#      opnfv/functest /bin/bash
#
# NOTE: $(pwd)/config_functest.yaml means that it will take the one in the
#       current directory.
#
# If it is not provided, take the existing one in the functest repo
#

# this pull is to be removed right before the B release, once we build
# a release candidate docker
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
#

mkdir -p /home/opnfv/functest/conf
config_file=/home/opnfv/functest/conf/config_functest.yaml
if [ ! -f ${config_file} ]; then
    default_config_file=$(find /home/opnfv/repos -name config_functest.yaml)
    cp $default_config_file $config_file
    echo "config_functest.yaml not provided. Using default one"
fi


# Parse config_functest.yaml file
# TODO: this is not the best way to parse a yaml file in bash...

# Directories
REPOS_DIR=$(cat $config_file | grep -w dir_repos | awk 'END {print $NF}')
FUNCTEST_REPO_DIR=$(cat $config_file | grep -w dir_repo_functest | awk 'END {print $NF}')
FUNCTEST_DIR=$(cat $config_file | grep -w dir_functest | awk 'END {print $NF}')
FUNCTEST_RESULTS_DIR=$(cat $config_file | grep -w dir_results | awk 'END {print $NF}')
FUNCTEST_CONF_DIR=$(cat $config_file | grep -w dir_functest_conf | awk 'END {print $NF}')
FUNCTEST_DATA_DIR=$(cat $config_file | grep -w dir_functest_data | awk 'END {print $NF}')
RALLY_VENV_DIR=$(cat $config_file | grep -w dir_rally_inst | awk 'END {print $NF}')


info ()  {
    logger -s -t "FUNCTEST.info" "$*"
}

error () {
    logger -s -t "FUNCTEST.error" "$*"
    exit 1
}
> COUNT=0 until ping -c 1 $METADATA_IP &> /dev/null; do COUNT=$(( $COUNT + 1 )) if [ $COUNT -eq 10 ]; then echo "FAILURE" echo "$METADATA_IP is not pingable." >&2 exit 1 fi done echo "SUCCESS" else echo "No metadata IP found. Skipping." fi } function configure_safe_defaults() { [[ $? == 0 ]] && return 0 cat > /etc/os-net-config/dhcp_all_interfaces.yaml <<EOF_CAT # This file is an autogenerated safe defaults file for os-net-config # which runs DHCP on all discovered interfaces to ensure connectivity # back to the undercloud for updates network_config: EOF_CAT for iface in $(ls /sys/class/net | grep -v ^lo$); do local mac_addr_type="$(cat /sys/class/net/${iface}/addr_assign_type)" if [ "$mac_addr_type" != "0" ]; then echo "Device has generated MAC, skipping." else ip link set dev $iface up &>/dev/null HAS_LINK="$(cat /sys/class/net/${iface}/carrier)" TRIES=10 while [ "$HAS_LINK" == "0" -a $TRIES -gt 0 ]; do HAS_LINK="$(cat /sys/class/net/${iface}/carrier)" if [ "$HAS_LINK" == "1" ]; then break else sleep 1 fi TRIES=$(( TRIES - 1 )) done if [ "$HAS_LINK" == "1" ] ; then cat >> /etc/os-net-config/dhcp_all_interfaces.yaml <<EOF_CAT - type: interface name: $iface use_dhcp: true EOF_CAT fi fi done set +e os-net-config -c /etc/os-net-config/dhcp_all_interfaces.yaml -v --detailed-exit-codes --cleanup RETVAL=$? set -e if [[ $RETVAL == 2 ]]; then ping_metadata_ip elif [[ $RETVAL != 0 ]]; then echo "ERROR: configuration of safe defaults failed." fi } if [ -n '$network_config' ]; then if [ -z "${disable_configure_safe_defaults:-''}" ]; then trap configure_safe_defaults EXIT fi mkdir -p /etc/os-net-config # Note these variables come from the calling heat SoftwareConfig echo '$network_config' > /etc/os-net-config/config.json if [ "$(type -t network_config_hook)" = "function" ]; then network_config_hook fi sed -i "s/bridge_name/${bridge_name:-''}/" /etc/os-net-config/config.json sed -i "s/interface_name/${interface_name:-''}/" /etc/os-net-config/config.json set +e os-net-config -c /etc/os-net-config/config.json -v --detailed-exit-codes RETVAL=$? set -e if [[ $RETVAL == 2 ]]; then ping_metadata_ip #NOTE: dprince this udev rule can apparently leak DHCP processes? # https://bugs.launchpad.net/tripleo/+bug/1538259 # until we discover the root cause we can simply disable the # rule because networking has already been configured at this point if [ -f /etc/udev/rules.d/99-dhcp-all-interfaces.rules ]; then rm /etc/udev/rules.d/99-dhcp-all-interfaces.rules fi elif [[ $RETVAL != 0 ]]; then echo "ERROR: os-net-config configuration failed." >&2 exit 1 fi fi