Skip to content

Commit

Permalink
fix removal of gpus from base-instance-type agg filter (#22)
Browse files Browse the repository at this point in the history
* fix removal of gpus from base-instance-type agg filter

* add base-instance-type gpu unit test
  • Loading branch information
bwagner5 authored Jul 8, 2020
1 parent 5b6ccee commit 594137b
Show file tree
Hide file tree
Showing 4 changed files with 688 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/selector/aggregates.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ func (itf Selector) TransformBaseInstanceType(filters Filters) (Filters, error)
filters.Fpga = &isFpgaSupported
}
if filters.GpusRange == nil {
gpuCount := 0
if instanceTypeInfo.GpuInfo != nil {
gpuCount := int(*getTotalGpusCount(instanceTypeInfo.GpuInfo))
filters.GpusRange = &IntRangeFilter{LowerBound: gpuCount, UpperBound: gpuCount}
gpuCount = int(*getTotalGpusCount(instanceTypeInfo.GpuInfo))
}
filters.GpusRange = &IntRangeFilter{LowerBound: gpuCount, UpperBound: gpuCount}
}
if filters.MemoryRange == nil {
lowerBound := int(float64(*instanceTypeInfo.MemoryInfo.SizeInMiB) * AggregateLowPercentile)
Expand Down
22 changes: 22 additions & 0 deletions pkg/selector/aggregates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ func TestTransformBaseInstanceType(t *testing.T) {
h.Assert(t, *filters.BareMetal == false, " should filter out bare metal instances")
h.Assert(t, *filters.Fpga == false, "should filter out FPGA instances")
h.Assert(t, *filters.CPUArchitecture == "x86_64", "should only return x86_64 instance types")
h.Assert(t, filters.GpusRange.LowerBound == 0 && filters.GpusRange.UpperBound == 0, "should only return non-gpu instance types")
}

func TestTransformBaseInstanceTypeWithGPU(t *testing.T) {
ec2Mock := mockedEC2{
DescribeInstanceTypesResp: setupMock(t, describeInstanceTypes, "g2_2xlarge.json").DescribeInstanceTypesResp,
DescribeInstanceTypesPagesResp: setupMock(t, describeInstanceTypesPages, "g2_2xlarge_group.json").DescribeInstanceTypesPagesResp,
DescribeInstanceTypeOfferingsResp: setupMock(t, describeInstanceTypeOfferings, "us-east-2a.json").DescribeInstanceTypeOfferingsResp,
}
itf := selector.Selector{
EC2: ec2Mock,
}
instanceTypeBase := "g2.2xlarge"
filters := selector.Filters{
InstanceTypeBase: &instanceTypeBase,
}
filters, err := itf.TransformBaseInstanceType(filters)
h.Ok(t, err)
h.Assert(t, *filters.BareMetal == false, " should filter out bare metal instances")
h.Assert(t, *filters.Fpga == false, "should filter out FPGA instances")
h.Assert(t, *filters.CPUArchitecture == "x86_64", "should only return x86_64 instance types")
h.Assert(t, filters.GpusRange.LowerBound == 1 && filters.GpusRange.UpperBound == 1, "should only return gpu instance types")
}

func TestTransformFamilyFlexibile(t *testing.T) {
Expand Down
82 changes: 82 additions & 0 deletions test/static/DescribeInstanceTypes/c4_2xlarge.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"InstanceTypes": [
{
"AutoRecoverySupported": true,
"BareMetal": false,
"BurstablePerformanceSupported": false,
"CurrentGeneration": true,
"DedicatedHostsSupported": true,
"EbsInfo": {
"EbsOptimizedInfo": {
"BaselineBandwidthInMbps": 1000,
"BaselineIops": 8000,
"BaselineThroughputInMBps": 125,
"MaximumBandwidthInMbps": 1000,
"MaximumIops": 8000,
"MaximumThroughputInMBps": 125
},
"EbsOptimizedSupport": "default",
"EncryptionSupport": "supported"
},
"FpgaInfo": null,
"FreeTierEligible": false,
"GpuInfo": null,
"HibernationSupported": true,
"Hypervisor": "xen",
"InferenceAcceleratorInfo": null,
"InstanceStorageInfo": null,
"InstanceStorageSupported": false,
"InstanceType": "c4.2xlarge",
"MemoryInfo": {
"SizeInMiB": 15360
},
"NetworkInfo": {
"EfaSupported": false,
"EnaSupport": "unsupported",
"Ipv4AddressesPerInterface": 15,
"Ipv6AddressesPerInterface": 15,
"Ipv6Supported": true,
"MaximumNetworkInterfaces": 4,
"NetworkPerformance": "High"
},
"PlacementGroupInfo": {
"SupportedStrategies": [
"cluster",
"partition",
"spread"
]
},
"ProcessorInfo": {
"SupportedArchitectures": [
"x86_64"
],
"SustainedClockSpeedInGhz": 2.9
},
"SupportedRootDeviceTypes": [
"ebs"
],
"SupportedUsageClasses": [
"on-demand",
"spot"
],
"SupportedVirtualizationTypes": [
"hvm"
],
"VCpuInfo": {
"DefaultCores": 4,
"DefaultThreadsPerCore": 2,
"DefaultVCpus": 8,
"ValidCores": [
1,
2,
3,
4
],
"ValidThreadsPerCore": [
1,
2
]
}
}
]
}
Loading

0 comments on commit 594137b

Please sign in to comment.