Skip to content

Commit 594137b

Browse files
authored
fix removal of gpus from base-instance-type agg filter (#22)
* fix removal of gpus from base-instance-type agg filter * add base-instance-type gpu unit test
1 parent 5b6ccee commit 594137b

File tree

4 files changed

+688
-2
lines changed

4 files changed

+688
-2
lines changed

pkg/selector/aggregates.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ func (itf Selector) TransformBaseInstanceType(filters Filters) (Filters, error)
5555
filters.Fpga = &isFpgaSupported
5656
}
5757
if filters.GpusRange == nil {
58+
gpuCount := 0
5859
if instanceTypeInfo.GpuInfo != nil {
59-
gpuCount := int(*getTotalGpusCount(instanceTypeInfo.GpuInfo))
60-
filters.GpusRange = &IntRangeFilter{LowerBound: gpuCount, UpperBound: gpuCount}
60+
gpuCount = int(*getTotalGpusCount(instanceTypeInfo.GpuInfo))
6161
}
62+
filters.GpusRange = &IntRangeFilter{LowerBound: gpuCount, UpperBound: gpuCount}
6263
}
6364
if filters.MemoryRange == nil {
6465
lowerBound := int(float64(*instanceTypeInfo.MemoryInfo.SizeInMiB) * AggregateLowPercentile)

pkg/selector/aggregates_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@ func TestTransformBaseInstanceType(t *testing.T) {
4040
h.Assert(t, *filters.BareMetal == false, " should filter out bare metal instances")
4141
h.Assert(t, *filters.Fpga == false, "should filter out FPGA instances")
4242
h.Assert(t, *filters.CPUArchitecture == "x86_64", "should only return x86_64 instance types")
43+
h.Assert(t, filters.GpusRange.LowerBound == 0 && filters.GpusRange.UpperBound == 0, "should only return non-gpu instance types")
44+
}
45+
46+
func TestTransformBaseInstanceTypeWithGPU(t *testing.T) {
47+
ec2Mock := mockedEC2{
48+
DescribeInstanceTypesResp: setupMock(t, describeInstanceTypes, "g2_2xlarge.json").DescribeInstanceTypesResp,
49+
DescribeInstanceTypesPagesResp: setupMock(t, describeInstanceTypesPages, "g2_2xlarge_group.json").DescribeInstanceTypesPagesResp,
50+
DescribeInstanceTypeOfferingsResp: setupMock(t, describeInstanceTypeOfferings, "us-east-2a.json").DescribeInstanceTypeOfferingsResp,
51+
}
52+
itf := selector.Selector{
53+
EC2: ec2Mock,
54+
}
55+
instanceTypeBase := "g2.2xlarge"
56+
filters := selector.Filters{
57+
InstanceTypeBase: &instanceTypeBase,
58+
}
59+
filters, err := itf.TransformBaseInstanceType(filters)
60+
h.Ok(t, err)
61+
h.Assert(t, *filters.BareMetal == false, " should filter out bare metal instances")
62+
h.Assert(t, *filters.Fpga == false, "should filter out FPGA instances")
63+
h.Assert(t, *filters.CPUArchitecture == "x86_64", "should only return x86_64 instance types")
64+
h.Assert(t, filters.GpusRange.LowerBound == 1 && filters.GpusRange.UpperBound == 1, "should only return gpu instance types")
4365
}
4466

4567
func TestTransformFamilyFlexibile(t *testing.T) {
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"InstanceTypes": [
3+
{
4+
"AutoRecoverySupported": true,
5+
"BareMetal": false,
6+
"BurstablePerformanceSupported": false,
7+
"CurrentGeneration": true,
8+
"DedicatedHostsSupported": true,
9+
"EbsInfo": {
10+
"EbsOptimizedInfo": {
11+
"BaselineBandwidthInMbps": 1000,
12+
"BaselineIops": 8000,
13+
"BaselineThroughputInMBps": 125,
14+
"MaximumBandwidthInMbps": 1000,
15+
"MaximumIops": 8000,
16+
"MaximumThroughputInMBps": 125
17+
},
18+
"EbsOptimizedSupport": "default",
19+
"EncryptionSupport": "supported"
20+
},
21+
"FpgaInfo": null,
22+
"FreeTierEligible": false,
23+
"GpuInfo": null,
24+
"HibernationSupported": true,
25+
"Hypervisor": "xen",
26+
"InferenceAcceleratorInfo": null,
27+
"InstanceStorageInfo": null,
28+
"InstanceStorageSupported": false,
29+
"InstanceType": "c4.2xlarge",
30+
"MemoryInfo": {
31+
"SizeInMiB": 15360
32+
},
33+
"NetworkInfo": {
34+
"EfaSupported": false,
35+
"EnaSupport": "unsupported",
36+
"Ipv4AddressesPerInterface": 15,
37+
"Ipv6AddressesPerInterface": 15,
38+
"Ipv6Supported": true,
39+
"MaximumNetworkInterfaces": 4,
40+
"NetworkPerformance": "High"
41+
},
42+
"PlacementGroupInfo": {
43+
"SupportedStrategies": [
44+
"cluster",
45+
"partition",
46+
"spread"
47+
]
48+
},
49+
"ProcessorInfo": {
50+
"SupportedArchitectures": [
51+
"x86_64"
52+
],
53+
"SustainedClockSpeedInGhz": 2.9
54+
},
55+
"SupportedRootDeviceTypes": [
56+
"ebs"
57+
],
58+
"SupportedUsageClasses": [
59+
"on-demand",
60+
"spot"
61+
],
62+
"SupportedVirtualizationTypes": [
63+
"hvm"
64+
],
65+
"VCpuInfo": {
66+
"DefaultCores": 4,
67+
"DefaultThreadsPerCore": 2,
68+
"DefaultVCpus": 8,
69+
"ValidCores": [
70+
1,
71+
2,
72+
3,
73+
4
74+
],
75+
"ValidThreadsPerCore": [
76+
1,
77+
2
78+
]
79+
}
80+
}
81+
]
82+
}

0 commit comments

Comments
 (0)