aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGwenael Lambrouin <gwenael.lambrouin@orange.com>2021-12-13 13:48:14 +0100
committerGwenael Lambrouin <gwenael.lambrouin@orange.com>2022-02-28 18:40:54 +0100
commitce062d315394b813ce79849c6595d198351c2cec (patch)
tree135e3fcb9623fa5d344f07f15f4c5682796a7ff5
parent1a9c875d35daf4e742cd980e824c862ad793a658 (diff)
nfvbenchvm: abort build on error
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>
-rwxr-xr-xnfvbenchvm/dib/build-image.sh3
-rwxr-xr-xnfvbenchvm/dib/elements/nfvbenchvm/finalise.d/51-add-cpu-isolation3
-rwxr-xr-xnfvbenchvm/dib/elements/nfvbenchvm/finalise.d/52-change-resolution3
-rwxr-xr-xnfvbenchvm/dib/elements/nfvbenchvm/finalise.d/53-boot-from-new-kernel3
-rwxr-xr-xnfvbenchvm/dib/elements/nfvbenchvm/post-install.d/01-update-kernel3
-rwxr-xr-xnfvbenchvm/dib/elements/nfvbenchvm/post-install.d/02-pip-package3
-rwxr-xr-xnfvbenchvm/dib/elements/nfvbenchvm/post-install.d/03-copy-rc-local5
-rwxr-xr-xnfvbenchvm/dib/elements/nfvbenchvm/post-install.d/04-add-execute-attribute3
-rwxr-xr-xnfvbenchvm/dib/elements/nfvbenchvm/post-install.d/52-nfvbench-script3
-rwxr-xr-xnfvbenchvm/dib/elements/nfvbenchvm/post-install.d/53-sshd-script5
-rwxr-xr-xnfvbenchvm/dib/elements/nfvbenchvm/post-install.d/99-cleanup3
11 files changed, 35 insertions, 2 deletions
diff --git a/nfvbenchvm/dib/build-image.sh b/nfvbenchvm/dib/build-image.sh
index 4559bb6..3423140 100755
--- a/nfvbenchvm/dib/build-image.sh
+++ b/nfvbenchvm/dib/build-image.sh
@@ -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"
diff --git a/nfvbenchvm/dib/elements/nfvbenchvm/finalise.d/51-add-cpu-isolation b/nfvbenchvm/dib/elements/nfvbenchvm/finalise.d/51-add-cpu-isolation
index 12ffcdc..14cb913 100755
--- a/nfvbenchvm/dib/elements/nfvbenchvm/finalise.d/51-add-cpu-isolation
+++ b/nfvbenchvm/dib/elements/nfvbenchvm/finalise.d/51-add-cpu-isolation
@@ -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"
diff --git a/nfvbenchvm/dib/elements/nfvbenchvm/finalise.d/52-change-resolution b/nfvbenchvm/dib/elements/nfvbenchvm/finalise.d/52-change-resolution
index 26f2f6a..cc9f136 100755
--- a/nfvbenchvm/dib/elements/nfvbenchvm/finalise.d/52-change-resolution
+++ b/nfvbenchvm/dib/elements/nfvbenchvm/finalise.d/52-change-resolution
@@ -1,3 +1,6 @@
#!/bin/bash
+# Stop on error
+set -euo pipefail
+
grubby --update-kernel=ALL --args="vga=792"
diff --git a/nfvbenchvm/dib/elements/nfvbenchvm/finalise.d/53-boot-from-new-kernel b/nfvbenchvm/dib/elements/nfvbenchvm/finalise.d/53-boot-from-new-kernel
index 6607b0b..4728bca 100755
--- a/nfvbenchvm/dib/elements/nfvbenchvm/finalise.d/53-boot-from-new-kernel
+++ b/nfvbenchvm/dib/elements/nfvbenchvm/finalise.d/53-boot-from-new-kernel
@@ -1,3 +1,6 @@
#!/bin/bash
+# Stop on error
+set -euo pipefail
+
grubby --set-default-index=0
diff --git a/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/01-update-kernel b/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/01-update-kernel
index 8094006..7f5c342 100755
--- a/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/01-update-kernel
+++ b/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/01-update-kernel
@@ -1,5 +1,8 @@
#!/bin/bash
+# Stop on error
+set -euo pipefail
+
if [ $DIB_USE_ELREPO_KERNEL != "True" ]; then
exit 0
fi
diff --git a/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/02-pip-package b/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/02-pip-package
index 79dea6c..d175473 100755
--- a/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/02-pip-package
+++ b/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/02-pip-package
@@ -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
diff --git a/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/03-copy-rc-local b/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/03-copy-rc-local
index 3311530..24facec 100755
--- a/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/03-copy-rc-local
+++ b/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/03-copy-rc-local
@@ -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
diff --git a/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/04-add-execute-attribute b/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/04-add-execute-attribute
index 666d9dc..c96740f 100755
--- a/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/04-add-execute-attribute
+++ b/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/04-add-execute-attribute
@@ -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
diff --git a/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/52-nfvbench-script b/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/52-nfvbench-script
index 5cc52e3..782d9b6 100755
--- a/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/52-nfvbench-script
+++ b/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/52-nfvbench-script
@@ -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
diff --git a/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/53-sshd-script b/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/53-sshd-script
index 64e8877..c735506 100755
--- a/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/53-sshd-script
+++ b/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/53-sshd-script
@@ -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
diff --git a/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/99-cleanup b/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/99-cleanup
index e48ca52..80dc3c0 100755
--- a/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/99-cleanup
+++ b/nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/99-cleanup
@@ -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