From b9fedb6868306a6e3145b7ee851ea3a84353df9c Mon Sep 17 00:00:00 2001 From: "guillaume.lambert" Date: Tue, 10 May 2022 22:04:23 +0200 Subject: [PATCH] Stop bashing functest scripts 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 Change-Id: I32c5490f9eab54e6cac594f3eac1e392edf8b272 --- .travis.yml | 42 +++++++++++----------- PI.md | 4 +-- README.md | 14 ++++---- build.sh | 10 +++--- docker/benchmarking/hooks/post_checkout | 2 +- docker/core/Dockerfile | 5 +-- docker/smoke/hooks/post_checkout | 2 +- docker/vnf/hooks/post_checkout | 2 +- docs/com/pres/dockerslicing/dockerslicing.md | 2 +- .../pres/euphrates_functest_evolution/euphrates.md | 2 +- docs/com/pres/gambia/gambia.md | 2 +- docs/testing/user/configguide/configguide.rst | 2 +- functest/ci/add_proxy.sh | 9 ++--- functest/ci/convert_images.sh | 8 +++-- functest/ci/download_images.sh | 2 +- .../opnfv_tests/openstack/vping/vping_userdata.py | 2 +- functest/opnfv_tests/vnf/ims/clearwater.py | 2 +- tox.ini | 6 ++-- 18 files changed, 61 insertions(+), 57 deletions(-) diff --git a/.travis.yml b/.travis.yml index ba6310af5..6b6e0a672 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 1a695a1b5..cc7c25bc8 100644 --- 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 ``` diff --git a/README.md b/README.md index a8fb4c5e5..a1d201e1b 100644 --- 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 \ diff --git a/build.sh b/build.sh index 16332ad7f..033d31310 100644 --- 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" ] && diff --git a/docker/benchmarking/hooks/post_checkout b/docker/benchmarking/hooks/post_checkout index 8d0e98124..c347524ea 100644 --- a/docker/benchmarking/hooks/post_checkout +++ b/docker/benchmarking/hooks/post_checkout @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh from="${DOCKER_REPO%/*}/functest-core:${DOCKER_TAG}" sed -i "s|^FROM.*$|FROM ${from}|" Dockerfile diff --git a/docker/core/Dockerfile b/docker/core/Dockerfile index c4d8de309..66bef0e69 100644 --- a/docker/core/Dockerfile +++ b/docker/core/Dockerfile @@ -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 && \ diff --git a/docker/smoke/hooks/post_checkout b/docker/smoke/hooks/post_checkout index 3e5670b4a..b23f6f449 100644 --- a/docker/smoke/hooks/post_checkout +++ b/docker/smoke/hooks/post_checkout @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh from="${DOCKER_REPO%/*}/functest-tempest:${DOCKER_TAG}" sed -i "s|^FROM.*$|FROM ${from}|" Dockerfile diff --git a/docker/vnf/hooks/post_checkout b/docker/vnf/hooks/post_checkout index 8d0e98124..c347524ea 100644 --- a/docker/vnf/hooks/post_checkout +++ b/docker/vnf/hooks/post_checkout @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh from="${DOCKER_REPO%/*}/functest-core:${DOCKER_TAG}" sed -i "s|^FROM.*$|FROM ${from}|" Dockerfile diff --git a/docs/com/pres/dockerslicing/dockerslicing.md b/docs/com/pres/dockerslicing/dockerslicing.md index a66453248..0d1ce5e21 100644 --- a/docs/com/pres/dockerslicing/dockerslicing.md +++ b/docs/com/pres/dockerslicing/dockerslicing.md @@ -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 diff --git a/docs/com/pres/euphrates_functest_evolution/euphrates.md b/docs/com/pres/euphrates_functest_evolution/euphrates.md index 49aab16cd..2c3105539 100644 --- a/docs/com/pres/euphrates_functest_evolution/euphrates.md +++ b/docs/com/pres/euphrates_functest_evolution/euphrates.md @@ -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 diff --git a/docs/com/pres/gambia/gambia.md b/docs/com/pres/gambia/gambia.md index 88dd524cc..4a65e9905 100644 --- a/docs/com/pres/gambia/gambia.md +++ b/docs/com/pres/gambia/gambia.md @@ -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 diff --git a/docs/testing/user/configguide/configguide.rst b/docs/testing/user/configguide/configguide.rst index 55585ed64..47c25adb1 100644 --- a/docs/testing/user/configguide/configguide.rst +++ b/docs/testing/user/configguide/configguide.rst @@ -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 diff --git a/functest/ci/add_proxy.sh b/functest/ci/add_proxy.sh index 082141073..9d7db22e4 100644 --- a/functest/ci/add_proxy.sh +++ b/functest/ci/add_proxy.sh @@ -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 diff --git a/functest/ci/convert_images.sh b/functest/ci/convert_images.sh index d7ed3887b..2159d2a60 100644 --- a/functest/ci/convert_images.sh +++ b/functest/ci/convert_images.sh @@ -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 diff --git a/functest/ci/download_images.sh b/functest/ci/download_images.sh index 72e885530..6bafc7837 100644 --- a/functest/ci/download_images.sh +++ b/functest/ci/download_images.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh set -ex diff --git a/functest/opnfv_tests/openstack/vping/vping_userdata.py b/functest/opnfv_tests/openstack/vping/vping_userdata.py index 7de70f677..8a8f26f37 100644 --- a/functest/opnfv_tests/openstack/vping/vping_userdata.py +++ b/functest/opnfv_tests/openstack/vping/vping_userdata.py @@ -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 diff --git a/functest/opnfv_tests/vnf/ims/clearwater.py b/functest/opnfv_tests/vnf/ims/clearwater.py index bbd5291eb..4c143fd70 100644 --- a/functest/opnfv_tests/vnf/ims/clearwater.py +++ b/functest/opnfv_tests/vnf/ims/clearwater.py @@ -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 b3e514681..953cbccc8 100644 --- 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" -- 2.16.6