Stop bashing functest scripts 24/73424/4
authorguillaume.lambert <guillaume.lambert@orange.com>
Tue, 10 May 2022 20:04:23 +0000 (22:04 +0200)
committerGuillaume Lambert <guillaume.lambert@orange.com>
Tue, 21 Mar 2023 09:13:19 +0000 (09:13 +0000)
Though bash is a good interactive user shell
and apart portability concerns,
many UN*X systems and GNU+Linux distributions now prefers Almquist
or Kornshell variants for scripting in order to improve the system
performance and maintenability.

https://wiki.ubuntu.com/DashAsBinSh
https://mywiki.wooledge.org/Bashism
https://en.wikipedia.org/wiki/Almquist_shell

Signed-off-by: guillaume.lambert <guillaume.lambert@orange.com>
Change-Id: I32c5490f9eab54e6cac594f3eac1e392edf8b272

18 files changed:
.travis.yml
PI.md
README.md
build.sh
docker/benchmarking/hooks/post_checkout
docker/core/Dockerfile
docker/smoke/hooks/post_checkout
docker/vnf/hooks/post_checkout
docs/com/pres/dockerslicing/dockerslicing.md
docs/com/pres/euphrates_functest_evolution/euphrates.md
docs/com/pres/gambia/gambia.md
docs/testing/user/configguide/configguide.rst
functest/ci/add_proxy.sh
functest/ci/convert_images.sh
functest/ci/download_images.sh
functest/opnfv_tests/openstack/vping/vping_userdata.py
functest/opnfv_tests/vnf/ims/clearwater.py
tox.ini

index ba6310a..6b6e0a6 100644 (file)
@@ -20,19 +20,19 @@ jobs:
         tox -e \
           docs,pep8,pylint,yamllint,bashate,bandit,py38,cover
     - stage: build functest-core images
-      script: sudo -E bash build.sh
+      script: sudo -E sh build.sh
       env:
         - REPO="${DOCKER_USERNAME}"
         - amd64_dirs="docker/core"
         - arm64_dirs=""
         - arm_dirs=""
-    - script: sudo -E bash build.sh
+    - script: sudo -E sh build.sh
       env:
         - REPO="${DOCKER_USERNAME}"
         - amd64_dirs=""
         - arm64_dirs="docker/core"
         - arm_dirs=""
-    - script: sudo -E bash build.sh
+    - script: sudo -E sh build.sh
       env:
         - REPO="${DOCKER_USERNAME}"
         - amd64_dirs=""
@@ -45,73 +45,73 @@ jobs:
           --template ${DOCKER_USERNAME}/functest-core:ARCH-latest \
           --target ${DOCKER_USERNAME}/functest-core:latest
     - stage: build all functest images
-      script: sudo -E bash build.sh
+      script: sudo -E sh build.sh
       env:
         - REPO="${DOCKER_USERNAME}"
         - amd64_dirs="docker/healthcheck"
         - arm64_dirs=""
         - arm_dirs=""
-    - script: sudo -E bash build.sh
+    - script: sudo -E sh build.sh
       env:
         - REPO="${DOCKER_USERNAME}"
         - amd64_dirs=""
         - arm64_dirs="docker/healthcheck"
         - arm_dirs=""
-    - script: sudo -E bash build.sh
+    - script: sudo -E sh build.sh
       env:
         - REPO="${DOCKER_USERNAME}"
         - amd64_dirs=""
         - arm64_dirs=""
         - arm_dirs="docker/healthcheck"
-    - script: sudo -E bash build.sh
+    - script: sudo -E sh build.sh
       env:
         - REPO="${DOCKER_USERNAME}"
         - amd64_dirs="docker/smoke"
         - arm64_dirs=""
         - arm_dirs=""
-    - script: sudo -E bash build.sh
+    - script: sudo -E sh build.sh
       env:
         - REPO="${DOCKER_USERNAME}"
         - amd64_dirs=""
         - arm64_dirs="docker/smoke"
         - arm_dirs=""
-    - script: sudo -E bash build.sh
+    - script: sudo -E sh build.sh
       env:
         - REPO="${DOCKER_USERNAME}"
         - amd64_dirs=""
         - arm64_dirs=""
         - arm_dirs="docker/smoke"
