Skip to content

Commit

Permalink
fix testflinger test
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiocazzolato committed Mar 28, 2024
1 parent c63905a commit cd61616
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
6 changes: 5 additions & 1 deletion tests/tesflinger/fake_testflinger.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ def mock_result_error():
if count_calls_result < 3:
return jsonify({"job_state":"waiting"})
else:
return jsonify({"job_state":"cancelled"})
return jsonify({"job_state":"cancelled",
"allocate_output":"test_allocate",
"provision_output":"test_provision",
"reserve_output":"test_reserve",
"setup_output":"test_setup"})


# Complete scenario
Expand Down
23 changes: 17 additions & 6 deletions tests/tesflinger/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ environment:
TF_ENDPOINT: http://127.0.0.1:5005
TF_API_VERSION: v1

kill-timeout: 20m

prepare: |
if [ ! -f .spread-reuse.yaml ]; then
touch /run/spread-reuse.yaml
Expand All @@ -21,7 +23,7 @@ restore: |
apt remove -y python3-flask jq
# Clean all the data files generated by the mock
rm *.data mock.log
rm -f *.data mock.log .spread*.log
debug: |
cat /tmp/task.out || true
Expand All @@ -39,11 +41,14 @@ execute: |
kill -9 "$pid"
done
fi
sleep 1
}
# Basic scenario rpi4 with url
start_mock 00000000-0000-0000-0000-000000000001
! spread -reuse -resend testflinger:ubuntu-core-22-rpi4: &> /tmp/task.out
stop_mock
cat /tmp/task.out | grep 'TestFlinger job 00000000-0000-0000-0000-000000000001 created for'
cat /tmp/task.out | grep 'Waiting for TestFlinger ubuntu-core-22-rpi4 to have an address...'
cat /tmp/task.out | grep 'Allocated device with ip 127.0.0.1'
Expand All @@ -52,27 +57,31 @@ execute: |
test "$(jq -r '.action' action_00000000-0000-0000-0000-000000000001.data)" = "cancel"
test "$(jq -r '.provision_data.url' job_00000000-0000-0000-0000-000000000001.data)" = "https://url/pi.img.xz"
test -z "$(jq -r '.provision_data | keys[]' job_00000000-0000-0000-0000-000000000001.data | grep distro)"
stop_mock
# Cancel scenario with distro
start_mock 00000000-0000-0000-0000-000000000002
! spread -reuse -resend testflinger:ubuntu-core-22-64: &> /tmp/task.out
stop_mock
cat /tmp/task.out | grep 'TestFlinger job 00000000-0000-0000-0000-000000000002 created for'
cat /tmp/task.out | grep 'Waiting for TestFlinger ubuntu-core-22-64 to have an address...'
cat /tmp/task.out | grep 'Job state is either cancelled or completed'
cat /tmp/task.out | grep 'result output saved to file .spread-output.000000000002.log'
test "$(jq -r '.job_queue' job_00000000-0000-0000-0000-000000000002.data)" = "x64"
test "$(jq -r '.provision_data.distro' job_00000000-0000-0000-0000-000000000002.data)" = "jammy"
test -z "$(jq -r '.provision_data | keys[]' job_00000000-0000-0000-0000-000000000002.data | grep url)"
! test -f action_00000000-0000-0000-0000-000000000002.data
stop_mock
test -f ".spread-output.000000000002.log"
grep "test_allocate" .spread-output.000000000002.log
# Complete scenario
start_mock 00000000-0000-0000-0000-000000000003
! spread -reuse -resend testflinger:ubuntu-core-22-rpi4: &> /tmp/task.out
stop_mock
cat /tmp/task.out | grep 'TestFlinger job 00000000-0000-0000-0000-000000000003 created for'
cat /tmp/task.out | grep 'Waiting for TestFlinger ubuntu-core-22-rpi4 to have an address...'
cat /tmp/task.out | grep 'Job state is either cancelled or completed'
stop_mock
# Garbage collection scenario
# Job 4: has to be deleted (it is active and halt-timeout exceeded)
Expand All @@ -81,8 +90,10 @@ execute: |
# Job 7: has not to be deleted (it is not active)
start_mock 00000000-0000-0000-0000-000000000004
spread -gc &> /tmp/task.out
stop_mock
cat /tmp/task.out | grep 'Checking 00000000-0000-0000-0000-000000000004'
cat /tmp/task.out | grep 'Job 00000000-0000-0000-0000-000000000004 exceeds halt-timeout. Shutting it down...'
cat /tmp/task.out | grep 'Checking 00000000-0000-0000-0000-000000000005'
test "$(jq -r '.action' action_00000000-0000-0000-0000-000000000004.data)" = "cancel"
stop_mock

0 comments on commit cd61616

Please sign in to comment.