mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(autoscaling): warm pools, scheduled actions, traffic sources, and process suspension (#2973)
* feat(autoscaling): warm pools, scheduled actions, traffic sources, and process suspension PutWarmPool/DescribeWarmPool/DeleteWarmPool, PutScheduledUpdateGroupAction/ DescribeScheduledActions/DeleteScheduledAction, AttachTrafficSources/ DetachTrafficSources/DescribeTrafficSources, and SuspendProcesses/ ResumeProcesses, parsed against botocore's autoscaling/2011-01-01 wire model. Deleting a group also removes its scheduled actions and warm pool. * fix(autoscaling): scope scheduled-action cleanup to the group's region Deleting a group removed scheduled actions with the same group name in every region. PutScheduledUpdateGroupAction now rejects a malformed StartTime or EndTime with ValidationError instead of treating it as absent.
This commit is contained in:
1 parent
84ec8ae8e7
commit
09801146b1
8 files changed
+939
-5
No files matched your search
+260
-4
@@ -777,8 +777,264 @@ class AutoScalingIntegrationTest {
|
||||
assertThat(overrides, not(containsString("<InstanceType>t4g.medium</InstanceType>")));
|
||||
}
|
||||
|
||||
// The AWS provider calls SuspendProcesses/ResumeProcesses unconditionally around ASG
|
||||
// creation whenever wait_for_capacity_timeout is non-zero (the default), so an
|
||||
// unimplemented SuspendProcesses fails ASG creation outright - found crossing
|
||||
// terraform-aws-modules/terraform-aws-eks against floci.
|
||||
@Test
|
||||
@Order(31)
|
||||
void suspendProcesses() {
|
||||
given()
|
||||
.formParam("Action", "SuspendProcesses")
|
||||
.formParam("AutoScalingGroupName", "my-asg")
|
||||
.formParam("ScalingProcesses.member.1", "Launch")
|
||||
.formParam("ScalingProcesses.member.2", "Terminate")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("SuspendProcessesResponse"));
|
||||
|
||||
given()
|
||||
.formParam("Action", "DescribeAutoScalingGroups")
|
||||
.formParam("AutoScalingGroupNames.member.1", "my-asg")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<SuspendedProcesses>"))
|
||||
.body(containsString("<ProcessName>Launch</ProcessName>"))
|
||||
.body(containsString("<ProcessName>Terminate</ProcessName>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(32)
|
||||
void resumeProcesses() {
|
||||
given()
|
||||
.formParam("Action", "ResumeProcesses")
|
||||
.formParam("AutoScalingGroupName", "my-asg")
|
||||
.formParam("ScalingProcesses.member.1", "Launch")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("ResumeProcessesResponse"));
|
||||
|
||||
given()
|
||||
.formParam("Action", "DescribeAutoScalingGroups")
|
||||
.formParam("AutoScalingGroupNames.member.1", "my-asg")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(not(containsString("<ProcessName>Launch</ProcessName>")))
|
||||
.body(containsString("<ProcessName>Terminate</ProcessName>"));
|
||||
}
|
||||
|
||||
// AttachTrafficSources/DetachTrafficSources/DescribeTrafficSources - the modern,
|
||||
// unified elbv2/vpc-lattice ASG-to-load-balancer wiring API that
|
||||
// aws_autoscaling_traffic_source_attachment uses instead of the older
|
||||
// AttachLoadBalancerTargetGroups above. Found crossing
|
||||
// terraform-aws-modules/terraform-aws-autoscaling's "complete" example against
|
||||
// floci (its traffic_source_attachments block wires an ALB target group this way).
|
||||
@Test
|
||||
@Order(33)
|
||||
void attachDescribeAndDetachTrafficSources() {
|
||||
given()
|
||||
.formParam("Action", "AttachTrafficSources")
|
||||
.formParam("AutoScalingGroupName", "my-asg")
|
||||
.formParam("TrafficSources.member.1.Identifier",
|
||||
"arn:aws:elasticloadbalancing:us-east-1:000000000000:targetgroup/ex-asg/abc123")
|
||||
.formParam("TrafficSources.member.1.Type", "elbv2")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("AttachTrafficSourcesResponse"));
|
||||
|
||||
given()
|
||||
.formParam("Action", "DescribeTrafficSources")
|
||||
.formParam("AutoScalingGroupName", "my-asg")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<Identifier>arn:aws:elasticloadbalancing:us-east-1:000000000000:targetgroup/ex-asg/abc123</Identifier>"))
|
||||
.body(containsString("<Type>elbv2</Type>"))
|
||||
.body(containsString("<State>InService</State>"));
|
||||
|
||||
given()
|
||||
.formParam("Action", "DetachTrafficSources")
|
||||
.formParam("AutoScalingGroupName", "my-asg")
|
||||
.formParam("TrafficSources.member.1.Identifier",
|
||||
"arn:aws:elasticloadbalancing:us-east-1:000000000000:targetgroup/ex-asg/abc123")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("DetachTrafficSourcesResponse"));
|
||||
|
||||
given()
|
||||
.formParam("Action", "DescribeTrafficSources")
|
||||
.formParam("AutoScalingGroupName", "my-asg")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(not(containsString("<Identifier>")));
|
||||
}
|
||||
|
||||
// PutScheduledUpdateGroupAction/DescribeScheduledActions/DeleteScheduledAction -
|
||||
// aws_autoscaling_schedule's whole lifecycle. Found crossing
|
||||
// terraform-aws-modules/terraform-aws-autoscaling's "complete" example.
|
||||
@Test
|
||||
@Order(41)
|
||||
void putScheduledActionRejectsMalformedStartTime() {
|
||||
given()
|
||||
.formParam("Action", "PutScheduledUpdateGroupAction")
|
||||
.formParam("AutoScalingGroupName", "my-asg")
|
||||
.formParam("ScheduledActionName", "bad-start")
|
||||
.formParam("StartTime", "not-a-timestamp")
|
||||
.formParam("DesiredCapacity", "1")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("<Code>ValidationError</Code>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(34)
|
||||
void putDescribeAndDeleteScheduledAction() {
|
||||
given()
|
||||
.formParam("Action", "PutScheduledUpdateGroupAction")
|
||||
.formParam("AutoScalingGroupName", "my-asg")
|
||||
.formParam("ScheduledActionName", "morning")
|
||||
.formParam("Recurrence", "0 7 * * 1-5")
|
||||
.formParam("MinSize", "0")
|
||||
.formParam("MaxSize", "1")
|
||||
.formParam("DesiredCapacity", "1")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("PutScheduledUpdateGroupActionResponse"));
|
||||
|
||||
given()
|
||||
.formParam("Action", "DescribeScheduledActions")
|
||||
.formParam("AutoScalingGroupName", "my-asg")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<ScheduledActionName>morning</ScheduledActionName>"))
|
||||
.body(containsString("<Recurrence>0 7 * * 1-5</Recurrence>"))
|
||||
.body(containsString("<MinSize>0</MinSize>"))
|
||||
.body(containsString("<MaxSize>1</MaxSize>"))
|
||||
.body(containsString("<DesiredCapacity>1</DesiredCapacity>"));
|
||||
|
||||
given()
|
||||
.formParam("Action", "DeleteScheduledAction")
|
||||
.formParam("AutoScalingGroupName", "my-asg")
|
||||
.formParam("ScheduledActionName", "morning")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("DeleteScheduledActionResponse"));
|
||||
|
||||
given()
|
||||
.formParam("Action", "DescribeScheduledActions")
|
||||
.formParam("AutoScalingGroupName", "my-asg")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(not(containsString("<ScheduledActionName>")));
|
||||
}
|
||||
|
||||
// PutWarmPool/DescribeWarmPool/DeleteWarmPool - aws_autoscaling_group's warm_pool
|
||||
// block. Botocore's AutoScalingGroup shape documents WarmPoolConfiguration as a
|
||||
// member of DescribeAutoScalingGroups' own response too, not just the separate
|
||||
// DescribeWarmPool action - terraform-aws-autoscaling's warm_pool example reads
|
||||
// it that way, so both paths are asserted here.
|
||||
@Test
|
||||
@Order(35)
|
||||
void putDescribeAndDeleteWarmPool() {
|
||||
given()
|
||||
.formParam("Action", "PutWarmPool")
|
||||
.formParam("AutoScalingGroupName", "my-asg")
|
||||
.formParam("PoolState", "Stopped")
|
||||
.formParam("MinSize", "1")
|
||||
.formParam("MaxGroupPreparedCapacity", "2")
|
||||
.formParam("InstanceReusePolicy.ReuseOnScaleIn", "true")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("PutWarmPoolResponse"));
|
||||
|
||||
given()
|
||||
.formParam("Action", "DescribeWarmPool")
|
||||
.formParam("AutoScalingGroupName", "my-asg")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<PoolState>Stopped</PoolState>"))
|
||||
.body(containsString("<MinSize>1</MinSize>"))
|
||||
.body(containsString("<MaxGroupPreparedCapacity>2</MaxGroupPreparedCapacity>"))
|
||||
.body(containsString("<ReuseOnScaleIn>true</ReuseOnScaleIn>"));
|
||||
|
||||
given()
|
||||
.formParam("Action", "DescribeAutoScalingGroups")
|
||||
.formParam("AutoScalingGroupNames.member.1", "my-asg")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<WarmPoolConfiguration>"))
|
||||
.body(containsString("<PoolState>Stopped</PoolState>"));
|
||||
|
||||
given()
|
||||
.formParam("Action", "DeleteWarmPool")
|
||||
.formParam("AutoScalingGroupName", "my-asg")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("DeleteWarmPoolResponse"));
|
||||
|
||||
given()
|
||||
.formParam("Action", "DescribeWarmPool")
|
||||
.formParam("AutoScalingGroupName", "my-asg")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(not(containsString("<WarmPoolConfiguration>")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(36)
|
||||
void deleteLaunchTemplateAutoScalingGroup() {
|
||||
given()
|
||||
.formParam("Action", "DeleteAutoScalingGroup")
|
||||
@@ -795,7 +1051,7 @@ class AutoScalingIntegrationTest {
|
||||
// ── Cleanup ───────────────────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(32)
|
||||
@Order(37)
|
||||
void deleteAutoScalingGroup() {
|
||||
given()
|
||||
.formParam("Action", "DeleteAutoScalingGroup")
|
||||
@@ -810,7 +1066,7 @@ class AutoScalingIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(33)
|
||||
@Order(38)
|
||||
void deleteMixedInstancesAutoScalingGroup() {
|
||||
given()
|
||||
.formParam("Action", "DeleteAutoScalingGroup")
|
||||
@@ -825,7 +1081,7 @@ class AutoScalingIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(34)
|
||||
@Order(39)
|
||||
void deleteLaunchConfiguration() {
|
||||
given()
|
||||
.formParam("Action", "DeleteLaunchConfiguration")
|
||||
@@ -839,7 +1095,7 @@ class AutoScalingIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(35)
|
||||
@Order(40)
|
||||
void describeAutoScalingGroupsEmpty() {
|
||||
given()
|
||||
.formParam("Action", "DescribeAutoScalingGroups")
|
||||
|
||||
+115
@@ -14,6 +14,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
@@ -782,4 +783,118 @@ class AutoScalingServiceTest {
|
||||
.add(instance);
|
||||
}
|
||||
}
|
||||
|
||||
// The AWS provider calls SuspendProcesses/ResumeProcesses unconditionally around ASG
|
||||
// creation whenever wait_for_capacity_timeout is non-zero (the default), so an
|
||||
// unimplemented SuspendProcesses fails ASG creation outright - found crossing
|
||||
// terraform-aws-modules/terraform-aws-eks against floci.
|
||||
@Test
|
||||
void suspendProcessesRecordsNamedProcessesAndResumeClearsThem() {
|
||||
service.suspendProcesses(REGION, "test-asg", List.of("Launch", "Terminate"));
|
||||
|
||||
var group = service.describeAutoScalingGroups(REGION, List.of("test-asg")).getFirst();
|
||||
assertEquals(List.of("Launch", "Terminate"), group.getSuspendedProcesses());
|
||||
|
||||
service.resumeProcesses(REGION, "test-asg", List.of("Launch"));
|
||||
group = service.describeAutoScalingGroups(REGION, List.of("test-asg")).getFirst();
|
||||
assertEquals(List.of("Terminate"), group.getSuspendedProcesses());
|
||||
|
||||
service.resumeProcesses(REGION, "test-asg", List.of());
|
||||
group = service.describeAutoScalingGroups(REGION, List.of("test-asg")).getFirst();
|
||||
assertEquals(List.of(), group.getSuspendedProcesses());
|
||||
}
|
||||
|
||||
@Test
|
||||
void suspendProcessesWithNoNamesSuspendsEveryScalingProcess() {
|
||||
service.suspendProcesses(REGION, "test-asg", List.of());
|
||||
|
||||
var group = service.describeAutoScalingGroups(REGION, List.of("test-asg")).getFirst();
|
||||
assertTrue(group.getSuspendedProcesses().contains("Launch"));
|
||||
assertTrue(group.getSuspendedProcesses().contains("Terminate"));
|
||||
assertTrue(group.getSuspendedProcesses().contains("HealthCheck"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void attachTrafficSourcesRecordsIdentifierAndTypeAndDetachRemovesIt() {
|
||||
service.attachTrafficSources(REGION, "test-asg", List.of(
|
||||
new AutoScalingService.TrafficSourceIdentifier("arn:aws:elasticloadbalancing:...:tg/ex", "elbv2")));
|
||||
|
||||
assertEquals(Map.of("arn:aws:elasticloadbalancing:...:tg/ex", "elbv2"),
|
||||
service.describeTrafficSources(REGION, "test-asg", null));
|
||||
|
||||
service.detachTrafficSources(REGION, "test-asg", List.of(
|
||||
new AutoScalingService.TrafficSourceIdentifier("arn:aws:elasticloadbalancing:...:tg/ex", null)));
|
||||
|
||||
assertEquals(Map.of(), service.describeTrafficSources(REGION, "test-asg", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeTrafficSourcesFiltersByType() {
|
||||
service.attachTrafficSources(REGION, "test-asg", List.of(
|
||||
new AutoScalingService.TrafficSourceIdentifier("arn:elbv2-source", "elbv2"),
|
||||
new AutoScalingService.TrafficSourceIdentifier("arn:lattice-source", "vpc-lattice")));
|
||||
|
||||
assertEquals(Map.of("arn:elbv2-source", "elbv2"),
|
||||
service.describeTrafficSources(REGION, "test-asg", "elbv2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void putScheduledUpdateGroupActionRecordsScheduleAndDeleteRemovesIt() {
|
||||
service.putScheduledUpdateGroupAction(REGION, "test-asg", "morning",
|
||||
null, null, "0 7 * * 1-5", "Europe/Rome", 0, 1, 1);
|
||||
|
||||
var actions = service.describeScheduledActions(REGION, "test-asg", List.of());
|
||||
assertEquals(1, actions.size());
|
||||
assertEquals("morning", actions.getFirst().getScheduledActionName());
|
||||
assertEquals("0 7 * * 1-5", actions.getFirst().getRecurrence());
|
||||
assertEquals("Europe/Rome", actions.getFirst().getTimeZone());
|
||||
assertEquals(0, actions.getFirst().getMinSize());
|
||||
assertEquals(1, actions.getFirst().getMaxSize());
|
||||
assertEquals(1, actions.getFirst().getDesiredCapacity());
|
||||
assertNotNull(actions.getFirst().getScheduledActionArn());
|
||||
|
||||
service.deleteScheduledAction(REGION, "test-asg", "morning");
|
||||
assertEquals(List.of(), service.describeScheduledActions(REGION, "test-asg", List.of()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void putWarmPoolReplacesConfigurationAndMapsTheClearSentinel() {
|
||||
service.putWarmPool(REGION, "test-asg", 2, 1, "Running", true);
|
||||
|
||||
var pool = service.describeWarmPool(REGION, "test-asg");
|
||||
assertEquals(2, pool.getMaxGroupPreparedCapacity());
|
||||
assertEquals(1, pool.getMinSize());
|
||||
assertEquals("Running", pool.getPoolState());
|
||||
assertTrue(pool.isReuseOnScaleIn());
|
||||
|
||||
// A Put that omits fields resets them to the wire model's documented defaults,
|
||||
// and -1 is the documented sentinel for clearing MaxGroupPreparedCapacity.
|
||||
service.putWarmPool(REGION, "test-asg", -1, null, null, null);
|
||||
pool = service.describeWarmPool(REGION, "test-asg");
|
||||
assertNull(pool.getMaxGroupPreparedCapacity());
|
||||
assertEquals(0, pool.getMinSize());
|
||||
assertEquals("Stopped", pool.getPoolState());
|
||||
assertFalse(pool.isReuseOnScaleIn());
|
||||
|
||||
service.deleteWarmPool(REGION, "test-asg", false);
|
||||
assertNull(service.describeWarmPool(REGION, "test-asg"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteAutoScalingGroupAlsoRemovesItsScheduledActionsAndWarmPool() {
|
||||
service.putScheduledUpdateGroupAction(REGION, "test-asg", "morning",
|
||||
null, null, "0 7 * * 1-5", null, 0, 1, 1);
|
||||
service.putWarmPool(REGION, "test-asg", null, 1, "Stopped", false);
|
||||
service.createAutoScalingGroup("eu-west-1", "test-asg", null, "lt-original", null, "1", null,
|
||||
0, 3, 1, 300, List.of("eu-west-1a"), List.of("subnet-12345678"), List.of(), List.of(),
|
||||
"EC2", 0, List.of("Default"), Map.of(), Map.of());
|
||||
service.putScheduledUpdateGroupAction("eu-west-1", "test-asg", "morning",
|
||||
null, null, "0 7 * * 1-5", null, 0, 1, 1);
|
||||
|
||||
service.deleteAutoScalingGroup(REGION, "test-asg", true);
|
||||
|
||||
assertEquals(List.of(), service.describeScheduledActions(REGION, "test-asg", List.of()));
|
||||
assertThrows(AwsException.class, () -> service.describeWarmPool(REGION, "test-asg"));
|
||||
assertEquals(1, service.describeScheduledActions("eu-west-1", "test-asg", List.of()).size());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user