-    - script: sudo -E bash build.sh
+    - script: sudo -E sh build.sh
       env:
         - REPO="${DOCKER_USERNAME}"
         - amd64_dirs="docker/benchmarking"
         - arm64_dirs=""
         - arm_dirs=""
-    - script: sudo -E bash build.sh
+    - script: sudo -E sh build.sh
       env:
         - REPO="${DOCKER_USERNAME}"
         - amd64_dirs=""
         - arm64_dirs="docker/benchmarking"
         - arm_dirs=""
-    - script: sudo -E bash build.sh
+    - script: sudo -E sh build.sh
       env:
         - REPO="${DOCKER_USERNAME}"
         - amd64_dirs=""
         - arm64_dirs=""
         - arm_dirs="docker/benchmarking"
-    - script: sudo -E bash build.sh
+    - script: sudo -E sh build.sh
       env:
         - REPO="${DOCKER_USERNAME}"
         - amd64_dirs="docker/vnf"
         - arm64_dirs=""
         - arm_dirs=""
-    - script: sudo -E bash build.sh
+    - script: sudo -E sh build.sh
       env:
         - REPO="${DOCKER_USERNAME}"
         - amd64_dirs=""
         - arm64_dirs="docker/vnf"
         - arm_dirs=""
-    - script: sudo -E bash build.sh
+    - script: sudo -E sh build.sh
       env:
         - REPO="${DOCKER_USERNAME}"
         - amd64_dirs=""
@@ -139,37 +139,37 @@ jobs:
           --template ${DOCKER_USERNAME}/functest-vnf:ARCH-latest \
           --target ${DOCKER_USERNAME}/functest-vnf:latest
     - stage: build all functest cntt images
-      script: sudo -E bash build.sh
+      script: sudo -E sh build.sh
       env:
         - REPO="${DOCKER_USERNAME}"
         - amd64_dirs="docker/smoke-cntt"
         - arm64_dirs=""
         - arm_dirs=""
-    - script: sudo -E bash build.sh
+    - script: sudo -E sh build.sh
       env:
         - REPO="${DOCKER_USERNAME}"
         - amd64_dirs=""
         - arm64_dirs="docker/smoke-cntt"
         - arm_dirs=""
-    - script: sudo -E bash build.sh
+    - script: sudo -E sh build.sh
       env:
         - REPO="${DOCKER_USERNAME}"
         - amd64_dirs=""
         - arm64_dirs=""
         - arm_dirs="docker/smoke-cntt"
-    - script: sudo -E bash build.sh
+    - script: sudo -E sh build.sh
       env:
         - REPO="${DOCKER_USERNAME}"
         - amd64_dirs="docker/benchmarking-cntt"
         - arm64_dirs=""
         - arm_dirs=""
-    - script: sudo -E bash build.sh
+    - script: sudo -E sh build.sh
       env:
         - REPO="${DOCKER_USERNAME}"
         - amd64_dirs=""
         - arm64_dirs="docker/benchmarking-cntt"
         - arm_dirs=""
-    - script: sudo -E bash build.sh
+    - script: sudo -E sh build.sh
       env:
         - REPO="${DOCKER_USERNAME}"
         - amd64_dirs=""
diff --git a/PI.md b/PI.md
index 1a695a1..cc7c25b 100644 (file)
--- a/PI.md
+++ b/PI.md
@@ -17,7 +17,7 @@ commands whatever the architecture.
 
 ## Install Docker
 
-```bash
+```shell
 wget https://downloads.raspberrypi.org/raspbian/images/raspbian-2018-11-15/2018-11-13-raspbian-stretch.zip
 unzip 2018-11-13-raspbian-stretch.zip
 sudo dd bs=4M if=2018-11-13-raspbian-stretch.img of=/dev/mmcblk0 conv=fsync
@@ -25,7 +25,7 @@ sudo dd bs=4M if=2018-11-13-raspbian-stretch.img of=/dev/mmcblk0 conv=fsync
 
 ## Install Docker
 
