mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-14 01:13:59 -06:00
It was a mistake to switched fully to `==` when activating waiting for capacity on updates in #3947. Users that didn't set `min_elb_capacity == desired_capacity` and instead treated it as an actual "minimum" would see timeouts for every create, since their target numbers would never be reached exactly. Here, we fix that regression by restoring the minimum waiting behavior during creates. In order to preserve all the stated behavior, I had to split out different criteria for create and update, criteria which are now exhaustively unit tested. The set of fields that affect capacity waiting behavior has become a bit of a mess. Next major release I'd like to rework all of these into a more consistently named block of config. For now, just getting the behavior correct and documented. (Also removes all the fixed names from the ASG tests as I was hitting collision issues running them over here.) Fixes #4792
225 lines
5.5 KiB
Go
225 lines
5.5 KiB
Go
package aws
|
|
|
|
import "testing"
|
|
|
|
func TestCapacitySatisfiedCreate(t *testing.T) {
|
|
cases := map[string]struct {
|
|
Data map[string]interface{}
|
|
HaveASG int
|
|
HaveELB int
|
|
ExpectSatisfied bool
|
|
ExpectReason string
|
|
}{
|
|
"min_size, have less": {
|
|
Data: map[string]interface{}{
|
|
"min_size": 5,
|
|
},
|
|
HaveASG: 2,
|
|
ExpectSatisfied: false,
|
|
ExpectReason: "Need at least 5 healthy instances in ASG, have 2",
|
|
},
|
|
"min_size, got it": {
|
|
Data: map[string]interface{}{
|
|
"min_size": 5,
|
|
},
|
|
HaveASG: 5,
|
|
ExpectSatisfied: true,
|
|
},
|
|
"min_size, have more": {
|
|
Data: map[string]interface{}{
|
|
"min_size": 5,
|
|
},
|
|
HaveASG: 10,
|
|
ExpectSatisfied: true,
|
|
},
|
|
"desired_capacity, have less": {
|
|
Data: map[string]interface{}{
|
|
"desired_capacity": 5,
|
|
},
|
|
HaveASG: 2,
|
|
ExpectSatisfied: false,
|
|
ExpectReason: "Need at least 5 healthy instances in ASG, have 2",
|
|
},
|
|
"desired_capacity overrides min_size": {
|
|
Data: map[string]interface{}{
|
|
"min_size": 2,
|
|
"desired_capacity": 5,
|
|
},
|
|
HaveASG: 2,
|
|
ExpectSatisfied: false,
|
|
ExpectReason: "Need at least 5 healthy instances in ASG, have 2",
|
|
},
|
|
"desired_capacity, got it": {
|
|
Data: map[string]interface{}{
|
|
"desired_capacity": 5,
|
|
},
|
|
HaveASG: 5,
|
|
ExpectSatisfied: true,
|
|
},
|
|
"desired_capacity, have more": {
|
|
Data: map[string]interface{}{
|
|
"desired_capacity": 5,
|
|
},
|
|
HaveASG: 10,
|
|
ExpectSatisfied: true,
|
|
},
|
|
|
|
"min_elb_capacity, have less": {
|
|
Data: map[string]interface{}{
|
|
"min_elb_capacity": 5,
|
|
},
|
|
HaveELB: 2,
|
|
ExpectSatisfied: false,
|
|
ExpectReason: "Need at least 5 healthy instances in ELB, have 2",
|
|
},
|
|
"min_elb_capacity, got it": {
|
|
Data: map[string]interface{}{
|
|
"min_elb_capacity": 5,
|
|
},
|
|
HaveELB: 5,
|
|
ExpectSatisfied: true,
|
|
},
|
|
"min_elb_capacity, have more": {
|
|
Data: map[string]interface{}{
|
|
"min_elb_capacity": 5,
|
|
},
|
|
HaveELB: 10,
|
|
ExpectSatisfied: true,
|
|
},
|
|
"wait_for_elb_capacity, have less": {
|
|
Data: map[string]interface{}{
|
|
"wait_for_elb_capacity": 5,
|
|
},
|
|
HaveELB: 2,
|
|
ExpectSatisfied: false,
|
|
ExpectReason: "Need at least 5 healthy instances in ELB, have 2",
|
|
},
|
|
"wait_for_elb_capacity, got it": {
|
|
Data: map[string]interface{}{
|
|
"wait_for_elb_capacity": 5,
|
|
},
|
|
HaveELB: 5,
|
|
ExpectSatisfied: true,
|
|
},
|
|
"wait_for_elb_capacity, have more": {
|
|
Data: map[string]interface{}{
|
|
"wait_for_elb_capacity": 5,
|
|
},
|
|
HaveELB: 10,
|
|
ExpectSatisfied: true,
|
|
},
|
|
"wait_for_elb_capacity overrides min_elb_capacity": {
|
|
Data: map[string]interface{}{
|
|
"min_elb_capacity": 2,
|
|
"wait_for_elb_capacity": 5,
|
|
},
|
|
HaveELB: 2,
|
|
ExpectSatisfied: false,
|
|
ExpectReason: "Need at least 5 healthy instances in ELB, have 2",
|
|
},
|
|
}
|
|
|
|
r := resourceAwsAutoscalingGroup()
|
|
for tn, tc := range cases {
|
|
d := r.TestResourceData()
|
|
for k, v := range tc.Data {
|
|
if err := d.Set(k, v); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
}
|
|
gotSatisfied, gotReason := capacitySatifiedCreate(d, tc.HaveASG, tc.HaveELB)
|
|
|
|
if gotSatisfied != tc.ExpectSatisfied {
|
|
t.Fatalf("%s: expected satisfied: %t, got: %t (reason: %s)",
|
|
tn, tc.ExpectSatisfied, gotSatisfied, gotReason)
|
|
}
|
|
|
|
if gotReason != tc.ExpectReason {
|
|
t.Fatalf("%s: expected reason: %s, got: %s",
|
|
tn, tc.ExpectReason, gotReason)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestCapacitySatisfiedUpdate(t *testing.T) {
|
|
cases := map[string]struct {
|
|
Data map[string]interface{}
|
|
HaveASG int
|
|
HaveELB int
|
|
ExpectSatisfied bool
|
|
ExpectReason string
|
|
}{
|
|
"default is satisfied": {
|
|
Data: map[string]interface{}{},
|
|
ExpectSatisfied: true,
|
|
},
|
|
"desired_capacity, have less": {
|
|
Data: map[string]interface{}{
|
|
"desired_capacity": 5,
|
|
},
|
|
HaveASG: 2,
|
|
ExpectSatisfied: false,
|
|
ExpectReason: "Need exactly 5 healthy instances in ASG, have 2",
|
|
},
|
|
"desired_capacity, got it": {
|
|
Data: map[string]interface{}{
|
|
"desired_capacity": 5,
|
|
},
|
|
HaveASG: 5,
|
|
ExpectSatisfied: true,
|
|
},
|
|
"desired_capacity, have more": {
|
|
Data: map[string]interface{}{
|
|
"desired_capacity": 5,
|
|
},
|
|
HaveASG: 10,
|
|
ExpectSatisfied: false,
|
|
ExpectReason: "Need exactly 5 healthy instances in ASG, have 10",
|
|
},
|
|
"wait_for_elb_capacity, have less": {
|
|
Data: map[string]interface{}{
|
|
"wait_for_elb_capacity": 5,
|
|
},
|
|
HaveELB: 2,
|
|
ExpectSatisfied: false,
|
|
ExpectReason: "Need exactly 5 healthy instances in ELB, have 2",
|
|
},
|
|
"wait_for_elb_capacity, got it": {
|
|
Data: map[string]interface{}{
|
|
"wait_for_elb_capacity": 5,
|
|
},
|
|
HaveELB: 5,
|
|
ExpectSatisfied: true,
|
|
},
|
|
"wait_for_elb_capacity, have more": {
|
|
Data: map[string]interface{}{
|
|
"wait_for_elb_capacity": 5,
|
|
},
|
|
HaveELB: 10,
|
|
ExpectSatisfied: false,
|
|
ExpectReason: "Need exactly 5 healthy instances in ELB, have 10",
|
|
},
|
|
}
|
|
|
|
r := resourceAwsAutoscalingGroup()
|
|
for tn, tc := range cases {
|
|
d := r.TestResourceData()
|
|
for k, v := range tc.Data {
|
|
if err := d.Set(k, v); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
}
|
|
gotSatisfied, gotReason := capacitySatifiedUpdate(d, tc.HaveASG, tc.HaveELB)
|
|
|
|
if gotSatisfied != tc.ExpectSatisfied {
|
|
t.Fatalf("%s: expected satisfied: %t, got: %t (reason: %s)",
|
|
tn, tc.ExpectSatisfied, gotSatisfied, gotReason)
|
|
}
|
|
|
|
if gotReason != tc.ExpectReason {
|
|
t.Fatalf("%s: expected reason: %s, got: %s",
|
|
tn, tc.ExpectReason, gotReason)
|
|
}
|
|
}
|
|
}
|