Adding error checking 13/10013/1
authorDan Radez <dradez@redhat.com>
Fri, 12 Feb 2016 19:42:02 +0000 (14:42 -0500)
committerTim Rozet <trozet@redhat.com>
Mon, 15 Feb 2016 15:50:13 +0000 (15:50 +0000)
Change-Id: I515ac692a1a2251f16f4b9e06f94c6a626374285
JIRA: APEX-81, APEX-69
(cherry picked from commit 2ae5311eee12b177054b002febea203b17b7cd8b)

build/opnfv-apex-undercloud.spec
ci/deploy.sh

index 1809274..8d585db 100644 (file)
@@ -9,8 +9,8 @@ URL:            https://gerrit.opnfv.org/gerrit/apex.git
 Source0:       opnfv-apex-undercloud.tar.gz
 
 BuildArch:     noarch
-BuildRequires: openvswitch qemu-kvm python-docutils
-Requires:      openvswitch qemu-kvm bridge-utils libguestfs-tools
+BuildRequires: openvswitch libvirt qemu-kvm python-docutils
+Requires:      openvswitch libvirt qemu-kvm bridge-utils libguestfs-tools
 
 %description
 Scripts and Disk images to launch Instack Undercloud for OPNFV Apex
index 39f76c0..6c94091 100755 (executable)
@@ -303,7 +303,7 @@ parse_inventory_file() {
     exit 1
   fi
 
-  eval $(parse_yaml $INVENTORY_FILE)
+  eval $(parse_yaml $INVENTORY_FILE) || echo "${red}Failed to parse inventory.yaml. Aborting.${reset}" && exit 1
 
   instack_env_output="
 {
@@ -388,7 +388,8 @@ function configure_deps {
   fi
 
   # ensure networks are configured
-  systemctl start openvswitch
+  systemctl status libvirtd || systemctl start libvirtd
+  systemctl status openvswitch || systemctl start openvswitch
 
   # If flat we only use admin network
   if [[ "$net_isolation_enabled" == "FALSE" ]]; then
@@ -400,10 +401,15 @@ function configure_deps {
     virsh_enabled_networks=$enabled_network_list
   fi
 
+  virsh net-list | grep default || virsh net-define /usr/share/libvirt/networks/default.xml
+  virsh net-list | grep -E "default\s+active" > /dev/null || virsh net-start default
+  virsh net-list | grep -E "default\s+active\s+yes" > /dev/null || virsh net-autostart --network default
+
   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-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]}
+    virsh net-list | grep -E "${NET_MAP[$network]}\s+active\s+yes" > /dev/null || virsh net-autostart --network ${NET_MAP[$network]}
   done
 
   echo -e "${blue}INFO: Bridges set: ${reset}"
@@ -491,7 +497,7 @@ function setup_instack_vm {
       #error: internal error: received hangup / error event on socket
       #error: Reconnected to the hypervisor
 
-      instack_dst=/var/lib/libvirt/images/instack.qcow2
+      local instack_dst=/var/lib/libvirt/images/instack.qcow2
       cp -f $RESOURCES/instack.qcow2 $instack_dst
 
       # resize instack machine
@@ -499,8 +505,8 @@ function setup_instack_vm {
       instack_size=$(LIBGUESTFS_BACKEND=direct virt-filesystems --long -h --all -a $instack_dst |grep device | grep -Eo "[0-9\.]+G" | sed -n 's/\([0-9][0-9]*\).*/\1/p')
       if [ "$instack_size" -lt 30 ]; then
         qemu-img resize /var/lib/libvirt/images/instack.qcow2 +25G
-       LIBGUESTFS_BACKEND=direct virt-resize --expand /dev/sda1 $RESOURCES/instack.qcow2 $instack_dst
-       LIBGUESTFS_BACKEND=direct virt-customize -a $instack_dst --run-command 'xfs_growfs -d /dev/sda1 || true'
+        LIBGUESTFS_BACKEND=direct virt-resize --expand /dev/sda1 $RESOURCES/instack.qcow2 $instack_dst
+        LIBGUESTFS_BACKEND=direct virt-customize -a $instack_dst --run-command 'xfs_growfs -d /dev/sda1 || true'
         new_size=$(LIBGUESTFS_BACKEND=direct virt-filesystems --long -h --all -a $instack_dst |grep filesystem | grep -Eo "[0-9\.]+G" | sed -n 's/\([0-9][0-9]*\).*/\1/p')
         if [ "$new_size" -lt 30 ]; then
           echo "Error resizing instack machine, disk size is ${new_size}"
@@ -519,7 +525,7 @@ function setup_instack_vm {
   # if the VM is not running update the authkeys and start it
   if ! virsh list | grep instack > /dev/null; then
     echo "Injecting ssh key to instack VM"
-    virt-customize -c qemu:///system -d instack --run-command "mkdir -p /root/.ssh/" \
+    LIBGUESTFS_BACKEND=direct virt-customize -a $instack_dst --run-command "mkdir -p /root/.ssh/" \
         --upload ~/.ssh/id_rsa.pub:/root/.ssh/authorized_keys \
         --run-command "chmod 600 /root/.ssh/authorized_keys && restorecon /root/.ssh/authorized_keys" \
         --run-command "cp /root/.ssh/authorized_keys /home/stack/.ssh/" \
@@ -798,6 +804,11 @@ function undercloud_prep_overcloud_deploy {
     SDN_IMAGE=opendaylight
     if [ "${deploy_options_array['sfc']}" == 'true' ]; then
       SDN_IMAGE+=-sfc
+      if [ ! -f $RESOURCES/overcloud-full-${SDN_IMAGE}.qcow2 ]; then
+          echo "${red} $RESOURCES/overcloud-full-${SDN_IMAGE}.qcow2 is required to execute an SFC deployment."
+          echo "Please install the opnfv-apex-opendaylight-sfc package to provide this overcloud image for deployment.${reset}"
+          exit 1
+      fi
     fi
   elif [ "${deploy_options_array['sdn_controller']}" == 'opendaylight-external' ]; then
     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight-external.yaml"
@@ -817,6 +828,14 @@ function undercloud_prep_overcloud_deploy {
     exit 1
   fi
 
+  # Make sure the correct overcloud image is available
+  if [ ! -f $RESOURCES/overcloud-full-${SDN_IMAGE}.qcow2 ]; then
+      echo "${red} $RESOURCES/overcloud-full-${SDN_IMAGE}.qcow2 is required to execute your deployment."
+      echo "Both ONOS and OpenDaylight are currently deployed from this image."
+      echo "Please install the opnfv-apex package to provide this overcloud image for deployment.${reset}"
+      exit 1
+  fi
+
   echo "Copying overcloud image to instack"
   scp ${SSH_OPTIONS[@]} $RESOURCES/overcloud-full-${SDN_IMAGE}.qcow2 "stack@$UNDERCLOUD":overcloud-full.qcow2
 
@@ -932,10 +951,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)
+service_tenant_id="\$(keystone tenant-get service | grep id | awk '{ print \$4 }')"
 echo "Configuring Neutron external network"
-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}
+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}"
@@ -999,7 +1018,7 @@ for node in \$(nova list | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"); do
  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
+if [ "$debug" == "TRUE" ]; then
     nova list --ip \$node
     echo "---------------------------"
     echo "-----/var/log/messages-----"
@@ -1013,12 +1032,12 @@ fi
  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"
+# Print out the dashboard URL
+source stackrc
+publicvip=\$(heat output-show overcloud PublicVip | sed 's/"//g')
+echo "Overcloud dashboard available at http://\$publicvip/dashboard"
+EOI
 
 }