nfvbenchvm: abort build on error 32/73232/1
authorGwenael Lambrouin <gwenael.lambrouin@orange.com>
Mon, 13 Dec 2021 12:48:14 +0000 (13:48 +0100)
committerGwenael Lambrouin <gwenael.lambrouin@orange.com>
Mon, 28 Feb 2022 17:40:54 +0000 (18:40 +0100)
Make sure a VM image build fails if any step fails.  Else we can end up
with a bad image not containing all that we want, and we discover this
later at run time.

For instance, without the current patch, we can get a generator VM image
without nfvbench installed because "pip install" failed, but this is not
detected by the build process because the last step in
post-install.d/52-nfvbench-script is an "echo" command that returns a
success code.

We fix this by making all the Bash scripts fail if any command whose
return code is not tested fails (set -euo pipefail).

Change-Id: Ic5ec9eb85a8d6e7e4d1dcbac8ebcac5931e4808e
Signed-off-by: Gwenael Lambrouin <gwenael.lambrouin@orange.com>
nfvbenchvm/dib/build-image.sh
nfvbenchvm/dib/elements/nfvbenchvm/finalise.d/51-add-cpu-isolation
nfvbenchvm/dib/elements/nfvbenchvm/finalise.d/52-change-resolution
nfvbenchvm/dib/elements/nfvbenchvm/finalise.d/53-boot-from-new-kernel
nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/01-update-kernel
nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/02-pip-package
nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/03-copy-rc-local
nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/04-add-execute-attribute
nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/52-nfvbench-script
nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/53-sshd-script
nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/99-cleanup

index 4559bb6..3423140 100755 (executable)
@@ -6,6 +6,9 @@
 # Ubuntu: sudo apt-get -y install python3 python3-venv qemu-utils kpartx
 # CentOS: sudo yum install -y python3 qemu-img kpartx
 
+# Stop on error (see https://wizardzines.com/comics/bash-errors/)
+set -euo pipefail
+
 usage() {
     echo "Usage: $0 [-l] [-g] [-v]"
     echo "   -l    build NFVbench loop VM image"
index 12ffcdc..14cb913 100755 (executable)
@@ -1,5 +1,8 @@
 #!/bin/bash
 
+# Stop on error
+set -euo pipefail
+
 grubby --update-kernel=ALL --args="isolcpus=1-7 rcu_nocbs=1 nohz=on nohz_full=1 nmi_watchdog=0"
 grubby --update-kernel=ALL --args="default_hugepagesz=1G hugepagesz=1G hugepages=4"
 grubby --update-kernel=ALL --args="intel_iommu=on iommu=pt"
index 8094006..7f5c342 100755 (executable)
@@ -1,5 +1,8 @@
 #!/bin/bash
 
+# Stop on error
+set -euo pipefail
+
 if [ $DIB_USE_ELREPO_KERNEL != "True" ]; then
     exit 0
 fi
index 79dea6c..d175473 100755 (executable)
@@ -1,5 +1,8 @@
 #!/bin/bash
 
+# Stop on error
+set -euo pipefail
+
 python3 -m pip install --upgrade pip
 python3 -m pip install setuptools wheel pbr
 python3 -m pip install pyyaml
index 3311530..24facec 100755 (executable)
@@ -1,8 +1,11 @@
 #!/bin/bash
 
+# Stop on error
+set -euo pipefail
+
 # set accurate rc.local file corresponding to current image built
 if [ $DIB_DEV_IMAGE = "loopvm" ]; then
     mv /etc/rc.d/rc.local.loopvm /etc/rc.d/rc.local
 else
     mv /etc/rc.d/rc.local.generator /etc/rc.d/rc.local
-fi
\ No newline at end of file
+fi
index 666d9dc..c96740f 100755 (executable)
@@ -1,5 +1,8 @@
 #!/bin/bash
 
+# Stop on error
+set -euo pipefail
+
 chmod +x /etc/rc.d/rc.local
 chmod +x /etc/sysconfig/network-scripts/ifcfg-eth0
 chmod +x /etc/profile.d/nfvbench.sh
index 5cc52e3..782d9b6 100755 (executable)
@@ -1,5 +1,8 @@
 #!/bin/bash
 
+# Make sure the disk image build fails if nfvbench installation fails
+set -euo pipefail
+
 if [ $DIB_DEV_IMAGE != "generator" ]; then
     exit 0
 fi
index 64e8877..c735506 100755 (executable)
@@ -1,4 +1,7 @@
 #!/bin/bash
 
+# Stop on error
+set -euo pipefail
+
 # Set UseDNS no value in sshd_config to reduce time to connect
-echo "UseDNS no" >> /etc/ssh/sshd_config
\ No newline at end of file
+echo "UseDNS no" >> /etc/ssh/sshd_config
index e48ca52..80dc3c0 100755 (executable)
@@ -1,3 +1,6 @@
 #!/bin/bash
 
+# Stop on error
+set -euo pipefail
+
 yum erase -y python-devel libyaml-devel numactl-devel kernel-devel kernel-headers kernel-lt-headers kernel-lt-devel gcc git python3-dev libpython3.6-dev