Merge "Updates the real time kvm kernel from 4.4.6-rt14 to 4.4.50-rt62."
[apex.git] / lib / common-functions.sh
index 079b088..709dbf9 100644 (file)
@@ -1,4 +1,13 @@
 #!/usr/bin/env bash
+##############################################################################
+# Copyright (c) 2015 Tim Rozet (Red Hat), Dan Radez (Red Hat) and others.
+#
+# 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
+##############################################################################
+
 # Common Functions used by  OPNFV Apex
 # author: Tim Rozet (trozet@redhat.com)
 
@@ -12,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
@@ -57,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
 
@@ -248,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}"
+}
+