Browse Source

test(automatic-decompression): Add tests for automatic decompression

This change required some changes to the current test scripts. Most notably, the
whole conversion is now run two times. One for the compressed input image, and
one for the already decompressed image.

Also, the test framework was cleaned up significantly, and the number of
arguments passed to the 'convert_and_test' function has been decreased to remove
the redundancies that were present (like passing the image name, and the image
name with the extension, in two separate parameters).

These changes are a result of the changes introduced with:

* MEN-3052: https://tracker.mender.io/browse/MEN-3052

Changelog: None

Signed-off-by: Ole Petter <ole.orhagen@northern.tech>
2.1.x
Ole Petter 5 years ago
parent
commit
275615e58d
No known key found for this signature in database GPG Key ID: A7100375167A7B21
  1. 78
      scripts/test/run-tests.sh
  2. 118
      scripts/test/test-utils.sh

78
scripts/test/run-tests.sh

@ -15,20 +15,15 @@ fi
WORKSPACE=./tests
BBB_DEBIAN_IMAGE="bone-debian-9.5-iot-armhf-2018-08-30-4gb.img"
BBB_DEBIAN_IMAGE_URL="http://debian.beagleboard.org/images/${BBB_DEBIAN_IMAGE}.xz"
BBB_DEBIAN_IMAGE_URL="http://debian.beagleboard.org/images/bone-debian-9.5-iot-armhf-2018-08-30-4gb.img.xz"
RASPBIAN_IMAGE="2019-09-26-raspbian-buster-lite"
RASPBIAN_IMAGE_URL="http://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2019-09-30/2019-09-26-raspbian-buster-lite.zip"
TINKER_IMAGE="20170417-tinker-board-linaro-stretch-alip-v1.8"
TINKER_IMAGE_URL="http://dlcdnet.asus.com/pub/ASUS/mb/Linux/Tinker_Board_2GB/${TINKER_IMAGE}.zip"
TINKER_IMAGE_URL="http://dlcdnet.asus.com/pub/ASUS/mb/Linux/Tinker_Board_2GB/20170417-tinker-board-linaro-stretch-alip-v1.8.zip"
UBUNTU_IMAGE="Ubuntu-Bionic-x86-64.img"
UBUNTU_IMAGE_URL="https://d1b0l86ne08fsf.cloudfront.net/mender-convert/images/${UBUNTU_IMAGE}.gz"
UBUNTU_IMAGE_URL="https://d1b0l86ne08fsf.cloudfront.net/mender-convert/images/Ubuntu-Bionic-x86-64.img.gz"
UBUNTU_SERVER_RPI_IMAGE="ubuntu-18.04.4-preinstalled-server-armhf+raspi3.img"
UBUNTU_SERVER_RPI_IMAGE_URL="http://cdimage.ubuntu.com/ubuntu/releases/bionic/release/${UBUNTU_SERVER_RPI_IMAGE}.xz"
UBUNTU_SERVER_RPI_IMAGE_URL="http://cdimage.ubuntu.com/ubuntu/releases/bionic/release/ubuntu-18.04.4-preinstalled-server-armhf+raspi3.img.xz"
# Keep common function declarations in separate utils script
UTILS_PATH=${0/$(basename $0)/test-utils.sh}
@ -60,21 +55,39 @@ if [ "$1" == "--prebuilt-image" ]; then
else
if [ "$1" == "--all" -o "$1" == "--only" -a "$2" == "qemux86_64" ]; then
wget --progress=dot:giga -N ${UBUNTU_IMAGE_URL} -P input/
convert_and_test "qemux86_64" \
"release-1" \
"${UBUNTU_IMAGE_URL}" \
"${UBUNTU_IMAGE}" \
"${UBUNTU_IMAGE}.gz" \
"configs/qemux86-64_config" || test_result=$?
"input/Ubuntu-Bionic-x86-64.img.gz" \
"--config configs/qemux86-64_config" || test_result=$?
echo >&2 "----------------------------------------"
echo >&2 "Running the uncompressed test"
echo >&2 "----------------------------------------"
rm -rf deploy
gunzip --force "input/Ubuntu-Bionic-x86-64.img.gz"
convert_and_test "qemux86_64" \
"release-1" \
"input/Ubuntu-Bionic-x86-64.img" \
"--config configs/qemux86-64_config" || test_result=$?
fi
if [ "$1" == "--all" -o "$1" == "--only" -a "$2" == "raspberrypi3" ]; then
wget --progress=dot:giga -N ${RASPBIAN_IMAGE_URL} -P input/
convert_and_test "raspberrypi3" \
"release-1" \
"${RASPBIAN_IMAGE_URL}" \
"${RASPBIAN_IMAGE}.img" \
"${RASPBIAN_IMAGE}.zip" \
"configs/raspberrypi3_config" || test_result=$?
"input/2019-09-26-raspbian-buster-lite.zip" \
"--config configs/raspberrypi3_config" || test_result=$?
echo >&2 "----------------------------------------"
echo >&2 "Running the uncompressed test"
echo >&2 "----------------------------------------"
rm -rf deploy
unzip -o "input/2019-09-26-raspbian-buster-lite.zip" -d "./input"
convert_and_test "raspberrypi3" \
"release-1" \
"input/2019-09-26-raspbian-buster-lite.img" \
"--config configs/raspberrypi3_config" || test_result=$?
fi
if [ "$1" == "--all" -o "$1" == "--only" -a "$2" == "linaro-alip" ]; then
@ -88,20 +101,37 @@ else
fi
if [ "$1" == "--all" -o "$1" == "--only" -a "$2" == "beaglebone" ]; then
wget --progress=dot:giga -N ${BBB_DEBIAN_IMAGE_URL} -P input/
convert_and_test "beaglebone" \
"release-1" \
"${BBB_DEBIAN_IMAGE_URL}" \
"${BBB_DEBIAN_IMAGE}" \
"${BBB_DEBIAN_IMAGE}.xz" || test_result=$?
"input/bone-debian-9.5-iot-armhf-2018-08-30-4gb.img.xz" || test_result=$?
echo >&2 "----------------------------------------"
echo >&2 "Running the uncompressed test"
echo >&2 "----------------------------------------"
rm -rf deploy
unxz --force "input/bone-debian-9.5-iot-armhf-2018-08-30-4gb.img.xz"
convert_and_test "beaglebone" \
"release-1" \
"input/bone-debian-9.5-iot-armhf-2018-08-30-4gb.img" || test_result=$?
fi
if [ "$1" == "--all" -o "$1" == "--only" -a "$2" == "ubuntu" ]; then
wget --progress=dot:giga -N ${UBUNTU_SERVER_RPI_IMAGE_URL} -P input/
convert_and_test "raspberrypi3" \
"release-1" \
"input/ubuntu-18.04.4-preinstalled-server-armhf+raspi3.img.xz" \
"--config configs/raspberrypi3_config" || test_result=$?
echo >&2 "----------------------------------------"
echo >&2 "Running the uncompressed test"
echo >&2 "----------------------------------------"
rm -rf deploy
unxz --force "input/ubuntu-18.04.4-preinstalled-server-armhf+raspi3.img.xz"
convert_and_test "raspberrypi3" \
"release-1" \
"${UBUNTU_SERVER_RPI_IMAGE_URL}" \
"${UBUNTU_SERVER_RPI_IMAGE}" \
"${UBUNTU_SERVER_RPI_IMAGE}.xz" \
"configs/raspberrypi3_config" || test_result=$?
"input/ubuntu-18.04.4-preinstalled-server-armhf+raspi3.img" \
"--config configs/raspberrypi3_config" || test_result=$?
fi
exit $test_result