-```bash
+```shell
 curl -sSL https://get.docker.com | sudo sh
 ```
 
index a8fb4c5..a1d201e 100644 (file)
--- a/README.md
+++ b/README.md
@@ -49,7 +49,7 @@ export OS_IDENTITY_API_VERSION=3
 export OS_REGION_NAME=XXX
 ```
 
-mkdir -p images && wget -q -O- https://git.opnfv.org/functest/plain/functest/ci/download_images.sh | bash -s -- images && ls -1 images/*
+mkdir -p images && wget -q -O- https://git.opnfv.org/functest/plain/functest/ci/download_images.sh | sh -s -- images && ls -1 images/*
 ```
 images/cirros-0.5.1-aarch64-disk.img
 images/cirros-0.5.1-x86_64-disk.img
@@ -64,7 +64,7 @@ images/vyos-1.1.8-amd64.qcow2
 
 ## Run healthcheck suite
 
-```bash
+```shell
 sudo docker run --env-file env \
     -v $(pwd)/openstack.creds:/home/opnfv/functest/conf/env_file \
     -v $(pwd)/images:/home/opnfv/functest/images \
@@ -93,7 +93,7 @@ sudo docker run --env-file env \
 
 ## Run smoke suite
 
-```bash
+```shell
 sudo docker run --env-file env \
     -v $(pwd)/openstack.creds:/home/opnfv/functest/conf/env_file \
     -v $(pwd)/images:/home/opnfv/functest/images \
@@ -127,7 +127,7 @@ sudo docker run --env-file env \
 
 ## Run smoke CNTT suite
 
-```bash
+```shell
 sudo docker run --env-file env \
     -v $(pwd)/openstack.creds:/home/opnfv/functest/conf/env_file \
     -v $(pwd)/images:/home/opnfv/functest/images \
@@ -151,7 +151,7 @@ sudo docker run --env-file env \
 
 ## Run benchmarking suite
 
-```bash
+```shell
 sudo docker run --env-file env \
     -v $(pwd)/openstack.creds:/home/opnfv/functest/conf/env_file \
     -v $(pwd)/images:/home/opnfv/functest/images \
@@ -171,7 +171,7 @@ sudo docker run --env-file env \
 
 ## Run benchmarking CNTT suite
 
-```bash
+```shell
 sudo docker run --env-file env \
     -v $(pwd)/openstack.creds:/home/opnfv/functest/conf/env_file \
     -v $(pwd)/images:/home/opnfv/functest/images \
@@ -191,7 +191,7 @@ sudo docker run --env-file env \
 
 ## Run vnf suite
 
-```bash
+```shell
 sudo docker run --env-file env \
     -v $(pwd)/openstack.creds:/home/opnfv/functest/conf/env_file \
     -v $(pwd)/images:/home/opnfv/functest/images \
index 16332ad..033d313 100644 (file)
--- a/build.sh
+++ b/build.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 set -e
 
@@ -13,7 +13,7 @@ docker/smoke-cntt \
 docker/benchmarking-cntt"}
 arm_dirs=${arm_dirs-${amd64_dirs}}
 arm64_dirs=${arm64_dirs-${amd64_dirs}}
-build_opts=("--pull=true" --no-cache "--force-rm=true")
+build_opts="--pull=true --no-cache --force-rm=true"
 
 find . -name Dockerfile -exec sed -i \
     -e "s|opnfv/functest-core|${repo}/functest-core:amd64-latest|g" {} +
@@ -24,7 +24,7 @@ find . -name Dockerfile -exec sed -i \
 ${repo}/functest-benchmarking:amd64-latest|g" {} +
 for dir in ${amd64_dirs}; do
     (cd "${dir}" &&
-        docker build "${build_opts[@]}" \
+        docker build $build_opts \
             -t "${repo}/functest-${dir##**/}:amd64-latest" .)
         docker push "${repo}/functest-${dir##**/}:amd64-latest"
     [ "${dir}" != "docker/core" ] &&
@@ -44,7 +44,7 @@ find . -name Dockerfile -exec sed -i \
     -e "s|opnfv/functest-benchmarking|\
 ${repo}/functest-benchmarking:arm64-latest|g" {} +
 for dir in ${arm64_dirs}; do
-    (cd "${dir}" && docker build "${build_opts[@]}" \
+    (cd "${dir}" && docker build $build_opts \
         -t "${repo}/functest-${dir##**/}:arm64-latest" .)
     docker push "${repo}/functest-${dir##**/}:arm64-latest"
     [ "${dir}" != "docker/core" ] &&
@@ -65,7 +65,7 @@ find . -name Dockerfile -exec sed -i \
     -e "s|opnfv/functest-benchmarking|\
 ${repo}/functest-benchmarking:arm-latest|g" {} +
 for dir in ${arm_dirs}; do
-    (cd "${dir}" && docker build "${build_opts[@]}" \
+    (cd "${dir}" && docker build $build_opts \
         -t "${repo}/functest-${dir##**/}:arm-latest" .)
     docker push "${repo}/functest-${dir##**/}:arm-latest"
     [ "${dir}" != "docker/core" ] &&
index 8d0e981..c347524 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 from="${DOCKER_REPO%/*}/functest-core:${DOCKER_TAG}"
 sed -i "s|^FROM.*$|FROM ${from}|" Dockerfile
index c4d8de3..66bef0e 100644 (file)
@@ -45,9 +45,10 @@ RUN apk -U upgrade && \
     mkdir -p /etc/xtesting && \
     cp /src/functest/functest/ci/logging.ini /etc/xtesting/ && \
     cp /src/functest/functest/ci/logging.debug.ini /etc/xtesting/ && \
-    bash -c "mkdir -p /var/lib/xtesting /home/opnfv" && \
+    sh -c "mkdir -p /var/lib/xtesting /home/opnfv" && \
     ln -s /var/lib/xtesting /home/opnfv/functest && \
-    bash -c "mkdir -p /home/opnfv/functest{/conf,/data,/images,/results} /home/opnfv/repos/vnfs" && \
+    sh -c "mkdir -p /home/opnfv/functest/conf /home/opnfv/functest/conf/data /home/opnfv/functest/conf/images /home/opnfv/functest/conf/results && \
+    mkdir -p /home/opnfv/repos/vnfs" && \
     mkdir -p /etc/rally && \
     printf "[database]\nconnection = 'sqlite:////var/lib/rally/database/rally.sqlite'\n" > /etc/rally/rally.conf && \
     printf "\n[openstack]\nneutron_bind_l2_agent_types = Open vSwitch agent,Linux bridge agent,OVN Controller Gateway agent\n" >> /etc/rally/rally.conf && \
index 3e5670b..b23f6f4 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 from="${DOCKER_REPO%/*}/functest-tempest:${DOCKER_TAG}"
 sed -i "s|^FROM.*$|FROM ${from}|" Dockerfile
index 8d0e981..c347524 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 from="${DOCKER_REPO%/*}/functest-core:${DOCKER_TAG}"
 sed -i "s|^FROM.*$|FROM ${from}|" Dockerfile
index a664532..0d1ce5e 100644 (file)
@@ -63,7 +63,7 @@
 
 ### 8 Functest containers
 
-```bash
+```shell
 $ sudo docker search opnfv |grep functest-
 opnfv/functest-core         OPNFV Functest core image
 opnfv/functest-restapi      OPNFV Functest restapi image
index 49aab16..2c31055 100644 (file)
@@ -120,7 +120,7 @@ export OS_IDENTITY_API_VERSION=3
 
 #### Retrieve all the images
 ```
