Merge "Move deploy options check to network settings section"
[apex.git] / lib / common-functions.sh
index 6b259ac..6941093 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,13 +21,19 @@ 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.4 -B $LIB/python/apex_python_utils.py find-ip -i $1 -af $af
 }
 
 ##attach interface to OVS and set the network config correctly
@@ -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 www.google.com > /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}"
+}
+