diff --git a/mender-convert b/mender-convert index 375bc4d..880a2f3 100755 --- a/mender-convert +++ b/mender-convert @@ -1,6 +1,6 @@ #! /usr/bin/env bash # -# Copyright 2019 Northern.tech AS +# Copyright 2021 Northern.tech AS # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ source modules/bootstrap.sh source modules/cliparser.sh source modules/decompressinput.sh +source modules/testscfg.sh export MENDER_CONVERT_LOG_FILE=$(pwd)/${MENDER_CONVERT_LOG_FILE:-logs/convert.log} touch ${MENDER_CONVERT_LOG_FILE} @@ -118,6 +119,8 @@ if [ -z "${MENDER_ARTIFACT_NAME}" ]; then exit 1 fi +testscfg_init + parse_cli_options "$@" compression_type=$(compression_type "${disk_image}") diff --git a/mender-convert-modify b/mender-convert-modify index 2dd1e11..b4d3b26 100755 --- a/mender-convert-modify +++ b/mender-convert-modify @@ -1,6 +1,6 @@ #! /usr/bin/env bash # -# Copyright 2020 Northern.tech AS +# Copyright 2021 Northern.tech AS # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -50,6 +50,7 @@ source modules/bootstrap.sh source modules/disk.sh source modules/probe.sh source modules/deb.sh +source modules/testscfg.sh # The mender_convert_config is always used and provides all the defaults declare -a configs=("configs/mender_convert_config") @@ -113,6 +114,9 @@ fi deb_extract_package "work/deb-packages/${deb_name}" "work/rootfs/" +# Save installed client version for tests in Yocto variable format +testscfg_add "PREFERRED_VERSION_mender-client" "$(echo ${deb_name} | sed -r 's/.*_([0-9]+\.[0-9]+\.[0-9]+).*/\1/')" + if [ "${MENDER_ENABLE_SYSTEMD}" == "y" ]; then run_and_log_cmd "sudo ln -sf /lib/systemd/system/mender-client.service \ work/rootfs/etc/systemd/system/multi-user.target.wants/mender-client.service" diff --git a/mender-convert-package b/mender-convert-package index 48659ac..44c7237 100755 --- a/mender-convert-package +++ b/mender-convert-package @@ -1,6 +1,6 @@ #! /usr/bin/env bash # -# Copyright 2020 Northern.tech AS +# Copyright 2021 Northern.tech AS # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -38,6 +38,7 @@ echo "Running $(basename $0): $@" source modules/bootstrap.sh source modules/disk.sh +source modules/testscfg.sh # The mender_convert_config is always used and provides all the defaults declare -a configs=("configs/mender_convert_config") @@ -350,35 +351,31 @@ else fi mender_features="${bootloader_feature} mender-convert" -cat <<- EOF > deploy/${image_name}.cfg -MENDER_BOOT_PART="${boot_part_device}" -MENDER_ROOTFS_PART_A="${root_part_a_device}" -MENDER_ROOTFS_PART_B="${root_part_b_device}" -MENDER_DATA_PART="${data_part_device}" -MENDER_BOOT_PART_MOUNT_LOCATION="${boot_part_mountpoint}" -MENDER_BOOT_PART_SIZE_MB="$(disk_sectors_to_mb ${boot_part_sectors})" -MENDER_DATA_PART_SIZE_MB="${MENDER_DATA_PART_SIZE_MB}" -MENDER_DEVICE_TYPE="${device_type}" -MENDER_PARTITIONING_OVERHEAD_KB="$(( (${overhead_sectors} * 512) / 1024 ))" -MENDER_PARTITION_ALIGNMENT="${MENDER_PARTITION_ALIGNMENT}" -MENDER_STORAGE_TOTAL_SIZE_MB="${MENDER_STORAGE_TOTAL_SIZE_MB}" -MENDER_UBOOT_ENV_STORAGE_DEVICE_OFFSET="12582912" -MENDER_ARTIFACT_NAME="${artifact_name}" -MENDER_FEATURES="${mender_features}" -DEPLOY_DIR_IMAGE="${PWD}/deploy" -MENDER_MACHINE="${device_type}" -EOF - +testscfg_add "MENDER_BOOT_PART" "${boot_part_device}" +testscfg_add "MENDER_ROOTFS_PART_A" "${root_part_a_device}" +testscfg_add "MENDER_ROOTFS_PART_B" "${root_part_b_device}" +testscfg_add "MENDER_DATA_PART" "${data_part_device}" +testscfg_add "MENDER_BOOT_PART_MOUNT_LOCATION" "${boot_part_mountpoint}" +testscfg_add "MENDER_BOOT_PART_SIZE_MB" "$(disk_sectors_to_mb ${boot_part_sectors})" +testscfg_add "MENDER_DATA_PART_SIZE_MB" "${MENDER_DATA_PART_SIZE_MB}" +testscfg_add "MENDER_DEVICE_TYPE" "${device_type}" +testscfg_add "MENDER_PARTITIONING_OVERHEAD_KB" "$(( (${overhead_sectors} * 512) / 1024 ))" +testscfg_add "MENDER_PARTITION_ALIGNMENT" "${MENDER_PARTITION_ALIGNMENT}" +testscfg_add "MENDER_STORAGE_TOTAL_SIZE_MB" "${MENDER_STORAGE_TOTAL_SIZE_MB}" +testscfg_add "MENDER_UBOOT_ENV_STORAGE_DEVICE_OFFSET" "12582912" +testscfg_add "MENDER_ARTIFACT_NAME" "${artifact_name}" +testscfg_add "MENDER_FEATURES" "${mender_features}" +testscfg_add "DEPLOY_DIR_IMAGE" "${PWD}/deploy" +testscfg_add "MENDER_MACHINE" "${device_type}" # Outputting device base only relevant for some configurations if [ "${MENDER_ENABLE_PARTUUID}" != "y" ]; then - cat <<- EOF >> deploy/${image_name}.cfg -MENDER_STORAGE_DEVICE_BASE="${MENDER_STORAGE_DEVICE_BASE}" -EOF + testscfg_add "MENDER_STORAGE_DEVICE_BASE" "${MENDER_STORAGE_DEVICE_BASE}" fi # Something that the tests expect to be defined (originally from Yocto) -cat <<- EOF >> deploy/${image_name}.cfg -IMAGE_FSTYPES="${image_fs_type} mender sdimg" -ARTIFACTIMG_FSTYPE="${image_fs_type}" -EOF +testscfg_add "IMAGE_FSTYPES" "${image_fs_type} mender sdimg" +testscfg_add "ARTIFACTIMG_FSTYPE" "${image_fs_type}" + +# Save configuration file for tests +testscfg_save deploy/${image_name}.cfg diff --git a/modules/testscfg.sh b/modules/testscfg.sh new file mode 100644 index 0000000..e6b82ba --- /dev/null +++ b/modules/testscfg.sh @@ -0,0 +1,47 @@ +# +# Copyright 2021 Northern.tech AS +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Init tests configuration file +# +function testscfg_init () { + rm -f work/testscfg.tmp + touch work/testscfg.tmp +} + +# Add key/value to tests configuration file +# +# $1 - key +# $2 - value +# +function testscfg_add () { + if [[ $# -ne 2 ]]; then + log_fatal "testscfg_add() requires 2 arguments" + fi + local -r key="${1}" + local -r value="${2}" + echo "${key}=\"${value}\"" >> work/testscfg.tmp +} + +# Save tests configuration file into the given location +# +# $1 - Filename +# +function testscfg_save () { + if [[ $# -ne 1 ]]; then + log_fatal "testscfg_save() requires 1 argument" + fi + local -r filename="${1}" + cp work/testscfg.tmp ${filename} +}