-mkdir -p images && wget -q -O- https://git.opnfv.org/functest/plain/functest/ci/download_images.sh | bash -s -- images && ls -1 images/*
+mkdir -p images && wget -q -O- https://git.opnfv.org/functest/plain/functest/ci/download_images.sh | sh -s -- images && ls -1 images/*
 images/CentOS-7-aarch64-GenericCloud.qcow2
 images/CentOS-7-aarch64-GenericCloud.qcow2.xz
 images/CentOS-7-x86_64-GenericCloud.qcow2
index 88dd524..4a65e99 100644 (file)
@@ -94,7 +94,7 @@ the classical ONAP testing virtual machine (**> 1GB**).
   full CI/CD toolchains in few minutes** (Jenkins, Minio, TestAPI, MongoDB and
   Docker registry)
 
-```bash
+```shell
 virtualenv xtesting
 . xtesting/bin/activate
 pip install ansible docker
index 55585ed..47c25ad 100644 (file)
@@ -52,7 +52,7 @@ See section on OpenStack credentials for details.
 
 Create a directory for the different images (attached as a Docker volume)::
 
-  mkdir -p images && wget -q -O- https://git.opnfv.org/functest/plain/functest/ci/download_images.sh | bash -s -- images && ls -1 images/*
+  mkdir -p images && wget -q -O- https://git.opnfv.org/functest/plain/functest/ci/download_images.sh | sh -s -- images && ls -1 images/*
 
   images/cirros-0.5.1-aarch64-disk.img
   images/cirros-0.5.1-x86_64-disk.img
