From 9171aae39f0af9f31dfa319923b910fd839cb319 Mon Sep 17 00:00:00 2001 From: melanie witt Date: Tue, 8 Feb 2022 23:24:26 +0000 Subject: [PATCH] Make perfload jobs fail if write allocation fails This uses curl -f when writing an allocation in order to detect when the server has responded with a HTTP error code and then fails the job if so. The idea behind this is to catch when PUT /allocations/{consumer_uuid} required parameters change and the perfload jobs need to be updated. The curl -S option is also added to show the error if curl fails. Change-Id: Ic06e64b1031ff37d7ada55449ae71cd39b1298a2 --- gate/perfload-nested-runner.sh | 13 ++++++++++++- gate/perfload-runner.sh | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/gate/perfload-nested-runner.sh b/gate/perfload-nested-runner.sh index 869116b12..03f318876 100755 --- a/gate/perfload-nested-runner.sh +++ b/gate/perfload-nested-runner.sh @@ -55,8 +55,19 @@ function write_allocation { # Take the first allocation request and send it back as a well-formed allocation curl -s -H 'x-auth-token: admin' -H 'openstack-api-version: placement latest' "${PLACEMENT_URL}/allocation_candidates?${PLACEMENT_QUERY}&limit=5" \ | jq --arg proj $(uuidgen) --arg user $(uuidgen) '.allocation_requests[0] + {consumer_generation: null, project_id: $proj, user_id: $user, consumer_type: "TEST"}' \ - | curl -s -H 'x-auth-token: admin' -H 'content-type: application/json' -H 'openstack-api-version: placement latest' \ + | curl -f -s -S -H 'x-auth-token: admin' -H 'content-type: application/json' -H 'openstack-api-version: placement latest' \ -X PUT -d @- "${PLACEMENT_URL}/allocations/$(uuidgen)" + # curl -f will fail silently on server errors and return code 22 + # When used with -s, --silent, -S makes curl show an error message if it fails + # If we failed to write an allocation, skip measurements and log a message + rc=$? + if [[ $rc -eq 22 ]]; then + echo "Failed to write allocation due to a server error. See logs/placement-api.log for additional detail." + exit 1 + elif [[ $rc -ne 0 ]]; then + echo "Failed to write allocation, curl returned code: $rc. See job-output.txt for additional detail." + exit 1 + fi } function load_candidates { diff --git a/gate/perfload-runner.sh b/gate/perfload-runner.sh index 33737c38b..9529f6635 100755 --- a/gate/perfload-runner.sh +++ b/gate/perfload-runner.sh @@ -69,8 +69,19 @@ function write_allocation { # Take the first allocation request and send it back as a well-formed allocation curl -s -H 'x-auth-token: admin' -H 'openstack-api-version: placement latest' "${PLACEMENT_URL}/allocation_candidates?${PLACEMENT_QUERY}&limit=5" \ | jq --arg proj $(uuidgen) --arg user $(uuidgen) '.allocation_requests[0] + {consumer_generation: null, project_id: $proj, user_id: $user, consumer_type: "TEST"}' \ - | curl -s -H 'x-auth-token: admin' -H 'content-type: application/json' -H 'openstack-api-version: placement latest' \ + | curl -f -s -S -H 'x-auth-token: admin' -H 'content-type: application/json' -H 'openstack-api-version: placement latest' \ -X PUT -d @- "${PLACEMENT_URL}/allocations/$(uuidgen)" + rc=$? + # curl -f will fail silently on server errors and return code 22 + # When used with -s, --silent, -S makes curl show an error message if it fails + # If we failed to write an allocation, skip measurements and log a message + if [[ $rc -eq 22 ]]; then + echo "Failed to write allocation due to a server error. See logs/placement-api.log for additional detail." + exit 1 + elif [[ $rc -ne 0 ]]; then + echo "Failed to write allocation, curl returned code: $rc. See job-output.txt for additional detail." + exit 1 + fi } function load_candidates {