From 32f0721666cb2d7810daddf6b0771d3c7434800f Mon Sep 17 00:00:00 2001 From: Ole Petter Date: Mon, 2 Dec 2019 09:26:49 +0100 Subject: [PATCH 1/3] Tidying: Escape extra double quotes The double-quote inside the double quote was not escaped. Changelog: None Signed-off-by: Ole Petter --- mender-convert | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mender-convert b/mender-convert index e732fbb..f9d9f9d 100755 --- a/mender-convert +++ b/mender-convert @@ -82,7 +82,7 @@ if [ -z "${MENDER_ARTIFACT_NAME}" ]; then echo "Sorry, it seems that you have not defined MENDER_ARTIFACT_NAME" echo "You can do this with the following command:" echo "" - echo -e "\tMENDER_ARTIFACT_NAME="release-1" ./mender-convert" + echo -e "\tMENDER_ARTIFACT_NAME=\"release-1\" ./mender-convert" exit 1 fi From d7808f24f4ca6592b893eda42b7415a31cc8d212 Mon Sep 17 00:00:00 2001 From: Ole Petter Date: Mon, 2 Dec 2019 10:21:54 +0100 Subject: [PATCH 2/3] Tidying: Unify the shebang call in all convert scripts Previously some scripts were calling env and bash, some were only calling bash. This commit unifies the scripts to all use `#! /usr/bin/env bash` Changelog: None Signed-off-by: Ole Petter --- mender-convert | 2 +- mender-convert-extract | 2 +- mender-convert-modify | 2 +- mender-convert-package | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mender-convert b/mender-convert index f9d9f9d..ccd5987 100755 --- a/mender-convert +++ b/mender-convert @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#! /usr/bin/env bash # # Copyright 2019 Northern.tech AS # diff --git a/mender-convert-extract b/mender-convert-extract index 9514310..a14f899 100755 --- a/mender-convert-extract +++ b/mender-convert-extract @@ -1,4 +1,4 @@ -#!/bin/bash +#! /usr/bin/env bash # # Copyright 2019 Northern.tech AS # diff --git a/mender-convert-modify b/mender-convert-modify index 716636f..6588447 100755 --- a/mender-convert-modify +++ b/mender-convert-modify @@ -1,4 +1,4 @@ -#!/bin/bash +#! /usr/bin/env bash # # Copyright 2019 Northern.tech AS # diff --git a/mender-convert-package b/mender-convert-package index d707b83..db30f4d 100755 --- a/mender-convert-package +++ b/mender-convert-package @@ -1,4 +1,4 @@ -#!/bin/bash +#! /usr/bin/env bash # # Copyright 2019 Northern.tech AS # From 69553bac0a9d9f1b19998b10d67e1e0322de6416 Mon Sep 17 00:00:00 2001 From: Ole Petter Date: Mon, 2 Dec 2019 12:48:07 +0100 Subject: [PATCH 3/3] Tidying: Move all indents to use two spaces Previously there was a mix between two, and four spaces. This commits unifies all scripts to use two-spaces for indentation. Changelog: None Signed-off-by: Ole Petter --- docker-mender-convert | 14 +- mender-convert | 32 +-- mender-convert-extract | 8 +- mender-convert-modify | 4 +- mender-convert-package | 14 +- modules/config.sh | 4 +- modules/disk.sh | 18 +- modules/probe.sh | 56 ++--- .../bootstrap-rootfs-overlay-demo-server.sh | 12 +- .../bootstrap-rootfs-overlay-hosted-server.sh | 12 +- ...tstrap-rootfs-overlay-production-server.sh | 18 +- scripts/run-tests.sh | 210 +++++++++--------- 12 files changed, 202 insertions(+), 200 deletions(-) diff --git a/docker-mender-convert b/docker-mender-convert index 59195f8..724a2be 100755 --- a/docker-mender-convert +++ b/docker-mender-convert @@ -21,10 +21,10 @@ IMAGE_NAME=${IMAGE_NAME:-mender-convert} MENDER_CONVERT_DIR="$(pwd)" docker run \ - -v $MENDER_CONVERT_DIR:/mender-convert \ - --privileged=true \ - --cap-add=SYS_MODULE \ - -v /dev:/dev \ - -v /lib/modules:/lib/modules:ro \ - --env MENDER_ARTIFACT_NAME=${MENDER_ARTIFACT_NAME} \ - $IMAGE_NAME "$@" + -v $MENDER_CONVERT_DIR:/mender-convert \ + --privileged=true \ + --cap-add=SYS_MODULE \ + -v /dev:/dev \ + -v /lib/modules:/lib/modules:ro \ + --env MENDER_ARTIFACT_NAME=${MENDER_ARTIFACT_NAME} \ + $IMAGE_NAME "$@" diff --git a/mender-convert b/mender-convert index ccd5987..38e46e8 100755 --- a/mender-convert +++ b/mender-convert @@ -56,26 +56,26 @@ trap trap_exit EXIT # We only handle a selection of the arguments here, the rest are passed on # to the sub-scripts. -while (( "$#" )); do - case "$1" in - -h | --help) - show_help - exit 0 - ;; - -v | --version) - show_version - exit 0 - ;; - *) - break; - ;; - esac +while (("$#")); do + case "$1" in + -h | --help) + show_help + exit 0 + ;; + -v | --version) + show_version + exit 0 + ;; + *) + break + ;; + esac done mender_convert_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) if [ "${mender_convert_dir}" != "${PWD}" ]; then - echo "You must execute mender-convert from the root directory: ${mender_convert_dir}" - exit 1 + echo "You must execute mender-convert from the root directory: ${mender_convert_dir}" + exit 1 fi if [ -z "${MENDER_ARTIFACT_NAME}" ]; then diff --git a/mender-convert-extract b/mender-convert-extract index a14f899..e611677 100755 --- a/mender-convert-extract +++ b/mender-convert-extract @@ -61,7 +61,7 @@ source modules/config.sh $(printf "%q " "${configs[@]}") MKFS_VFAT="/usr/bin/mkfs.vfat" if [ ! -f ${MKFS_VFAT} ]; then - MKFS_VFAT="/sbin/mkfs.vfat" + MKFS_VFAT="/sbin/mkfs.vfat" fi declare -i nr_of_parts=$(disk_get_nr_of_parts ${disk_image}) @@ -93,9 +93,9 @@ done # but we do require it be present and hence we might need to generate # a filesystem image here. if [ ${nr_of_parts} -eq 1 ]; then - log_info "Generating boot partition (required, does not exist in original image)" - run_and_log_cmd "dd if=/dev/zero of=work/boot-generated.vfat count=${MENDER_BOOT_PART_SIZE_MB} bs=1M status=none" - run_and_log_cmd "${MKFS_VFAT} work/boot-generated.vfat" + log_info "Generating boot partition (required, does not exist in original image)" + run_and_log_cmd "dd if=/dev/zero of=work/boot-generated.vfat count=${MENDER_BOOT_PART_SIZE_MB} bs=1M status=none" + run_and_log_cmd "${MKFS_VFAT} work/boot-generated.vfat" fi # Extract boot gap, that is the area from sector 1 until first part, and diff --git a/mender-convert-modify b/mender-convert-modify index 6588447..36d36d1 100755 --- a/mender-convert-modify +++ b/mender-convert-modify @@ -17,11 +17,11 @@ # Default that can be overridden by providing this method in a # configuration file passed with '--config' function platform_modify() { - true + true } function user_local_modify() { - true + true } function trap_exit() { diff --git a/mender-convert-package b/mender-convert-package index db30f4d..1109a45 100755 --- a/mender-convert-package +++ b/mender-convert-package @@ -17,7 +17,7 @@ # Default that can be overridden by providing this method in a # configuration file passed with '--config' function platform_package() { - true + true } function trap_exit() { @@ -69,7 +69,7 @@ source modules/config.sh $(printf "%q " "${configs[@]}") PARTED="/usr/bin/parted" if [ ! -f ${PARTED} ]; then - PARTED="/sbin/parted" + PARTED="/sbin/parted" fi output_dir=work @@ -129,8 +129,8 @@ fi boot_part_sectors=$(disk_align_sectors ${boot_part_sectors} ${MENDER_PARTITION_ALIGNMENT} ) # Calculate rootfs size -rootfs_part_sectors=$(( (${disk_image_total_sectors} - ${data_part_sectors} \ - - ${boot_part_sectors} - ${overhead_sectors}) / 2 )) +rootfs_part_sectors=$(((${disk_image_total_sectors} - ${data_part_sectors} - \ + ${boot_part_sectors} - ${overhead_sectors}) / 2)) # Make sure rootfs size is aligned to MENDER_PARTITION_ALIGNMENT rootfs_part_sectors=$(disk_align_sectors ${rootfs_part_sectors} ${MENDER_PARTITION_ALIGNMENT} ) @@ -146,9 +146,9 @@ actual_rootfs_size=$(sudo du --apparent-size -s --block-size=512 work/rootfs | c rootfs_image_sectors=$(awk -v r1="$actual_rootfs_size" 'BEGIN{printf "%.0f", r1 * 1.50}') if [ ${rootfs_image_sectors} -gt ${rootfs_part_sectors} ]; then - log_warn "The calculated rootfs partition size $(disk_sectors_to_mb ${rootfs_part_sectors}) MiB is too small." - log_warn "The actual rootfs image size is $(disk_sectors_to_mb ${rootfs_image_sectors}) MiB" - log_fatal "You can try adjusting the MENDER_STORAGE_TOTAL_SIZE_MB variable to increase available space" + log_warn "The calculated rootfs partition size $(disk_sectors_to_mb ${rootfs_part_sectors}) MiB is too small." + log_warn "The actual rootfs image size is $(disk_sectors_to_mb ${rootfs_image_sectors}) MiB" + log_fatal "You can try adjusting the MENDER_STORAGE_TOTAL_SIZE_MB variable to increase available space" fi # Extract file-system type from rootfs diff --git a/modules/config.sh b/modules/config.sh index e2dafea..26d8716 100644 --- a/modules/config.sh +++ b/modules/config.sh @@ -17,6 +17,6 @@ # Read in the array of config files to process read -a configs <<< "${@}" for config in "${configs[@]}"; do - log_info "Using configuration file: ${config}" - source "${config}" + log_info "Using configuration file: ${config}" + source "${config}" done diff --git a/modules/disk.sh b/modules/disk.sh index b29b97d..e2359da 100644 --- a/modules/disk.sh +++ b/modules/disk.sh @@ -65,17 +65,16 @@ disk_extract_part() { # # $1 - MiB value disk_mb_to_sectors() { - echo "$(( (${1} * 1024 * 1024) / 512 ))" + echo "$(( (${1} * 1024 * 1024) / 512 ))" } # Convert 512 sectors to MiB # # $1 - number of 512 sectors disk_sectors_to_mb() { - echo "$(( (${1} * 512) / 1024 / 1024 ))" + echo "$(( (${1} * 512) / 1024 / 1024 ))" } - # Align value (result is number of 512 sectors) # # $1 - value to align (number of 512 sectors) @@ -115,7 +114,7 @@ disk_create_file_system_from_folder() { "ext4") MKFS_EXT4="/usr/bin/mkfs.ext4" if [ ! -f ${MKFS_EXT4} ]; then - MKFS_EXT4="/sbin/mkfs.ext4" + MKFS_EXT4="/sbin/mkfs.ext4" fi run_and_log_cmd "${MKFS_EXT4} -q -F ${2}" ;; @@ -123,12 +122,13 @@ disk_create_file_system_from_folder() { "xfs") MKFS_XFS="/usr/bin/mkfs.xfs" if [ ! -f ${MKFS_XFS} ]; then - MKFS_XFS="/sbin/mkfs.xfs" + MKFS_XFS="/sbin/mkfs.xfs" fi run_and_log_cmd "${MKFS_XFS} -q -f ${2}" ;; *) - log_fatal "Unknown file system type specified: ${4}" + log_fatal "Unknown file system type specified: ${4}" + ;; esac run_and_log_cmd "mkdir -p work/output" @@ -158,7 +158,7 @@ disk_boot_part() { # boot part was extracted or generated. boot_part="work/boot-generated.vfat" if [ ! -f ${boot_part} ]; then - boot_part="work/part-1.fs" + boot_part="work/part-1.fs" fi echo "${boot_part}" } @@ -168,9 +168,9 @@ disk_boot_part() { disk_root_part() { boot_part="work/boot-generated.vfat" if [ ! -f ${boot_part} ]; then - root_part="work/part-2.fs" + root_part="work/part-2.fs" else - root_part="work/part-1.fs" + root_part="work/part-1.fs" fi echo "${root_part}" } diff --git a/modules/probe.sh b/modules/probe.sh index 51515eb..31f7fd4 100644 --- a/modules/probe.sh +++ b/modules/probe.sh @@ -19,31 +19,31 @@ # No input parameters and these work on the assumption that boot and root parts # are mounted at work/boot and work/rootfs probe_arch() { - # --dereference, means to follow symlinks because 'ls' could be a symlink - # to busybox - file_info="" - for location in bin/ls usr/bin/ls; do - if [ -e work/rootfs/${location} ]; then - file_info=$(file -b --dereference work/rootfs/${location}) - break - fi - done - - if [ -z "${file_info}" ]; then - log_fatal "Sorry, where not able to determinate target architecture" + # --dereference, means to follow symlinks because 'ls' could be a symlink + # to busybox + file_info="" + for location in bin/ls usr/bin/ls; do + if [ -e work/rootfs/${location} ]; then + file_info=$(file -b --dereference work/rootfs/${location}) + break fi + done - target_arch="unknown" - if grep -q x86-64 <<< "${file_info}"; then - target_arch="x86-64" - elif grep -Eq "ELF 32-bit.*ARM" <<< "${file_info}"; then - target_arch="arm" - elif grep -Eq "ELF 64-bit.*aarch64" <<< "${file_info}"; then - target_arch="aarch64" - else - log_fatal "Unsupported architecture: ${file_info}" - fi - echo "${target_arch}" + if [ -z "${file_info}" ]; then + log_fatal "Sorry, where not able to determinate target architecture" + fi + + target_arch="unknown" + if grep -q x86-64 <<< "${file_info}"; then + target_arch="x86-64" + elif grep -Eq "ELF 32-bit.*ARM" <<< "${file_info}"; then + target_arch="arm" + elif grep -Eq "ELF 64-bit.*aarch64" <<< "${file_info}"; then + target_arch="aarch64" + else + log_fatal "Unsupported architecture: ${file_info}" + fi + echo "${target_arch}" } # Prints GRUB EFI name depending on target architecture @@ -64,7 +64,8 @@ probe_grub_efi_name() { efi_name="grub-efi-bootaa64.efi" ;; *) - log_fatal "Unknown arch: ${arch}" + log_fatal "Unknown arch: ${arch}" + ;; esac echo "$efi_name" } @@ -87,7 +88,8 @@ probe_debian_arch_name() { deb_arch="arm64" ;; *) - log_fatal "Unknown arch: ${arch}" + log_fatal "Unknown arch: ${arch}" + ;; esac echo "${deb_arch}" } @@ -112,7 +114,8 @@ probe_grub_efi_target_name() { efi_target_name="bootaa64.efi" ;; *) - log_fatal "Unknown arch: ${arch}" + log_fatal "Unknown arch: ${arch}" + ;; esac echo "$efi_target_name" } @@ -163,7 +166,6 @@ probe_initrd_image() { echo "${initrd_image_path}" } - # Prints Linux kernel image name # # It will look for it in both boot and rootfs parts. If image is only present diff --git a/scripts/bootstrap-rootfs-overlay-demo-server.sh b/scripts/bootstrap-rootfs-overlay-demo-server.sh index 21ffc77..1d441f9 100755 --- a/scripts/bootstrap-rootfs-overlay-demo-server.sh +++ b/scripts/bootstrap-rootfs-overlay-demo-server.sh @@ -19,8 +19,8 @@ set -o errexit root_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd ) if [ "${root_dir}" != "${PWD}" ]; then - echo "You must execute $(basename $0) from the root directory: ${root_dir}" - exit 1 + echo "You must execute $(basename $0) from the root directory: ${root_dir}" + exit 1 fi server_ip="" @@ -44,12 +44,12 @@ while (( "$#" )); do done if [ -z "${output_dir}" ]; then - echo "Sorry, but you need to provide an output directory using the '-o/--output-dir' option" - exit 1 + echo "Sorry, but you need to provide an output directory using the '-o/--output-dir' option" + exit 1 fi if [ -z "${server_ip}" ]; then - echo "Sorry, but you need to provide a server IP address using the '-s/--server-ip' option" - exit 1 + echo "Sorry, but you need to provide a server IP address using the '-s/--server-ip' option" + exit 1 fi mkdir -p ${output_dir}/etc/mender diff --git a/scripts/bootstrap-rootfs-overlay-hosted-server.sh b/scripts/bootstrap-rootfs-overlay-hosted-server.sh index cd227f0..7f270ca 100755 --- a/scripts/bootstrap-rootfs-overlay-hosted-server.sh +++ b/scripts/bootstrap-rootfs-overlay-hosted-server.sh @@ -19,8 +19,8 @@ set -o errexit root_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd ) if [ "${root_dir}" != "${PWD}" ]; then - echo "You must execute $(basename $0) from the root directory: ${root_dir}" - exit 1 + echo "You must execute $(basename $0) from the root directory: ${root_dir}" + exit 1 fi tenant_token="" @@ -44,13 +44,13 @@ while (( "$#" )); do done if [ -z "${output_dir}" ]; then - echo "Sorry, but you need to provide an output directory using the '-o/--output-dir' option" - exit 1 + echo "Sorry, but you need to provide an output directory using the '-o/--output-dir' option" + exit 1 fi if [ -z "${tenant_token}" ]; then - echo "Sorry, but you need to provide a tenant token using the '-t/--tenant-token' option" - exit 1 + echo "Sorry, but you need to provide a tenant token using the '-t/--tenant-token' option" + exit 1 fi mkdir -p ${output_dir}/etc/mender diff --git a/scripts/bootstrap-rootfs-overlay-production-server.sh b/scripts/bootstrap-rootfs-overlay-production-server.sh index 3d079b0..3e73881 100755 --- a/scripts/bootstrap-rootfs-overlay-production-server.sh +++ b/scripts/bootstrap-rootfs-overlay-production-server.sh @@ -19,8 +19,8 @@ set -o errexit root_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd ) if [ "${root_dir}" != "${PWD}" ]; then - echo "You must execute $(basename $0) from the root directory: ${root_dir}" - exit 1 + echo "You must execute $(basename $0) from the root directory: ${root_dir}" + exit 1 fi server_url="" @@ -48,13 +48,13 @@ while (( "$#" )); do done if [ -z "${output_dir}" ]; then - echo "Sorry, but you need to provide an output directory using the '-o/--output-dir' option" - exit 1 + echo "Sorry, but you need to provide an output directory using the '-o/--output-dir' option" + exit 1 fi if [ -z "${server_url}" ]; then - echo "Sorry, but you need to provide a server URL using the '-s/--server-url' option" - exit 1 + echo "Sorry, but you need to provide a server URL using the '-s/--server-url' option" + exit 1 fi mkdir -p ${output_dir}/etc/mender @@ -65,11 +65,11 @@ cat <<- EOF > ${output_dir}/etc/mender/mender.conf "ServerURL": "${server_url}", EOF -if [ -n "${server_cert}" ] ; then -cat <<- EOF >> ${output_dir}/etc/mender/mender.conf +if [ -n "${server_cert}" ]; then + cat <<- EOF >> ${output_dir}/etc/mender/mender.conf "ServerCertificate": "/etc/mender/server.crt", EOF -cp -f "${server_cert}" ${output_dir}/etc/mender/server.crt + cp -f "${server_cert}" ${output_dir}/etc/mender/server.crt fi cat <<- EOF >> ${output_dir}/etc/mender/mender.conf diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh index 0d90590..cdef884 100755 --- a/scripts/run-tests.sh +++ b/scripts/run-tests.sh @@ -4,8 +4,8 @@ set -e root_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd ) if [ "${root_dir}" != "${PWD}" ]; then - echo "You must execute $(basename $0) from the root directory: ${root_dir}" - exit 1 + echo "You must execute $(basename $0) from the root directory: ${root_dir}" + exit 1 fi WORKSPACE=./tests @@ -34,104 +34,104 @@ MENDER_ACCEPTANCE_URL="https://raw.githubusercontent.com/mendersoftware/meta-men export PATH="${PATH}:/sbin" convert_and_test() { - device_type=$1 - artifact_name=$2 - image_url=$3 - image_name=$4 - image_name_compressed=$5 - config=$6 # Optional + device_type=$1 + artifact_name=$2 + image_url=$3 + image_name=$4 + image_name_compressed=$5 + config=$6 # Optional - wget --progress=dot:giga -N ${image_url} -P input/ + wget --progress=dot:giga -N ${image_url} -P input/ - echo "Extracting: ${image_name_compressed}" - case "${image_name_compressed}" in + echo "Extracting: ${image_name_compressed}" + case "${image_name_compressed}" in *.gz) - gunzip -f input/${image_name_compressed} - ;; + gunzip -f input/${image_name_compressed} + ;; *.zip) - cd input - unzip -o ${image_name_compressed} - cd - + cd input + unzip -o ${image_name_compressed} + cd - ;; *.xz) - xz -d -f input/${image_name_compressed} - ;; + xz -d -f input/${image_name_compressed} + ;; *) - echo "Unknown image type: ${image_name_compressed}" - exit 1 - esac - - 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=y. 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=n" > ${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_name} \ - ${MENDER_CONVERT_EXTRA_ARGS} - - if pip3 list | grep -q -e pytest-html; then - html_report_args="--html=${MENDER_CONVERT_DIR}/report_${device_type}.html --self-contained-html" - fi - - # Need to decompress images built with MENDER_COMPRESS_DISK_IMAGE=y before - # running tests. - if [ -f deploy/${device_type}-${artifact_name}.sdimg.gz ]; then - # sudo is needed because the image is created using docker-mender-convert - # which sets root permissions on the image - sudo gunzip --force deploy/${device_type}-${artifact_name}.sdimg.gz - fi - - cd ${WORKSPACE}/mender-image-tests - - # This is a trick to make pytest generate different junit reports - # for different runs: renaming the tests folder to tests_ - cp -r tests tests_${device_type} - - python3 -m pytest --verbose \ - --junit-xml="${MENDER_CONVERT_DIR}/results_${device_type}.xml" \ - ${html_report_args} \ - --test-conversion \ - --test-variables="${MENDER_CONVERT_DIR}/deploy/${device_type}-${artifact_name}.cfg" \ - --board-type="${device_type}" \ - --mender-image=${device_type}-${artifact_name}.sdimg \ - --sdimg-location="${MENDER_CONVERT_DIR}/deploy" \ - tests_${device_type} - exitcode=$? - - cd - - - return $exitcode + echo "Unknown image type: ${image_name_compressed}" + exit 1 + ;; + esac + + 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=y. 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=n" > ${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_name} \ + ${MENDER_CONVERT_EXTRA_ARGS} + + if pip3 list | grep -q -e pytest-html; then + html_report_args="--html=${MENDER_CONVERT_DIR}/report_${device_type}.html --self-contained-html" + fi + + # Need to decompress images built with MENDER_COMPRESS_DISK_IMAGE=y before + # running tests. + if [ -f deploy/${device_type}-${artifact_name}.sdimg.gz ]; then + # sudo is needed because the image is created using docker-mender-convert + # which sets root permissions on the image + sudo gunzip --force deploy/${device_type}-${artifact_name}.sdimg.gz + fi + + cd ${WORKSPACE}/mender-image-tests + + # This is a trick to make pytest generate different junit reports + # for different runs: renaming the tests folder to tests_ + cp -r tests tests_${device_type} + + python3 -m pytest --verbose \ + --junit-xml="${MENDER_CONVERT_DIR}/results_${device_type}.xml" \ + ${html_report_args} \ + --test-conversion \ + --test-variables="${MENDER_CONVERT_DIR}/deploy/${device_type}-${artifact_name}.cfg" \ + --board-type="${device_type}" \ + --mender-image=${device_type}-${artifact_name}.sdimg \ + --sdimg-location="${MENDER_CONVERT_DIR}/deploy" \ + tests_${device_type} + exitcode=$? + + cd - + + return $exitcode } get_pytest_files() { - wget -N ${MENDER_ACCEPTANCE_URL}/pytest.ini -P $WORKSPACE/mender-image-tests - wget -N ${MENDER_ACCEPTANCE_URL}/common.py -P $WORKSPACE/mender-image-tests - wget -N ${MENDER_ACCEPTANCE_URL}/conftest.py -P $WORKSPACE/mender-image-tests - wget -N ${MENDER_ACCEPTANCE_URL}/fixtures.py -P $WORKSPACE/mender-image-tests + wget -N ${MENDER_ACCEPTANCE_URL}/pytest.ini -P $WORKSPACE/mender-image-tests + wget -N ${MENDER_ACCEPTANCE_URL}/common.py -P $WORKSPACE/mender-image-tests + wget -N ${MENDER_ACCEPTANCE_URL}/conftest.py -P $WORKSPACE/mender-image-tests + wget -N ${MENDER_ACCEPTANCE_URL}/fixtures.py -P $WORKSPACE/mender-image-tests } if [ ! -d ${WORKSPACE}/mender-image-tests ]; then - git clone https://github.com/mendersoftware/mender-image-tests ${WORKSPACE}/mender-image-tests + git clone https://github.com/mendersoftware/mender-image-tests ${WORKSPACE}/mender-image-tests else - cd ${WORKSPACE}/mender-image-tests - git pull - cd - + cd ${WORKSPACE}/mender-image-tests + git pull + cd - fi mkdir -p ${WORKSPACE} @@ -141,18 +141,18 @@ get_pytest_files test_result=0 convert_and_test "qemux86_64" \ - "release-1" \ - "${UBUNTU_IMAGE_URL}" \ - "${UBUNTU_IMAGE}" \ - "${UBUNTU_IMAGE}.gz" \ - "configs/qemux86-64_config" || test_result=$? + "release-1" \ + "${UBUNTU_IMAGE_URL}" \ + "${UBUNTU_IMAGE}" \ + "${UBUNTU_IMAGE}.gz" \ + "configs/qemux86-64_config" || test_result=$? convert_and_test "raspberrypi" \ - "release-1" \ - "${RASPBIAN_IMAGE_URL}" \ - "${RASPBIAN_IMAGE}.img" \ - "${RASPBIAN_IMAGE}.zip" \ - "configs/raspberrypi3_config" || test_result=$? + "release-1" \ + "${RASPBIAN_IMAGE_URL}" \ + "${RASPBIAN_IMAGE}.img" \ + "${RASPBIAN_IMAGE}.zip" \ + "configs/raspberrypi3_config" || test_result=$? # MEN-2809: Disabled due broken download link #convert_and_test "linaro-alip" \ @@ -162,16 +162,16 @@ convert_and_test "raspberrypi" \ # "${TINKER_IMAGE}.zip" || test_result=$? convert_and_test "beaglebone" \ - "release-1" \ - "${BBB_DEBIAN_IMAGE_URL}" \ - "${BBB_DEBIAN_IMAGE}" \ - "${BBB_DEBIAN_IMAGE}.xz" || test_result=$? + "release-1" \ + "${BBB_DEBIAN_IMAGE_URL}" \ + "${BBB_DEBIAN_IMAGE}" \ + "${BBB_DEBIAN_IMAGE}.xz" || test_result=$? convert_and_test "ubuntu" \ - "release-1" \ - "${UBUNTU_SERVER_RPI_IMAGE_URL}" \ - "${UBUNTU_SERVER_RPI_IMAGE}" \ - "${UBUNTU_SERVER_RPI_IMAGE}.xz" \ - "configs/raspberrypi3_config" || test_result=$? + "release-1" \ + "${UBUNTU_SERVER_RPI_IMAGE_URL}" \ + "${UBUNTU_SERVER_RPI_IMAGE}" \ + "${UBUNTU_SERVER_RPI_IMAGE}.xz" \ + "configs/raspberrypi3_config" || test_result=$? exit $test_result