aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilosz Wasilewski <milosz.wasilewski@foundries.io>2022-11-22 13:21:10 +0000
committerAnders Roxell <anders.roxell@gmail.com>2022-11-29 10:59:42 +0100
commit0432ad0716218769149c74caf9dc87a6db064b8f (patch)
tree7546d766af075837de6ca4fdcb6da32c35a770c0
parentc6ab761fe1d911cf0417db1be92831994e66832b (diff)
automated: linux: Add LmP factory reset test2022.12.01
The test creates a file that is used by scripts in ramdisk to determine whether to do a device factory reset. Signed-off-by: Milosz Wasilewski <milosz.wasilewski@foundries.io>
-rwxr-xr-xautomated/linux/factory-reset/aklite-callback.sh4
-rwxr-xr-xautomated/linux/factory-reset/prepare-reset.sh82
-rw-r--r--automated/linux/factory-reset/prepare-reset.yaml41
-rwxr-xr-xautomated/linux/factory-reset/verify-reboot.sh70
-rw-r--r--automated/linux/factory-reset/verify-reboot.yaml28
-rw-r--r--automated/linux/factory-reset/z-99-aklite-callback.toml5
6 files changed, 230 insertions, 0 deletions
diff --git a/automated/linux/factory-reset/aklite-callback.sh b/automated/linux/factory-reset/aklite-callback.sh
new file mode 100755
index 00000000..b1fa1df8
--- /dev/null
+++ b/automated/linux/factory-reset/aklite-callback.sh
@@ -0,0 +1,4 @@
+#!/bin/bash -e
+
+echo "${MESSAGE}" > /var/sota/ota.signal
+echo "${RESULT}" > /var/sota/ota.result
diff --git a/automated/linux/factory-reset/prepare-reset.sh b/automated/linux/factory-reset/prepare-reset.sh
new file mode 100755
index 00000000..5db825a5
--- /dev/null
+++ b/automated/linux/factory-reset/prepare-reset.sh
@@ -0,0 +1,82 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-only
+# Copyright (C) 2022 Foundries.io Ltd.
+
+# shellcheck disable=SC1091
+. ../../lib/sh-test-lib
+OUTPUT="$(pwd)/output"
+RESULT_FILE="${OUTPUT}/result.txt"
+export RESULT_FILE
+TYPE="factory_reset"
+ADDITIONAL_TYPE=""
+
+usage() {
+ echo "\
+ Usage: $0 [-t <factory_reset|factory_reset_keep_sota|factory_reset_keep_sota_docker>]
+ [-a <factory_reset|factory_reset_keep_sota|factory_reset_keep_sota_docker>]
+
+ -t <factory_reset|factory_reset_keep_sota|factory_reset_keep_sota_docker>
+ factory_reset: Full reset, removes contents of /etc/ and /var/
+ factory_reset_keep_sota: Keeps /var/sota without changes
+ factory_reset_keep_sota_docker: Keeps /var/sota and /var/lib without changes
+ -a <factory_reset|factory_reset_keep_sota|factory_reset_keep_sota_docker>
+ same as -t. Allows to create 2 files and test the priority order
+ "
+}
+
+while getopts "t:a:h" opts; do
+ case "$opts" in
+ t) TYPE="${OPTARG}";;
+ a) ADDITIONAL_TYPE="${OPTARG}";;
+ h|*) usage ; exit 1 ;;
+ esac
+done
+
+# the script works only on builds with aktualizr-lite
+# and lmp-device-auto-register
+
+! check_root && error_msg "You need to be root to run this script."
+create_out_dir "${OUTPUT}"
+
+# configure aklite callback
+cp aklite-callback.sh /var/sota/
+chmod 755 /var/sota/aklite-callback.sh
+
+mkdir -p /etc/sota/conf.d
+cp z-99-aklite-callback.toml /etc/sota/conf.d/
+# create signal files
+touch /var/sota/ota.signal
+touch /var/sota/ota.result
+
+#systemctl mask aktualizr-lite
+# enabling lmp-device-auto-register will fail because aklite is masked
+systemctl enable --now lmp-device-auto-register || error_fatal "Unable to register device"
+
+while ! systemctl is-active aktualizr-lite; do
+ echo "Waiting for aktualizr-lite to start"
+ sleep 1
+done
+
+while ! journalctl --no-pager -u aktualizr-lite | grep "Device is up-to-date"; do
+ echo "Waiting for aktualizr-lite to complete initialization"
+ sleep 1
+done
+
+ls -l /etc/sota
+ls -l /var/sota
+
+if [ -f /etc/sota/conf.d/z-99-aklite-callback.toml ]; then
+ report_pass "${TYPE}-aklite-callback-created"
+else
+ report_fail "${TYPE}-aklite-callback-created"
+fi
+
+if [ -f /var/sota/sql.db ]; then
+ report_pass "${TYPE}-device-registration"
+else
+ report_fail "${TYPE}-device-registration"
+fi
+touch "/var/.${TYPE}"
+if [ -n "${ADDITIONAL_TYPE}" ]; then
+ touch "/var/.${ADDITIONAL_TYPE}"
+fi
diff --git a/automated/linux/factory-reset/prepare-reset.yaml b/automated/linux/factory-reset/prepare-reset.yaml
new file mode 100644
index 00000000..97ac4323
--- /dev/null
+++ b/automated/linux/factory-reset/prepare-reset.yaml
@@ -0,0 +1,41 @@
+# SPDX-License-Identifier: GPL-2.0-only
+# Copyright (C) 2021 Foundries.io
+metadata:
+ format: Lava-Test Test Definition 1.0
+ name: lmp-factory-reset
+ description: "Perform device factory reset.
+ The end result should be a device filesystem
+ restored to the condition after initial manufacturing.
+ Only a limited subset of files is checked.
+ Reset type is evaluated in the following priority:
+
+ 1. factory_reset
+ 2. factory_reset_keep_sota
+ 3. factory_reset_keep_sota_docker
+
+ If higher priority type is present, lower priority
+ type is ignored.
+ "
+
+ maintainer:
+ - milosz.wasilewski@foundries.io
+ os:
+ - openembedded
+ scope:
+ - functional
+
+ devices:
+ - imx8mm
+ - imx6ull
+
+params:
+ # primary type of reset
+ TYPE: "factory_reset"
+ # additional type. Behaviour depens on both
+ # TYPE and ADDITIONAL_TYPE
+ ADDITIONAL_TYPE: ""
+run:
+ steps:
+ - cd ./automated/linux/factory-reset
+ - ./prepare-reset.sh -t "${TYPE}" -a "${ADDITIONAL_TYPE}"
+ - ../../utils/send-to-lava.sh ./output/result.txt
diff --git a/automated/linux/factory-reset/verify-reboot.sh b/automated/linux/factory-reset/verify-reboot.sh
new file mode 100755
index 00000000..6359cd66
--- /dev/null
+++ b/automated/linux/factory-reset/verify-reboot.sh
@@ -0,0 +1,70 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-only
+# Copyright (C) 2022 Foundries.io Ltd.
+
+# shellcheck disable=SC1091
+. ../../lib/sh-test-lib
+OUTPUT="$(pwd)/output"
+RESULT_FILE="${OUTPUT}/result.txt"
+export RESULT_FILE
+TYPE="factory_reset"
+
+usage() {
+ echo "\
+ Usage: $0 [-t <factory_reset|factory_reset_keep_sota|factory_reset_keep_sota_docker>]
+
+ -t <factory_reset|factory_reset_keep_sota|factory_reset_keep_sota_docker>
+ factory_reset: Full reset, removes contents of /etc/ and /var/
+ factory_reset_keep_sota: Keeps /var/sota without changes
+ factory_reset_keep_sota_docker: Keeps /var/sota and /var/lib without changes
+ "
+}
+
+while getopts "t:h" opts; do
+ case "$opts" in
+ t) TYPE="${OPTARG}";;
+ h|*) usage ; exit 1 ;;
+ esac
+done
+
+# the script works only on builds with aktualizr-lite
+# and lmp-device-auto-register
+
+! check_root && error_msg "You need to be root to run this script."
+create_out_dir "${OUTPUT}"
+
+ls -l /etc/
+ls -l /var/sota
+
+if [ -f /etc/sota/conf.d/z-99-aklite-callback.toml ]; then
+ report_fail "${TYPE}-reset-aklite-callback-exists"
+else
+ report_pass "${TYPE}-reset-aklite-callback-exists"
+fi
+
+if [ "${TYPE}" = "factory_reset_keep_sota" ]; then
+ # aktualizr-lite should be running
+ if systemctl status --no-pager aktualizr-lite; then
+ report_pass "${TYPE}-reset-aklite-running"
+ else
+ report_fail "${TYPE}-reset-aklite-running"
+ fi
+ if [ -f /var/sota/sql.db ]; then
+ report_pass "${TYPE}-reset-device-registration"
+ else
+ report_fail "${TYPE}-reset-device-registration"
+ fi
+else
+ # aktualizr-lite should NOT be running
+ if systemctl status --no-pager aktualizr-lite; then
+ report_fail "${TYPE}-reset-aklite-running"
+ else
+ report_pass "${TYPE}-reset-aklite-running"
+ fi
+ if [ -f /var/sota/sql.db ]; then
+ report_fail "${TYPE}-reset-device-registration"
+ else
+ report_pass "${TYPE}-reset-device-registration"
+ fi
+fi
+exit 0
diff --git a/automated/linux/factory-reset/verify-reboot.yaml b/automated/linux/factory-reset/verify-reboot.yaml
new file mode 100644
index 00000000..64537d4d
--- /dev/null
+++ b/automated/linux/factory-reset/verify-reboot.yaml
@@ -0,0 +1,28 @@
+# SPDX-License-Identifier: GPL-2.0-only
+# Copyright (C) 2021 Foundries.io
+metadata:
+ format: Lava-Test Test Definition 1.0
+ name: lmp-factory-reset-verify
+ description: "Verify device factory reset.
+ The end result should be a device filesystem
+ restored to the condition after initial manufacturing.
+ Only a limited subset of files is checked."
+
+ maintainer:
+ - milosz.wasilewski@foundries.io
+ os:
+ - openembedded
+ scope:
+ - functional
+
+ devices:
+ - imx8mm
+ - imx6ull
+
+params:
+ TYPE: "factory_reset"
+run:
+ steps:
+ - cd ./automated/linux/factory-reset
+ - ./verify-reboot.sh -t "${TYPE}"
+ - ../../utils/send-to-lava.sh ./output/result.txt
diff --git a/automated/linux/factory-reset/z-99-aklite-callback.toml b/automated/linux/factory-reset/z-99-aklite-callback.toml
new file mode 100644
index 00000000..7a8ae68c
--- /dev/null
+++ b/automated/linux/factory-reset/z-99-aklite-callback.toml
@@ -0,0 +1,5 @@
+[pacman]
+callback_program = "/var/sota/aklite-callback.sh"
+[bootloader]
+reboot_command = "/bin/true"
+