diff options
author | Brendan Wood <brendan.wood@foundries.io> | 2023-02-10 16:16:35 +0000 |
---|---|---|
committer | Anders Roxell <anders.roxell@gmail.com> | 2023-03-08 09:12:09 +0100 |
commit | d6768685f7105f469c218b0495efe9de81691653 (patch) | |
tree | 4efd156f194a4c00a87c555476a65946a34381ee | |
parent | 8603a138e4aceb25c2eaa5f62d612f33faa291f3 (diff) |
Add docker-prune tests2023.03.01
Tests that check whether docker correctly prunes
app images after update or disable
Signed-off-by: Brendan Wood <brendan.wood@foundries.io>
-rwxr-xr-x | automated/linux/docker-prune/aklite-callback.sh | 4 | ||||
-rwxr-xr-x | automated/linux/docker-prune/disable-prune.sh | 47 | ||||
-rw-r--r-- | automated/linux/docker-prune/disable-prune.yaml | 21 | ||||
-rw-r--r-- | automated/linux/docker-prune/prune-lib.sh | 88 | ||||
-rwxr-xr-x | automated/linux/docker-prune/prune.sh | 39 | ||||
-rw-r--r-- | automated/linux/docker-prune/prune.yaml | 22 | ||||
-rw-r--r-- | automated/linux/docker-prune/z-99-aklite-callback.toml | 5 |
7 files changed, 226 insertions, 0 deletions
diff --git a/automated/linux/docker-prune/aklite-callback.sh b/automated/linux/docker-prune/aklite-callback.sh new file mode 100755 index 00000000..b1fa1df8 --- /dev/null +++ b/automated/linux/docker-prune/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/docker-prune/disable-prune.sh b/automated/linux/docker-prune/disable-prune.sh new file mode 100755 index 00000000..e0267599 --- /dev/null +++ b/automated/linux/docker-prune/disable-prune.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# shellcheck disable=SC1091 +. ../../lib/sh-test-lib +. ./prune-lib.sh + +OUTPUT="$(pwd)/output" +RESULT_FILE="${OUTPUT}/result.txt" +export RESULT_FILE + +TOKEN=$(cat /etc/lmp-device-register-token) +DEVICE_NAME=$(cat /etc/hostname) +API_DATA='{ "reason": "Prune Test", "files": +[{"name":"z-50-fioctl.toml","on-changed":["/usr/share/fioconfig/handlers/aktualizr-toml-update"],"unencrypted":true,"value":"\n[pacman]\n compose_apps = \"\"\n"}]}' +FACTORY=$(grep -w "LMP_FACTORY" /etc/os-release | cut -d'=' -f2 | sed 's/\"//g') + + +! check_root && error_msg "You need to be root to run this script." +create_out_dir "${OUTPUT}" + +setup_callback + +auto_register + +while ! docker ps -a | grep "shellhttpd"; do + echo "waiting for container" + sleep 1 +done + +get_image_sha + +curl --data "$API_DATA" -H "Content-Type: application/json" -H "OSF-TOKEN: $TOKEN" -X PATCH https://api.foundries.io/ota/devices/"$DEVICE_NAME"/config/?factory="$FACTORY" + +wait_for_signal + +if check_image_prune; then + report_pass "disable-prune" +else + report_fail "disable-prune" +fi + +if check_image shellhttpd; then + report_fail "image-removed" +else + report_pass "image-removed" +fi + +rm "$(pwd)/sha.txt" diff --git a/automated/linux/docker-prune/disable-prune.yaml b/automated/linux/docker-prune/disable-prune.yaml new file mode 100644 index 00000000..f03af420 --- /dev/null +++ b/automated/linux/docker-prune/disable-prune.yaml @@ -0,0 +1,21 @@ +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (C) 2021 Foundries.io +metadata: + format: Lava-Test Test Definition 1.0 + name: docker-prune + description: "Prune app image after disabling app" + + maintainer: + - brendan.wood@foundries.io + os: + - openembedded + scope: + - functional + devices: + - imx8mm + +run: + steps: + - cd ./automated/linux/docker-prune + - ./disable_prune.sh + - ../../utils/send-to-lava.sh ./output/result.txt diff --git a/automated/linux/docker-prune/prune-lib.sh b/automated/linux/docker-prune/prune-lib.sh new file mode 100644 index 00000000..fecdcb0b --- /dev/null +++ b/automated/linux/docker-prune/prune-lib.sh @@ -0,0 +1,88 @@ +#!/bin/bash + +verify_app_present () { + app="$1" + + if docker ps | grep -q "${app}"; then + return 0 + fi + + return 1 +} + +check_image () { + image_name="$1" + + if [[ "$(docker images -q "${image_name}" 2> /dev/null)" == "" ]] ; then + return 1 + fi + + return 0 +} + +get_image_sha () { + ls /var/sota/reset-apps/apps/shellhttpd > "$(pwd)/sha.txt" +} + +check_image_prune () { + runtime="5 minutes" + endtime=$(date -ud "$runtime" +%s) + + while true; do + if [ "$(date -u +%s)" -ge "$endtime" ]; then + echo "Not found" + return 1 + elif (journalctl --no-pager -u aktualizr-lite | grep "Pruning unused docker containers"); then + echo "Found" + return 0 + fi + sleep 1 + done +} + +compare_sha () { + if diff "$(pwd)/sha.txt" <(ls /var/sota/reset-apps/apps/shellhttpd) > /dev/null; then + return 1 + fi + + return 0 +} + +setup_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/ + report_pass "create-aklite-callback" + touch /var/sota/ota.signal + touch /var/sota/ota.result + report_pass "create-signal-files" +} + +wait_for_signal () { + SIGNAL=$(</var/sota/ota.signal) + while [ ! "${SIGNAL}" = "check-for-update-post" ] + do + echo "Sleeping 1s" + sleep 1 + cat /var/sota/ota.signal + SIGNAL=$(</var/sota/ota.signal) + echo "SIGNAL: ${SIGNAL}." + done + report_pass "update-post-received" +} + +auto_register () { + if [ -f "/var/sota/sql.db" ]; then + echo "Device registered, skipping registration" + else + systemctl enable --now lmp-device-auto-register || error_fatal "Unable to register device" + fi + + while ! systemctl is-active aktualizr-lite; do + echo "Waiting for aktualizr-lite to start" + sleep 1 + done +# add some delay so aklite can setup variables + sleep 5 +} diff --git a/automated/linux/docker-prune/prune.sh b/automated/linux/docker-prune/prune.sh new file mode 100755 index 00000000..11f7b3ec --- /dev/null +++ b/automated/linux/docker-prune/prune.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# shellcheck disable=SC1091 +. ../../lib/sh-test-lib +. ./prune-lib.sh + +OUTPUT="$(pwd)/output" +RESULT_FILE="${OUTPUT}/result.txt" +export RESULT_FILE + +! check_root && error_msg "You need to be root to run this script." +create_out_dir "${OUTPUT}" + +if check_image hub.foundries.io/lmp-ci-testing-apps/shellhttpd; then + report_pass "image-present" +else + report_fail "image-present" +fi + +get_image_sha + +setup_callback + +auto_register + +wait_for_signal + +if check_image_prune; then + report_pass "update-prune" +else + report_fail "update-prune" +fi + +if compare_sha; then + report_pass "check-sha" +else + report_fail "check-sha" +fi + +rm "$(pwd)/sha.txt" diff --git a/automated/linux/docker-prune/prune.yaml b/automated/linux/docker-prune/prune.yaml new file mode 100644 index 00000000..b7d4feee --- /dev/null +++ b/automated/linux/docker-prune/prune.yaml @@ -0,0 +1,22 @@ +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (C) 2021 Foundries.io +metadata: + format: Lava-Test Test Definition 1.0 + name: docker-prune + description: "Download OTA update and prune + old container images" + + maintainer: + - brendan.wood@foundries.io + os: + - openembedded + scope: + - functional + devices: + - imx8mm + +run: + steps: + - cd ./automated/linux/docker-prune + - ./prune.sh + - ../../utils/send-to-lava.sh ./output/result.txt diff --git a/automated/linux/docker-prune/z-99-aklite-callback.toml b/automated/linux/docker-prune/z-99-aklite-callback.toml new file mode 100644 index 00000000..7a8ae68c --- /dev/null +++ b/automated/linux/docker-prune/z-99-aklite-callback.toml @@ -0,0 +1,5 @@ +[pacman] +callback_program = "/var/sota/aklite-callback.sh" +[bootloader] +reboot_command = "/bin/true" + |