Check for errors by default in scripts 75/3875/2
authorTodd Malsbary <todd.malsbary@intel.com>
Thu, 5 Nov 2020 17:40:31 +0000 (09:40 -0800)
committerKuralamudhan Ramakrishnan <kuralamudhan.ramakrishnan@intel.com>
Fri, 6 Nov 2020 23:26:49 +0000 (23:26 +0000)
Inconsistent usage led to continuing after failure in, for example,
kud_bm_deploy_mini when kud_bm_launch.sh failed to get the necessary
packages.

Scripts in ci, cmd/bpa-operator/vendor, deploy/kud-plugin-addons, and
sdwan are excluded from this change.

Issue-ID: ICN-498
Signed-off-by: Todd Malsbary <todd.malsbary@intel.com>
Change-Id: Ib97fc73208e74115568974262ac2d213271fd649

43 files changed:
cmd/bpa-operator/bpa_operator_launch.sh
cmd/bpa-operator/e2etest/bpa_bmh_verifier.sh
cmd/bpa-operator/e2etest/bpa_remote_virtletvm_verifier.sh
cmd/bpa-operator/e2etest/bpa_virtletvm_verifier.sh
cmd/bpa-operator/e2etest/bpa_vm_verifier.sh
cmd/bpa-restapi-agent/bpa_api_install.sh
cmd/bpa-restapi-agent/bpa_api_uninstall.sh
cmd/bpa-restapi-agent/e2e_test.sh
cmd/bpa-restapi-agent/install_go.sh
deploy/kud/kud_bm_launch.sh
deploy/kud/kud_launch.sh
deploy/metal3-vm/01_install_requirements.sh
deploy/metal3-vm/02_configure_host.sh
deploy/metal3-vm/03_launch_mgmt_cluster.sh
deploy/metal3-vm/04_verify.sh
deploy/metal3-vm/05_host_cleanup.sh
deploy/metal3-vm/disable_apparmor_driver_libvirtd.sh
deploy/metal3-vm/lib/common.sh
deploy/metal3-vm/lib/logging.sh
deploy/metal3-vm/ubuntu_bridge_network_configuration.sh
deploy/metal3-vm/ubuntu_install_requirements.sh
deploy/metal3-vm/vm-setup/roles/libvirt/files/get-domain-ip.sh
deploy/metal3-vm/vm-setup/roles/virtbmc/files/vbmc_start.sh
deploy/metal3/scripts/01_metal3.sh
deploy/metal3/scripts/02_verify.sh
deploy/metal3/scripts/03_verify_deprovisioning.sh
env/cd_package_installer.sh
env/lib/common.sh
env/lib/logging.sh
env/metal3/01_install_package.sh
env/metal3/02_configure.sh
env/metal3/03_launch_prereq.sh
env/metal3/06_host_cleanup.sh
env/ubuntu/bootloader-env/01_bootloader_package_req.sh
env/ubuntu/bootloader-env/02_clean_bootloader_package_req.sh
tools/cloud-configs.sh
tools/collect.sh
tools/create_usb_bootable.sh
tools/openness/eaa/build_image.sh
tools/openness/edgeapps/sample-app/build-images.sh
tools/setup_build_machine.sh
user_config.sh
verify.sh

index d1f1448..ae118d7 100755 (executable)
@@ -1,4 +1,5 @@
-#!/bin/bash
+#!/usr/bin/env bash
+set -eu -o pipefail
 
 #Get Go ENV variables
 eval "$(go env)"
index 5dece3a..edf93df 100755 (executable)
@@ -1,4 +1,5 @@
-#!/bin/bash
+#!/usr/bin/env bash
+set -eu -o pipefail
 
 CLUSTER_NAME=test-bmh-cluster
 
@@ -25,9 +26,7 @@ then
    KUBECONFIG=--kubeconfig=/opt/kud/multi-cluster/${CLUSTER_NAME}/artifacts/admin.conf
    APISERVER=$(kubectl ${KUBECONFIG} config view --minify -o jsonpath='{.clusters[0].cluster.server}')
    TOKEN=$(kubectl ${KUBECONFIG} get secret $(kubectl ${KUBECONFIG} get serviceaccount default -o jsonpath='{.secrets[0].name}') -o jsonpath='{.data.token}' | base64 --decode )
-   call_api $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure
-   ret=$?
-   if [[ $ret != 0 ]];
+   if ! call_api $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure;
    then
      printf "\nKubernetes Cluster Install did not complete successfully\n"
    else
