Adds check to ensure that provided static_ip_range param is correct
[genesis.git] / foreman / ci / deploy.sh
index a978e38..0803993 100755 (executable)
@@ -30,6 +30,7 @@ declare -A admin_ip_arr
 declare -A public_ip_arr
 
 vm_dir=/var/opt/opnfv
+script=`realpath $0`
 ##END VARS
 
 ##FUNCTIONS
@@ -324,7 +325,7 @@ parse_cmdline() {
   fi
 
   ##Validate nic args
-  if [ $nic_arg_flag -eq 1 ]; then
+  if [[ $nic_arg_flag -eq 1 ]]; then
     if [ -z "$virtual" ]; then
       for nic_type in admin_nic private_nic public_nic; do
         eval "nic_value=\$$nic_type"
@@ -476,20 +477,12 @@ clean_tmp() {
 }
 
 ##clone genesis and move to node vm dir
-##params: none
-##usage: clone_bgs
+##params: destination directory
+##usage: clone_bgs /tmp/myvm/
 clone_bgs() {
-  cd /tmp/
-  rm -rf /tmp/genesis/
-
-  ##clone artifacts and move into foreman_vm dir
-  if ! GIT_SSL_NO_VERIFY=true git clone https://gerrit.opnfv.org/gerrit/genesis.git; then
-    printf '%s\n' 'deploy.sh: Unable to clone genesis repo' >&2
-    exit 1
-  fi
-
-  mv -f /tmp/genesis/foreman/ci $vm_dir/foreman_vm
-  rm -rf /tmp/genesis/
+  script_dir="`dirname "$script"`"
+  cp -fr $script_dir/ $1
+  cp -fr $script_dir/../../common/puppet-opnfv $1
 }
 
 ##validates the network settings and update VagrantFile with network settings
@@ -500,7 +493,7 @@ configure_network() {
 
   ##if nic_arg_flag is set, then we don't figure out
   ##NICs dynamically
-  if [ $nic_arg_flag -eq 1 ]; then
+  if [[ $nic_arg_flag -eq 1 ]]; then
     echo "${blue}Static Network Interfaces Defined.  Updating Vagrantfile...${reset}"
     if [ $virtual ]; then
       nic_list="$public_nic"
@@ -516,7 +509,7 @@ configure_network() {
     echo "${blue}Detecting network configuration...${reset}"
     ##detect host 1 or 3 interface configuration
     #output=`ip link show | grep -E "^[0-9]" | grep -Ev ": lo|tun|virbr|vboxnet" | awk '{print $2}' | sed 's/://'`
-    output=`ifconfig | grep -E "^[a-zA-Z0-9]+:"| grep -Ev "lo|tun|virbr|vboxnet" | awk '{print $1}' | sed 's/://'`
+    output=`/bin/ls -l /sys/class/net | tail -n +2 | grep -v virtual | cut -d " " -f10`
   fi
 
   if [ ! "$output" ]; then
@@ -546,6 +539,13 @@ configure_network() {
     ##set variable info
     if [ ! -z "$static_ip_range" ]; then
       new_ip=$(echo $static_ip_range | cut -d , -f1)
+      subnet_mask=$(find_netmask $this_default_gw_interface)
+      host_subnet=$(find_subnet $interface_ip $subnet_mask)
+      ip_range_subnet=$(find_subnet $new_ip $subnet_mask)
+      if [ "$ip_range_subnet" != "$host_subnet" ]; then
+        echo "${red}static_ip_range: ${static_ip_range} is not in the same subnet as your default gateway interface: ${host_subnet}.  Please use a correct range!${reset}"
+        exit 1
+      fi
     else
       new_ip=$(next_usable_ip $interface_ip)
       if [ ! "$new_ip" ]; then
@@ -1000,20 +1000,13 @@ start_virtual_nodes() {
     compute_wait_completed=false
 
     for node in ${nodes}; do
-      cd /tmp/
 
       ##remove VM nodes incase it wasn't cleaned up
       rm -rf $vm_dir/$node
       rm -rf /tmp/genesis/
 
       ##clone genesis and move into node folder
-      if ! GIT_SSL_NO_VERIFY=true git clone https://gerrit.opnfv.org/gerrit/genesis.git; then
-        printf '%s\n' 'deploy.sh: Unable to clone vagrant repo' >&2
-        exit 1
-      fi
-
-      mv -f /tmp/genesis/foreman/ci $vm_dir/$node
-      rm -rf /tmp/genesis/
+      clone_bgs $vm_dir/$node
 
       cd $vm_dir/$node
 
@@ -1140,6 +1133,7 @@ start_virtual_nodes() {
       if ! vagrant ssh -c "route | grep default | grep $this_default_gw"; then
         echo "${blue} Adding public route back to $node! ${reset}"
         vagrant ssh -c "route add default gw $this_default_gw"
+        vagrant ssh -c "route delete default gw 10.0.2.2"
       fi
       popd
     done
@@ -1230,7 +1224,7 @@ main() {
   install_vagrant
   clean_tmp
   verify_vm_dir
-  clone_bgs
+  clone_bgs $vm_dir/foreman_vm
   configure_network
   configure_virtual
   start_foreman