Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 20 additions & 31 deletions test/agent/microshift-test-agent.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/bash
set -xeuo pipefail

GREENBOOT_CONFIGURATION_FILE=/etc/greenboot/greenboot.conf
AGENT_CFG=/var/lib/microshift-test-agent.json
SYSTEMD_NOTIFIED=false

Expand Down Expand Up @@ -58,32 +57,6 @@ _debug_info() {
cat "${AGENT_CFG}" || true
}

_get_current_boot_number() {
if ! /usr/bin/grub2-editenv list | grep -q boot_counter; then
echo "boot_counter is missing - script only for newly staged deployments"
exit 0
fi

local -r boot_counter=$(/usr/bin/grub2-editenv list | grep boot_counter | sed 's,boot_counter=,,')
local max_boot_attempts

if test -f "${GREENBOOT_CONFIGURATION_FILE}"; then
# shellcheck source=/dev/null
source "${GREENBOOT_CONFIGURATION_FILE}"
fi

if [ -v GREENBOOT_MAX_BOOT_ATTEMPTS ]; then
max_boot_attempts="${GREENBOOT_MAX_BOOT_ATTEMPTS}"
else
max_boot_attempts=3
fi

# When deployment is staged, greenboot sets boot_counter to 3
# and this variable gets decremented on each boot.
# First boot of new deployment will have it set to 2.
echo "$((max_boot_attempts - boot_counter))"
}

_get_current_deployment_id() {
local -r id="$(rpm-ostree status --booted --json | jq -r ".deployments[0].id")"
echo "${id}"
Expand Down Expand Up @@ -147,18 +120,34 @@ if [ ! -f "${AGENT_CFG}" ] ; then
exit 0
fi

current_boot="$(_get_current_boot_number)"
current_deployment_id="$(_get_current_deployment_id)"

deploy=$(jq -c ".\"${current_deployment_id}\"" "${AGENT_CFG}")
if [[ "${deploy}" == "null" ]]; then
exit 0
fi

every_boot_actions=$(echo "${deploy}" | jq -c ".\"every\"")
current_boot_actions=$(echo "${deploy}" | jq -c ".\"${current_boot}\"")
current_boot_actions=$(echo "${deploy}" | jq -c "[.[]] | flatten")

# greenboot-rs takes a different approach compared to bash greenboot implementation.
# bash greenboot: when deployment is staged, boot_counter is set immediately,
# when host boots again, the variable is present on 1st boot of new deployment.
# greenboot-rs: boot_counter is set only when the healthchecks fail for the new deployment.
#
# Therefore, test-agent cannot depend on boot_counter anymore to do
# actions on first boot of the new deployment.
# For this reason, the way how the test agent config is interpreted changed:
# the .deployment.number is no longer the "ordinal boot number" (i.e. 1st, 2nd, 3rd boot of the deployment)
# but "how many boots this action should be active".
#
# After collecting actions for the current boot, numbers are decremented, and if reach 0,
# removed from the config.
jq \
--arg key "${current_deployment_id}" \
'.[$key] |= (with_entries(if (.key | test("^[0-9]+$")) then .key |= (tonumber - 1 | tostring) else . end) | with_entries(select(.key != "0")))' \
"${AGENT_CFG}" > "${AGENT_CFG}.tmp" && \
mv "${AGENT_CFG}.tmp" "${AGENT_CFG}"

_run_actions "${every_boot_actions}"
_run_actions "${current_boot_actions}"

# If running under systemd, notify systemd that the service is ready so that
Expand Down
10 changes: 5 additions & 5 deletions test/bin/ci_phase_iso_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ if [ $# -gt 0 ] && [ "$1" = "-update_cache" ] ; then
fi
else
GOT_CACHED_DATA=false
if ${HAS_CACHE_ACCESS} ; then
if download_build_cache ; then
GOT_CACHED_DATA=true
fi
fi
# if ${HAS_CACHE_ACCESS} ; then
# if download_build_cache ; then
# GOT_CACHED_DATA=true
# fi
# fi
if ! ${GOT_CACHED_DATA} ; then
echo "WARNING: Build cache is not available, rebuilding all the artifacts"
fi
Comment on lines +191 to 198
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Default build path now bypasses cache unconditionally.

At Line 191–195, the cache download logic is disabled, so GOT_CACHED_DATA never flips to true. That makes the Line 197 warning effectively unconditional and forces full rebuilds even when cache access exists.

Suggested fix
-    # if ${HAS_CACHE_ACCESS} ; then
-    #     if download_build_cache ; then
-    #         GOT_CACHED_DATA=true
-    #     fi
-    # fi
+    if ${HAS_CACHE_ACCESS} ; then
+        if download_build_cache ; then
+            GOT_CACHED_DATA=true
+        fi
+    fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# if ${HAS_CACHE_ACCESS} ; then
# if download_build_cache ; then
# GOT_CACHED_DATA=true
# fi
# fi
if ! ${GOT_CACHED_DATA} ; then
echo "WARNING: Build cache is not available, rebuilding all the artifacts"
fi
if ${HAS_CACHE_ACCESS} ; then
if download_build_cache ; then
GOT_CACHED_DATA=true
fi
fi
if ! ${GOT_CACHED_DATA} ; then
echo "WARNING: Build cache is not available, rebuilding all the artifacts"
fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/bin/ci_phase_iso_build.sh` around lines 191 - 198, Re-enable the
cache-download conditional so GOT_CACHED_DATA can become true when cache is
available: restore the commented block that checks HAS_CACHE_ACCESS and calls
download_build_cache (setting GOT_CACHED_DATA=true on success), ensure
GOT_CACHED_DATA is initialized (e.g., GOT_CACHED_DATA=false) before use, and
change the test from the brittle "if ! ${GOT_CACHED_DATA}" to a proper shell
test like "if [ \"$GOT_CACHED_DATA\" != true ]" so the warning on
GOT_CACHED_DATA only prints when the download actually failed; relevant symbols:
GOT_CACHED_DATA, HAS_CACHE_ACCESS, download_build_cache.

Expand Down