Skip to content

Commit c5c2770

Browse files
committed
tests/ai-conformance: work with zones
1 parent a6e7a80 commit c5c2770

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

tests/e2e/scenarios/ai-conformance/run-test.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@ export CLOUD_PROVIDER=aws
3636
export AWS_REGION="${AWS_REGION:-us-east-2}"
3737
SCENARIO_ROOT="${REPO_ROOT}/tests/e2e/scenarios/ai-conformance"
3838

39+
3940
# Check for g6.xlarge availability in the region
4041
echo "Checking availability of g6.xlarge in ${AWS_REGION}..."
4142
(cd "${SCENARIO_ROOT}/tools/check-aws-availability" && go build -o check-aws-availability main.go)
42-
AVAILABILITY=$("${SCENARIO_ROOT}/tools/check-aws-availability/check-aws-availability" -region "${AWS_REGION}" -instance-type g6.xlarge)
43-
if [[ "${AVAILABILITY}" == "false" ]]; then
44-
echo "Error: g6.xlarge instances are not available in ${AWS_REGION}. Please choose a region with L4 GPU support."
45-
exit 1
46-
fi
43+
# Run and source the output to get the ZONES variable
44+
source <("${SCENARIO_ROOT}/tools/check-aws-availability/check-aws-availability" -region "${AWS_REGION}" -instance-type g6.xlarge)
45+
46+
echo "ZONES=${ZONES}"
47+
export ZONES
48+
4749
rm -f "${SCENARIO_ROOT}/tools/check-aws-availability/check-aws-availability"
4850

4951
kops-acquire-latest

tests/e2e/scenarios/ai-conformance/tools/check-aws-availability/main.go

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"flag"
2222
"fmt"
2323
"os"
24+
"strings"
2425

2526
"github.com/aws/aws-sdk-go-v2/aws"
2627
"github.com/aws/aws-sdk-go-v2/config"
@@ -29,6 +30,14 @@ import (
2930
)
3031

3132
func main() {
33+
ctx := context.Background()
34+
if err := run(ctx); err != nil {
35+
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
36+
os.Exit(1)
37+
}
38+
}
39+
40+
func run(ctx context.Context) error {
3241
var region string
3342
var instanceType string
3443

@@ -37,15 +46,12 @@ func main() {
3746
flag.Parse()
3847

3948
if region == "" || instanceType == "" {
40-
fmt.Println("Usage: check-aws-availability -region <region> -instance-type <type>")
41-
os.Exit(1)
49+
return fmt.Errorf("Usage: check-aws-availability -region <region> -instance-type <type>")
4250
}
4351

44-
ctx := context.TODO()
4552
cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion(region))
4653
if err != nil {
47-
fmt.Printf("Error loading configuration: %v\n", err)
48-
os.Exit(1)
54+
return fmt.Errorf("Error loading configuration: %w", err)
4955
}
5056

5157
client := ec2.NewFromConfig(cfg)
@@ -62,13 +68,21 @@ func main() {
6268

6369
result, err := client.DescribeInstanceTypeOfferings(ctx, input)
6470
if err != nil {
65-
fmt.Printf("Error describing instance type offerings: %v\n", err)
66-
os.Exit(1)
71+
return fmt.Errorf("Error describing instance type offerings: %w", err)
6772
}
6873

69-
if len(result.InstanceTypeOfferings) > 0 {
70-
fmt.Println("true")
71-
} else {
72-
fmt.Println("false")
74+
var zones []string
75+
76+
// Gather the availability zones where the instance type is offered
77+
for _, offering := range result.InstanceTypeOfferings {
78+
zone := aws.ToString(offering.Location)
79+
zones = append(zones, zone)
7380
}
81+
82+
if len(zones) == 0 {
83+
return fmt.Errorf("Instance type %s is not available in any availability zones in region %s", instanceType, region)
84+
}
85+
86+
fmt.Fprintf(os.Stdout, "ZONES=%s\n", strings.Join(zones, ","))
87+
return nil
7488
}

0 commit comments

Comments
 (0)