mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(autoscaling): round-trip the dropped Auto Scaling group fields (#3494)
* fix(autoscaling): round-trip the dropped Auto Scaling group fields CreateAutoScalingGroup and UpdateAutoScalingGroup accepted DesiredCapacityType, CapacityRebalance, MaxInstanceLifetime and DefaultInstanceWarmup and threw them away, so DescribeAutoScalingGroups never read them back. A mixed instances policy launch template override that selected instance types by InstanceRequirements instead of by name was dropped the same way, and because the override parser used InstanceType's presence as its only "is there another override" signal, such an override also truncated the whole Overrides list. The four scalar members now travel into AutoScalingService as one AsgOptionalFields record and are stored on AutoScalingGroup as boxed, uninitialised fields, so a group that never set one omits it from the Describe response rather than reporting a default. Update keeps its partial-update semantics: an absent member leaves the stored value alone. DefaultInstanceWarmup honours the documented -1 removal sentinel, MaxInstanceLifetime must be 0 or at least 86400, and DesiredCapacityType is checked against units, vcpu and memory-mib. LaunchTemplateOverrides.InstanceRequirements parses and echoes every member of the botocore shape except BaselinePerformanceFactors, and an override that sets both InstanceType and InstanceRequirements raises ValidationError as AWS does. Verified against botocore autoscaling/2011-01-01/service-2.json from awscli 2.35.24. * fix(autoscaling): enforce the attribute-based instance selection rules Two rules that botocore states but does not encode as constraints were missing. DesiredCapacityType is typed XmlStringMaxLen255 with no enum, and CreateAutoScalingGroupType.members.DesiredCapacityType.documentation carries the rule: "Amazon EC2 Auto Scaling supports DesiredCapacityType for attribute-based instance type selection only." Floci accepted vcpu and memory-mib for a group whose launch template names a fixed instance type. Both values now raise ValidationError unless the mixed instances policy left in effect by the request carries a launch template override with a non-empty InstanceRequirements. units is the documented default and stays legal everywhere, and an absent member is not validated. The effective policy is the one the request supplies on create. On update it is the policy the request supplies, the stored policy when the request names no launch source, or none when the request switches the group to a launch configuration or a plain launch template. The effective DesiredCapacityType is likewise the request value or, when absent, the stored one, so an update cannot strip attribute-based selection out from under a stored vcpu. shapes.InstanceRequirements.required is ["VCpuCount", "MemoryMiB"] and the shape documentation repeats it as "You must specify VCpuCount and MemoryMiB". An override carrying InstanceRequirements without both ranges was stored and returned 200; it now raises ValidationError. Both rules run on create and on update. createGroupCarryingEveryOptionalField is @Order(1) and seeds the group the later ordered tests reuse, so its setup moved from a launch template naming t3.micro to a mixed instances policy whose override sets VCpuCount and MemoryMiB. That makes its DesiredCapacityType=vcpu legal without relaxing any assertion, and the ordered updates that follow still see attribute-based selection in effect.
This commit is contained in:
1 parent
29e9ae9221
commit
cebb011a00
10 files changed
+1390
-27
No files matched your search
+454
@@ -0,0 +1,454 @@
|
||||
package io.github.hectorvent.floci.services.autoscaling;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
/**
|
||||
* Wire-level coverage for the optional CreateAutoScalingGroup/UpdateAutoScalingGroup members that
|
||||
* DescribeAutoScalingGroups echoes back: DesiredCapacityType, CapacityRebalance,
|
||||
* MaxInstanceLifetime, DefaultInstanceWarmup, and a mixed instances policy launch template
|
||||
* override that selects instance types by requirements instead of by name.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class AutoScalingGroupOptionalFieldsIntegrationTest {
|
||||
|
||||
private static final String AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260501/us-east-1/autoscaling/aws4_request";
|
||||
private static final String EC2_AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260501/us-east-1/ec2/aws4_request";
|
||||
|
||||
private static final String GROUP = "opt-fields-asg";
|
||||
private static final String BARE_GROUP = "opt-fields-bare-asg";
|
||||
private static final String REQUIREMENTS_GROUP = "opt-fields-requirements-asg";
|
||||
|
||||
private static final String OVERRIDE_REQUIREMENTS =
|
||||
"MixedInstancesPolicy.LaunchTemplate.Overrides.member.1.InstanceRequirements";
|
||||
|
||||
private static String launchTemplateId;
|
||||
|
||||
// DesiredCapacityType is legal only for attribute-based instance type selection, so the group the
|
||||
// later ordered tests build on is created from a mixed instances policy whose override selects
|
||||
// instance types by InstanceRequirements rather than from a launch template naming t3.micro.
|
||||
@Test
|
||||
@Order(1)
|
||||
void createGroupCarryingEveryOptionalField() {
|
||||
launchTemplateId = createLaunchTemplate("opt-fields-lt");
|
||||
|
||||
given()
|
||||
.formParam("Action", "CreateAutoScalingGroup")
|
||||
.formParam("AutoScalingGroupName", GROUP)
|
||||
.formParam("MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.LaunchTemplateId",
|
||||
launchTemplateId)
|
||||
.formParam("MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.Version", "1")
|
||||
.formParam(OVERRIDE_REQUIREMENTS + ".VCpuCount.Min", "2")
|
||||
.formParam(OVERRIDE_REQUIREMENTS + ".VCpuCount.Max", "8")
|
||||
.formParam(OVERRIDE_REQUIREMENTS + ".MemoryMiB.Min", "2048")
|
||||
.formParam(OVERRIDE_REQUIREMENTS + ".MemoryMiB.Max", "16384")
|
||||
.formParam("MinSize", "0")
|
||||
.formParam("MaxSize", "4")
|
||||
.formParam("DesiredCapacity", "0")
|
||||
.formParam("AvailabilityZones.member.1", "us-east-1a")
|
||||
.formParam("DesiredCapacityType", "vcpu")
|
||||
.formParam("CapacityRebalance", "true")
|
||||
.formParam("MaxInstanceLifetime", "604800")
|
||||
.formParam("DefaultInstanceWarmup", "120")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("CreateAutoScalingGroupResponse"));
|
||||
|
||||
describe(GROUP)
|
||||
.body(containsString("<DesiredCapacityType>vcpu</DesiredCapacityType>"))
|
||||
.body(containsString("<CapacityRebalance>true</CapacityRebalance>"))
|
||||
.body(containsString("<MaxInstanceLifetime>604800</MaxInstanceLifetime>"))
|
||||
.body(containsString("<DefaultInstanceWarmup>120</DefaultInstanceWarmup>"))
|
||||
.body(containsString("<VCpuCount><Min>2</Min><Max>8</Max></VCpuCount>"))
|
||||
.body(containsString("<MemoryMiB><Min>2048</Min><Max>16384</Max></MemoryMiB>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void groupThatSetsNoneOfThemOmitsThemFromDescribe() {
|
||||
given()
|
||||
.formParam("Action", "CreateAutoScalingGroup")
|
||||
.formParam("AutoScalingGroupName", BARE_GROUP)
|
||||
.formParam("LaunchTemplate.LaunchTemplateId", launchTemplateId)
|
||||
.formParam("LaunchTemplate.Version", "1")
|
||||
.formParam("MinSize", "0")
|
||||
.formParam("MaxSize", "2")
|
||||
.formParam("DesiredCapacity", "0")
|
||||
.formParam("AvailabilityZones.member.1", "us-east-1a")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
describe(BARE_GROUP)
|
||||
.body(not(containsString("<DesiredCapacityType>")))
|
||||
.body(not(containsString("<CapacityRebalance>")))
|
||||
.body(not(containsString("<MaxInstanceLifetime>")))
|
||||
.body(not(containsString("<DefaultInstanceWarmup>")));
|
||||
}
|
||||
|
||||
// The request names no launch source, so the stored attribute-based policy stays in effect and
|
||||
// memory-mib remains legal.
|
||||
@Test
|
||||
@Order(3)
|
||||
void updateOverwritesOnlyTheOptionalFieldsTheRequestCarries() {
|
||||
given()
|
||||
.formParam("Action", "UpdateAutoScalingGroup")
|
||||
.formParam("AutoScalingGroupName", GROUP)
|
||||
.formParam("MaxInstanceLifetime", "86400")
|
||||
.formParam("DesiredCapacityType", "memory-mib")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("UpdateAutoScalingGroupResponse"));
|
||||
|
||||
describe(GROUP)
|
||||
.body(containsString("<MaxInstanceLifetime>86400</MaxInstanceLifetime>"))
|
||||
.body(containsString("<DesiredCapacityType>memory-mib</DesiredCapacityType>"))
|
||||
.body(containsString("<CapacityRebalance>true</CapacityRebalance>"))
|
||||
.body(containsString("<DefaultInstanceWarmup>120</DefaultInstanceWarmup>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void maxInstanceLifetimeAcceptsTheZeroSentinel() {
|
||||
given()
|
||||
.formParam("Action", "UpdateAutoScalingGroup")
|
||||
.formParam("AutoScalingGroupName", GROUP)
|
||||
.formParam("MaxInstanceLifetime", "0")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
describe(GROUP).body(containsString("<MaxInstanceLifetime>0</MaxInstanceLifetime>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void defaultInstanceWarmupMinusOneRemovesThePreviouslySetValue() {
|
||||
given()
|
||||
.formParam("Action", "UpdateAutoScalingGroup")
|
||||
.formParam("AutoScalingGroupName", GROUP)
|
||||
.formParam("DefaultInstanceWarmup", "-1")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
describe(GROUP)
|
||||
.body(not(containsString("<DefaultInstanceWarmup>")))
|
||||
.body(containsString("<CapacityRebalance>true</CapacityRebalance>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void createRejectsAnUnknownDesiredCapacityType() {
|
||||
given()
|
||||
.formParam("Action", "CreateAutoScalingGroup")
|
||||
.formParam("AutoScalingGroupName", "opt-fields-bad-capacity-type")
|
||||
.formParam("LaunchTemplate.LaunchTemplateId", launchTemplateId)
|
||||
.formParam("MinSize", "0")
|
||||
.formParam("MaxSize", "1")
|
||||
.formParam("AvailabilityZones.member.1", "us-east-1a")
|
||||
.formParam("DesiredCapacityType", "gpu")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("ValidationError"))
|
||||
.body(containsString("units, vcpu, memory-mib"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void createRejectsAMaxInstanceLifetimeUnderOneDay() {
|
||||
given()
|
||||
.formParam("Action", "CreateAutoScalingGroup")
|
||||
.formParam("AutoScalingGroupName", "opt-fields-bad-lifetime")
|
||||
.formParam("LaunchTemplate.LaunchTemplateId", launchTemplateId)
|
||||
.formParam("MinSize", "0")
|
||||
.formParam("MaxSize", "1")
|
||||
.formParam("AvailabilityZones.member.1", "us-east-1a")
|
||||
.formParam("MaxInstanceLifetime", "3600")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("ValidationError"))
|
||||
.body(containsString("MaxInstanceLifetime"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void mixedInstancesPolicyOverrideRoundTripsInstanceRequirements() {
|
||||
String prefix = OVERRIDE_REQUIREMENTS;
|
||||
|
||||
given()
|
||||
.formParam("Action", "CreateAutoScalingGroup")
|
||||
.formParam("AutoScalingGroupName", REQUIREMENTS_GROUP)
|
||||
.formParam("MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.LaunchTemplateId",
|
||||
launchTemplateId)
|
||||
.formParam("MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.Version", "1")
|
||||
.formParam(prefix + ".VCpuCount.Min", "2")
|
||||
.formParam(prefix + ".VCpuCount.Max", "8")
|
||||
.formParam(prefix + ".MemoryMiB.Min", "2048")
|
||||
.formParam(prefix + ".MemoryMiB.Max", "16384")
|
||||
.formParam(prefix + ".MemoryGiBPerVCpu.Min", "2.0")
|
||||
.formParam(prefix + ".NetworkInterfaceCount.Min", "1")
|
||||
.formParam(prefix + ".NetworkInterfaceCount.Max", "4")
|
||||
.formParam(prefix + ".AcceleratorCount.Max", "2")
|
||||
.formParam(prefix + ".AcceleratorTotalMemoryMiB.Min", "1024")
|
||||
.formParam(prefix + ".BaselineEbsBandwidthMbps.Min", "125")
|
||||
.formParam(prefix + ".TotalLocalStorageGB.Max", "500.0")
|
||||
.formParam(prefix + ".NetworkBandwidthGbps.Min", "1.5")
|
||||
.formParam(prefix + ".CpuManufacturers.member.1", "intel")
|
||||
.formParam(prefix + ".CpuManufacturers.member.2", "amd")
|
||||
.formParam(prefix + ".ExcludedInstanceTypes.member.1", "m1.*")
|
||||
.formParam(prefix + ".InstanceGenerations.member.1", "current")
|
||||
.formParam(prefix + ".LocalStorageTypes.member.1", "ssd")
|
||||
.formParam(prefix + ".AcceleratorTypes.member.1", "gpu")
|
||||
.formParam(prefix + ".AcceleratorManufacturers.member.1", "nvidia")
|
||||
.formParam(prefix + ".AcceleratorNames.member.1", "t4")
|
||||
.formParam(prefix + ".AllowedInstanceTypes.member.1", "m6i.*")
|
||||
.formParam(prefix + ".BareMetal", "excluded")
|
||||
.formParam(prefix + ".BurstablePerformance", "included")
|
||||
.formParam(prefix + ".LocalStorage", "required")
|
||||
.formParam(prefix + ".RequireHibernateSupport", "false")
|
||||
.formParam(prefix + ".SpotMaxPricePercentageOverLowestPrice", "100")
|
||||
.formParam(prefix + ".MaxSpotPriceAsPercentageOfOptimalOnDemandPrice", "90")
|
||||
.formParam(prefix + ".OnDemandMaxPricePercentageOverLowestPrice", "20")
|
||||
.formParam("MinSize", "0")
|
||||
.formParam("MaxSize", "4")
|
||||
.formParam("DesiredCapacity", "0")
|
||||
.formParam("DesiredCapacityType", "units")
|
||||
.formParam("AvailabilityZones.member.1", "us-east-1a")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("CreateAutoScalingGroupResponse"));
|
||||
|
||||
describe(REQUIREMENTS_GROUP)
|
||||
.body(containsString("<Overrides><member><InstanceRequirements>"))
|
||||
.body(containsString("<VCpuCount><Min>2</Min><Max>8</Max></VCpuCount>"))
|
||||
.body(containsString("<MemoryMiB><Min>2048</Min><Max>16384</Max></MemoryMiB>"))
|
||||
.body(containsString("<MemoryGiBPerVCpu><Min>2.0</Min></MemoryGiBPerVCpu>"))
|
||||
.body(containsString("<NetworkInterfaceCount><Min>1</Min><Max>4</Max></NetworkInterfaceCount>"))
|
||||
.body(containsString("<AcceleratorCount><Max>2</Max></AcceleratorCount>"))
|
||||
.body(containsString("<AcceleratorTotalMemoryMiB><Min>1024</Min></AcceleratorTotalMemoryMiB>"))
|
||||
.body(containsString("<BaselineEbsBandwidthMbps><Min>125</Min></BaselineEbsBandwidthMbps>"))
|
||||
.body(containsString("<TotalLocalStorageGB><Max>500.0</Max></TotalLocalStorageGB>"))
|
||||
.body(containsString("<NetworkBandwidthGbps><Min>1.5</Min></NetworkBandwidthGbps>"))
|
||||
.body(containsString("<CpuManufacturers><member>intel</member><member>amd</member></CpuManufacturers>"))
|
||||
.body(containsString("<ExcludedInstanceTypes><member>m1.*</member></ExcludedInstanceTypes>"))
|
||||
.body(containsString("<InstanceGenerations><member>current</member></InstanceGenerations>"))
|
||||
.body(containsString("<LocalStorageTypes><member>ssd</member></LocalStorageTypes>"))
|
||||
.body(containsString("<AcceleratorTypes><member>gpu</member></AcceleratorTypes>"))
|
||||
.body(containsString("<AcceleratorManufacturers><member>nvidia</member></AcceleratorManufacturers>"))
|
||||
.body(containsString("<AcceleratorNames><member>t4</member></AcceleratorNames>"))
|
||||
.body(containsString("<AllowedInstanceTypes><member>m6i.*</member></AllowedInstanceTypes>"))
|
||||
.body(containsString("<BareMetal>excluded</BareMetal>"))
|
||||
.body(containsString("<BurstablePerformance>included</BurstablePerformance>"))
|
||||
.body(containsString("<LocalStorage>required</LocalStorage>"))
|
||||
.body(containsString("<RequireHibernateSupport>false</RequireHibernateSupport>"))
|
||||
.body(containsString("<SpotMaxPricePercentageOverLowestPrice>100</SpotMaxPricePercentageOverLowestPrice>"))
|
||||
.body(containsString("<MaxSpotPriceAsPercentageOfOptimalOnDemandPrice>90"
|
||||
+ "</MaxSpotPriceAsPercentageOfOptimalOnDemandPrice>"))
|
||||
.body(containsString("<OnDemandMaxPricePercentageOverLowestPrice>20"
|
||||
+ "</OnDemandMaxPricePercentageOverLowestPrice>"))
|
||||
.body(containsString("<DesiredCapacityType>units</DesiredCapacityType>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void overrideRejectsInstanceTypeAlongsideInstanceRequirements() {
|
||||
given()
|
||||
.formParam("Action", "CreateAutoScalingGroup")
|
||||
.formParam("AutoScalingGroupName", "opt-fields-conflicting-override")
|
||||
.formParam("MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.LaunchTemplateId",
|
||||
launchTemplateId)
|
||||
.formParam("MixedInstancesPolicy.LaunchTemplate.Overrides.member.1.InstanceType", "m6i.large")
|
||||
.formParam("MixedInstancesPolicy.LaunchTemplate.Overrides.member.1."
|
||||
+ "InstanceRequirements.VCpuCount.Min", "2")
|
||||
.formParam("MinSize", "0")
|
||||
.formParam("MaxSize", "1")
|
||||
.formParam("AvailabilityZones.member.1", "us-east-1a")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("ValidationError"))
|
||||
.body(containsString("InstanceRequirements"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void createRejectsVcpuDesiredCapacityTypeWithoutAttributeBasedSelection() {
|
||||
given()
|
||||
.formParam("Action", "CreateAutoScalingGroup")
|
||||
.formParam("AutoScalingGroupName", "opt-fields-fixed-type-vcpu")
|
||||
.formParam("LaunchTemplate.LaunchTemplateId", launchTemplateId)
|
||||
.formParam("LaunchTemplate.Version", "1")
|
||||
.formParam("MinSize", "0")
|
||||
.formParam("MaxSize", "1")
|
||||
.formParam("AvailabilityZones.member.1", "us-east-1a")
|
||||
.formParam("DesiredCapacityType", "vcpu")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("ValidationError"))
|
||||
.body(containsString("attribute-based instance type selection only"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
void updateRejectsMemoryMibDesiredCapacityTypeWithoutAttributeBasedSelection() {
|
||||
given()
|
||||
.formParam("Action", "UpdateAutoScalingGroup")
|
||||
.formParam("AutoScalingGroupName", BARE_GROUP)
|
||||
.formParam("DesiredCapacityType", "memory-mib")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("ValidationError"))
|
||||
.body(containsString("attribute-based instance type selection only"));
|
||||
|
||||
describe(BARE_GROUP).body(not(containsString("<DesiredCapacityType>")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
void updateAcceptsVcpuOnceTheSameRequestSuppliesInstanceRequirements() {
|
||||
given()
|
||||
.formParam("Action", "UpdateAutoScalingGroup")
|
||||
.formParam("AutoScalingGroupName", BARE_GROUP)
|
||||
.formParam("MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.LaunchTemplateId",
|
||||
launchTemplateId)
|
||||
.formParam("MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.Version", "1")
|
||||
.formParam(OVERRIDE_REQUIREMENTS + ".VCpuCount.Min", "4")
|
||||
.formParam(OVERRIDE_REQUIREMENTS + ".MemoryMiB.Min", "8192")
|
||||
.formParam("DesiredCapacityType", "vcpu")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
describe(BARE_GROUP)
|
||||
.body(containsString("<DesiredCapacityType>vcpu</DesiredCapacityType>"))
|
||||
.body(containsString("<VCpuCount><Min>4</Min></VCpuCount>"))
|
||||
.body(containsString("<MemoryMiB><Min>8192</Min></MemoryMiB>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(13)
|
||||
void createRejectsAnInstanceRequirementsOverrideMissingMemoryMiB() {
|
||||
given()
|
||||
.formParam("Action", "CreateAutoScalingGroup")
|
||||
.formParam("AutoScalingGroupName", "opt-fields-partial-requirements")
|
||||
.formParam("MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.LaunchTemplateId",
|
||||
launchTemplateId)
|
||||
.formParam("MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.Version", "1")
|
||||
.formParam(OVERRIDE_REQUIREMENTS + ".VCpuCount.Min", "2")
|
||||
.formParam("MinSize", "0")
|
||||
.formParam("MaxSize", "1")
|
||||
.formParam("AvailabilityZones.member.1", "us-east-1a")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("ValidationError"))
|
||||
.body(containsString("VCpuCount and MemoryMiB"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(14)
|
||||
void updateRejectsAnInstanceRequirementsOverrideMissingVCpuCount() {
|
||||
given()
|
||||
.formParam("Action", "UpdateAutoScalingGroup")
|
||||
.formParam("AutoScalingGroupName", REQUIREMENTS_GROUP)
|
||||
.formParam("MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.LaunchTemplateId",
|
||||
launchTemplateId)
|
||||
.formParam("MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.Version", "1")
|
||||
.formParam(OVERRIDE_REQUIREMENTS + ".MemoryMiB.Min", "2048")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("ValidationError"))
|
||||
.body(containsString("VCpuCount and MemoryMiB"));
|
||||
|
||||
describe(REQUIREMENTS_GROUP).body(containsString("<VCpuCount><Min>2</Min><Max>8</Max></VCpuCount>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(15)
|
||||
void cleanUp() {
|
||||
for (String name : new String[] {GROUP, BARE_GROUP, REQUIREMENTS_GROUP}) {
|
||||
given()
|
||||
.formParam("Action", "DeleteAutoScalingGroup")
|
||||
.formParam("AutoScalingGroupName", name)
|
||||
.formParam("ForceDelete", "true")
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
}
|
||||
|
||||
private static ValidatableResponse describe(String name) {
|
||||
return given()
|
||||
.formParam("Action", "DescribeAutoScalingGroups")
|
||||
.formParam("AutoScalingGroupNames.member.1", name)
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
private static String createLaunchTemplate(String name) {
|
||||
return given()
|
||||
.formParam("Action", "CreateLaunchTemplate")
|
||||
.formParam("LaunchTemplateName", name)
|
||||
.formParam("LaunchTemplateData.ImageId", "ami-12345678")
|
||||
.formParam("LaunchTemplateData.InstanceType", "t3.micro")
|
||||
.header("Authorization", EC2_AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().path("CreateLaunchTemplateResponse.launchTemplate.launchTemplateId");
|
||||
}
|
||||
}
|
||||
+69
-9
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.autoscaling;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.AsgInstance;
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.AsgOptionalFields;
|
||||
import jakarta.ws.rs.core.MultivaluedHashMap;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -9,6 +10,7 @@ import org.junit.jupiter.api.Test;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class AutoScalingQueryHandlerTest {
|
||||
@@ -37,7 +39,7 @@ class AutoScalingQueryHandlerTest {
|
||||
"EC2",
|
||||
0,
|
||||
List.of("Default"),
|
||||
java.util.Map.of(), java.util.Map.of());
|
||||
java.util.Map.of(), java.util.Map.of(), AsgOptionalFields.none());
|
||||
|
||||
AutoScalingQueryHandler handler = new AutoScalingQueryHandler(service);
|
||||
MultivaluedHashMap<String, String> startParams = new MultivaluedHashMap<>();
|
||||
@@ -103,7 +105,7 @@ class AutoScalingQueryHandlerTest {
|
||||
0,
|
||||
List.of("Default"),
|
||||
java.util.Map.of(),
|
||||
java.util.Map.of());
|
||||
java.util.Map.of(), AsgOptionalFields.none());
|
||||
AsgInstance instance = new AsgInstance();
|
||||
instance.setInstanceId("i-original");
|
||||
instance.setAvailabilityZone("us-east-1a");
|
||||
@@ -158,7 +160,7 @@ class AutoScalingQueryHandlerTest {
|
||||
"EC2",
|
||||
0,
|
||||
List.of("Default"),
|
||||
java.util.Map.of(), java.util.Map.of());
|
||||
java.util.Map.of(), java.util.Map.of(), AsgOptionalFields.none());
|
||||
AsgInstance instance = new AsgInstance();
|
||||
instance.setInstanceId("i-current");
|
||||
instance.setAvailabilityZone("us-east-1a");
|
||||
@@ -191,7 +193,7 @@ class AutoScalingQueryHandlerTest {
|
||||
service.regionResolver = new RegionResolver(REGION, "000000000000");
|
||||
service.createAutoScalingGroup(REGION, "protected-asg", null, "lt", null, "1", null,
|
||||
0, 2, 1, 300, List.of("us-east-1a"), List.of(), List.of(), List.of(),
|
||||
"EC2", 0, List.of("Default"), java.util.Map.of(), java.util.Map.of());
|
||||
"EC2", 0, List.of("Default"), java.util.Map.of(), java.util.Map.of(), AsgOptionalFields.none());
|
||||
AsgInstance instance = new AsgInstance();
|
||||
instance.setInstanceId("i-protected");
|
||||
instance.setLifecycleState("InService");
|
||||
@@ -218,7 +220,7 @@ class AutoScalingQueryHandlerTest {
|
||||
service.regionResolver = new RegionResolver(REGION, "000000000000");
|
||||
service.createAutoScalingGroup(REGION, "health-asg", null, "lt", null, "1", null,
|
||||
0, 2, 1, 300, List.of("us-east-1a"), List.of(), List.of(), List.of(),
|
||||
"EC2", 0, List.of("Default"), java.util.Map.of(), java.util.Map.of());
|
||||
"EC2", 0, List.of("Default"), java.util.Map.of(), java.util.Map.of(), AsgOptionalFields.none());
|
||||
AsgInstance instance = new AsgInstance();
|
||||
instance.setInstanceId("i-unhealthy");
|
||||
instance.setLifecycleState("InService");
|
||||
@@ -244,7 +246,7 @@ class AutoScalingQueryHandlerTest {
|
||||
service.regionResolver = new RegionResolver(REGION, "000000000000");
|
||||
service.createAutoScalingGroup(REGION, "no-protection-flag-asg", null, "lt", null, "1", null,
|
||||
0, 2, 1, 300, List.of("us-east-1a"), List.of(), List.of(), List.of(),
|
||||
"EC2", 0, List.of("Default"), java.util.Map.of(), java.util.Map.of());
|
||||
"EC2", 0, List.of("Default"), java.util.Map.of(), java.util.Map.of(), AsgOptionalFields.none());
|
||||
AsgInstance instance = new AsgInstance();
|
||||
instance.setInstanceId("i-flagless");
|
||||
instance.setLifecycleState("InService");
|
||||
@@ -273,7 +275,7 @@ class AutoScalingQueryHandlerTest {
|
||||
service.regionResolver = new RegionResolver(REGION, "000000000000");
|
||||
service.createAutoScalingGroup(REGION, "malformed-flag-asg", null, "lt", null, "1", null,
|
||||
0, 2, 1, 300, List.of("us-east-1a"), List.of(), List.of(), List.of(),
|
||||
"EC2", 0, List.of("Default"), java.util.Map.of(), java.util.Map.of());
|
||||
"EC2", 0, List.of("Default"), java.util.Map.of(), java.util.Map.of(), AsgOptionalFields.none());
|
||||
AsgInstance instance = new AsgInstance();
|
||||
instance.setInstanceId("i-malformed");
|
||||
instance.setLifecycleState("InService");
|
||||
@@ -301,7 +303,7 @@ class AutoScalingQueryHandlerTest {
|
||||
service.regionResolver = new RegionResolver(REGION, "000000000000");
|
||||
service.createAutoScalingGroup(REGION, "grace-asg", null, "lt", null, "1", null,
|
||||
0, 2, 1, 300, List.of("us-east-1a"), List.of(), List.of(), List.of(),
|
||||
"EC2", 0, List.of("Default"), java.util.Map.of(), java.util.Map.of());
|
||||
"EC2", 0, List.of("Default"), java.util.Map.of(), java.util.Map.of(), AsgOptionalFields.none());
|
||||
AsgInstance instance = new AsgInstance();
|
||||
instance.setInstanceId("i-grace");
|
||||
instance.setLifecycleState("InService");
|
||||
@@ -342,7 +344,7 @@ class AutoScalingQueryHandlerTest {
|
||||
"EC2",
|
||||
0,
|
||||
List.of("Default"),
|
||||
java.util.Map.of(), java.util.Map.of());
|
||||
java.util.Map.of(), java.util.Map.of(), AsgOptionalFields.none());
|
||||
|
||||
AutoScalingQueryHandler handler = new AutoScalingQueryHandler(service);
|
||||
MultivaluedHashMap<String, String> putParams = new MultivaluedHashMap<>();
|
||||
@@ -419,4 +421,62 @@ class AutoScalingQueryHandlerTest {
|
||||
assertTrue(xml.contains("<OnDemandPercentageAboveBaseCapacity>25</OnDemandPercentageAboveBaseCapacity>"));
|
||||
assertTrue(xml.contains("<SpotAllocationStrategy>capacity-optimized</SpotAllocationStrategy>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void overrideThatSetsOnlyInstanceRequirementsSurvivesCreateAndDescribe() {
|
||||
AutoScalingService service = new AutoScalingService();
|
||||
service.regionResolver = new RegionResolver(REGION, "000000000000");
|
||||
AutoScalingQueryHandler handler = new AutoScalingQueryHandler(service);
|
||||
|
||||
String overrides = "MixedInstancesPolicy.LaunchTemplate.Overrides.member.";
|
||||
MultivaluedHashMap<String, String> createParams = new MultivaluedHashMap<>();
|
||||
createParams.add("AutoScalingGroupName", "requirements-asg");
|
||||
createParams.add("MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.LaunchTemplateId", "lt-1");
|
||||
createParams.add(overrides + "1.InstanceRequirements.VCpuCount.Min", "2");
|
||||
createParams.add(overrides + "1.InstanceRequirements.VCpuCount.Max", "8");
|
||||
createParams.add(overrides + "1.InstanceRequirements.MemoryMiB.Min", "2048");
|
||||
createParams.add(overrides + "1.InstanceRequirements.CpuManufacturers.member.1", "intel");
|
||||
createParams.add(overrides + "2.InstanceType", "m6i.large");
|
||||
createParams.add("MinSize", "0");
|
||||
createParams.add("MaxSize", "3");
|
||||
createParams.add("AvailabilityZones.member.1", "us-east-1a");
|
||||
|
||||
assertEquals(200, handler.handle("CreateAutoScalingGroup", createParams, REGION).getStatus());
|
||||
|
||||
MultivaluedHashMap<String, String> describeParams = new MultivaluedHashMap<>();
|
||||
describeParams.add("AutoScalingGroupNames.member.1", "requirements-asg");
|
||||
Response describeResponse = handler.handle("DescribeAutoScalingGroups", describeParams, REGION);
|
||||
|
||||
assertEquals(200, describeResponse.getStatus());
|
||||
String xml = (String) describeResponse.getEntity();
|
||||
assertTrue(xml.contains("<VCpuCount><Min>2</Min><Max>8</Max></VCpuCount>"));
|
||||
assertTrue(xml.contains("<MemoryMiB><Min>2048</Min></MemoryMiB>"));
|
||||
assertTrue(xml.contains("<CpuManufacturers><member>intel</member></CpuManufacturers>"));
|
||||
assertTrue(xml.contains("<InstanceType>m6i.large</InstanceType>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeOmitsTheOptionalGroupFieldsTheCreateRequestNeverSet() {
|
||||
AutoScalingService service = new AutoScalingService();
|
||||
service.regionResolver = new RegionResolver(REGION, "000000000000");
|
||||
AutoScalingQueryHandler handler = new AutoScalingQueryHandler(service);
|
||||
|
||||
MultivaluedHashMap<String, String> createParams = new MultivaluedHashMap<>();
|
||||
createParams.add("AutoScalingGroupName", "bare-asg");
|
||||
createParams.add("LaunchTemplate.LaunchTemplateId", "lt-1");
|
||||
createParams.add("MinSize", "0");
|
||||
createParams.add("MaxSize", "1");
|
||||
createParams.add("AvailabilityZones.member.1", "us-east-1a");
|
||||
|
||||
assertEquals(200, handler.handle("CreateAutoScalingGroup", createParams, REGION).getStatus());
|
||||
|
||||
MultivaluedHashMap<String, String> describeParams = new MultivaluedHashMap<>();
|
||||
describeParams.add("AutoScalingGroupNames.member.1", "bare-asg");
|
||||
String xml = (String) handler.handle("DescribeAutoScalingGroups", describeParams, REGION).getEntity();
|
||||
|
||||
assertFalse(xml.contains("<DesiredCapacityType>"));
|
||||
assertFalse(xml.contains("<CapacityRebalance>"));
|
||||
assertFalse(xml.contains("<MaxInstanceLifetime>"));
|
||||
assertFalse(xml.contains("<DefaultInstanceWarmup>"));
|
||||
}
|
||||
}
|
||||
+292
-8
@@ -3,6 +3,8 @@ package io.github.hectorvent.floci.services.autoscaling;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.AsgInstance;
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.AsgOptionalFields;
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.AutoScalingGroup;
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.InstanceRefresh;
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.LaunchConfigurationBlockDeviceMapping;
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.MixedInstancesPolicy;
|
||||
@@ -50,7 +52,7 @@ class AutoScalingServiceTest {
|
||||
"EC2",
|
||||
0,
|
||||
List.of("Default"),
|
||||
java.util.Map.of(), java.util.Map.of());
|
||||
java.util.Map.of(), java.util.Map.of(), AsgOptionalFields.none());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -122,7 +124,7 @@ class AutoScalingServiceTest {
|
||||
"EC2",
|
||||
0,
|
||||
List.of("Default"),
|
||||
java.util.Map.of(), java.util.Map.of()));
|
||||
java.util.Map.of(), java.util.Map.of(), AsgOptionalFields.none()));
|
||||
|
||||
assertEquals("ValidationError", error.getErrorCode());
|
||||
assertEquals(AutoScalingService.MISSING_LAUNCH_TEMPLATE_IMAGE_ID_MESSAGE, error.getMessage());
|
||||
@@ -280,7 +282,7 @@ class AutoScalingServiceTest {
|
||||
"EC2",
|
||||
0,
|
||||
List.of("Default"),
|
||||
java.util.Map.of(), java.util.Map.of()));
|
||||
java.util.Map.of(), java.util.Map.of(), AsgOptionalFields.none()));
|
||||
|
||||
assertEquals("ValidationError", error.getErrorCode());
|
||||
assertEquals(AutoScalingService.INVALID_LAUNCH_TEMPLATE_MESSAGE, error.getMessage());
|
||||
@@ -313,7 +315,7 @@ class AutoScalingServiceTest {
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null));
|
||||
null, AsgOptionalFields.none()));
|
||||
|
||||
assertEquals("ValidationError", error.getErrorCode());
|
||||
assertEquals(AutoScalingService.MISSING_LAUNCH_TEMPLATE_IMAGE_ID_MESSAGE, error.getMessage());
|
||||
@@ -340,7 +342,7 @@ class AutoScalingServiceTest {
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null));
|
||||
null, AsgOptionalFields.none()));
|
||||
|
||||
assertEquals("ValidationError", error.getErrorCode());
|
||||
assertEquals("LaunchTemplateVersion requires a LaunchTemplateId or LaunchTemplateName.", error.getMessage());
|
||||
@@ -373,7 +375,7 @@ class AutoScalingServiceTest {
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null));
|
||||
null, AsgOptionalFields.none()));
|
||||
|
||||
assertEquals("ValidationError", error.getErrorCode());
|
||||
assertEquals(AutoScalingService.ACTIVE_INSTANCE_REFRESH_DESIRED_CONFIGURATION_MESSAGE, error.getMessage());
|
||||
@@ -684,7 +686,7 @@ class AutoScalingServiceTest {
|
||||
"EC2",
|
||||
0,
|
||||
List.of("Default"),
|
||||
java.util.Map.of(), java.util.Map.of());
|
||||
java.util.Map.of(), java.util.Map.of(), AsgOptionalFields.none());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -937,7 +939,7 @@ class AutoScalingServiceTest {
|
||||
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());
|
||||
"EC2", 0, List.of("Default"), Map.of(), Map.of(), AsgOptionalFields.none());
|
||||
service.putScheduledUpdateGroupAction("eu-west-1", "test-asg", "morning",
|
||||
null, null, "0 7 * * 1-5", null, 0, 1, 1);
|
||||
|
||||
@@ -947,4 +949,286 @@ class AutoScalingServiceTest {
|
||||
assertThrows(AwsException.class, () -> service.describeWarmPool(REGION, "test-asg"));
|
||||
assertEquals(1, service.describeScheduledActions("eu-west-1", "test-asg", List.of()).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAutoScalingGroupStoresTheOptionalFieldsAndLeavesUnsetOnesNull() {
|
||||
service.createAutoScalingGroup(REGION, "optional-asg", null, null, null, null,
|
||||
attributeBasedPolicy(2, 2048),
|
||||
0, 3, 1, 300, List.of("us-east-1a"), List.of(), List.of(), List.of(), "EC2", 0,
|
||||
List.of("Default"), Map.of(), Map.of(),
|
||||
new AsgOptionalFields("vcpu", true, 604800, 120));
|
||||
|
||||
AutoScalingGroup group = service.describeAutoScalingGroups(REGION, List.of("optional-asg")).getFirst();
|
||||
|
||||
assertEquals("vcpu", group.getDesiredCapacityType());
|
||||
assertEquals(Boolean.TRUE, group.getCapacityRebalance());
|
||||
assertEquals(604800, group.getMaxInstanceLifetime());
|
||||
assertEquals(120, group.getDefaultInstanceWarmup());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aFreshAutoScalingGroupCarriesNoInitialiserForTheOptionalFields() {
|
||||
AutoScalingGroup group = new AutoScalingGroup();
|
||||
|
||||
assertNull(group.getDesiredCapacityType());
|
||||
assertNull(group.getCapacityRebalance());
|
||||
assertNull(group.getMaxInstanceLifetime());
|
||||
assertNull(group.getDefaultInstanceWarmup());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAutoScalingGroupLeavesEveryOptionalFieldNullWhenTheRequestOmitsThem() {
|
||||
AutoScalingGroup group = service.describeAutoScalingGroups(REGION, List.of("test-asg")).getFirst();
|
||||
|
||||
assertNull(group.getDesiredCapacityType());
|
||||
assertNull(group.getCapacityRebalance());
|
||||
assertNull(group.getMaxInstanceLifetime());
|
||||
assertNull(group.getDefaultInstanceWarmup());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAutoScalingGroupOverwritesOnlyTheOptionalFieldsTheRequestCarries() {
|
||||
service.createAutoScalingGroup(REGION, "partial-update-asg", null, null, null, null,
|
||||
attributeBasedPolicy(2, 2048),
|
||||
0, 3, 1, 300, List.of("us-east-1a"), List.of(), List.of(), List.of(), "EC2", 0,
|
||||
List.of("Default"), Map.of(), Map.of(),
|
||||
new AsgOptionalFields("vcpu", true, 604800, 120));
|
||||
|
||||
service.updateAutoScalingGroup(REGION, "partial-update-asg", null, null, null, null, null,
|
||||
null, null, null, null, null, null, null, null, null,
|
||||
new AsgOptionalFields(null, null, 86400, null));
|
||||
|
||||
AutoScalingGroup group = service.describeAutoScalingGroups(REGION, List.of("partial-update-asg")).getFirst();
|
||||
|
||||
assertEquals(86400, group.getMaxInstanceLifetime());
|
||||
assertEquals("vcpu", group.getDesiredCapacityType());
|
||||
assertEquals(Boolean.TRUE, group.getCapacityRebalance());
|
||||
assertEquals(120, group.getDefaultInstanceWarmup());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAutoScalingGroupClearsDefaultInstanceWarmupOnTheRemovalSentinel() {
|
||||
service.createAutoScalingGroup(REGION, "warmup-asg", null, "lt-original", null, "1", null,
|
||||
0, 3, 1, 300, List.of("us-east-1a"), List.of(), List.of(), List.of(), "EC2", 0,
|
||||
List.of("Default"), Map.of(), Map.of(),
|
||||
new AsgOptionalFields(null, null, null, 300));
|
||||
|
||||
service.updateAutoScalingGroup(REGION, "warmup-asg", null, null, null, null, null,
|
||||
null, null, null, null, null, null, null, null, null,
|
||||
new AsgOptionalFields(null, null, null, -1));
|
||||
|
||||
AutoScalingGroup group = service.describeAutoScalingGroups(REGION, List.of("warmup-asg")).getFirst();
|
||||
|
||||
assertNull(group.getDefaultInstanceWarmup());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAutoScalingGroupRejectsAnUnknownDesiredCapacityType() {
|
||||
AwsException error = assertThrows(AwsException.class, () -> service.createAutoScalingGroup(REGION,
|
||||
"bad-capacity-type-asg", null, "lt-original", null, "1", null,
|
||||
0, 3, 1, 300, List.of("us-east-1a"), List.of(), List.of(), List.of(), "EC2", 0,
|
||||
List.of("Default"), Map.of(), Map.of(),
|
||||
new AsgOptionalFields("gpu", null, null, null)));
|
||||
|
||||
assertEquals("ValidationError", error.getErrorCode());
|
||||
assertEquals(AutoScalingService.INVALID_DESIRED_CAPACITY_TYPE_MESSAGE, error.getMessage());
|
||||
assertEquals(400, error.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAutoScalingGroupRejectsAMaxInstanceLifetimeUnderOneDayButAcceptsZero() {
|
||||
AwsException error = assertThrows(AwsException.class, () -> service.createAutoScalingGroup(REGION,
|
||||
"short-lifetime-asg", null, "lt-original", null, "1", null,
|
||||
0, 3, 1, 300, List.of("us-east-1a"), List.of(), List.of(), List.of(), "EC2", 0,
|
||||
List.of("Default"), Map.of(), Map.of(),
|
||||
new AsgOptionalFields(null, null, 3600, null)));
|
||||
|
||||
assertEquals(AutoScalingService.INVALID_MAX_INSTANCE_LIFETIME_MESSAGE, error.getMessage());
|
||||
|
||||
service.createAutoScalingGroup(REGION, "unbounded-lifetime-asg", null, "lt-original", null, "1", null,
|
||||
0, 3, 1, 300, List.of("us-east-1a"), List.of(), List.of(), List.of(), "EC2", 0,
|
||||
List.of("Default"), Map.of(), Map.of(),
|
||||
new AsgOptionalFields(null, null, 0, null));
|
||||
|
||||
assertEquals(0, service.describeAutoScalingGroups(REGION, List.of("unbounded-lifetime-asg"))
|
||||
.getFirst().getMaxInstanceLifetime());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAutoScalingGroupRejectsADefaultInstanceWarmupBelowTheRemovalSentinel() {
|
||||
AwsException error = assertThrows(AwsException.class, () -> service.createAutoScalingGroup(REGION,
|
||||
"bad-warmup-asg", null, "lt-original", null, "1", null,
|
||||
0, 3, 1, 300, List.of("us-east-1a"), List.of(), List.of(), List.of(), "EC2", 0,
|
||||
List.of("Default"), Map.of(), Map.of(),
|
||||
new AsgOptionalFields(null, null, null, -2)));
|
||||
|
||||
assertEquals(AutoScalingService.INVALID_DEFAULT_INSTANCE_WARMUP_MESSAGE, error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAutoScalingGroupRejectsAnOverrideSettingBothInstanceTypeAndInstanceRequirements() {
|
||||
MixedInstancesPolicy.InstanceRequirements requirements = new MixedInstancesPolicy.InstanceRequirements();
|
||||
MixedInstancesPolicy.IntRange vCpuCount = new MixedInstancesPolicy.IntRange();
|
||||
vCpuCount.setMin(2);
|
||||
requirements.setVCpuCount(vCpuCount);
|
||||
MixedInstancesPolicy.LaunchTemplateOverride override = new MixedInstancesPolicy.LaunchTemplateOverride();
|
||||
override.setInstanceType("m6i.large");
|
||||
override.setInstanceRequirements(requirements);
|
||||
MixedInstancesPolicy.LaunchTemplateSpecification specification =
|
||||
new MixedInstancesPolicy.LaunchTemplateSpecification();
|
||||
specification.setLaunchTemplateId("lt-original");
|
||||
MixedInstancesPolicy.LaunchTemplate launchTemplate = new MixedInstancesPolicy.LaunchTemplate();
|
||||
launchTemplate.setLaunchTemplateSpecification(specification);
|
||||
launchTemplate.setOverrides(List.of(override));
|
||||
MixedInstancesPolicy policy = new MixedInstancesPolicy();
|
||||
policy.setLaunchTemplate(launchTemplate);
|
||||
|
||||
AwsException error = assertThrows(AwsException.class, () -> service.createAutoScalingGroup(REGION,
|
||||
"conflicting-override-asg", null, null, null, null, policy,
|
||||
0, 3, 1, 300, List.of("us-east-1a"), List.of(), List.of(), List.of(), "EC2", 0,
|
||||
List.of("Default"), Map.of(), Map.of(), AsgOptionalFields.none()));
|
||||
|
||||
assertEquals("ValidationError", error.getErrorCode());
|
||||
assertEquals(AutoScalingService.INSTANCE_REQUIREMENTS_AND_INSTANCE_TYPE_MESSAGE, error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAutoScalingGroupRejectsVcpuDesiredCapacityTypeWhenInstanceTypesAreNamed() {
|
||||
AwsException error = assertThrows(AwsException.class, () -> service.createAutoScalingGroup(REGION,
|
||||
"fixed-type-vcpu-asg", null, "lt-original", null, "1", null,
|
||||
0, 3, 1, 300, List.of("us-east-1a"), List.of(), List.of(), List.of(), "EC2", 0,
|
||||
List.of("Default"), Map.of(), Map.of(),
|
||||
new AsgOptionalFields("vcpu", null, null, null)));
|
||||
|
||||
assertEquals("ValidationError", error.getErrorCode());
|
||||
assertEquals(AutoScalingService.DESIRED_CAPACITY_TYPE_NEEDS_INSTANCE_REQUIREMENTS_MESSAGE,
|
||||
error.getMessage());
|
||||
assertEquals(400, error.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAutoScalingGroupRejectsMemoryMibDesiredCapacityTypeForOverridesNamingInstanceTypes() {
|
||||
MixedInstancesPolicy.LaunchTemplateOverride override = new MixedInstancesPolicy.LaunchTemplateOverride();
|
||||
override.setInstanceType("m6i.large");
|
||||
|
||||
AwsException error = assertThrows(AwsException.class, () -> service.createAutoScalingGroup(REGION,
|
||||
"named-override-memory-asg", null, null, null, null, policyWithOverrides(List.of(override)),
|
||||
0, 3, 1, 300, List.of("us-east-1a"), List.of(), List.of(), List.of(), "EC2", 0,
|
||||
List.of("Default"), Map.of(), Map.of(),
|
||||
new AsgOptionalFields("memory-mib", null, null, null)));
|
||||
|
||||
assertEquals(AutoScalingService.DESIRED_CAPACITY_TYPE_NEEDS_INSTANCE_REQUIREMENTS_MESSAGE,
|
||||
error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAutoScalingGroupAcceptsUnitsDesiredCapacityTypeWithoutInstanceRequirements() {
|
||||
service.createAutoScalingGroup(REGION, "units-asg", null, "lt-original", null, "1", null,
|
||||
0, 3, 1, 300, List.of("us-east-1a"), List.of(), List.of(), List.of(), "EC2", 0,
|
||||
List.of("Default"), Map.of(), Map.of(),
|
||||
new AsgOptionalFields("units", null, null, null));
|
||||
|
||||
assertEquals("units", service.describeAutoScalingGroups(REGION, List.of("units-asg"))
|
||||
.getFirst().getDesiredCapacityType());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAutoScalingGroupRejectsVcpuDesiredCapacityTypeWhenInstanceTypesAreNamed() {
|
||||
AwsException error = assertThrows(AwsException.class, () -> service.updateAutoScalingGroup(REGION,
|
||||
"test-asg", null, null, null, null, null,
|
||||
null, null, null, null, null, null, null, null, null,
|
||||
new AsgOptionalFields("vcpu", null, null, null)));
|
||||
|
||||
assertEquals(AutoScalingService.DESIRED_CAPACITY_TYPE_NEEDS_INSTANCE_REQUIREMENTS_MESSAGE,
|
||||
error.getMessage());
|
||||
assertNull(service.describeAutoScalingGroups(REGION, List.of("test-asg"))
|
||||
.getFirst().getDesiredCapacityType());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAutoScalingGroupAcceptsVcpuWhenTheSameRequestSuppliesInstanceRequirements() {
|
||||
service.updateAutoScalingGroup(REGION, "test-asg", null, null, null, null,
|
||||
attributeBasedPolicy(4, 8192),
|
||||
null, null, null, null, null, null, null, null, null,
|
||||
new AsgOptionalFields("vcpu", null, null, null));
|
||||
|
||||
assertEquals("vcpu", service.describeAutoScalingGroups(REGION, List.of("test-asg"))
|
||||
.getFirst().getDesiredCapacityType());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAutoScalingGroupRejectsDroppingInstanceRequirementsWhileVcpuStaysInEffect() {
|
||||
service.createAutoScalingGroup(REGION, "drop-requirements-asg", null, null, null, null,
|
||||
attributeBasedPolicy(2, 2048),
|
||||
0, 3, 1, 300, List.of("us-east-1a"), List.of(), List.of(), List.of(), "EC2", 0,
|
||||
List.of("Default"), Map.of(), Map.of(),
|
||||
new AsgOptionalFields("vcpu", null, null, null));
|
||||
|
||||
AwsException error = assertThrows(AwsException.class, () -> service.updateAutoScalingGroup(REGION,
|
||||
"drop-requirements-asg", null, "lt-replacement", null, "1", null,
|
||||
null, null, null, null, null, null, null, null, null,
|
||||
AsgOptionalFields.none()));
|
||||
|
||||
assertEquals(AutoScalingService.DESIRED_CAPACITY_TYPE_NEEDS_INSTANCE_REQUIREMENTS_MESSAGE,
|
||||
error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAutoScalingGroupRejectsAnOverrideMissingMemoryMiB() {
|
||||
MixedInstancesPolicy.InstanceRequirements requirements = new MixedInstancesPolicy.InstanceRequirements();
|
||||
requirements.setVCpuCount(intRange(2));
|
||||
MixedInstancesPolicy.LaunchTemplateOverride override = new MixedInstancesPolicy.LaunchTemplateOverride();
|
||||
override.setInstanceRequirements(requirements);
|
||||
|
||||
AwsException error = assertThrows(AwsException.class, () -> service.createAutoScalingGroup(REGION,
|
||||
"partial-requirements-asg", null, null, null, null, policyWithOverrides(List.of(override)),
|
||||
0, 3, 1, 300, List.of("us-east-1a"), List.of(), List.of(), List.of(), "EC2", 0,
|
||||
List.of("Default"), Map.of(), Map.of(), AsgOptionalFields.none()));
|
||||
|
||||
assertEquals("ValidationError", error.getErrorCode());
|
||||
assertEquals(AutoScalingService.INSTANCE_REQUIREMENTS_MISSING_RANGES_MESSAGE, error.getMessage());
|
||||
assertEquals(400, error.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAutoScalingGroupRejectsAnOverrideMissingVCpuCount() {
|
||||
MixedInstancesPolicy.InstanceRequirements requirements = new MixedInstancesPolicy.InstanceRequirements();
|
||||
requirements.setMemoryMiB(intRange(2048));
|
||||
MixedInstancesPolicy.LaunchTemplateOverride override = new MixedInstancesPolicy.LaunchTemplateOverride();
|
||||
override.setInstanceRequirements(requirements);
|
||||
|
||||
AwsException error = assertThrows(AwsException.class, () -> service.updateAutoScalingGroup(REGION,
|
||||
"test-asg", null, null, null, null, policyWithOverrides(List.of(override)),
|
||||
null, null, null, null, null, null, null, null, null, AsgOptionalFields.none()));
|
||||
|
||||
assertEquals(AutoScalingService.INSTANCE_REQUIREMENTS_MISSING_RANGES_MESSAGE, error.getMessage());
|
||||
}
|
||||
|
||||
private static MixedInstancesPolicy attributeBasedPolicy(int minVCpuCount, int minMemoryMiB) {
|
||||
MixedInstancesPolicy.InstanceRequirements requirements = new MixedInstancesPolicy.InstanceRequirements();
|
||||
requirements.setVCpuCount(intRange(minVCpuCount));
|
||||
requirements.setMemoryMiB(intRange(minMemoryMiB));
|
||||
MixedInstancesPolicy.LaunchTemplateOverride override = new MixedInstancesPolicy.LaunchTemplateOverride();
|
||||
override.setInstanceRequirements(requirements);
|
||||
return policyWithOverrides(List.of(override));
|
||||
}
|
||||
|
||||
private static MixedInstancesPolicy policyWithOverrides(
|
||||
List<MixedInstancesPolicy.LaunchTemplateOverride> overrides) {
|
||||
MixedInstancesPolicy.LaunchTemplateSpecification specification =
|
||||
new MixedInstancesPolicy.LaunchTemplateSpecification();
|
||||
specification.setLaunchTemplateId("lt-original");
|
||||
MixedInstancesPolicy.LaunchTemplate launchTemplate = new MixedInstancesPolicy.LaunchTemplate();
|
||||
launchTemplate.setLaunchTemplateSpecification(specification);
|
||||
launchTemplate.setOverrides(overrides);
|
||||
MixedInstancesPolicy policy = new MixedInstancesPolicy();
|
||||
policy.setLaunchTemplate(launchTemplate);
|
||||
return policy;
|
||||
}
|
||||
|
||||
private static MixedInstancesPolicy.IntRange intRange(int min) {
|
||||
MixedInstancesPolicy.IntRange range = new MixedInstancesPolicy.IntRange();
|
||||
range.setMin(min);
|
||||
return range;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user