fix(rds): list Aurora engines in DescribeOrderableDBInstanceOptions (#5585)

* fix(rds): list Aurora engines in DescribeOrderableDBInstanceOptions

DescribeOrderableDBInstanceOptions returned nothing for aurora-mysql or
aurora-postgresql, so clients that pick an instance class from the
orderable list could not create Aurora cluster instances. Add the
default Aurora MySQL (8.0.mysql_aurora.3.05.2) and Aurora PostgreSQL
(16.3) versions with db.t3.medium, db.t4g.medium, db.r5.large and
db.r6g.large.

* fix(ec2): honour block-device-mapping.volume-type in DescribeImages

The filter fell through to the default case and matched every image.
Registered images now match on any block device mapping's EBS volume
type, mirroring block-device-mapping.snapshot-id. Catalog images model
no block devices, so an optional rootVolumeType catalog field carries
the type where the AMI name states it (gp2 for the Amazon Linux 2
image, gp3 for the hvm-ssd-gp3 Ubuntu images); images without it match
no value. DescribeImages output is unchanged.

* fix(rds): report general-public-license for aurora-mysql orderable options

* fix(ec2): carry catalog root volume type into the image's EBS mapping

* fix(ec2,rds): address review on catalog AMI mappings and Aurora default version

- Catalog AMI root mappings no longer advertise an invented SnapshotId that
  DescribeSnapshots cannot resolve (EbsBlockDevice.SnapshotId is optional);
  a copy or capture still mints a real root snapshot.
- RunInstances sizes the root volume type from the AMI's root mapping,
  falling back to gp3, so the gp2 catalog AMI launches a gp2 root.
- aurora-mysql defaults to 8.0.mysql_aurora.3.05.2, the version
  DescribeOrderableDBInstanceOptions lists.

* test(ec2): assert the volume-type filter, not a single gp2 volume

Instances launched earlier in the class now get gp2 roots from the gp2
catalog AMI, so filtering on gp2 returns several volumes. Check every
result is gp2 and the created volume is among them.

* test(rds): read EngineVersion with XmlPath, import RequestSpecification

* fix(ec2): honour a RunInstances root BlockDeviceMapping volume type

A request BlockDeviceMapping naming the AMI's root device overrides the
AMI's root VolumeType, as on AWS; previously the launch always took the
AMI mapping, so a gp3 root on the gp2 Amazon Linux 2 AMI came out gp2.

* test: explicit RequestSpecification type in Ec2IntegrationTest (NoVar checkstyle rule)

* refactor(ec2): fold RunInstances BlockDeviceMappings into the placement overload

Adds the mappings parameter to the existing hostId/tenancy overload
instead of a new one, and updates the two callers that named that
signature: Ec2RunInstancesPublicIpParamTest's stub/verify (whose
unmatched stub returned null and NPE'd the handler) and the
dedicated-host race test.

* fix(ec2): apply launch template block device mappings and capture the real root type

RunInstances and CreateFleet now layer the request's BlockDeviceMappings
over the launch template's (a request entry for a device replaces the
template's), so a template asking for a gp3 root is honoured instead of
the AMI's gp2. CreateImage records the instance's actual root volume type
on the new AMI's root mapping rather than the source AMI's.

A mapping naming a VolumeType outside the model's enum (standard, io1,
io2, gp2, sc1, st1, gp3) is rejected with the same InvalidParameterValue
ModifyVolume returns, through one shared check.

The RunInstances-only parser is gone: request mappings are read by the
launch template parser, which already treats every member as optional.

* test(rds): fold the Aurora default-version orderable check into RdsCatalogueReadIntegrationTest

* fix(autoscaling): launch group instances with the template's block device mappings

Auto Scaling scale-out now hands the launch template's BlockDeviceMappings
to runInstances, as RunInstances and CreateFleet do, so a group launched
from a template that asks for a gp3 root gets a gp3 root instead of the
AMI's type. Mixed-instances templates take the same path; launch
configurations pass none.

* test(ec2): template devices the request does not name still apply

Covers a launch whose request maps only a data device: the template's
root mapping still sets the root volume type. Also covers a template
naming an unknown VolumeType, which CreateLaunchTemplate stores and the
launch rejects; the EC2 docs paragraph now says so and is rewrapped to
the file's width.

* fix(ec2): merge launch template block device mappings field by field

EC2 documents template block device overrides per member: a request entry
for a DeviceName the template maps changes only what it sets, and every
other member keeps the template's value. The merge replaced the whole
entry, so a request that only resized the root dropped a template's gp3.
The merged entry is now built from a copy of the template's, overlaid
member by member, leaving the stored template untouched.
This commit is contained in:
Allen Sanborn authored and GitHub committed 2026-10-14 15:02:53 -04:00
1 parent 804335d071
commit 025af9d215
21 files changed
+632 -45

No files matched your search