index 0821410..9d7db22 100644 (file)
@@ -1,8 +1,9 @@
-#!/bin/bash
+#!/bin/sh
 
 set -e
 
-pushd "${1:-/home/opnfv/functest/images}" > /dev/null
+initdir=$(pwd)
+cd "${1:-/home/opnfv/functest/images}"
 
 http_proxy_host=${http_proxy_host:-proxy}
 http_proxy_port=${http_proxy_port:-8080}
@@ -89,7 +90,7 @@ for image in $images; do
     fi
     guestmount -a "${image}" -i --rw "${tmpdir}"
     add_proxy "${tmpdir}/etc/environment"
-    if [[ ${image} == "ubuntu"* ]]; then
+    if expr "$image" : 'ubuntu' ; then
         add_proxy_apt "${tmpdir}/etc/apt/apt.conf"
         add_proxy_juju_env "${tmpdir}/etc/juju-proxy.conf"
         add_proxy_juju_systemd "${tmpdir}/etc/juju-proxy-systemd.conf"
@@ -133,5 +134,5 @@ else
 fi
 
 rmdir "${tmpdir}"
-popd > /dev/null
+cd initdir
 
index d7ed388..2159d2a 100644 (file)
@@ -1,11 +1,13 @@
-#!/bin/bash
+#!/bin/sh
 
 set -ex
 
-pushd "${1:-/home/opnfv/functest/images}"
+initdir=$(pwd)
+
+cd "${1:-/home/opnfv/functest/images}"
 
 for i in *.img *.qcow2; do
     qemu-img convert -f qcow2 -O vmdk "$i" "${i%.*}.vmdk"
 done
 
-popd
+cd $initdir
index 72e8855..6bafc78 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 set -ex
 
index 7de70f6..8a8f26f 100644 (file)
@@ -104,7 +104,7 @@ class VPingUserdata(singlevm.VmReady2):
         """
         Returns the post VM creation script to be added into the VM's userdata
         :param test_ip: the IP value to substitute into the script
-        :return: the bash script contents
+        :return: the shell script contents
         """
         ip4 = self.vm1.private_v4 or self.vm1.addresses[
             self.network.name][0].addr
index bbd5291..4c143fd 100644 (file)
@@ -155,7 +155,7 @@ class ClearwaterTesting():
             subscript = f' PROXY={self.bono_ip} ELLIS={self.ellis_ip}'
             script = f'{script}{subscript}'
         script = f'{script} --trace'
-        cmd = f"/bin/bash -c '{script}'"
+        cmd = f"/bin/sh -c '{script}'"
         self.logger.debug('Live test cmd: %s', cmd)
         output_file = os.path.join(self.result_dir, "ims_test_output.txt")
         ft_utils.execute_command(cmd,
diff --git a/tox.ini b/tox.ini
index b3e5146..953cbcc 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -84,11 +84,11 @@ commands =
 
 [testenv:perm]
 basepython = python3.10
-whitelist_externals = bash
+whitelist_externals = sh
 path=. -not -path './.tox/*' -not -path './.git/*' -not -path './docs/com/pres/reveal.js/*'
 commands =
-  bash -c "\
+  sh -c "\
     find {[testenv:perm]path} \( -type f -not -perm 644 -o -type d -not -perm 755 \) \
     -exec ls -l \{\} + | grep '.' && exit 1 || exit 0"
-  bash -c "\
+  sh -c "\
     find {[testenv:perm]path} -exec file \{\} + | grep CRLF && exit 1 || exit 0"