From b228fa0fb08c1226aa803a05550fc3570da23f5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janne=20Kiiskil=C3=A4?= Date: Thu, 17 Aug 2023 11:06:24 +0300 Subject: [PATCH 1/7] Add handling of missing jq dependency We do require jq to operatore, document and check for it. --- scripts/perts.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/scripts/perts.sh b/scripts/perts.sh index 228590d..ae2855a 100755 --- a/scripts/perts.sh +++ b/scripts/perts.sh @@ -42,12 +42,23 @@ usage() { echo " -e echo commands (debug), default off" echo " --help Show this help message and exit" echo "" + echo "Requires jq to be installed." + echo "" echo "NOTE! Must be run as sudo, installation steps require sudo rights." echo "You must run this script from the $REPONAME -folder." - echo "I.e. scripts/$SCRIPTNAME -a " + echo "I.e. sudo scripts/$SCRIPTNAME -a " exit 1 } +assertInstalled() { + for var in "$@"; do + if ! which "$var" &> /dev/null; then + echo "Please install $var - for example sudo apt-get install $var!" + exit 1 + fi + done +} + curdir=$(pwd) lastdir="${curdir##*/}" if [[ "$lastdir" != "pelion-edge-ready-test-suite" ]]; then @@ -106,6 +117,8 @@ case $(uname -m) in ;; esac +assertInstalled jq + # Get nodejs # wget https://nodejs.org/dist/v16.14.2/node-v16.14.2-linux-arm64.tar.gz # or (depending on your CPU-architecture) From 876e67e2ea85da09a84d1ec2210d0562f5137009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janne=20Kiiskil=C3=A4?= Date: Wed, 23 Aug 2023 12:04:59 +0300 Subject: [PATCH 2/7] perts.sh - figure out the KaaS server address from config file No point in feeding it via the config file and then separately via the -s option as well, it's just ... Not good usability. --- scripts/perts.sh | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/scripts/perts.sh b/scripts/perts.sh index ae2855a..5eac709 100755 --- a/scripts/perts.sh +++ b/scripts/perts.sh @@ -21,7 +21,8 @@ set -e SCRIPTNAME="perts.sh" REPONAME="pelion-edge-ready-test-suite" -SERVER="https://edge-k8s.us-east-1.mbedcloud.com" +KAASSERVER="https://edge-k8s.us-east-1.mbedcloud.com" +KAASSERVER_GIVEN=0 CURDIR=$(pwd) CONFIG="" TESTCONFIG="test-config.json" @@ -37,7 +38,7 @@ usage() { echo "Usage: scripts/$SCRIPTNAME -a access-key [-s Edge K8S server URL] [-e]" echo " -a access key" echo " -c config file to use (will try to auto-detect if not give)" - echo " -s Edge K8S edge-server URL, default $SERVER" + echo " -s Edge K8S edge-server URL, default $KAASSERVER (if -c config is given, picked up from there)" echo " -p edge status port, default $EDGEPORT" echo " -e echo commands (debug), default off" echo " --help Show this help message and exit" @@ -46,7 +47,9 @@ usage() { echo "" echo "NOTE! Must be run as sudo, installation steps require sudo rights." echo "You must run this script from the $REPONAME -folder." - echo "I.e. sudo scripts/$SCRIPTNAME -a " + echo "I.e." + echo " sudo scripts/$SCRIPTNAME -a " + echo " sudo scripts/$SCRIPTNAME -a -c " exit 1 } @@ -71,7 +74,8 @@ while getopts "a:c:s:p:e" opt; do case $opt in a ) ACCESSKEY="$OPTARG" ;; c ) CONFIG="$OPTARG" ;; - s ) SERVER="$OPTARG" ;; + s ) KAASSERVER="$OPTARG" + KAASSERVER_GIVEN=1 ;; p ) EDGEPORT="$OPTARG" EDGEPORT_GIVEN=1 ;; @@ -179,12 +183,17 @@ if [ -e "$ROOTKUBECFG" ]; then mv "$ROOTKUBECFG" "$ROOTKUBECFG.$rand_kube" fi -echo "Creating kubectl config file to $ROOTKUBECFG" -mkdir -p "/home/root/.kube" +# Only try digging up KaaS server from conf file, if it was not given already +cd "$CURDIR" +if [ -n "$CONFIG" ] && [ $KAASSERVER_GIVEN = 0 ]; then + KAASSERVER=$(jq -r '.specifications.kaasServicesAddress' < "$CONFIG" ) +fi + +echo "Creating kubectl config file to $ROOTKUBECFG against $KAASSERVER" echo "apiVersion: v1 clusters: - cluster: - server: $SERVER + server: $KAASSERVER name: edge-k8s contexts: - context: From 7940c629ee4a82cbb544810cad776f957c829aa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janne=20Kiiskil=C3=A4?= Date: Wed, 23 Aug 2023 12:05:49 +0300 Subject: [PATCH 3/7] test_pod.yaml - upgrade alpine to 3.18 We're using a fairly old Alpine image, let's upgrade to a newer one. --- conf/test_pod.yaml | 2 +- utils/kaas_utils.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/conf/test_pod.yaml b/conf/test_pod.yaml index 95f76d3..cc55a26 100644 --- a/conf/test_pod.yaml +++ b/conf/test_pod.yaml @@ -43,7 +43,7 @@ spec: - echo 'pod is running'; sleep 6000000 command: - /bin/sh - image: alpine:3.9 + image: alpine:3.18 imagePullPolicy: IfNotPresent name: client resources: diff --git a/utils/kaas_utils.js b/utils/kaas_utils.js index c474a5e..cf16e88 100644 --- a/utils/kaas_utils.js +++ b/utils/kaas_utils.js @@ -25,7 +25,7 @@ module.exports.podConfig = ( nodename, label = { app: 'test' }, containername = 'client', - conatinerimage = 'alpine:3.9' + conatinerimage = 'alpine:3.18' ) => { return { apiVersion: 'v1', @@ -55,7 +55,7 @@ module.exports.podWithHostNW = ( nodename, label = { app: 'test' }, containername = 'client', - conatinerimage = 'alpine:3.9' + conatinerimage = 'alpine:3.18' ) => { return { apiVersion: 'v1', @@ -86,7 +86,7 @@ module.exports.podWithFixHostname = ( nodename, label = { app: 'test' }, containername = 'client', - conatinerimage = 'alpine:3.9' + conatinerimage = 'alpine:3.18' ) => { return { apiVersion: 'v1', From d66fc0c841b918eb45cc6838f3dfc3ee1d8f0d51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janne=20Kiiskil=C3=A4?= Date: Fri, 25 Aug 2023 15:10:44 +0300 Subject: [PATCH 4/7] kaas_utils - fix conaitername typo It really needs to be containername. --- utils/kaas_utils.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/utils/kaas_utils.js b/utils/kaas_utils.js index cf16e88..3cca51b 100644 --- a/utils/kaas_utils.js +++ b/utils/kaas_utils.js @@ -25,7 +25,7 @@ module.exports.podConfig = ( nodename, label = { app: 'test' }, containername = 'client', - conatinerimage = 'alpine:3.18' + containerimage = 'alpine:3.18' ) => { return { apiVersion: 'v1', @@ -41,7 +41,7 @@ module.exports.podConfig = ( containers: [ { name: containername, - image: conatinerimage, + image: containerimage, command: ['/bin/sh'], args: ['-c', "echo 'hello'; sleep 6000000"] } @@ -55,7 +55,7 @@ module.exports.podWithHostNW = ( nodename, label = { app: 'test' }, containername = 'client', - conatinerimage = 'alpine:3.18' + containerimage = 'alpine:3.18' ) => { return { apiVersion: 'v1', @@ -72,7 +72,7 @@ module.exports.podWithHostNW = ( containers: [ { name: containername, - image: conatinerimage, + image: containerimage, command: ['/bin/sh'], args: ['-c', "echo 'hello'; sleep 6000000"] } @@ -86,7 +86,7 @@ module.exports.podWithFixHostname = ( nodename, label = { app: 'test' }, containername = 'client', - conatinerimage = 'alpine:3.18' + containerimage = 'alpine:3.18' ) => { return { apiVersion: 'v1', @@ -102,7 +102,7 @@ module.exports.podWithFixHostname = ( containers: [ { name: containername, - image: conatinerimage, + image: containerimage, command: ['/bin/sh'], args: ['-c', "echo 'hello'; sleep 6000000"] } From 68e38d9357ae4faf6921b5542e1177ef1bf1ae7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janne=20Kiiskil=C3=A4?= Date: Fri, 25 Aug 2023 15:25:52 +0300 Subject: [PATCH 5/7] kaas_utils / add CPU/mem limits to pods (200ms, 100MiB) Otherwise they can be default to too large values and more limited hardwares can see failures due to Out Of Memory. --- utils/kaas_utils.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/utils/kaas_utils.js b/utils/kaas_utils.js index 3cca51b..489e0a4 100644 --- a/utils/kaas_utils.js +++ b/utils/kaas_utils.js @@ -42,6 +42,12 @@ module.exports.podConfig = ( { name: containername, image: containerimage, + resources: { + limits: { + cpu: '200m', + memory: '100Mi' + } + }, command: ['/bin/sh'], args: ['-c', "echo 'hello'; sleep 6000000"] } @@ -73,6 +79,12 @@ module.exports.podWithHostNW = ( { name: containername, image: containerimage, + resources: { + limits: { + cpu: '200m', + memory: '100Mi' + } + }, command: ['/bin/sh'], args: ['-c', "echo 'hello'; sleep 6000000"] } @@ -103,6 +115,12 @@ module.exports.podWithFixHostname = ( { name: containername, image: containerimage, + resources: { + limits: { + cpu: '200m', + memory: '100Mi' + } + }, command: ['/bin/sh'], args: ['-c', "echo 'hello'; sleep 6000000"] } From 378453c9f163757b1e462677b6e00fedb35ff216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janne=20Kiiskil=C3=A4?= Date: Fri, 1 Sep 2023 10:30:30 +0300 Subject: [PATCH 6/7] test-configs - update version to 2.6.1 Upgrade from 2.6.0 to 2.6.1. --- test-configs/avnet-config.json | 2 +- test-configs/imx8-config.json | 2 +- test-configs/rpi3-config.json | 2 +- test-configs/rpi4-config.json | 2 +- test-configs/snap-config.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test-configs/avnet-config.json b/test-configs/avnet-config.json index 79ad6e4..d391d68 100644 --- a/test-configs/avnet-config.json +++ b/test-configs/avnet-config.json @@ -1,6 +1,6 @@ { "title": "pelion-edge-ready-test-suite", - "version":"2.6.0", + "version":"2.6.1", "device_type": "avnet", "tests_directory": "test-cases", "accountID": "", diff --git a/test-configs/imx8-config.json b/test-configs/imx8-config.json index fa22c4b..57c2882 100644 --- a/test-configs/imx8-config.json +++ b/test-configs/imx8-config.json @@ -1,6 +1,6 @@ { "title": "pelion-edge-ready-test-suite", - "version":"2.6.0", + "version":"2.6.1", "device_type": "i.MX8", "tests_directory": "test-cases", "accountID": "", diff --git a/test-configs/rpi3-config.json b/test-configs/rpi3-config.json index cc8bb0b..cd795a4 100644 --- a/test-configs/rpi3-config.json +++ b/test-configs/rpi3-config.json @@ -1,6 +1,6 @@ { "title": "pelion-edge-ready-test-suite", - "version":"2.6.0", + "version":"2.6.1", "device_type": "rpi3bplus", "tests_directory": "test-cases", "accountID": "", diff --git a/test-configs/rpi4-config.json b/test-configs/rpi4-config.json index 8af36f6..9146e5b 100644 --- a/test-configs/rpi4-config.json +++ b/test-configs/rpi4-config.json @@ -1,6 +1,6 @@ { "title": "pelion-edge-ready-test-suite", - "version":"2.6.0", + "version":"2.6.1", "device_type": "rpi4", "tests_directory": "test-cases", "accountID": "", diff --git a/test-configs/snap-config.json b/test-configs/snap-config.json index 7491f0f..f0e76ca 100644 --- a/test-configs/snap-config.json +++ b/test-configs/snap-config.json @@ -1,6 +1,6 @@ { "title": "pelion-edge-ready-test-suite", - "version":"2.6.0", + "version":"2.6.1", "tests_directory": "test-cases", "accountID": "", "internal_id": "", From f90b8cc2b6e6fd2ce884934b32d64d025522e527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janne=20Kiiskil=C3=A4?= Date: Mon, 4 Sep 2023 15:24:52 +0300 Subject: [PATCH 7/7] Trap errors & cleanup Add a cleanup function to make sure we do not leave files containing credentials floating about. --- scripts/perts.sh | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/scripts/perts.sh b/scripts/perts.sh index 5eac709..bff0d76 100755 --- a/scripts/perts.sh +++ b/scripts/perts.sh @@ -62,6 +62,39 @@ assertInstalled() { done } +# cleanup - delete the created config files before exiting. +# - if a parameters is not given, we exit with error code +# as we assume we got trapped. +cleanup() { + local exit_code=0 + if [ $# -eq 0 ]; then + exit_code=1 + fi + echo "Cleaning up..." + + # Check if the config file exists before attempting to delete it + if [ -e "$ROOTKUBECFG" ]; then + rm -f "$ROOTKUBECFG" + echo "Configuration file deleted: $ROOTKUBECFG" + fi + if [ -e "$TESTCONFIG" ]; then + rm -f "$TESTCONFIG" + echo "Test configuration file deleted: $TESTCONFIG" + fi + + if [[ -n "$rand_kube" ]];then + mv "$ROOTKUBECFG.$rand_kube" "$ROOTKUBECFG" + fi + if [[ -n "$rand_cfg" ]];then + mv "$TESTCONFIG.$rand_cfg" "$TESTCONFIG" + fi + # Exit the script + + exit $exit_code +} + +trap 'cleanup' INT TERM ERR + curdir=$(pwd) lastdir="${curdir##*/}" if [[ "$lastdir" != "pelion-edge-ready-test-suite" ]]; then @@ -297,13 +330,6 @@ sudo --preserve-env "$NODECMD" index.js -c "$TESTCONFIG" # Do not leave credentials floating about, delete the kubectl config file. # Restore original files, if there were any... -rm "$ROOTKUBECFG" -rm "$TESTCONFIG" -if [[ -n "$rand_kube" ]];then - mv "$ROOTKUBECFG.$rand_kube" "$ROOTKUBECFG" -fi -if [[ -n "$rand_cfg" ]];then - mv "$TESTCONFIG.$rand_cfg" "$TESTCONFIG" -fi +cleanup 0 echo "DONE - Check test results under suite_results -folder."