Skip to content

Commit

Permalink
Fix get_instance_type
Browse files Browse the repository at this point in the history
  • Loading branch information
Issacwww committed Oct 10, 2024
1 parent 52e23af commit 9b265c5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
2 changes: 1 addition & 1 deletion e2e2/test/images/nvidia/gpu_unit_tests/bash_unit
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ skip() {
local message=${1:-}
notify_test_skipped "$__bash_unit_current_test__" "$message"
echo "skipped $message" > $__bash_unit_test_skipped__
exit 1
exit 0
}

_notify_trace() {
Expand Down
14 changes: 2 additions & 12 deletions e2e2/test/images/nvidia/gpu_unit_tests/tests/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,12 @@ get_instance_type()
# Retrieve instance metadata: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html#instance-metadata-retrieval-examples
[ -n "$FORCE_INSTANCE_TYPE" ] && echo $FORCE_INSTANCE_TYPE

local token=$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
local token_exit_code=$?
local token=$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600" 2>/dev/null)

if [ $token_exit_code -eq 0 ]; then
echo "Token retrieved successfully, retrieving instance type using the token..."
if [ -n "$token" ]; then
curl -H "X-aws-ec2-metadata-token: $token" http://169.254.169.254/latest/meta-data/instance-type
local instance_type_exit_code=$?
else
echo "Failed to retrieve instance metadata token. Falling back to direct instance type retrieval."
curl http://169.254.169.254/latest/meta-data/instance-type
local instance_type_exit_code=$?
fi

if [ $instance_type_exit_code -ne 0 ]; then
echo "Failed to retrieve instance type." >&2
return 1
fi
}

Expand Down

0 comments on commit 9b265c5

Please sign in to comment.