index 8f54d2f..78096b5 100755 (executable)
@@ -1,4 +1,5 @@
-#!/bin/bash
+#!/usr/bin/env bash
+set -eu -o pipefail
 
 printf "\n\nStart Remote Virtlet VM provisioning E2E test\n\n"
 
@@ -8,9 +9,7 @@ CLUSTER_NAME=bpa-remote
 KUBECONFIG=--kubeconfig=/opt/kud/multi-cluster/${CLUSTER_NAME}/artifacts/admin.conf
 APISERVER=$(kubectl ${KUBECONFIG} config view --minify -o jsonpath='{.clusters[0].cluster.server}')
 TOKEN=$(kubectl ${KUBECONFIG} get secret $(kubectl ${KUBECONFIG} get serviceaccount default -o jsonpath='{.secrets[0].name}') -o jsonpath='{.data.token}' | base64 --decode )
-call_api $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure
-ret=$?
-if [[ $ret != 0 ]];
+if ! call_api $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure;
 then
   printf "\nRemote Kubernetes Cluster Install did not complete successfully\n"
 else
index 3a45727..946a1f9 100755 (executable)
@@ -1,4 +1,5 @@
-#!/bin/bash
+#!/usr/bin/env bash
+set -eu -o pipefail
 
 printf "\n\nStart Virtlet VM provisioning E2E test\n\n"
 
index 2d0ce08..e18de25 100755 (executable)
@@ -1,4 +1,5 @@
-#!/bin/bash
+#!/usr/bin/env bash
+set -eu -o pipefail
 
 CLUSTER_NAME=cluster-test
 
@@ -84,9 +85,7 @@ then
    KUBECONFIG=--kubeconfig=/opt/kud/multi-cluster/${CLUSTER_NAME}/artifacts/admin.conf
    APISERVER=$(kubectl ${KUBECONFIG} config view --minify -o jsonpath='{.clusters[0].cluster.server}')
    TOKEN=$(kubectl ${KUBECONFIG} get secret $(kubectl ${KUBECONFIG} get serviceaccount default -o jsonpath='{.secrets[0].name}') -o jsonpath='{.data.token}' | base64 --decode )
-   call_api $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure
-   ret=$?
-   if [[ $ret != 0 ]];
+   if ! call_api $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure;
    then
      printf "\nKubernetes Cluster Install did not complete successfully\n"
    else
index 3b8428e..533bebd 100755 (executable)
@@ -1,4 +1,5 @@
-#!/bin/bash
+#!/usr/bin/env bash
+set -eu -o pipefail
 
 ICN_DIR=$(dirname "$(dirname "$PWD")")
 
index f1f8836..89748df 100755 (executable)
@@ -1,4 +1,5 @@
-#!/bin/bash
+#!/usr/bin/env bash
+set -eu -o pipefail
 
 ICN_DIR=$(dirname "$(dirname "$PWD")")
 
index 48c8f30..4742bdb 100755 (executable)
@@ -1,4 +1,5 @@
-#!/bin/bash
+#!/usr/bin/env bash
+set -eu -o pipefail
 
 ICN_DIR=$(dirname "$(dirname "$PWD")")
 
index 944a58b..e3341cb 100755 (executable)
@@ -1,4 +1,5 @@
-#1/bin/bash
+#!/usr/bin/env bash
+set -eu -o pipefail
 
 if which go > /dev/null; then
     sudo apt-get -yq install golang-go
index 2d0aea6..2e5f9aa 100755 (executable)
@@ -1,5 +1,5 @@
-#!/bin/bash
-set +x
+#!/usr/bin/env bash
+set -eu -o pipefail
 
 LIBDIR="$(dirname "$(dirname "$PWD")")"
 