+11
View File
@@ -677,6 +677,17 @@ These members of `RequestLaunchTemplateData` are stored and read back unchanged
Within `NetworkInterfaces`, `ConnectionTrackingSpecification` is stored and read back with all
three of its timeout members.
At launch, `RunInstances` and `CreateFleet` apply the template's `BlockDeviceMappings` under the
request's, field by field: a request entry for a `DeviceName` the template maps changes only the
members it sets, and the rest keep the template's values; devices only one side maps apply as
given. An Auto Scaling group launching from a template gets the template's mappings the same
way. The root volume's type comes from the mapping for the AMI's root device, else from the
AMI's own root mapping, else `gp3`, and `CreateImage` records that type on the new AMI's root
mapping. A mapping naming a `VolumeType` outside the service model's enum fails with
`InvalidParameterValue`, as `ModifyVolume` does. Template versions are not checked when they are
stored, so a template naming an unknown `VolumeType` is accepted by `CreateLaunchTemplate` and
fails at launch.
Both blocks are validated by `CreateLaunchTemplate` and `CreateLaunchTemplateVersion` before
anything is stored. An `InstanceRequirements` block must carry `VCpuCount` and `MemoryMiB`, each
with its `Min`, which the service model declares required; a request missing either fails with
@@ -11,6 +11,7 @@ import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.github.hectorvent.floci.services.ec2.Ec2UserDataDecoder;
import io.github.hectorvent.floci.services.ec2.model.Instance;
import io.github.hectorvent.floci.services.ec2.model.LaunchTemplate;
import io.github.hectorvent.floci.services.ec2.model.LaunchTemplateData;
import io.github.hectorvent.floci.services.ec2.model.Reservation;
import io.github.hectorvent.floci.services.ec2.model.Subnet;
import io.github.hectorvent.floci.services.elb.ElbClassicService;
@@ -375,7 +376,8 @@ public class AutoScalingReconciler {
launchSource.iamInstanceProfile(),
launchSource.associatePublicIpAddress(), null, 0, null, null, null,
launchSource.encodedUserData() != null ? launchSource.encodedUserData()
: encodeLegacyUserData(launchSource.userData()));
: encodeLegacyUserData(launchSource.userData()),
false, null, null, launchSource.blockDeviceMappings());
for (Instance ec2Inst : reservation.getInstances()) {
AsgInstance asgInst = new AsgInstance();
@@ -695,7 +697,8 @@ public class AutoScalingReconciler {
// Forwarded as-is: an explicit false has to beat a public
// subnet's MapPublicIpOnLaunch, and only null means
// "fall back to the subnet default".
lc.getAssociatePublicIpAddress());
lc.getAssociatePublicIpAddress(),
null);
}
LaunchTemplate launchTemplate = resolveLaunchTemplate(asg);
@@ -723,7 +726,8 @@ public class AutoScalingReconciler {
asg.getLaunchTemplateId(),
asg.getLaunchTemplateName(),
resolvedVersion,
null);
null,
version.getData().getBlockDeviceMappings());
}
MixedInstancesPolicy.LaunchTemplateSpecification specification =
@@ -757,7 +761,8 @@ public class AutoScalingReconciler {
: specification.getLaunchTemplateId(),
specification.getLaunchTemplateName(),
resolvedVersion,
null);
null,
version.getData().getBlockDeviceMappings());
}
}
@@ -868,7 +873,8 @@ public class AutoScalingReconciler {
String launchTemplateId,
String launchTemplateName,
String launchTemplateVersion,
Boolean associatePublicIpAddress) {}
Boolean associatePublicIpAddress,
List<LaunchTemplateData.BlockDeviceMapping> blockDeviceMappings) {}
// Override for describeAutoScalingGroups with null region (all regions)
// The service only filters by region when non-null; null means all.
@@ -4,6 +4,8 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.ec2.model.BlockDeviceMapping;
import io.github.hectorvent.floci.services.ec2.model.EbsBlockDevice;
import io.github.hectorvent.floci.services.ec2.model.Image;
import io.github.hectorvent.floci.services.eks.EksClusterManager;
import io.quarkus.runtime.annotations.RegisterForReflection;
@@ -203,6 +205,8 @@ public class Ec2ImageCatalog {
public String architecture;
public String rootDeviceType;
public String rootDeviceName;
/** Root EBS volume type, set only where the AMI name states it; answers block-device-mapping.volume-type. */
public String rootVolumeType;
public String virtualizationType;
public String hypervisor;
public String platform;
@@ -330,6 +334,20 @@ public class Ec2ImageCatalog {
image.setImageOwnerAlias(imageOwnerAlias);
}
image.setCreationDate(creationDate);
if (rootVolumeType != null) {
// Same value the volume-type filter matches on, so the returned image shows
// the mapping it was selected by and a CopyImage keeps that type.
EbsBlockDevice ebs = new EbsBlockDevice();
// No SnapshotId: it is optional in EbsBlockDevice, and an invented one would not
// resolve through DescribeSnapshots.
ebs.setVolumeSize(8);
ebs.setVolumeType(rootVolumeType);
ebs.setDeleteOnTermination(true);
BlockDeviceMapping mapping = new BlockDeviceMapping();
mapping.setDeviceName(image.getRootDeviceName());
mapping.setEbs(ebs);
image.setBlockDeviceMappings(List.of(mapping));
}
return image;
}
}
@@ -793,9 +793,14 @@ public class Ec2QueryHandler {
LaunchTemplateData.MetadataOptions metadataOptions = parseMetadataOptions(p, "MetadataOptions.");
String creditSpecificationCpuCredits = p.getFirst("CreditSpecification.CpuCredits");
List<LaunchTemplateData.BlockDeviceMapping> blockDeviceMappings =
parseLaunchTemplateBlockDeviceMappings(p, "");
LaunchTemplateData launchTemplateData = resolveRunInstancesLaunchTemplateData(
p, region, userDataEncoded == null || userDataEncoded.isBlank());
if (launchTemplateData != null) {
blockDeviceMappings = LaunchTemplateData.BlockDeviceMapping.merge(
launchTemplateData.getBlockDeviceMappings(), blockDeviceMappings);
if (launchTemplateData.getMetadataOptions() != null) {
metadataOptions = LaunchTemplateData.MetadataOptions.merge(
launchTemplateData.getMetadataOptions(), metadataOptions);
@@ -829,7 +834,7 @@ public class Ec2QueryHandler {
keyName, sgIds, subnetId, clientToken, instanceTags, userData, iamInstanceProfileArn,
associatePublicIp, networkInterfaceId, networkInterfaceDeviceIndex, null, metadataOptions,
creditSpecificationCpuCredits, userDataEncoded, Boolean.parseBoolean(p.getFirst("DryRun")),
p.getFirst("Placement.HostId"), p.getFirst("Placement.Tenancy"));
p.getFirst("Placement.HostId"), p.getFirst("Placement.Tenancy"), blockDeviceMappings);
if (!networkInterfaceTags.isEmpty()) {
List<String> eniIds = new ArrayList<>();
@@ -953,7 +958,8 @@ public class Ec2QueryHandler {
null,
null,
0,
launch.availabilityZone(), null, null, launch.encodedUserData());
launch.availabilityZone(), null, null, launch.encodedUserData(), false,
null, null, launch.blockDeviceMappings());
Instance instance = reservation.getInstances().get(0);
launchedInstanceIds.add(instance.getInstanceId());
results.add(new FleetLaunchResult(instance, launch));
@@ -1111,7 +1117,8 @@ public class Ec2QueryHandler {
template.getEncodedUserData(),
service.iamInstanceProfileArn(template),
template.effectiveSecurityGroupIds(),
new ArrayList<>(tags.values()));
new ArrayList<>(tags.values()),
template.getBlockDeviceMappings());
}
/**
@@ -1156,7 +1163,8 @@ public class Ec2QueryHandler {
private record FleetLaunch(String launchTemplateId, String launchTemplateName, String launchTemplateVersion,
String instanceType, String imageId, String subnetId, String availabilityZone,
String keyName, String userData, String encodedUserData, String iamInstanceProfileArn,
List<String> securityGroupIds, List<Tag> instanceTags) {}
List<String> securityGroupIds, List<Tag> instanceTags,
List<LaunchTemplateData.BlockDeviceMapping> blockDeviceMappings) {}
private record FleetLaunchKey(String launchTemplateId, String launchTemplateName, String launchTemplateVersion,
String instanceType, String imageId, String subnetId, String availabilityZone) {
@@ -5706,7 +5714,8 @@ public class Ec2QueryHandler {
MultivaluedMap<String, String> p, String prefix) {
List<LaunchTemplateData.BlockDeviceMapping> mappings = new ArrayList<>();
for (int i = 1; ; i++) {
String base = prefix + ".BlockDeviceMapping." + i;
// An empty prefix reads RunInstances' own top-level BlockDeviceMapping.N members.
String base = (prefix.isEmpty() ? "" : prefix + ".") + "BlockDeviceMapping." + i;
if (!anyParamStartsWith(p, base + ".")) {
break;
}
@@ -3241,13 +3241,16 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
return runInstances(region, imageId, instanceType, minCount, maxCount, keyName,
securityGroupIds, subnetId, clientToken, instanceTags, userData, iamInstanceProfileArn,
associatePublicIp, networkInterfaceId, networkInterfaceDeviceIndex, availabilityZone,
metadataOptions, creditSpecificationCpuCredits, encodedUserData, dryRun, null, null);
metadataOptions, creditSpecificationCpuCredits, encodedUserData, dryRun, null, null, null);
}
/**
* @param hostId Placement.HostId: the Dedicated Host to launch onto. It must exist and not be
* released; with no subnet or zone named, the launch lands in the host's zone.
* @param tenancy Placement.Tenancy; defaults to {@code host} when a host is named.
* @param blockDeviceMappings the launch's BlockDeviceMappings (request merged over launch
* template), or null. An entry naming the AMI's root device
* overrides the root volume type, as on AWS.
*/
public Reservation runInstances(String region, String imageId, String instanceType,
int minCount, int maxCount, String keyName,
@@ -3258,7 +3261,8 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
int networkInterfaceDeviceIndex, String availabilityZone,
LaunchTemplateData.MetadataOptions metadataOptions,
String creditSpecificationCpuCredits, String encodedUserData, boolean dryRun,
String hostId, String tenancy) {
String hostId, String tenancy,
List<LaunchTemplateData.BlockDeviceMapping> blockDeviceMappings) {
if (hostId != null && !hostId.isBlank()) {
Host host = getRequiredAvailableHost(region, hostId);
if ((availabilityZone == null || availabilityZone.isBlank())
@@ -3355,6 +3359,12 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
validateArchitectureCompatibility(region, imageId, effectiveInstanceType);
int count = Math.min(maxCount, Math.max(minCount, 1));
String architecture = architectureFor(region, imageId, effectiveInstanceType);
if (blockDeviceMappings != null) {
blockDeviceMappings.stream()
.filter(m -> m.getEbs() != null && m.getEbs().getVolumeType() != null)
.forEach(m -> requireValidVolumeType(m.getEbs().getVolumeType()));
}
String rootVolumeType = rootVolumeTypeFor(findImageForCapture(region, imageId), blockDeviceMappings);
List<Instance> launched = new ArrayList<>();
// Resolving the AMI, building the instances that depend on it and publishing them is one
// step. A DeregisterImage releases the captured layer only when no live instance resolves
@@ -3489,7 +3499,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
Volume rootVol = new Volume();
rootVol.setVolumeId(rootVolId);
rootVol.setAvailabilityZone(az);
rootVol.setVolumeType(DEFAULT_ROOT_VOLUME_TYPE);
rootVol.setVolumeType(rootVolumeType);
rootVol.setSize(DEFAULT_ROOT_VOLUME_SIZE_GIB);
rootVol.setState("in-use");
rootVol.setRegion(region);
@@ -6722,6 +6732,16 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
private List<BlockDeviceMapping> captureBlockDeviceMappings(String region, Instance source,
Image sourceImage) {
List<BlockDeviceMapping> mappings = new ArrayList<>(sourceImageMappings(sourceImage));
// The root is captured from the volume the instance actually has, which a launch mapping
// may have given a different type from the source AMI's.
Volume rootVolume = source.getRootVolumeId() == null ? null
: volumes.get(key(region, source.getRootVolumeId())).orElse(null);
if (rootVolume != null && sourceImage != null) {
mappings.stream()
.filter(m -> m.getEbs() != null
&& Objects.equals(m.getDeviceName(), sourceImage.getRootDeviceName()))
.forEach(m -> m.getEbs().setVolumeType(rootVolume.getVolumeType()));
}
Set<String> devices = mappings.stream()
.map(BlockDeviceMapping::getDeviceName)
.filter(Objects::nonNull)
@@ -6766,7 +6786,9 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
}
List<BlockDeviceMapping> declared = sourceImage.getBlockDeviceMappings();
if (declared != null && !declared.isEmpty()) {
return declared.stream().map(this::recapture).toList();
return declared.stream()
.map(m -> recapture(m, Objects.equals(m.getDeviceName(), sourceImage.getRootDeviceName())))
.toList();
}
String rootDeviceName = sourceImage.getRootDeviceName();
if (rootDeviceName == null || rootDeviceName.isBlank()) {
@@ -6788,7 +6810,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
* would leave two images sharing one snapshot, so deleting either would appear to take the
* other's backing with it.
*/
private BlockDeviceMapping recapture(BlockDeviceMapping source) {
private BlockDeviceMapping recapture(BlockDeviceMapping source, boolean root) {
BlockDeviceMapping mapping = new BlockDeviceMapping();
mapping.setDeviceName(source.getDeviceName());
EbsBlockDevice sourceEbs = source.getEbs();
@@ -6796,7 +6818,9 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
return mapping;
}
EbsBlockDevice ebs = new EbsBlockDevice();
ebs.setSnapshotId(sourceEbs.getSnapshotId() != null ? "snap-" + randomHex(17) : null);
// A catalog AMI's root mapping carries no SnapshotId (there is no snapshot record behind
// it), but the root of a copy or capture is always a snapshot.
ebs.setSnapshotId(sourceEbs.getSnapshotId() != null || root ? "snap-" + randomHex(17) : null);
ebs.setVolumeSize(sourceEbs.getVolumeSize());
ebs.setVolumeType(sourceEbs.getVolumeType());
ebs.setDeleteOnTermination(sourceEbs.getDeleteOnTermination());
@@ -6805,6 +6829,33 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
return mapping;
}
/**
* The root volume takes the type a request mapping for the AMI's root device names, else the
* type the AMI's root mapping declares, as on AWS.
*/
private static String rootVolumeTypeFor(Image image,
List<LaunchTemplateData.BlockDeviceMapping> requestMappings) {
String rootDeviceName = image != null && image.getRootDeviceName() != null
? image.getRootDeviceName() : new Instance().getRootDeviceName();
if (requestMappings != null) {
for (LaunchTemplateData.BlockDeviceMapping m : requestMappings) {
if (m.getEbs() != null && m.getEbs().getVolumeType() != null
&& Objects.equals(m.getDeviceName(), rootDeviceName)) {
return m.getEbs().getVolumeType();
}
}
}
if (image == null || image.getBlockDeviceMappings() == null) {
return DEFAULT_ROOT_VOLUME_TYPE;
}
return image.getBlockDeviceMappings().stream()
.filter(m -> m.getEbs() != null && m.getEbs().getVolumeType() != null
&& Objects.equals(m.getDeviceName(), image.getRootDeviceName()))
.map(m -> m.getEbs().getVolumeType())
.findFirst()
.orElse(DEFAULT_ROOT_VOLUME_TYPE);
}
/** The image a CreateImage source was launched from, whether catalog-backed or registered. */
private Image findImageForCapture(String region, String imageId) {
if (imageId == null || imageId.isBlank()) {
@@ -7611,6 +7662,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
}
return switch (name) {
case "architecture" -> matchesFilterValue(values, image.getArchitecture());
case "block-device-mapping.volume-type" -> matchesFilterValue(values, catalogImage.rootVolumeType);
case "hypervisor" -> matchesFilterValue(values, image.getHypervisor());
case "image-id" -> catalogImage.idsAndAliases().stream().anyMatch(id -> matchesFilterValue(values, id));
case "image-type" -> matchesFilterValue(values, "machine");
@@ -7687,6 +7739,11 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
.filter(Objects::nonNull)
.map(EbsBlockDevice::getSnapshotId)
.anyMatch(snapshotId -> matchesFilterValue(values, snapshotId));
case "block-device-mapping.volume-type" -> image.getBlockDeviceMappings().stream()
.map(BlockDeviceMapping::getEbs)
.filter(Objects::nonNull)
.map(EbsBlockDevice::getVolumeType)
.anyMatch(volumeType -> matchesFilterValue(values, volumeType));
case "description" -> matchesFilterValue(values, image.getDescription());
case "hypervisor" -> matchesFilterValue(values, image.getHypervisor());
case "image-id" -> matchesFilterValue(values, image.getImageId());
@@ -10282,6 +10339,13 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
return false;
}
private static void requireValidVolumeType(String volumeType) {
if (!VALID_VOLUME_TYPES.contains(volumeType)) {
throw new AwsException("InvalidParameterValue",
"Value (" + volumeType + ") for parameter volumeType is invalid. Unknown volume type.", 400);
}
}
public VolumeModification modifyVolume(String region, String volumeId, Integer size,
String volumeType, Integer iops, Integer throughput,
Boolean multiAttachEnabled, boolean dryRun) {
@@ -10302,9 +10366,8 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
}
String targetVolumeType = volumeType != null ? volumeType : volume.getVolumeType();
if (volumeType != null && !VALID_VOLUME_TYPES.contains(volumeType)) {
throw new AwsException("InvalidParameterValue",
"Value (" + volumeType + ") for parameter volumeType is invalid. Unknown volume type.", 400);
if (volumeType != null) {
requireValidVolumeType(volumeType);
}
if (throughput != null && !"gp3".equals(targetVolumeType)) {
@@ -6,7 +6,9 @@ import com.fasterxml.jackson.annotation.JsonSetter;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* The subset of EC2 {@code RequestLaunchTemplateData} / {@code ResponseLaunchTemplateData} that
@@ -387,6 +389,28 @@ public class LaunchTemplateData {
public Ebs getEbs() { return ebs; }
public void setEbs(Ebs ebs) { this.ebs = ebs; }
/**
* A launch's mappings, as EC2 documents template overrides: a request entry for a device the
* template maps changes only the members it sets, and every other device keeps its own
* entry. The template's stored entries are never modified.
*/
public static List<BlockDeviceMapping> merge(List<BlockDeviceMapping> template,
List<BlockDeviceMapping> request) {
Map<String, BlockDeviceMapping> byDevice = new LinkedHashMap<>();
template.forEach(m -> byDevice.put(m.deviceName, m));
request.forEach(m -> byDevice.merge(m.deviceName, m, BlockDeviceMapping::overlaid));
return new ArrayList<>(byDevice.values());
}
private static BlockDeviceMapping overlaid(BlockDeviceMapping base, BlockDeviceMapping override) {
BlockDeviceMapping merged = new BlockDeviceMapping();
merged.deviceName = base.deviceName;
merged.virtualName = override.virtualName != null ? override.virtualName : base.virtualName;
merged.noDevice = override.noDevice != null ? override.noDevice : base.noDevice;
merged.ebs = Ebs.overlaid(base.ebs, override.ebs);
return merged;
}
}
@RegisterForReflection
@@ -424,6 +448,23 @@ public class LaunchTemplateData {
public Integer getThroughput() { return throughput; }
public void setThroughput(Integer throughput) { this.throughput = throughput; }
private static Ebs overlaid(Ebs base, Ebs override) {
if (base == null || override == null) {
return override != null ? override : base;
}
Ebs merged = new Ebs();
merged.encrypted = override.encrypted != null ? override.encrypted : base.encrypted;
merged.deleteOnTermination = override.deleteOnTermination != null
? override.deleteOnTermination : base.deleteOnTermination;
merged.iops = override.iops != null ? override.iops : base.iops;
merged.kmsKeyId = override.kmsKeyId != null ? override.kmsKeyId : base.kmsKeyId;
merged.snapshotId = override.snapshotId != null ? override.snapshotId : base.snapshotId;
merged.volumeSize = override.volumeSize != null ? override.volumeSize : base.volumeSize;
merged.volumeType = override.volumeType != null ? override.volumeType : base.volumeType;
merged.throughput = override.throughput != null ? override.throughput : base.throughput;
return merged;
}
}
@RegisterForReflection
@@ -26,6 +26,8 @@ final class RdsEngineCatalog {
}
private static final List<String> PROVISIONED = List.of("provisioned");
private static final List<String> AURORA_CLASSES =
List.of("db.t3.medium", "db.t4g.medium", "db.r5.large", "db.r6g.large");
static final List<EngineVersion> VERSIONS = List.of(
postgres("13.20", "13", false, List.of()),
@@ -51,11 +53,11 @@ final class RdsEngineCatalog {
new EngineVersion("aurora-postgresql", "15.12", "15", "aurora-postgresql15",
"Aurora (PostgreSQL)", false, List.of(), PROVISIONED),
new EngineVersion("aurora-postgresql", "16.3", "16", "aurora-postgresql16",
"Aurora (PostgreSQL)", true, List.of(), PROVISIONED),
"Aurora (PostgreSQL)", true, AURORA_CLASSES, PROVISIONED),
new EngineVersion("aurora-postgresql", "17.4", "17", "aurora-postgresql17",
"Aurora (PostgreSQL)", false, List.of(), PROVISIONED),
new EngineVersion("aurora-mysql", "8.0.mysql_aurora.3.05.2", "8.0", "aurora-mysql8.0",
"Aurora MySQL", true, List.of(), PROVISIONED),
"Aurora MySQL", true, AURORA_CLASSES, PROVISIONED),
new EngineVersion("aurora-mysql", "8.0.mysql_aurora.3.08.0", "8.0", "aurora-mysql8.0",
"Aurora MySQL", false, List.of(), PROVISIONED));
@@ -912,6 +912,9 @@ public class RdsQueryHandler {
if (engine != null && engine.regionMatches(true, 0, "sqlserver", 0, 9)) {
return "license-included";
}
if (engine != null && engine.equalsIgnoreCase("aurora-mysql")) {
return "general-public-license";
}
return "postgresql-license";
}
@@ -11,6 +11,7 @@ images:
- /aws/service/eks/optimized-ami/{k8s-version}/amazon-linux-2/recommended/image_id
dockerImage: public.ecr.aws/amazonlinux/amazonlinux:2
name: amzn2-ami-hvm-2.0.20230404.0-x86_64-gp2
rootVolumeType: gp2
description: Amazon Linux 2 AMI
ownerId: "137112412989"
imageOwnerAlias: amazon
@@ -72,6 +73,7 @@ images:
- ami-ubuntu2404
dockerImage: public.ecr.aws/docker/library/ubuntu:24.04
name: ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-arm64-server-20260515
rootVolumeType: gp3
description: Canonical, Ubuntu, 24.04 LTS
ownerId: "099720109477"
imageOwnerAlias: canonical
@@ -81,6 +83,7 @@ images:
- imageId: ami-ubuntu2404-amd64
dockerImage: public.ecr.aws/docker/library/ubuntu:24.04
name: ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-server-20260515
rootVolumeType: gp3
description: Canonical, Ubuntu, 24.04 LTS
ownerId: "099720109477"
imageOwnerAlias: canonical
@@ -92,6 +95,7 @@ images:
- ami-ubuntu2404-cloud
dockerImage: floci/ami-ubuntu:24.04-arm64
name: ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-arm64-server-20260515
rootVolumeType: gp3
description: Canonical, Ubuntu, 24.04 LTS cloud image
ownerId: "099720109477"
imageOwnerAlias: canonical
@@ -67,7 +67,8 @@ class AutoScalingCapacitySuspensionTest {
when(ec2.describeLaunchTemplateVersions(eq(REGION), eq("lt-original"), isNull(), anyList()))
.thenReturn(List.of(template));
when(ec2.runInstances(eq(REGION), any(), any(), anyInt(), anyInt(), any(), anyList(), any(), any(),
anyList(), any(), any(), any(), isNull(), eq(0), isNull(), isNull(), isNull(), isNull()))
anyList(), any(), any(), any(), isNull(), eq(0), isNull(), isNull(), isNull(), isNull(),
anyBoolean(), isNull(), isNull(), any()))
.thenReturn(reservation("i-replacement"));
}
@@ -83,7 +84,8 @@ class AutoScalingCapacitySuspensionTest {
if (paused) {
verify(ec2, never()).terminateInstances(anyString(), anyList());
verify(ec2, never()).runInstances(eq(REGION), any(), any(), anyInt(), anyInt(), any(), anyList(),
any(), any(), anyList(), any(), any(), any(), isNull(), eq(0), isNull(), isNull(), isNull(), isNull());
any(), any(), anyList(), any(), any(), any(), isNull(), eq(0), isNull(), isNull(), isNull(), isNull(),
anyBoolean(), isNull(), isNull(), any());
assertEquals(List.of("i-original"), group.getInstances().stream()
.map(AsgInstance::getInstanceId).toList());
service.resumeProcesses(REGION, "suspended-group", processes);
@@ -94,7 +96,8 @@ class AutoScalingCapacitySuspensionTest {
verify(ec2).terminateInstances(REGION, List.of("i-original"));
} else {
verify(ec2).runInstances(eq(REGION), any(), any(), eq(1), eq(1), any(), anyList(),
any(), any(), anyList(), any(), any(), any(), isNull(), eq(0), isNull(), isNull(), isNull(), isNull());
any(), any(), anyList(), any(), any(), any(), isNull(), eq(0), isNull(), isNull(), isNull(), isNull(),
anyBoolean(), isNull(), isNull(), any());
}
}
@@ -161,7 +164,8 @@ class AutoScalingCapacitySuspensionTest {
clearInvocations(ec2);
reconciler.reconcile(group);
verify(ec2, never()).runInstances(eq(REGION), any(), any(), anyInt(), anyInt(), any(), anyList(),
any(), any(), anyList(), any(), any(), any(), isNull(), eq(0), isNull(), isNull(), isNull(), isNull());
any(), any(), anyList(), any(), any(), any(), isNull(), eq(0), isNull(), isNull(), isNull(), isNull(),
anyBoolean(), isNull(), isNull(), any());
verify(ec2, never()).terminateInstances(anyString(), anyList());
} finally {
releaseOperation.countDown();
@@ -183,7 +187,8 @@ class AutoScalingCapacitySuspensionTest {
clearInvocations(ec2);
reconciler.reconcile(group);
verify(ec2, never()).runInstances(eq(REGION), any(), any(), anyInt(), anyInt(), any(), anyList(),
any(), any(), anyList(), any(), any(), any(), isNull(), eq(0), isNull(), isNull(), isNull(), isNull());
any(), any(), anyList(), any(), any(), any(), isNull(), eq(0), isNull(), isNull(), isNull(), isNull(),
anyBoolean(), isNull(), isNull(), any());
if (recreate) {
assertTrue(service.describeAutoScalingGroups(REGION, List.of("suspended-group"))
.getFirst().getInstances().isEmpty());
@@ -28,6 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.anyList;
import static org.mockito.Mockito.anyString;
@@ -354,7 +355,8 @@ class AutoScalingPlacementTest {
return List.of(reservation);
});
when(ec2.runInstances(any(), any(), any(), anyInt(), anyInt(), any(), any(), any(), any(),
any(), any(), any(), any(), any(), anyInt(), any(), any(), any(), any())).thenAnswer(call -> {
any(), any(), any(), any(), any(), anyInt(), any(), any(), any(), any(),
anyBoolean(), any(), any(), any())).thenAnswer(call -> {
if (allocations >= failAfter) {
if (deleteOnFailure) {
groupPresent = false;
@@ -35,6 +35,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.anyList;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.doAnswer;
@@ -129,7 +130,8 @@ class AutoScalingReconcilerTest {
verify(service).saveAutoScalingGroupIfPresent(group);
verify(service).completeInstanceRefreshIfSettled("us-east-1", "bad-data");
verify(ec2, never()).runInstances(any(), any(), any(), any(Integer.class), any(Integer.class), any(),
any(), any(), any(), any(), any(), any(), any(), any(), any(Integer.class), any(), any(), any(), any());
any(), any(), any(), any(), any(), any(), any(), any(), any(Integer.class), any(), any(), any(), any(),
anyBoolean(), isNull(), isNull(), any());
}
static Stream<Arguments> templateUserData() {
@@ -190,7 +192,8 @@ class AutoScalingReconcilerTest {
eq(1), eq(1), eq(null), eq(List.of()), eq(null), eq(null),
anyList(), eq(expectedText),
eq("arn:aws:iam::000000000000:instance-profile/app-profile"), eq(null),
isNull(), eq(0), isNull(), isNull(), isNull(), eq(expectedEncoding))).thenReturn(reservation);
isNull(), eq(0), isNull(), isNull(), isNull(), eq(expectedEncoding),
anyBoolean(), isNull(), isNull(), any())).thenReturn(reservation);
reconciler.reconcile(asg);
@@ -203,7 +206,8 @@ class AutoScalingReconcilerTest {
eq(1), eq(1), eq(null), eq(List.of()), eq(null), eq(null),
tags.capture(), eq(expectedText),
eq("arn:aws:iam::000000000000:instance-profile/app-profile"), eq(null),
isNull(), eq(0), isNull(), isNull(), isNull(), eq(expectedEncoding));
isNull(), eq(0), isNull(), isNull(), isNull(), eq(expectedEncoding),
anyBoolean(), isNull(), isNull(), any());
assertEquals(storedText, version.getData().getUserData());
assertEquals(storedEncoding, version.getData().getEncodedUserData());
assertEquals(propagatedTags.size(), tags.getValue().size());
@@ -230,7 +234,8 @@ class AutoScalingReconcilerTest {
when(ec2Service.runInstances(eq("us-east-1"), eq("ami-version-1"), eq("t3.micro"),
eq(1), eq(1), eq(null), eq(List.of()), eq(null), eq(null), eq(List.of()),
eq(null), eq(null), eq(null),
isNull(), eq(0), isNull(), isNull(), isNull(), any())).thenReturn(reservation);
isNull(), eq(0), isNull(), isNull(), isNull(), any(),
anyBoolean(), isNull(), isNull(), any())).thenReturn(reservation);
reconciler.reconcile(asg);
@@ -238,6 +243,38 @@ class AutoScalingReconcilerTest {
verify(asgService, never()).completeInstanceRefreshIfSettled("us-east-1", "app-asg");
}
@Test
void scaleOutPassesTheLaunchTemplateBlockDeviceMappings() {
AutoScalingService asgService = scalingService();
Ec2Service ec2Service = mock(Ec2Service.class);
AutoScalingReconciler reconciler = new AutoScalingReconciler(asgService, ec2Service, mock(ElbV2Service.class));
AutoScalingGroup asg = launchTemplateAsg();
stubLaunchTemplate(ec2Service, "ami-version-1", "t3.micro");
LaunchTemplateData.Ebs ebs = new LaunchTemplateData.Ebs();
ebs.setVolumeType("gp3");
LaunchTemplateData.BlockDeviceMapping root = new LaunchTemplateData.BlockDeviceMapping();
root.setDeviceName("/dev/xvda");
root.setEbs(ebs);
ec2Service.describeLaunchTemplateVersions("us-east-1", "lt-123", null, List.of("1"))
.getFirst().getData().setBlockDeviceMappings(List.of(root));
when(asgService.saveAutoScalingGroupIfPresent(asg)).thenReturn(true);
Instance ec2Instance = new Instance();
ec2Instance.setInstanceId("i-gp3");
Reservation reservation = new Reservation();
reservation.setInstances(List.of(ec2Instance));
when(ec2Service.runInstances(any(), any(), any(), any(Integer.class), any(Integer.class), any(),
any(), any(), any(), any(), any(), any(), any(), any(), any(Integer.class), any(), any(), any(), any(),
anyBoolean(), any(), any(), any())).thenReturn(reservation);
reconciler.reconcile(asg);
ArgumentCaptor<List<LaunchTemplateData.BlockDeviceMapping>> mappings = ArgumentCaptor.captor();
verify(ec2Service).runInstances(any(), any(), any(), any(Integer.class), any(Integer.class), any(),
any(), any(), any(), any(), any(), any(), any(), any(), any(Integer.class), any(), any(), any(), any(),
anyBoolean(), any(), any(), mappings.capture());
assertEquals(List.of(root), mappings.getValue());
}
@Test
void scaleOutPersistsInstancesWhenGroupStillExists() {
AutoScalingService asgService = scalingService();
@@ -255,7 +292,8 @@ class AutoScalingReconcilerTest {
when(ec2Service.runInstances(eq("us-east-1"), eq("ami-version-1"), eq("t3.micro"),
eq(1), eq(1), eq(null), eq(List.of()), eq(null), eq(null), eq(List.of()),
eq(null), eq(null), eq(null),
isNull(), eq(0), isNull(), isNull(), isNull(), any())).thenReturn(reservation);
isNull(), eq(0), isNull(), isNull(), isNull(), any(),
anyBoolean(), isNull(), isNull(), any())).thenReturn(reservation);
reconciler.reconcile(asg);
@@ -300,14 +338,15 @@ class AutoScalingReconcilerTest {
when(ec2Service.runInstances(eq("us-east-1"), eq("ami-lc"), eq("t3.micro"),
eq(1), eq(1), eq(null), anyList(), eq(null), eq(null),
anyList(), eq(null), eq(null), eq(associatePublicIp),
isNull(), eq(0), isNull(), isNull(), isNull(), any())).thenReturn(reservation);
isNull(), eq(0), isNull(), isNull(), isNull(), any(),
anyBoolean(), isNull(), isNull(), any())).thenReturn(reservation);
reconciler.reconcile(asg);
verify(ec2Service).runInstances(eq("us-east-1"), eq("ami-lc"), eq("t3.micro"),
eq(1), eq(1), eq(null), anyList(), eq(null), eq(null),
anyList(), eq(null), eq(null), eq(associatePublicIp),
isNull(), eq(0), isNull(), isNull(), isNull(), any());
isNull(), eq(0), isNull(), isNull(), isNull(), any(), anyBoolean(), isNull(), isNull(), any());
}
@Test
@@ -341,7 +380,8 @@ class AutoScalingReconcilerTest {
when(ec2Service.runInstances(eq("us-east-1"), eq("ami-version-7"), eq("t3.micro"),
eq(1), eq(1), eq(null), eq(List.of()), eq(null), eq(null),
eq(List.of()), eq(null), eq(null), eq(null),
isNull(), eq(0), isNull(), isNull(), isNull(), any())).thenReturn(reservation);
isNull(), eq(0), isNull(), isNull(), isNull(), any(),
anyBoolean(), isNull(), isNull(), any())).thenReturn(reservation);
reconciler.reconcile(asg);
@@ -393,7 +433,8 @@ class AutoScalingReconcilerTest {
when(ec2Service.runInstances(eq("us-east-1"), eq("ami-version-3"), eq("t3.small"),
eq(1), eq(1), eq(null), eq(List.of()), eq(null), eq(null),
eq(List.of()), eq("#!/bin/bash\necho hi\n"), eq(null), eq(null),
isNull(), eq(0), isNull(), isNull(), isNull(), any())).thenReturn(reservation);
isNull(), eq(0), isNull(), isNull(), isNull(), any(),
anyBoolean(), isNull(), isNull(), any())).thenReturn(reservation);
reconciler.reconcile(asg);
@@ -405,7 +446,7 @@ class AutoScalingReconcilerTest {
verify(ec2Service).runInstances(eq("us-east-1"), eq("ami-version-3"), eq("t3.small"),
eq(1), eq(1), eq(null), eq(List.of()), eq(null), eq(null),
eq(List.of()), eq("#!/bin/bash\necho hi\n"), eq(null), eq(null),
isNull(), eq(0), isNull(), isNull(), isNull(), any());
isNull(), eq(0), isNull(), isNull(), isNull(), any(), anyBoolean(), isNull(), isNull(), any());
assertNull(version.getData().getUserData());
}
@@ -477,7 +518,11 @@ class AutoScalingReconcilerTest {
org.mockito.ArgumentMatchers.any(),
org.mockito.ArgumentMatchers.any(),
org.mockito.ArgumentMatchers.any(),
isNull(), eq(0), isNull(), isNull(), isNull(), any());
isNull(), eq(0), isNull(), isNull(), isNull(), any(),
org.mockito.ArgumentMatchers.anyBoolean(),
org.mockito.ArgumentMatchers.isNull(),
org.mockito.ArgumentMatchers.isNull(),
org.mockito.ArgumentMatchers.any());
}
@Test
@@ -103,14 +103,16 @@ class LaunchConfigurationUserDataStorageTest {
result.setInstances(List.of(launched));
when(ec2.runInstances(eq(REGION), eq("ami-original"), eq("t3.micro"), eq(1), eq(1),
isNull(), anyList(), isNull(), isNull(), anyList(), eq(text), isNull(), isNull(),
isNull(), eq(0), isNull(), isNull(), isNull(), eq(encoded))).thenReturn(result);
isNull(), eq(0), isNull(), isNull(), isNull(), eq(encoded),
anyBoolean(), isNull(), isNull(), any())).thenReturn(result);
AutoScalingReconciler reconciler = new AutoScalingReconciler(service, ec2, mock(ElbV2Service.class));
try {
reconciler.reconcile(group);
assertEquals(List.of("i-created"), group.getInstances().stream().map(i -> i.getInstanceId()).toList());
verify(ec2).runInstances(eq(REGION), eq("ami-original"), eq("t3.micro"), eq(1), eq(1),
isNull(), anyList(), isNull(), isNull(), anyList(), eq(text), isNull(), isNull(),
isNull(), eq(0), isNull(), isNull(), isNull(), eq(encoded));
isNull(), eq(0), isNull(), isNull(), isNull(), eq(encoded),
anyBoolean(), isNull(), isNull(), any());
assertEquals(origin.equals("legacy") ? null : Boolean.TRUE, restored.getUserDataBase64Encoded());
assertEquals(origin.equals("legacy") ? input : encoded, restored.getUserData());
} finally {
@@ -185,6 +185,52 @@ class Ec2CreateFleetIntegrationTest {
equalTo(CONTRACT_IMAGE_ID));
}
@Test
@Order(6)
void createFleetRootVolumeTakesTheLaunchTemplateRootMappingType() {
// ami-0abcdef1234567890 is gp2-rooted at /dev/xvda; the template asks for gp3.
String templateId = given()
.formParam("Action", "CreateLaunchTemplate")
.formParam("LaunchTemplateName", "create-fleet-gp3-root")
.formParam("LaunchTemplateData.ImageId", "ami-0abcdef1234567890")
.formParam("LaunchTemplateData.InstanceType", "t3.micro")
.formParam("LaunchTemplateData.BlockDeviceMapping.1.DeviceName", "/dev/xvda")
.formParam("LaunchTemplateData.BlockDeviceMapping.1.Ebs.VolumeType", "gp3")
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.extract()
.path("CreateLaunchTemplateResponse.launchTemplate.launchTemplateId");
String instanceId = given()
.formParam("Action", "CreateFleet")
.formParam("Type", "instant")
.formParam("LaunchTemplateConfig.1.LaunchTemplateSpecification.LaunchTemplateId", templateId)
.formParam("LaunchTemplateConfig.1.LaunchTemplateSpecification.Version", "1")
.formParam("TargetCapacitySpecification.TotalTargetCapacity", "1")
.formParam("TargetCapacitySpecification.DefaultTargetCapacityType", "on-demand")
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.extract()
.path("CreateFleetResponse.fleetInstanceSet.item.instanceIds.item");
given()
.formParam("Action", "DescribeVolumes")
.formParam("Filter.1.Name", "attachment.instance-id")
.formParam("Filter.1.Value.1", instanceId)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("DescribeVolumesResponse.volumeSet.item.volumeType", equalTo("gp3"));
}
private static String createLaunchTemplate() {
return given()
.formParam("Action", "CreateLaunchTemplate")
@@ -18,6 +18,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -42,7 +43,8 @@ class Ec2CreateFleetRollbackTest {
anyList(), nullable(String.class), nullable(String.class), anyList(), nullable(String.class),
nullable(String.class), nullable(Boolean.class), nullable(String.class), anyInt(),
nullable(String.class), nullable(LaunchTemplateData.MetadataOptions.class),
nullable(String.class), nullable(String.class)))
nullable(String.class), nullable(String.class), eq(false), nullable(String.class),
nullable(String.class), anyList()))
.thenReturn(reservation("i-first"))
.thenReturn(reservation("i-second"))
.thenThrow(new AwsException("InvalidSubnetID.NotFound", "launch failed", 400));
@@ -14,6 +14,7 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.zip.GZIPOutputStream;
@@ -4285,7 +4286,11 @@ class Ec2IntegrationTest {
.post("/")
.then()
.statusCode(200)
.body("DescribeVolumesResponse.volumeSet.item.volumeType", equalTo("gp2"));
// Earlier tests launch from gp2-rooted catalog AMIs, so the result holds their root
// volumes too: assert the filter, not a count.
.body("DescribeVolumesResponse.volumeSet.item.findAll { it.volumeType != 'gp2' }.size()", equalTo(0))
.body("DescribeVolumesResponse.volumeSet.item.findAll { it.volumeId == '" + volumeId + "' }.size()",
equalTo(1));
}
@Test
@@ -5642,4 +5647,163 @@ class Ec2IntegrationTest {
.then()
.statusCode(200);
}
@Test
@Order(329)
void runInstancesRootBlockDeviceMappingOverridesAmiRootVolumeType() {
// ami-0abcdef1234567890 is gp2-rooted at /dev/xvda; a root mapping overrides it.
assertEquals("gp3", rootVolumeType(launch(Map.of(
"BlockDeviceMapping.1.DeviceName", "/dev/xvda",
"BlockDeviceMapping.1.Ebs.VolumeSize", "8",
"BlockDeviceMapping.1.Ebs.VolumeType", "gp3"))));
assertEquals("gp2", rootVolumeType(launch(Map.of())));
}
@Test
@Order(330)
void runInstancesLaunchTemplateRootMappingOverridesAmiAndYieldsToRequest() {
String templateId = given()
.formParam("Action", "CreateLaunchTemplate")
.formParam("LaunchTemplateName", "gp3-root-template")
.formParam("LaunchTemplateData.BlockDeviceMapping.1.DeviceName", "/dev/xvda")
.formParam("LaunchTemplateData.BlockDeviceMapping.1.Ebs.VolumeType", "gp3")
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.extract().path("CreateLaunchTemplateResponse.launchTemplate.launchTemplateId");
assertEquals("gp3", rootVolumeType(launch(Map.of("LaunchTemplate.LaunchTemplateId", templateId))));
// A request mapping for the same device wins over the template's.
assertEquals("io1", rootVolumeType(launch(Map.of(
"LaunchTemplate.LaunchTemplateId", templateId,
"BlockDeviceMapping.1.DeviceName", "/dev/xvda",
"BlockDeviceMapping.1.Ebs.VolumeType", "io1"))));
}
@Test
@Order(331)
void runInstancesRejectsAnUnknownBlockDeviceMappingVolumeType() {
given()
.formParam("Action", "RunInstances")
.formParam("ImageId", "ami-0abcdef1234567890")
.formParam("InstanceType", "t2.micro")
.formParam("MinCount", "1")
.formParam("MaxCount", "1")
.formParam("BlockDeviceMapping.1.DeviceName", "/dev/xvda")
.formParam("BlockDeviceMapping.1.Ebs.VolumeType", "gp9")
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(400)
.body(containsString("<Code>InvalidParameterValue</Code>"))
.body(containsString("Value (gp9) for parameter volumeType is invalid. Unknown volume type."));
}
@Test
@Order(332)
void runInstancesKeepsTemplateDevicesTheRequestDoesNotName() {
String templateId = given()
.formParam("Action", "CreateLaunchTemplate")
.formParam("LaunchTemplateName", "gp3-root-data-request-template")
.formParam("LaunchTemplateData.BlockDeviceMapping.1.DeviceName", "/dev/xvda")
.formParam("LaunchTemplateData.BlockDeviceMapping.1.Ebs.VolumeType", "gp3")
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.extract().path("CreateLaunchTemplateResponse.launchTemplate.launchTemplateId");
// The request maps only a data device, so the template's root mapping still applies.
assertEquals("gp3", rootVolumeType(launch(Map.of(
"LaunchTemplate.LaunchTemplateId", templateId,
"BlockDeviceMapping.1.DeviceName", "/dev/xvdb",
"BlockDeviceMapping.1.Ebs.VolumeSize", "10",
"BlockDeviceMapping.1.Ebs.VolumeType", "io1"))));
}
@Test
@Order(334)
void runInstancesRequestEntryForATemplateDeviceChangesOnlyWhatItSets() {
String templateId = given()
.formParam("Action", "CreateLaunchTemplate")
.formParam("LaunchTemplateName", "gp3-root-size-override-template")
.formParam("LaunchTemplateData.BlockDeviceMapping.1.DeviceName", "/dev/xvda")
.formParam("LaunchTemplateData.BlockDeviceMapping.1.Ebs.VolumeType", "gp3")
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.extract().path("CreateLaunchTemplateResponse.launchTemplate.launchTemplateId");
// The request resizes the root but names no type, so the template's gp3 stands.
assertEquals("gp3", rootVolumeType(launch(Map.of(
"LaunchTemplate.LaunchTemplateId", templateId,
"BlockDeviceMapping.1.DeviceName", "/dev/xvda",
"BlockDeviceMapping.1.Ebs.VolumeSize", "20"))));
}
@Test
@Order(333)
void launchTemplateWithAnUnknownVolumeTypeIsStoredButFailsAtLaunch() {
String templateId = given()
.formParam("Action", "CreateLaunchTemplate")
.formParam("LaunchTemplateName", "unknown-volume-type-template")
.formParam("LaunchTemplateData.BlockDeviceMapping.1.DeviceName", "/dev/xvdb")
.formParam("LaunchTemplateData.BlockDeviceMapping.1.Ebs.VolumeType", "gp9")
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.extract().path("CreateLaunchTemplateResponse.launchTemplate.launchTemplateId");
given()
.formParam("Action", "RunInstances")
.formParam("ImageId", "ami-0abcdef1234567890")
.formParam("InstanceType", "t2.micro")
.formParam("MinCount", "1")
.formParam("MaxCount", "1")
.formParam("LaunchTemplate.LaunchTemplateId", templateId)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(400)
.body(containsString("<Code>InvalidParameterValue</Code>"))
.body(containsString("Value (gp9) for parameter volumeType is invalid. Unknown volume type."));
}
private String launch(Map<String, String> params) {
return given()
.formParam("Action", "RunInstances")
.formParam("ImageId", "ami-0abcdef1234567890")
.formParam("InstanceType", "t2.micro")
.formParam("MinCount", "1")
.formParam("MaxCount", "1")
.formParams(params)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.extract().path("RunInstancesResponse.instancesSet.item.instanceId");
}
private String rootVolumeType(String instanceId) {
return given()
.formParam("Action", "DescribeVolumes")
.formParam("Filter.1.Name", "attachment.instance-id")
.formParam("Filter.1.Value.1", instanceId)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.extract().path("DescribeVolumesResponse.volumeSet.item.volumeType");
}
}
@@ -9,6 +9,8 @@ import jakarta.ws.rs.core.MultivaluedMap;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -62,7 +64,7 @@ class Ec2RunInstancesPublicIpParamTest {
nullable(String.class), anyList(), nullable(String.class), nullable(String.class),
nullable(Boolean.class), nullable(String.class), anyInt(), nullable(String.class),
nullable(LaunchTemplateData.MetadataOptions.class), nullable(String.class), nullable(String.class), eq(false),
nullable(String.class), nullable(String.class)))
nullable(String.class), nullable(String.class), nullable(List.class)))
.thenReturn(new Reservation());
Ec2QueryHandler handler = new Ec2QueryHandler(service, mock(EmulatorConfig.class),
@@ -77,7 +79,7 @@ class Ec2RunInstancesPublicIpParamTest {
nullable(String.class), anyList(), nullable(String.class), nullable(String.class),
associatePublicIp.capture(), nullable(String.class), anyInt(), nullable(String.class),
nullable(LaunchTemplateData.MetadataOptions.class), nullable(String.class), nullable(String.class), eq(false),
nullable(String.class), nullable(String.class));
nullable(String.class), nullable(String.class), nullable(List.class));
if (expected == null) {
assertNull(associatePublicIp.getValue(),
"an absent override must stay null so the subnet default decides");
@@ -82,6 +82,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiConsumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -1720,6 +1721,130 @@ class Ec2ServiceTest {
"catalog imageOwnerAlias values must not turn arbitrary owner strings into Owners selectors");
}
@Test
void describeImagesFiltersCatalogImagesByBlockDeviceMappingVolumeType() {
Ec2ImageCatalog imageCatalog = new Ec2ImageCatalog();
Ec2Service service = new Ec2Service(mockConfig(true), mock(Ec2ContainerManager.class),
mock(Ec2PortForwardManager.class),
new AmiImageResolver(imageCatalog), imageCatalog, new Ec2InstanceTypeCatalog(),
new InMemoryStorageFactory());
assertTrue(service.describeImages("us-east-1", List.of(), List.of(),
Map.of("block-device-mapping.volume-type", List.of("bogus"))).isEmpty());
assertEquals(List.of("ami-0abcdef1234567890"), service.describeImages("us-east-1", List.of(), List.of(),
Map.of("block-device-mapping.volume-type", List.of("gp2"))).stream().map(Image::getImageId).toList());
assertEquals(Set.of("ami-ubuntu2404-arm64", "ami-ubuntu2404-amd64", "ami-ubuntu2404-cloud-arm64"),
service.describeImages("us-east-1", List.of(), List.of(),
Map.of("block-device-mapping.volume-type", List.of("gp3"))).stream()
.map(Image::getImageId).collect(Collectors.toSet()));
}
@Test
void catalogImageSelectedByVolumeTypeReturnsAndCopiesThatMapping() {
Ec2ImageCatalog imageCatalog = new Ec2ImageCatalog();
Ec2Service service = new Ec2Service(mockConfig(true), mock(Ec2ContainerManager.class),
mock(Ec2PortForwardManager.class),
new AmiImageResolver(imageCatalog), imageCatalog, new Ec2InstanceTypeCatalog(),
new InMemoryStorageFactory());
Image found = service.describeImages("us-east-1", List.of(), List.of(),
Map.of("block-device-mapping.volume-type", List.of("gp2"))).get(0);
assertEquals("gp2", found.getBlockDeviceMappings().get(0).getEbs().getVolumeType());
Image copy = service.copyImage("us-east-1", "us-east-1", found.getImageId(), "copy", null);
assertEquals("gp2", copy.getBlockDeviceMappings().get(0).getEbs().getVolumeType());
}
@Test
void catalogImageSnapshotIdsResolveThroughDescribeSnapshots() {
Ec2ImageCatalog imageCatalog = new Ec2ImageCatalog();
Ec2Service service = new Ec2Service(mockConfig(true), mock(Ec2ContainerManager.class),
mock(Ec2PortForwardManager.class),
new AmiImageResolver(imageCatalog), imageCatalog, new Ec2InstanceTypeCatalog(),
new InMemoryStorageFactory());
Image catalog = service.describeImages("us-east-1", List.of("ami-0abcdef1234567890"), List.of(), Map.of())
.getFirst();
for (BlockDeviceMapping mapping : catalog.getBlockDeviceMappings()) {
String snapshotId = mapping.getEbs().getSnapshotId();
if (snapshotId != null) {
assertDoesNotThrow(() -> service.describeSnapshots("us-east-1", List.of(snapshotId), null, Map.of()),
"catalog AMI advertises snapshot " + snapshotId + " that DescribeSnapshots cannot find");
}
}
// A copy's root is still backed by a real snapshot record.
Image copy = service.copyImage("us-east-1", "us-east-1", catalog.getImageId(), "copy", null);
String copySnapshot = copy.getBlockDeviceMappings().getFirst().getEbs().getSnapshotId();
assertEquals(1, service.describeSnapshots("us-east-1", List.of(copySnapshot), null, Map.of()).size());
}
@Test
void runInstancesRootVolumeTakesTheAmiRootVolumeType() {
Ec2ImageCatalog imageCatalog = new Ec2ImageCatalog();
Ec2Service service = new Ec2Service(mockConfig(true), mock(Ec2ContainerManager.class),
mock(Ec2PortForwardManager.class),
new AmiImageResolver(imageCatalog), imageCatalog, new Ec2InstanceTypeCatalog(),
new InMemoryStorageFactory());
Instance gp2 = service.runInstances("us-east-1", "ami-0abcdef1234567890", "t3.micro",
1, 1, null, List.of(), null, null, List.of(), null, null).getInstances().getFirst();
assertEquals("gp2", service.describeVolumes("us-east-1", List.of(gp2.getRootVolumeId()), Map.of())
.getFirst().getVolumeType());
Instance gp3 = service.runInstances("us-east-1", "ami-ubuntu2404-amd64", "t3.micro",
1, 1, null, List.of(), null, null, List.of(), null, null).getInstances().getFirst();
assertEquals("gp3", service.describeVolumes("us-east-1", List.of(gp3.getRootVolumeId()), Map.of())
.getFirst().getVolumeType());
}
@Test
void createImageRecordsTheInstanceRootVolumeTypeNotTheSourceAmis() {
Ec2ImageCatalog imageCatalog = new Ec2ImageCatalog();
Ec2Service service = new Ec2Service(mockConfig(true), mock(Ec2ContainerManager.class),
mock(Ec2PortForwardManager.class),
new AmiImageResolver(imageCatalog), imageCatalog, new Ec2InstanceTypeCatalog(),
new InMemoryStorageFactory());
LaunchTemplateData.Ebs ebs = new LaunchTemplateData.Ebs();
ebs.setVolumeType("gp3");
LaunchTemplateData.BlockDeviceMapping root = new LaunchTemplateData.BlockDeviceMapping();
root.setDeviceName("/dev/xvda");
root.setEbs(ebs);
// ami-0abcdef1234567890 declares a gp2 root; the launch asked for gp3.
Instance instance = service.runInstances("us-east-1", "ami-0abcdef1234567890", "t3.micro",
1, 1, null, List.of(), null, null, List.of(), null, null, null, null, 0, null, null, null,
null, false, null, null, List.of(root)).getInstances().getFirst();
String imageId = service.createImage("us-east-1", instance.getInstanceId(), "gp3-capture", null, true)
.getImageId();
Image captured = service.describeImages("us-east-1", List.of(imageId), List.of(), Map.of()).getFirst();
BlockDeviceMapping capturedRoot = captured.getBlockDeviceMappings().stream()
.filter(m -> "/dev/xvda".equals(m.getDeviceName()))
.findFirst().orElseThrow();
assertEquals("gp3", capturedRoot.getEbs().getVolumeType());
}
@Test
void describeImagesFiltersRegisteredImagesByBlockDeviceMappingVolumeType() {
Ec2Service service = new Ec2Service(mockConfig(true), mock(Ec2ContainerManager.class),
mock(Ec2PortForwardManager.class),
mock(AmiImageResolver.class), mock(Ec2ImageCatalog.class), new Ec2InstanceTypeCatalog(),
new InMemoryStorageFactory());
EbsBlockDevice ebs = new EbsBlockDevice();
ebs.setVolumeType("io2");
BlockDeviceMapping mapping = new BlockDeviceMapping();
mapping.setDeviceName("/dev/sda1");
mapping.setEbs(ebs);
Image io2 = service.registerImage("us-east-1", "io2-image", null, null, null, List.of(mapping));
service.registerImage("us-east-1", "no-ebs-image", null, null, null, List.of());
assertEquals(List.of(io2.getImageId()), service.describeImages("us-east-1", List.of(), List.of(),
Map.of("block-device-mapping.volume-type", List.of("io2"))).stream().map(Image::getImageId).toList());
assertTrue(service.describeImages("us-east-1", List.of(), List.of(),
Map.of("block-device-mapping.volume-type", List.of("gp3"))).isEmpty());
}
@Test
void describeImagesMatchesCatalogAliasInImageIdFilter() {
Ec2ImageCatalog imageCatalog = new Ec2ImageCatalog();
@@ -5930,7 +6055,7 @@ class Ec2ServiceTest {
AwsException e = assertThrows(AwsException.class, () -> service.runInstances("us-east-1",
"ami-ubuntu2404-amd64", "m5.large", 1, 1, null, List.of(), null, null, List.of(), null, null,
null, null, 0, null, null, null, null, false, hostId[0], null));
null, null, 0, null, null, null, null, false, hostId[0], null, null));
assertTrue(released[0], "the hook must have released the host between the two checks");
assertEquals("InvalidHostID.NotFound", e.getErrorCode());
@@ -150,6 +150,10 @@ class RdsCatalogueReadIntegrationTest {
.extract().xmlPath().getString("CreateDBClusterResponse.CreateDBClusterResult.DBCluster.EngineVersion");
assertEquals(expected, created);
assertEquals(defaultVersion(engine), created);
// A caller sizing instances for the cluster must find an orderable class at that version.
query("DescribeOrderableDBInstanceOptions").formParam("Engine", engine).formParam("EngineVersion", created)
.when().post("/").then().statusCode(200)
.body(containsString("<OrderableDBInstanceOption>"));
query("DeleteDBCluster").formParam("DBClusterIdentifier", id).formParam("SkipFinalSnapshot", "true")
.when().post("/").then().statusCode(200);
}
@@ -1012,6 +1012,22 @@ class RdsQueryHandlerTest {
assertTrue(body.contains("<DBInstanceClass>db.t4g.medium</DBInstanceClass>"));
}
@Test
void describeOrderableDbInstanceOptions_auroraMysqlReportsGeneralPublicLicense() {
when(service.describeOrderableDbInstanceOptions("aurora-mysql", null, null))
.thenReturn(List.of(Map.of(
"engine", "aurora-mysql",
"engineVersion", "8.0.mysql_aurora.3.05.2",
"dbInstanceClass", "db.r5.large")));
MultivaluedMap<String, String> p = params();
p.add("Engine", "aurora-mysql");
String body = (String) handler.handle("DescribeOrderableDBInstanceOptions", p).getEntity();
assertTrue(body.contains("<LicenseModel>general-public-license</LicenseModel>"));
assertFalse(body.contains("postgresql-license"));
}
// ──────────────────────────── DBParameterGroups XML tag ──────────────────────
@Test
@@ -2992,6 +2992,23 @@ class RdsServiceTest {
assertEquals("16.14", result.getFirst().get("engineVersion"));
}
@Test
void describeOrderableDbInstanceOptionsListsAuroraEngines() {
List<String> auroraClasses = List.of("db.t3.medium", "db.t4g.medium", "db.r5.large", "db.r6g.large");
List<Map<String, String>> mysql = rdsService.describeOrderableDbInstanceOptions("aurora-mysql", null, null);
List<Map<String, String>> postgres = rdsService.describeOrderableDbInstanceOptions("aurora-postgresql", null, null);
assertEquals(auroraClasses, mysql.stream().map(o -> o.get("dbInstanceClass")).toList());
assertTrue(mysql.stream().allMatch(o -> "aurora-mysql".equals(o.get("engine"))
&& "8.0.mysql_aurora.3.05.2".equals(o.get("engineVersion"))));
assertEquals(auroraClasses, postgres.stream().map(o -> o.get("dbInstanceClass")).toList());
assertTrue(postgres.stream().allMatch(o -> "aurora-postgresql".equals(o.get("engine"))
&& "16.3".equals(o.get("engineVersion"))));
assertEquals(1, rdsService.describeOrderableDbInstanceOptions(
"aurora-postgresql", "16.3", "db.r6g.large").size());
}
@Test
void deleteDbClusterFailsWhenMembersRemain() {
DbCluster cluster = rdsService.createDbCluster("cluster1", "postgres", "13",