Skip to content

Commit

Permalink
Fix AWS CA tests for InstanceType generation changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gjtempleton committed Jul 21, 2020
1 parent c10b201 commit 090e8aa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ func testProvider(t *testing.T, m *AwsManager) *awsCloudProvider {
map[string]int64{cloudprovider.ResourceNameCores: 1, cloudprovider.ResourceNameMemory: 10000000},
map[string]int64{cloudprovider.ResourceNameCores: 10, cloudprovider.ResourceNameMemory: 100000000})

instanceTypes, _ := GetStaticEC2InstanceTypes()
provider, err := BuildAwsCloudProvider(m, instanceTypes, resourceLimiter)
provider, err := BuildAwsCloudProvider(m, resourceLimiter)
assert.NoError(t, err)
return provider.(*awsCloudProvider)
}
Expand All @@ -145,8 +144,7 @@ func TestBuildAwsCloudProvider(t *testing.T) {
map[string]int64{cloudprovider.ResourceNameCores: 1, cloudprovider.ResourceNameMemory: 10000000},
map[string]int64{cloudprovider.ResourceNameCores: 10, cloudprovider.ResourceNameMemory: 100000000})

instanceTypes, _ := GetStaticEC2InstanceTypes()
_, err := BuildAwsCloudProvider(testAwsManager, instanceTypes, resourceLimiter)
_, err := BuildAwsCloudProvider(testAwsManager, resourceLimiter)
assert.NoError(t, err)
}

