Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ab77 committed Apr 30, 2024
1 parent 85cdeec commit 0cf28d0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 47 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -443,14 +443,16 @@ jobs:
with_backoff ssh-uuid -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
${{ steps.register-test-device.outputs.balena_device_uuid }}.balena \
"balena ps -aq | xargs balena inspect \
| jq -re '.[] | select(.Name | contains(\"_supervisor\") | not).Id' \
| jq -re '.[]
| select(.Name | (contains(\"_supervisor\") or contains(\"sut_\") or contains(\"dut_\")) | not).Id' \
| xargs balena restart"
# wait for Docker healthchecks
while with_backoff ssh-uuid -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
${{ steps.register-test-device.outputs.balena_device_uuid }}.balena \
'balena ps -q | xargs balena inspect \
| jq -r ".[] | select(.State.Health.Status!=null).Name + \":\" + .State.Health.Status"' \
| grep -vE '^sut_|^dut_' \
| grep -E ':starting|:unhealthy'; do
echo "::warning::Still working..."
Expand All @@ -460,7 +462,7 @@ jobs:
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock

- name: device tests
- name: SUT&DUT
if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed'}}
timeout-minutes: 20
# https://giters.com/gfx/example-github-actions-with-tty
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ services:
io.balena.features.balena-api: 1
io.balena.features.supervisor-api: 1
restart: no
healthcheck:
test: balena fleet $$TEST_FLEET --json | jq -re .id

# virtual test device
dut:
Expand All @@ -353,6 +355,8 @@ services:
devices:
- /dev/net/tun
restart: no
healthcheck:
test: balena fleet $$TEST_FLEET --json | jq -re .id

# https://hub.docker.com/_/docker
# pseudo(builder) service for balena-tests
Expand Down
2 changes: 1 addition & 1 deletion src/balena-tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUN set -x; arch=$(uname -m | sed 's/86_64/64/g') \

ENV PATH=/opt/balena-cli:${PATH}

COPY docker-hc balena.sh /usr/sbin/
COPY balena.sh /usr/sbin/

WORKDIR /balena

Expand Down
29 changes: 24 additions & 5 deletions src/balena-tests/balena.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ function open_balena_login() {
function create_fleet() {
if ! balena fleet "${TEST_FLEET}"; then
# wait for API to load DT contracts
# (TBC) 'balena devices supported' always returns empty list
# FIXME: 'balena devices supported' always returns empty list
balena devices supported || true

while ! balena fleet create "${TEST_FLEET}" --type "${DEVICE_TYPE}"; do
sleep "$(( (RANDOM % 5) + 5 ))s"
done
Expand Down Expand Up @@ -130,9 +132,25 @@ function configure_virtual_device() {
touch "${GUEST_IMAGE%.*}.ready"
}

function check_device_status() {
if [[ -e /balena/config.json ]]; then
balena_device_uuid="$(cat < /balena/config.json | jq -r .uuid)"

if [[ -n $balena_device_uuid ]]; then
is_online="$(balena devices --json --fleet "${TEST_FLEET}" \
| jq -r --arg uuid "${balena_device_uuid}" '.[] | select(.uuid==$uuid).is_online == true')"

if [[ $is_online =~ true ]]; then
return 0
else
return 1
fi
fi
fi
}

function wait_for_device() {
while ! [[ -e /balena/config.json ]]; do sleep "$(( (RANDOM % 5) + 5 ))s"; done
while ! /usr/sbin/docker-hc; do sleep "$(( (RANDOM % 5) + 5 ))s"; done
while ! check_device_status; do sleep "$(( (RANDOM % 5) + 5 ))s"; done
}

function registry_auth() {
Expand Down Expand Up @@ -211,6 +229,7 @@ function get_os_version() {
}


# --- main
if [[ "$PRODUCTION_MODE" =~ true ]]; then
exit
fi
Expand Down Expand Up @@ -238,13 +257,13 @@ TEST_FLEET=${TEST_FLEET:-test-fleet}
update_ca_certificates
wait_for_api
balena whoami || open_balena_login
registry_auth
create_fleet

# critical section
set_update_lock
create_fleet
download_os_image
configure_virtual_device
registry_auth
deploy_release
remove_update_lock
# .. end
Expand Down
39 changes: 0 additions & 39 deletions src/balena-tests/docker-hc

This file was deleted.

0 comments on commit 0cf28d0

Please sign in to comment.