@@ -37,7 +37,7 @@ function set_bm_kud {
     pushd $DOWNLOAD_PATH/multicloud-k8s/kud/hosting_providers/vagrant/inventory
     HOST_IP=${HOST_IP:-$(hostname -I | cut -d ' ' -f 1)}
     if [ "$1" == "minimal" ] ; then
-    cat <<EOL > hosts.ini
+        cat <<EOL > hosts.ini
 [all]
 $HOSTNAME ansible_ssh_host=${HOST_IP} ansible_ssh_port=22
 
@@ -55,7 +55,7 @@ kube-node
 kube-master
 EOL
     else
-    cat <<EOL > hosts.ini
+        cat <<EOL > hosts.ini
 [all]
 $HOSTNAME ansible_ssh_host=${HOST_IP} ansible_ssh_port=22
 
index e63419a..53d7154 100755 (executable)
@@ -1,4 +1,6 @@
-#!/bin/bash
+#!/usr/bin/env bash
+set -eu -o pipefail
+
 LIBDIR="$(dirname "$(dirname "$PWD")")"
 
 source $LIBDIR/env/lib/common.sh
index a2c0775..ca9ce6c 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/bin/env bash
-set +x
+set -eu -o pipefail
 
 OS=$(awk -F= '/^ID=/ { print $2 }' /etc/os-release | tr -d '"')
 if [[ $OS == ubuntu ]]; then
index 80ee984..e99e8b5 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/bin/env bash
-set -xe
+set -eux -o pipefail
 
 # shellcheck disable=SC1091
 source lib/logging.sh
index d593380..0c3e707 100755 (executable)
@@ -1,5 +1,5 @@
-#!/bin/bash
-set -xe
+#!/usr/bin/env bash
+set -eux -o pipefail
 
 # shellcheck disable=SC1091
 source lib/logging.sh
index 0d6e5f2..ce42eba 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/bin/env bash
-#set -x
+set -eu -o pipefail
 
 # shellcheck disable=SC1091
 source lib/common.sh
@@ -47,15 +47,12 @@ function warm_up_time {
 }
 
 function wait_for_provisioned {
-    all_bmh_provisioned=1
     declare -i k=1
     declare -i t=$timeout
     while ((t > 0)); do
         echo "Try $k/$timeout iteration : Wait for $interval seconds to check all bmh state"
         sleep $interval
-        list_nodes | check_provisioned
-        all_bmh_state=$?
-        if [[ $all_bmh_state -eq $all_bmh_provisioned ]]; then
+        if ! list_nodes | check_provisioned; then
             echo "All the VMs are provisioned - success"
             warm_up_time
             exit 0
index 0c83b56..c8edd48 100755 (executable)
@@ -1,11 +1,14 @@
 #!/usr/bin/env bash
-set -x
+set -eux -o pipefail
 
 # shellcheck disable=SC1091
 source lib/logging.sh
 # shellcheck disable=SC1091
 source lib/common.sh
 
+BMO_RUN_LOCAL="${BMO_RUN_LOCAL:-false}"
+CAPBM_RUN_LOCAL="${CAPBM_RUN_LOCAL:-false}"
+
 # Kill and remove the running ironic containers
 for name in ironic ironic-inspector dnsmasq httpd mariadb ipa-downloader; do
     sudo "${CONTAINER_RUNTIME}" ps | grep -w "$name$" && sudo "${CONTAINER_RUNTIME}" kill $name
index 0c84350..5aca6d6 100644 (file)
@@ -1,4 +1,5 @@
 #!/usr/bin/env bash
+set -eu -o pipefail
 
 selinux="#security_driver = \"selinux\""
 apparmor="security_driver = \"apparmor\""
index 034c243..6c82637 100644 (file)
@@ -1,4 +1,5 @@
-#!/bin/bash
+#!/usr/bin/env bash
+set -eu -o pipefail
 
 eval "$(go env)"
 
index 0bef81a..e936439 100644 (file)
@@ -1,3 +1,6 @@
+#!/usr/bin/env bash
+set -eu -o pipefail
+
 # Log output automatically
 LOGDIR="$(dirname $0)/logs"
 if [ ! -d "$LOGDIR" ]; then
index dffa678..3f7b8b9 100755 (executable)
@@ -1,6 +1,5 @@
 #!/usr/bin/env bash
-
-set -xe
+set -eux -o pipefail
 
 # shellcheck disable=SC1091
 source lib/logging.sh
index 503813a..3886888 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/bin/env bash
-set -ex
+set -eux -o pipefail
 
 # shellcheck disable=SC1091
 source lib/logging.sh
index 8ccc078..ad0fd61 100644 (file)
@@ -1,9 +1,8 @@
-#!/bin/sh
+#!/usr/bin/env bash
+set -eu -o pipefail
 
 # This script will attempt to get the ip address of the a given libvirt guest.
 
-set -eu
-
 PATH=$PATH:/usr/sbin:/sbin
 
 VMNAME=$1
index 08d8c76..dbfa2d3 100755 (executable)
@@ -1,5 +1,5 @@
-#!/bin/bash
-set +ex
+#!/usr/bin/env bash
+set -eu -o pipefail
 
 LIBDIR="$(dirname "$(dirname "$(dirname "$PWD")")")"
 
index fff486b..85a2a29 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/bin/env bash
-#set -x
+set -eu -o pipefail
 
 LIBDIR="$(dirname "$(dirname "$(dirname "$PWD")")")"
 
@@ -50,14 +50,11 @@ function warm_up_time {
 }
 
 function wait_for_provisioned {
-    all_bmh_provisioned=1
     declare -i k=1
     while ((timeout > 0)); do
         echo "Try $k iteration : Wait for $interval seconds to check all bmh state"
         sleep $interval
-        list_nodes | check_provisioned
-        all_bmh_state=$?
-        if [[ $all_bmh_state -eq $all_bmh_provisioned ]]; then
+        if ! list_nodes | check_provisioned; then
             echo "All the Baremetal hosts are provisioned - success"
             warm_up_time
             exit 0
index 97a8a21..afe0497 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/bin/env bash
-#set -x
+set -eu -o pipefail
 
 LIBDIR="$(dirname "$(dirname "$(dirname "$PWD")")")"
 
@@ -26,7 +26,7 @@ function check_deprovisioned {
         echo "Baremetal $name     current_host_state : "$current_host_state
         echo "Previous Baremetals prev_host_state    : "$prev_host_state
 
-         if [ $j -eq 0 ]; then
+        if [ $j -eq 0 ]; then
             prev_host_state=$current_host_state
             ((j+=1))
             continue
@@ -50,14 +50,11 @@ function warm_up_time {
 }
 
 function wait_for_deprovisioned {
-    all_bmh_deprovisioned=1
     declare -i k=1
     while ((timeout > 0)); do
         echo "Try $k iteration : Wait for $interval seconds to check all bmh state"
         sleep $interval
-        list_nodes | check_deprovisioned
-        all_bmh_state=$?
-        if [[ $all_bmh_state -eq $all_bmh_deprovisioned ]]; then
+        if ! list_nodes | check_deprovisioned; then
             echo "All the Baremetal hosts are deprovisioned - success"
             warm_up_time
             exit 0
index 6370f01..e6641d6 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/bin/env bash
-set -ex
+set -eux -o pipefail
 
 if [[ $EUID -ne 0 ]]; then
     echo "This script must be run as root"
index 195c807..39125ef 100755 (executable)
@@ -1,4 +1,5 @@
-#!/bin/bash
+#!/usr/bin/env bash
+set -eu -o pipefail
 
 #supported OS version
 UBUNTU_BIONIC=${UBUNTU_BIONIC:-Ubuntu 18.04.2 LTS}
@@ -8,7 +9,7 @@ DOWNLOAD_PATH=${DOWNLOAD_PATH:-/opt/icn}
 LOCAL_APT_REPO=${LOCAL_APT_REPO:-$DOWNLOAD_PATH/apt}
 PIP_CACHE_DIR=${PIP_CACHE_DIR:-$DOWNLOAD_PATH/pip-cache-dir}
 BUILD_DIR=${BUILD_DIR:-$DOWNLOAD_PATH/build-dir}
-CONTAINER_IMAGES_DIR=${CONTAINER_IMAGES_DIR:-$OFFLINE_DOWNLOAD_PATH/docker-dir}
+CONTAINER_IMAGES_DIR=${CONTAINER_IMAGES_DIR:-$DOWNLOAD_PATH/docker-dir}
 
 #set variables
 #Todo include over all variables here
index 40a29f8..9f31833 100755 (executable)
@@ -1,4 +1,5 @@
-#!/bin/bash
+#!/usr/bin/env bash
+set -eu -o pipefail
 
 # Log output automatically
 # referred from metal3 project
index 56b65d3..bff8096 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/bin/env bash
-set -ex
+set -eux -o pipefail
 
 LIBDIR="$(dirname "$PWD")"
 
@@ -112,9 +112,10 @@ install() {
     #install_kubernetes_packages $1
 }
 
-if ["$1" == "-o"]; then
+if [ "$#" -eq 0 ]; then
+    install online
+elif [ "$1" == "-o" ]; then
     install offline
-    exit 0
+else
+    exit 1
 fi
-
-install
index e05abc1..085a162 100755 (executable)
@@ -1,5 +1,6 @@
 #!/usr/bin/env bash
-set -xe
+set -eux -o pipefail
+
 LIBDIR="$(dirname "$PWD")"
 
 source $LIBDIR/lib/logging.sh
@@ -163,9 +164,10 @@ function configure {
     configure_ironic_interfaces
 }
 
-if [ "$1" == "-o" ]; then
+if [ "$#" -eq 0 ]; then
+    configure online
+elif [ "$1" == "-o" ]; then
     configure offline
-    exit 0
+else
+    exit 1
 fi
-
-configure
index efd97c5..8b2b056 100755 (executable)
@@ -1,5 +1,5 @@
-#!/bin/bash
-set -xe
+#!/usr/bin/env bash
+set -eux -o pipefail
 
 LIBDIR="$(dirname "$PWD")"
 
@@ -182,23 +182,18 @@ function install {
     install_ironic_container
 }
 
-if [ "$1" == "-o" ]; then
+if [ "$#" -eq 0 ]; then
+    install online
+elif [ "$1" == "-o" ]; then
     install offline
-    exit 0
-fi
-
-if [ "$1" == "--dhcp-start" ]; then
+elif [ "$1" == "--dhcp-start" ]; then
     install_dhcp
     echo "wait for 320s for nodes to be assigned"
     sleep 6m
-    exit 0
-fi
-
-if [ "$1" == "--dhcp-reset" ]; then
+elif [ "$1" == "--dhcp-reset" ]; then
     reset_dhcp
     echo "wait for 320s for nodes to be re-assigned"
     sleep 6m
-    exit 0
+else
+    exit 1
 fi
-
-install
index 4085718..f82636a 100755 (executable)
@@ -1,5 +1,6 @@
 #!/usr/bin/env bash
-set -x
+set -eux -o pipefail
+
 LIBDIR="$(dirname "$PWD")"
 
 source $LIBDIR/lib/common.sh
index 082d973..8bbb226 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/bin/env bash
-set -ex
+set -eux -o pipefail
 shopt -s extglob
 
 source $(dirname $PWD)/../lib/common.sh
index 9c20cf2..54c9ab3 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/bin/env bash
-set -ex
+set -eux -o pipefail
 
 source $(dirname $PWD)/../lib/common.sh
 source $(dirname $PWD)/../lib/logging.sh
index acce8c1..94857b8 100644 (file)
@@ -1,4 +1,5 @@
-!/bin/bash
+#!/usr/bin/env bash
+set -eu -o pipefail
 
 # This script is called by cloud-init on worker nodes
 # What does this script do:
@@ -25,7 +26,7 @@ for module in $MODULES_LIST; do
     tar xvzf $filename
     if [ -d $module ]; then
         echo "Installing module $module ..."
-    pushd $module
+        pushd $module
         bash ./install.sh
         popd
     rm -rf $module
index 8351552..05450c2 100755 (executable)
@@ -1,7 +1,5 @@
 #!/usr/bin/env bash
-
-
-set -ex
+set -eux -o pipefail
 
 SCRIPT_PATH=`realpath $0`
 TOOL_PATH=`dirname "$SCRIPT_PATH"`
index ea64344..b493038 100755 (executable)
@@ -1,6 +1,5 @@
 #!/usr/bin/env bash
-
-set -ex
+set -eux -o pipefail
 
 SCRIPT_PATH=`realpath $0`
 TOOL_PATH=`dirname "$SCRIPT_PATH"`
index 439fe8a..3a8acbd 100755 (executable)
@@ -1,6 +1,5 @@
 #!/usr/bin/env bash
-
-set -ex
+set -eux -o pipefail
 
 source ../_common.sh
 
index 59c233d..a696a4a 100755 (executable)
@@ -1,6 +1,5 @@
 #!/usr/bin/env bash
-
-set -ex
+set -eux -o pipefail
 
 source ../../_common.sh
 
index 293bff9..2d5f857 100755 (executable)
@@ -1,4 +1,5 @@
 #!/usr/bin/env bash
+set -eu -o pipefail
 
 apt update
 apt install -y mkisofs coreutils
index 42689fc..a6fac44 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
 
 #Local controller - Bootstrap cluster DHCP connection
 export BS_DHCP_INTERFACE="eno3"
index 328b892..9e63eeb 100755 (executable)
--- a/verify.sh
+++ b/verify.sh
@@ -1,4 +1,5 @@
 #!/usr/bin/env bash
+set -eu -o pipefail
 
 # This file is called by jenkins CI job