Display overcloud dashboard URL after deploy
[apex.git] / ci / deploy.sh
index d0b8338..ad7d0d1 100755 (executable)
@@ -30,7 +30,7 @@ else
 fi
 
 vm_index=4
-ha_enabled="TRUE"
+interactive="FALSE"
 ping_site="8.8.8.8"
 ntp_server="pool.ntp.org"
 net_isolation_enabled="TRUE"
@@ -281,7 +281,7 @@ parse_inventory_file() {
   for entry in $inventory; do
     if echo $entry | grep -Eo "^nodes_node[0-9]+_" > /dev/null; then
       this_node=$(echo $entry | grep -Eo "^nodes_node[0-9]+_")
-      if [[ $inventory_list != *"$this_node"* ]]; then
+      if [[ "$inventory_list" != *"$this_node"* ]]; then
         inventory_list+="$this_node "
       fi
     fi
@@ -295,7 +295,7 @@ parse_inventory_file() {
 
   node_total=$node_count
 
-  if [[ "$node_total" -lt 5 && ha_enabled == "TRUE" ]]; then
+  if [[ "$node_total" -lt 5 && ( ha_enabled == "TRUE" || "$ha_enabled" == "true" ) ]]; then
     echo -e "${red}ERROR: You must provide at least 5 nodes for HA baremetal deployment${reset}"
     exit 1
   elif [[ "$node_total" -lt 2 ]]; then
@@ -402,7 +402,7 @@ function configure_deps {
 
   for network in ${OPNFV_NETWORK_TYPES}; do
     ovs-vsctl list-br | grep ${NET_MAP[$network]} > /dev/null || ovs-vsctl add-br ${NET_MAP[$network]}
-    virsh net-list --all | grep ${NET_MAP[$network]} > /dev/null || virsh net-create $CONFIG/${NET_MAP[$network]}-net.xml
+    virsh net-list --all | grep ${NET_MAP[$network]} > /dev/null || virsh net-define $CONFIG/${NET_MAP[$network]}-net.xml
     virsh net-list | grep -E "${NET_MAP[$network]}\s+active" > /dev/null || virsh net-start ${NET_MAP[$network]}
   done
 
@@ -658,11 +658,11 @@ function configure_network_environment {
   sed -i 's#^.*Controller::Net::SoftwareConfig:.*$#  OS::TripleO::Controller::Net::SoftwareConfig: nics/controller'${nic_ext}'.yaml#' $1
 
   # check for ODL L3
-  if [ ${deploy_options_array['sdn_l3']} == 'true' ]; then
+  if [ "${deploy_options_array['sdn_l3']}" == 'true' ]; then
       nic_ext+=_br-ex
   fi
 
-  if [ ${deploy_options_array['sdn_controller']} == 'onos' ]; then
+  if [ "${deploy_options_array['sdn_controller']}" == 'onos' ]; then
       nic_ext+=_no-public-ip
   fi
 
@@ -761,6 +761,15 @@ sudo sed -i '/CephClusterFSID:/c\\  CephClusterFSID: \\x27$(cat /proc/sys/kernel
 sudo sed -i '/CephMonKey:/c\\  CephMonKey: \\x27'"\$(ceph-authtool --gen-print-key)"'\\x27' /usr/share/openstack-tripleo-heat-templates/environments/storage-environment.yaml
 sudo sed -i '/CephAdminKey:/c\\  CephAdminKey: \\x27'"\$(ceph-authtool --gen-print-key)"'\\x27' /usr/share/openstack-tripleo-heat-templates/environments/storage-environment.yaml
 
+# we assume that packages will not need to be updated with undercloud install
+# and that it will be used only to configure the undercloud
+# packages updates would need to be handled manually with yum update
+sudo cp -f /usr/share/diskimage-builder/elements/yum/bin/install-packages /usr/share/diskimage-builder/elements/yum/bin/install-packages.bak
+cat << 'EOF' | sudo tee /usr/share/diskimage-builder/elements/yum/bin/install-packages > /dev/null
+#!/bin/sh
+exit 0
+EOF
+
 openstack undercloud install &> apex-undercloud-install.log
 sleep 30
 sudo systemctl restart openstack-glance-api
@@ -778,27 +787,30 @@ sleep 15
 ##preping it for deployment and launch the deploy
 ##params: none
 function undercloud_prep_overcloud_deploy {
-  if [[ ${#deploy_options_array[@]} -eq 0 || ${deploy_options_array['sdn_controller']} == 'opendaylight' ]]; then
-    if [ ${deploy_options_array['sdn_l3']} == 'true' ]; then
+  if [[ "${#deploy_options_array[@]}" -eq 0 || "${deploy_options_array['sdn_controller']}" == 'opendaylight' ]]; then
+    if [ "${deploy_options_array['sdn_l3']}" == 'true' ]; then
       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight_l3.yaml"
+    elif [ "${deploy_options_array['sfc']}" == 'true' ]; then
+      DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight_sfc.yaml"
     else
       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight.yaml"
     fi
     SDN_IMAGE=opendaylight
-    if [ ${deploy_options_array['sfc']} == 'true' ]; then
+    if [ "${deploy_options_array['sfc']}" == 'true' ]; then
       SDN_IMAGE+=-sfc
     fi
-  elif [ ${deploy_options_array['sdn_controller']} == 'opendaylight-external' ]; then
+  elif [ "${deploy_options_array['sdn_controller']}" == 'opendaylight-external' ]; then
     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight-external.yaml"
     SDN_IMAGE=opendaylight
-  elif [ ${deploy_options_array['sdn_controller']} == 'onos' ]; then
+  elif [ "${deploy_options_array['sdn_controller']}" == 'onos' ]; then
     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/onos.yaml"
     SDN_IMAGE=opendaylight
-  elif [ ${deploy_options_array['sdn_controller']} == 'opencontrail' ]; then
+  elif [ "${deploy_options_array['sdn_controller']}" == 'opencontrail' ]; then
     echo -e "${red}ERROR: OpenContrail is currently unsupported...exiting${reset}"
     exit 1
-  elif [[ -z ${deploy_options_array['sdn_controller']} || ${deploy_options_array['sdn_controller']} == 'false' ]]; then
+  elif [[ -z "${deploy_options_array['sdn_controller']}" || "${deploy_options_array['sdn_controller']}" == 'false' ]]; then
     echo -e "${blue}INFO: SDN Controller disabled...will deploy nosdn scenario${reset}"
+    SDN_IMAGE=opendaylight
   else
     echo "${red}Invalid sdn_controller: ${deploy_options_array['sdn_controller']}${reset}"
     echo "${red}Valid choices are opendaylight, opendaylight-external, onos, opencontrail, false, or null${reset}"
@@ -811,10 +823,24 @@ function undercloud_prep_overcloud_deploy {
   # make sure ceph is installed
   DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/storage-environment.yaml"
 
+  # scale compute nodes according to inventory
+  total_nodes=$(ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" "cat /home/stack/instackenv.json | grep -c memory")
+
   # check if HA is enabled
-  if [[ "$ha_enabled" == "TRUE" ]]; then
-     DEPLOY_OPTIONS+=" --control-scale 3 --compute-scale 2"
+  if [[ "$ha_enabled" == "TRUE" || "$ha_enabled" == "true" ]]; then
+     DEPLOY_OPTIONS+=" --control-scale 3"
+     compute_nodes=$((total_nodes - 3))
      DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/puppet-pacemaker.yaml"
+  else
+     compute_nodes=1
+  fi
+
+  if [ "$compute_nodes" -le 0 ]; then
+    echo -e "${red}ERROR: Invalid number of compute nodes: ${compute_nodes}. Check your inventory file.${reset}"
+    exit 1
+  else
+    echo -e "${blue}INFO: Number of compute nodes set for deployment: ${compute_nodes}${reset}"
+    DEPLOY_OPTIONS+=" --compute-scale ${compute_nodes}"
   fi
 
   if [[ "$net_isolation_enabled" == "TRUE" ]]; then
@@ -822,7 +848,7 @@ function undercloud_prep_overcloud_deploy {
      DEPLOY_OPTIONS+=" -e network-environment.yaml"
   fi
 
-  if [[ "$ha_enabled" == "TRUE" ]] || [[ "$net_isolation_enabled" == "TRUE" ]]; then
+  if [[ "$ha_enabled" == "TRUE" || "$ha_enabled" == "true"  ]] || [[ "$net_isolation_enabled" == "TRUE" ]]; then
      DEPLOY_OPTIONS+=" --ntp-server $ntp_server"
   fi
 
@@ -833,6 +859,9 @@ function undercloud_prep_overcloud_deploy {
   echo -e "${blue}INFO: Deploy options set:\n${DEPLOY_OPTIONS}${reset}"
 
   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
+if [ "$debug" == 'TRUE' ]; then
+    LIBGUESTFS_BACKEND=direct virt-customize -a overcloud-full.qcow2 --root-password password:opnfvapex
+fi
 source stackrc
 set -o errexit
 echo "Uploading overcloud glance images"
@@ -865,6 +894,18 @@ sleep 60 #wait for Hypervisor stats to check-in to nova
 cat > deploy_command << EOF
 openstack overcloud deploy --templates $DEPLOY_OPTIONS --timeout 90
 EOF
+EOI
+
+  if [ "$interactive" == "TRUE" ]; then
+    if ! prompt_user "Overcloud Deployment"; then
+      echo -e "${blue}INFO: User requests exit${reset}"
+      exit 0
+    fi
+  fi
+
+  ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
+source stackrc
+set -o errexit
 openstack overcloud deploy --templates $DEPLOY_OPTIONS --timeout 90
 EOI
 
@@ -875,6 +916,7 @@ echo "Keystone Endpoint List:"
 keystone endpoint-list
 echo "Keystone Service List"
 keystone service-list
+cinder quota-show \$(openstack project list | grep admin | awk {'print \$2'})
 EOI
   fi
 }
@@ -890,9 +932,10 @@ function configure_post_install {
   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
 source overcloudrc
 set -o errexit
+service_tenant_id=$(keystone tenant-get service 2>/dev/null | grep id | cut -d '|' -f 3)
 echo "Configuring Neutron external network"
-neutron net-create external --router:external=True
-neutron subnet-create --name external-net --disable-dhcp external --gateway ${public_network_gateway} --allocation-pool start=${public_network_floating_ip_range%%,*},end=${public_network_floating_ip_range##*,} ${public_network_cidr}
+neutron net-create external --router:external=True --tenant-id $service_tenant_id
+neutron subnet-create --name external-net --tenant-id $service_tenant_id --disable-dhcp external --gateway ${public_network_gateway} --allocation-pool start=${public_network_floating_ip_range%%,*},end=${public_network_floating_ip_range##*,} ${public_network_cidr}
 EOI
 
   echo -e "${blue}INFO: Checking if OVS bridges have IP addresses...${reset}"
@@ -929,6 +972,54 @@ EOI
       echo -e "${blue}INFO: Undercloud (instack VM) has been setup to NAT Overcloud public network${reset}"
     fi
   fi
+
+  # for sfc deployments we need the vxlan workaround
+  if [ "${deploy_options_array['sfc']}" == 'true' ]; then
+      ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
+source stackrc
+set -o errexit
+for node in \$(nova list | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"); do
+ssh -T ${SSH_OPTIONS[@]} "heat-admin@\$node" <<EOF
+sudo ifconfig br-int up
+sudo ip route add 123.123.123.0/24 dev br-int
+EOF
+done
+EOI
+  fi
+
+  # Collect deployment logs
+  ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
+mkdir -p ~/deploy_logs
+rm -rf deploy_logs/*
+source stackrc
+set -o errexit
+for node in \$(nova list | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"); do
+ ssh -T ${SSH_OPTIONS[@]} "heat-admin@\$node" <<EOF
+ sudo cp /var/log/messages /home/heat-admin/messages.log
+ sudo chown heat-admin /home/heat-admin/messages.log
+EOF
+scp ${SSH_OPTIONS[@]} heat-admin@\$node:/home/heat-admin/messages.log ~/deploy_logs/\$node.messages.log
+if [ "\$debug" == "TRUE" ]; then
+    nova list --ip \$node
+    echo "---------------------------"
+    echo "-----/var/log/messages-----"
+    echo "---------------------------"
+    cat ~/deploy_logs/\$node.messages.log
+    echo "---------------------------"
+    echo "----------END LOG----------"
+    echo "---------------------------"
+fi
+ ssh -T ${SSH_OPTIONS[@]} "heat-admin@\$node" <<EOF
+ sudo rm -f /home/heat-admin/messages.log
+EOF
+done
+EOI
+
+  # Print out the dashboard URL
+  source stackrc
+  publicvip=$(heat output-show overcloud PublicVip | sed 's/"//g')
+  echo "Overcloud dashboard available at http://$publicvip/dashboard"
+
 }
 
 display_usage() {
@@ -944,6 +1035,7 @@ display_usage() {
   echo -e "   --flat : disable Network Isolation and use a single flat network for the underlay network.\n"
   echo -e "   --no-post-config : disable Post Install configuration."
   echo -e "   --debug : enable debug output."
+  echo -e "   --interactive : enable interactive deployment mode which requires user to confirm steps of deployment."
 }
 
 ##translates the command line parameters into variables
@@ -1015,6 +1107,11 @@ parse_cmdline() {
                 echo "Enable debug output"
                 shift 1
             ;;
+        --interactive )
+                interactive="TRUE"
+                echo "Interactive mode enabled"
+                shift 1
+            ;;
         *)
                 display_usage
                 exit 1
@@ -1034,18 +1131,18 @@ parse_cmdline() {
     exit 1
   fi
 
-  if [[ ! -z "$DEPLOY_SETTINGS_FILE" && ! -f "$DEPLOY_SETTINGS_FILE" ]]; then
-    echo -e "${red}ERROR: ${DEPLOY_SETTINGS_FILE} does not exist! Exiting...${reset}"
+  if [[ -z "$DEPLOY_SETTINGS_FILE" || ! -f "$DEPLOY_SETTINGS_FILE" ]]; then
+    echo -e "${red}ERROR: Deploy Settings: ${DEPLOY_SETTINGS_FILE} does not exist! Exiting...${reset}"
     exit 1
   fi
 
   if [[ ! -z "$NETSETS" && ! -f "$NETSETS" ]]; then
-    echo -e "${red}ERROR: ${NETSETS} does not exist! Exiting...${reset}"
+    echo -e "${red}ERROR: Network Settings: ${NETSETS} does not exist! Exiting...${reset}"
     exit 1
   fi
 
   if [[ ! -z "$INVENTORY_FILE" && ! -f "$INVENTORY_FILE" ]]; then
-    echo -e "{$red}ERROR: ${DEPLOY_SETTINGS_FILE} does not exist! Exiting...${reset}"
+    echo -e "{$red}ERROR: Inventory File: ${INVENTORY_FILE} does not exist! Exiting...${reset}"
     exit 1
   fi
 
@@ -1097,7 +1194,7 @@ main() {
       echo -e "${blue}INFO: Post Install Configuration Complete${reset}"
     fi
   fi
-  if [[ ${deploy_options_array['sdn_controller']} == 'onos' ]]; then
+  if [[ "${deploy_options_array['sdn_controller']}" == 'onos' ]]; then
     if ! onos_update_gw_mac ${public_network_cidr} ${public_network_gateway}; then
       echo -e "${red}ERROR:ONOS Post Install Configuration Failed, Exiting.${reset}"
       exit 1