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
This commit is contained in:
melanie witt 2022-02-08 23:24:26 +00:00
parent a57215e8b6
commit 9171aae39f
2 changed files with 24 additions and 2 deletions

View File

@ -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 {

View File

@ -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 {