118
scripts/test/test-utils.sh

@ -4,76 +4,94 @@ WORKSPACE=${WORKSPACE:-./tests}
MENDER_CONVERT_DIR=$PWD
#
# function image_name_after_conversion()
#
# Transforms the given input image name to the name given to the output image by
# mender-convert.
#
# That is, an input image 'bone-debian-9.5-iot-armhf-2018-08-30-4gb.img.xz'
#
# T(bone-debian-9.5-iot-armhf-2018-08-30-4gb.img.xz)
# -> bone-debian-9.5-iot-armhf-2018-08-30-4gb-beaglebone-mender
#
# $1 - image name, with optional .img and compression endings
# $2 - the compression used for the image
# $3 - the device type
#
function image_name_after_conversion () {
if (( $# < 1 )); then
echo "image_name_after_conversion requires one argument. $# given."
exit 1
fi
local converted_image_name="$1"
local compression="${2}"
local device_type="${3}"
# Remove the compression if any
if [[ "${compression}" != "img" ]]; then
converted_image_name="${converted_image_name%.${compression}}"
fi
# remove the .img extension if any
converted_image_name="${converted_image_name%.img}"
# Add the extension which a successful mender-conversion will apply
converted_image_name="${converted_image_name}-${device_type}-mender.img"
# Add the compression back in
if [[ "${compression}" != "img" ]]; then
converted_image_name="${converted_image_name}.${compression}"
fi
echo "$(basename ${converted_image_name})"
}
function assert () {
if (( $# < 2 )); then
echo >&2 "assert() requires at least an expected and an actual value"
fi
if [[ "$1" == "$2" ]]; then
return
fi
# Neither string nor value matched the assertion
echo >&2 "Assertion error: $1 not equal to $2"
[[ -n "$3" ]] && echo >&2 "$3"
exit 1
}
source modules/decompressinput.sh
convert_and_test() {
device_type=$1
artifact_name=$2
image_url=$3
image_file=$4
image_file_compressed=$5
config=$6 # Optional
wget --progress=dot:giga -N ${image_url} -P input/
echo "Extracting: ${image_file_compressed}"
case "${image_file_compressed}" in
*.gz)
gunzip -f input/${image_file_compressed}
;;
*.zip)
cd input
unzip -o ${image_file_compressed}
cd -
;;
*.xz)
xz -d -f input/${image_file_compressed}
;;
*)
echo "Unknown image type: ${image_file_compressed}"
exit 1
;;
esac
image_file=$3
extra_args=$4 # Optional
rm -f ${WORKSPACE}/test_config
# Two motives for the following statement
#
# - speed up tests by avoiding decompression on all images (majority of images
# we test have a platform specific configuration)
#
# - test providing multiple '--config' options
#
# - (when no platform configuration is provided) test conversion without
# '--config' and with MENDER_COMPRESS_DISK_IMAGE=gzip. Compressed disk
# images is the default user facing option and we need to ensure that we
# cover this in the tests.
if [ -n "${config}" ]; then
echo "Will disable MENDER_COMPRESS_DISK_IMAGE for this image"
echo "MENDER_COMPRESS_DISK_IMAGE=none" > ${WORKSPACE}/test_config
local MENDER_CONVERT_EXTRA_ARGS="--config ${config} --config ${WORKSPACE}/test_config"
fi
MENDER_ARTIFACT_NAME=${artifact_name} ./docker-mender-convert \
--disk-image input/${image_file} \
${MENDER_CONVERT_EXTRA_ARGS}
--disk-image ${image_file} \
${extra_args}
local compression="${image_file##*.}"
local ret=0
# The output image name after conversion
image_name="${image_file%.img}-${device_type}-mender"
image_name=$(image_name_after_conversion "${image_file}" "${compression}" "${device_type}")
run_tests "${device_type}" "$image_name" || ret=$?
converted_image_file="${MENDER_CONVERT_DIR}/deploy/$(basename ${image_name})"
rm -f deploy/${image_file}*
converted_image_uncompressed="$(decompress_image ${converted_image_file} ${MENDER_CONVERT_DIR}/deploy)"
run_tests "${device_type}" "$(basename ${converted_image_uncompressed})" || ret=$?
assert "${ret}" "0" "Failed to convert ${image_file}"
return $ret
}
run_tests() {
device_type=$1
converted_image_name=$2
converted_image_file=$2
shift 2
pytest_args_extra=$@
converted_image_name="${converted_image_file%.img}"
if pip3 list | grep -q -e pytest-html; then
html_report_args="--html=${MENDER_CONVERT_DIR}/report_${device_type}.html --self-contained-html"
fi

Loading…
Cancel
Save