X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=lib%2Fcommon-functions.sh;h=709dbf97437ac05db724b85697c59022b33105cb;hb=4e1320c4235476d7e2a0a90f80997e8371c5f399;hp=365f8e3fe1fff25854483460da13a38af2402785;hpb=4f7925beb1103f57bcca0ce6875be79a3cea47ad;p=apex.git diff --git a/lib/common-functions.sh b/lib/common-functions.sh index 365f8e3f..709dbf97 100644 --- a/lib/common-functions.sh +++ b/lib/common-functions.sh @@ -21,18 +21,24 @@ function prefix2mask { } ##find ip of interface -##params: interface name +##params: interface name, address family function find_ip { + local af if [[ -z "$1" ]]; then return 1 fi + if [[ -z "$2" ]]; then + af=4 + else + af=$2 + fi - python3.4 -B $LIB/python/apex_python_utils.py find-ip -i $1 + python3 -B $LIB/python/apex_python_utils.py find-ip -i $1 -af $af } ##attach interface to OVS and set the network config correctly ##params: bride to attach to, interface to attach, network type (optional) -##public indicates attaching to a public interface +##external indicates attaching to a external interface function attach_interface_to_ovs { local bridge interface local if_ip if_mask if_gw if_file ovs_file if_prefix @@ -66,15 +72,15 @@ function attach_interface_to_ovs { if [ -z "$if_mask" ]; then # we can look for PREFIX here, then convert it to NETMASK - if_prefix=$(sed -n 's/^PREFIX=\(.*\)$/\1/p' ${if_file}) + if_prefix=$(sed -n 's/^PREFIX=[^0-9]*\([0-9][0-9]*\)[^0-9]*$/\1/p' ${if_file}) if_mask=$(prefix2mask ${if_prefix}) fi if [[ -z "$if_ip" || -z "$if_mask" ]]; then echo "ERROR: IPADDR or NETMASK/PREFIX missing for ${interface}" return 1 - elif [[ -z "$if_gw" && "$3" == "public_network" ]]; then - echo "ERROR: GATEWAY missing for ${interface}, which is public" + elif [[ -z "$if_gw" && "$3" == "external" ]]; then + echo "ERROR: GATEWAY missing for ${interface}, which is external" return 1 fi @@ -257,3 +263,46 @@ function prompt_user { fi done } + +##checks if prefix exists in string +##params: string, prefix +##usage: contains_prefix "deploy_setting_launcher=1" "deploy_setting" +contains_prefix() { + local mystr=$1 + local prefix=$2 + if echo $mystr | grep -E "^$prefix.*$" > /dev/null; then + return 0 + else + return 1 + fi +} + +##verify internet connectivity +#params: none +function verify_internet { + if ping -c 2 $ping_site > /dev/null; then + if ping -c 2 $dnslookup_site > /dev/null; then + echo "${blue}Internet connectivity detected${reset}" + return 0 + else + echo "${red}Internet connectivity detected, but DNS lookup failed${reset}" + return 1 + fi + else + echo "${red}No internet connectivity detected${reset}" + return 1 + fi +} + +##tests if overcloud nodes have external connectivity +#params:none +function test_overcloud_connectivity { + for node in $(undercloud_connect stack ". stackrc && nova list" | grep -Eo "controller-[0-9]+|compute-[0-9]+" | tr -d -) ; do + if ! overcloud_connect $node "ping -c 2 $ping_site > /dev/null"; then + echo "${blue}Node ${node} was unable to ping site ${ping_site}${reset}" + return 1 + fi + done + echo "${blue}Overcloud external connectivity OK${reset}" +} +