Expand Down
29 changes: 17 additions & 12 deletions cluster-autoscaler/cloudprovider/aws/aws_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ func TestFetchExplicitAsgs(t *testing.T) {
// #1449 Without AWS_REGION getRegion() lookup runs till timeout during tests.
defer resetAWSRegion(os.LookupEnv("AWS_REGION"))
os.Setenv("AWS_REGION", "fanghorn")
// fetchExplicitASGs is called at manager creation time.
m, err := createAWSManagerInternal(nil, do, &autoScalingWrapper{s, newLaunchConfigurationInstanceTypeCache()}, nil)
instanceTypes, _ := GetStaticEC2InstanceTypes()
m, err := createAWSManagerInternal(nil, do, &autoScalingWrapper{s, newLaunchConfigurationInstanceTypeCache()}, nil, instanceTypes)
assert.NoError(t, err)

asgs := m.asgCache.Get()
Expand Down Expand Up @@ -332,7 +332,8 @@ func TestBuildInstanceType(t *testing.T) {
// #1449 Without AWS_REGION getRegion() lookup runs till timeout during tests.
defer resetAWSRegion(os.LookupEnv("AWS_REGION"))
os.Setenv("AWS_REGION", "fanghorn")
m, err := createAWSManagerInternal(nil, cloudprovider.NodeGroupDiscoveryOptions{}, nil, &ec2Wrapper{s})
instanceTypes, _ := GetStaticEC2InstanceTypes()
m, err := createAWSManagerInternal(nil, cloudprovider.NodeGroupDiscoveryOptions{}, nil, &ec2Wrapper{s}, instanceTypes)
assert.NoError(t, err)

asg := asg{
Expand All @@ -347,7 +348,7 @@ func TestBuildInstanceType(t *testing.T) {

func TestBuildInstanceTypeMixedInstancePolicyOverride(t *testing.T) {
ltName, ltVersion, instanceType := "launcher", "1", "t2.large"
instanceTypes := []string{}
instanceTypeOverrides := []string{}

s := &EC2Mock{}
s.On("DescribeLaunchTemplateVersions", &ec2.DescribeLaunchTemplateVersionsInput{
Expand All @@ -365,14 +366,15 @@ func TestBuildInstanceTypeMixedInstancePolicyOverride(t *testing.T) {

defer resetAWSRegion(os.LookupEnv("AWS_REGION"))
os.Setenv("AWS_REGION", "fanghorn")
m, err := createAWSManagerInternal(nil, cloudprovider.NodeGroupDiscoveryOptions{}, nil, &ec2Wrapper{s})
instanceTypes, _ := GetStaticEC2InstanceTypes()
m, err := createAWSManagerInternal(nil, cloudprovider.NodeGroupDiscoveryOptions{}, nil, &ec2Wrapper{s}, instanceTypes)
assert.NoError(t, err)

lt := &launchTemplate{name: ltName, version: ltVersion}
asg := asg{
MixedInstancesPolicy: &mixedInstancesPolicy{
launchTemplate: lt,
instanceTypesOverrides: instanceTypes,
instanceTypesOverrides: instanceTypeOverrides,
},
}

Expand All @@ -384,25 +386,26 @@ func TestBuildInstanceTypeMixedInstancePolicyOverride(t *testing.T) {

func TestBuildInstanceTypeMixedInstancePolicyNoOverride(t *testing.T) {
ltName, ltVersion := "launcher", "1"
instanceTypes := []string{"m4.xlarge", "m5.xlarge"}
instanceTypeOverrides := []string{"m4.xlarge", "m5.xlarge"}

defer resetAWSRegion(os.LookupEnv("AWS_REGION"))
os.Setenv("AWS_REGION", "fanghorn")
m, err := createAWSManagerInternal(nil, cloudprovider.NodeGroupDiscoveryOptions{}, nil, &ec2Wrapper{})
instanceTypes, _ := GetStaticEC2InstanceTypes()
m, err := createAWSManagerInternal(nil, cloudprovider.NodeGroupDiscoveryOptions{}, nil, &ec2Wrapper{}, instanceTypes)
assert.NoError(t, err)

lt := &launchTemplate{name: ltName, version: ltVersion}
asg := asg{
MixedInstancesPolicy: &mixedInstancesPolicy{
launchTemplate: lt,
instanceTypesOverrides: instanceTypes,
instanceTypesOverrides: instanceTypeOverrides,
},
}

builtInstanceType, err := m.buildInstanceType(&asg)

assert.NoError(t, err)
assert.Equal(t, instanceTypes[0], builtInstanceType)
assert.Equal(t, instanceTypeOverrides[0], builtInstanceType)
}

func TestGetASGTemplate(t *testing.T) {
Expand Down Expand Up @@ -456,7 +459,8 @@ func TestGetASGTemplate(t *testing.T) {
// #1449 Without AWS_REGION getRegion() lookup runs till timeout during tests.
defer resetAWSRegion(os.LookupEnv("AWS_REGION"))
os.Setenv("AWS_REGION", "fanghorn")
m, err := createAWSManagerInternal(nil, cloudprovider.NodeGroupDiscoveryOptions{}, nil, &ec2Wrapper{s})
instanceTypes, _ := GetStaticEC2InstanceTypes()
m, err := createAWSManagerInternal(nil, cloudprovider.NodeGroupDiscoveryOptions{}, nil, &ec2Wrapper{s}, instanceTypes)
assert.NoError(t, err)

asg := &asg{
Expand Down Expand Up @@ -538,7 +542,8 @@ func TestFetchAutoAsgs(t *testing.T) {
defer resetAWSRegion(os.LookupEnv("AWS_REGION"))
os.Setenv("AWS_REGION", "fanghorn")
// fetchAutoASGs is called at manager creation time, via forceRefresh
m, err := createAWSManagerInternal(nil, do, &autoScalingWrapper{s, newLaunchConfigurationInstanceTypeCache()}, nil)
instanceTypes, _ := GetStaticEC2InstanceTypes()
m, err := createAWSManagerInternal(nil, do, &autoScalingWrapper{s, newLaunchConfigurationInstanceTypeCache()}, nil, instanceTypes)
assert.NoError(t, err)

asgs := m.asgCache.Get()
Expand Down

0 comments on commit 090e8aa

Please sign in to comment.