mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
feat(ec2): implement ModifyVolume and volume modification state (#4320)
This commit is contained in:
1 parent
4a51c0e814
commit
077b65df5c
6 files changed
+518
-2
No files matched your search
@@ -693,9 +693,19 @@ A standalone ENI created via `CreateNetworkInterface` can also be handed to `Run
|
||||
| CreateVolume | Creates an EBS volume record. |
|
||||
| DescribeVolumes | Lists or returns stored EBS volume records. |
|
||||
| DeleteVolume | Deletes an EBS volume record. |
|
||||
| ModifyVolume | Modifies size, type, IOPS, throughput, or multi-attach settings of an EBS volume record. |
|
||||
| DescribeVolumesModifications | Reports the current modification state for EBS volumes, filterable by volume ID and state. |
|
||||
| AttachVolume | Attaches a volume to an instance at the requested device; returns the attachment in `attaching` state. |
|
||||
| DetachVolume | Detaches a volume from an instance, optionally forced; returns the attachment in `detaching` state. |
|
||||
|
||||
Volumes are tracked as logical metadata records and are not backed by real block storage devices. Volume modifications update recorded state only without resizing an underlying medium. `ModifyVolume` applies attribute updates directly to the volume record and records a modification entry in `completed` state with 100% progress.
|
||||
|
||||
Validation matches AWS behavior:
|
||||
- Unknown volumes are rejected with `InvalidVolume.NotFound`.
|
||||
- Decreasing volume size is rejected with `InvalidParameterValue`.
|
||||
- Unsupported parameters (such as `Throughput` on non-gp3 volumes or `Iops` on non-provisioned IOPS volume types) are rejected with `InvalidParameterCombination`.
|
||||
- When querying `DescribeVolumesModifications` with an explicit volume ID for an unmodified volume, the request fails with `InvalidVolumeModification.NotFound`. Listing or filtering without explicit IDs returns only modified volumes.
|
||||
|
||||
### Snapshots
|
||||
|
||||
| Action | Description |
|
||||
|
||||
@@ -269,6 +269,8 @@ public class Ec2QueryHandler {
|
||||
case "CreateVolume" -> handleCreateVolume(params, region);
|
||||
case "DescribeVolumes" -> handleDescribeVolumes(params, region);
|
||||
case "DeleteVolume" -> handleDeleteVolume(params, region);
|
||||
case "ModifyVolume" -> handleModifyVolume(params, region);
|
||||
case "DescribeVolumesModifications" -> handleDescribeVolumesModifications(params, region);
|
||||
case "AttachVolume" -> handleAttachVolume(params, region);
|
||||
case "DetachVolume" -> handleDetachVolume(params, region);
|
||||
// Spot Instances
|
||||
@@ -5718,6 +5720,95 @@ public class Ec2QueryHandler {
|
||||
return booleanResponse("DeleteVolume");
|
||||
}
|
||||
|
||||
private Response handleModifyVolume(MultivaluedMap<String, String> p, String region) {
|
||||
String volumeId = p.getFirst("VolumeId");
|
||||
if (volumeId == null || volumeId.isBlank()) {
|
||||
throw new AwsException("MissingParameter", "The parameter VolumeId is missing", 400);
|
||||
}
|
||||
Integer size = parseOptionalInt(p.getFirst("Size"), "Size");
|
||||
String volumeType = p.getFirst("VolumeType");
|
||||
Integer iops = parseOptionalInt(p.getFirst("Iops"), "Iops");
|
||||
Integer throughput = parseOptionalInt(p.getFirst("Throughput"), "Throughput");
|
||||
Boolean multiAttachEnabled = p.getFirst("MultiAttachEnabled") != null
|
||||
? Boolean.parseBoolean(p.getFirst("MultiAttachEnabled"))
|
||||
: null;
|
||||
boolean dryRun = Boolean.parseBoolean(p.getFirst("DryRun"));
|
||||
VolumeModification mod = service.modifyVolume(region, volumeId, size, volumeType,
|
||||
iops, throughput, multiAttachEnabled, dryRun);
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.start("ModifyVolumeResponse", AwsNamespaces.EC2)
|
||||
.elem("requestId", UUID.randomUUID().toString())
|
||||
.raw(volumeModificationXml(mod, "volumeModification"))
|
||||
.end("ModifyVolumeResponse");
|
||||
return xmlResponse(xml.build());
|
||||
}
|
||||
|
||||
private Response handleDescribeVolumesModifications(MultivaluedMap<String, String> p, String region) {
|
||||
checkDryRun(p);
|
||||
List<String> ids = getList(p, "VolumeId");
|
||||
Map<String, List<String>> filters = getFilters(p);
|
||||
List<VolumeModification> modList = service.describeVolumesModifications(region, ids, filters);
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.start("DescribeVolumesModificationsResponse", AwsNamespaces.EC2)
|
||||
.elem("requestId", UUID.randomUUID().toString())
|
||||
.start("volumeModificationSet");
|
||||
for (VolumeModification mod : modList) {
|
||||
xml.raw(volumeModificationXml(mod, "item"));
|
||||
}
|
||||
xml.end("volumeModificationSet")
|
||||
.end("DescribeVolumesModificationsResponse");
|
||||
return xmlResponse(xml.build());
|
||||
}
|
||||
|
||||
private String volumeModificationXml(VolumeModification mod, String wrapperTag) {
|
||||
XmlBuilder xml = new XmlBuilder().start(wrapperTag)
|
||||
.elem("volumeId", mod.getVolumeId())
|
||||
.elem("modificationState", mod.getModificationState());
|
||||
if (mod.getTargetSize() != null) {
|
||||
xml.elem("targetSize", String.valueOf(mod.getTargetSize()));
|
||||
}
|
||||
if (mod.getTargetIops() != null) {
|
||||
xml.elem("targetIops", String.valueOf(mod.getTargetIops()));
|
||||
}
|
||||
if (mod.getTargetVolumeType() != null) {
|
||||
xml.elem("targetVolumeType", mod.getTargetVolumeType());
|
||||
}
|
||||
if (mod.getTargetThroughput() != null) {
|
||||
xml.elem("targetThroughput", String.valueOf(mod.getTargetThroughput()));
|
||||
}
|
||||
if (mod.getTargetMultiAttachEnabled() != null) {
|
||||
xml.elem("targetMultiAttachEnabled", String.valueOf(mod.getTargetMultiAttachEnabled()));
|
||||
}
|
||||
if (mod.getOriginalSize() != null) {
|
||||
xml.elem("originalSize", String.valueOf(mod.getOriginalSize()));
|
||||
}
|
||||
if (mod.getOriginalIops() != null) {
|
||||
xml.elem("originalIops", String.valueOf(mod.getOriginalIops()));
|
||||
}
|
||||
if (mod.getOriginalVolumeType() != null) {
|
||||
xml.elem("originalVolumeType", mod.getOriginalVolumeType());
|
||||
}
|
||||
if (mod.getOriginalThroughput() != null) {
|
||||
xml.elem("originalThroughput", String.valueOf(mod.getOriginalThroughput()));
|
||||
}
|
||||
if (mod.getOriginalMultiAttachEnabled() != null) {
|
||||
xml.elem("originalMultiAttachEnabled", String.valueOf(mod.getOriginalMultiAttachEnabled()));
|
||||
}
|
||||
if (mod.getProgress() != null) {
|
||||
xml.elem("progress", String.valueOf(mod.getProgress()));
|
||||
}
|
||||
if (mod.getStatusMessage() != null) {
|
||||
xml.elem("statusMessage", mod.getStatusMessage());
|
||||
}
|
||||
if (mod.getStartTime() != null) {
|
||||
xml.elem("startTime", ISO_FMT.format(mod.getStartTime()));
|
||||
}
|
||||
if (mod.getEndTime() != null) {
|
||||
xml.elem("endTime", ISO_FMT.format(mod.getEndTime()));
|
||||
}
|
||||
return xml.end(wrapperTag).build();
|
||||
}
|
||||
|
||||
private Response handleAttachVolume(MultivaluedMap<String, String> p, String region) {
|
||||
String volumeId = p.getFirst("VolumeId");
|
||||
String instanceId = p.getFirst("InstanceId");
|
||||
@@ -5759,6 +5850,9 @@ public class Ec2QueryHandler {
|
||||
.elem("status", vol.getState())
|
||||
.elem("availabilityZone", vol.getAvailabilityZone())
|
||||
.elem("encrypted", String.valueOf(vol.isEncrypted()));
|
||||
if (vol.getMultiAttachEnabled() != null) {
|
||||
xml.elem("multiAttachEnabled", String.valueOf(vol.getMultiAttachEnabled()));
|
||||
}
|
||||
if (vol.getIops() > 0) {
|
||||
xml.elem("iops", String.valueOf(vol.getIops()));
|
||||
}
|
||||
|
||||
@@ -104,6 +104,7 @@ import io.github.hectorvent.floci.services.ec2.model.TransitGatewayVpcAttachment
|
||||
import io.github.hectorvent.floci.services.ec2.model.UserIdGroupPair;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Volume;
|
||||
import io.github.hectorvent.floci.services.ec2.model.VolumeAttachment;
|
||||
import io.github.hectorvent.floci.services.ec2.model.VolumeModification;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Vpc;
|
||||
import io.github.hectorvent.floci.services.ec2.model.VpcCidrBlockAssociation;
|
||||
import io.github.hectorvent.floci.services.ec2.model.VpcIpv6CidrBlockAssociation;
|
||||
@@ -137,6 +138,8 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
|
||||
.withZone(ZoneOffset.UTC);
|
||||
private static final int DEFAULT_ROOT_VOLUME_SIZE_GIB = 8;
|
||||
private static final String DEFAULT_ROOT_VOLUME_TYPE = "gp3";
|
||||
private static final Set<String> VALID_VOLUME_TYPES =
|
||||
Set.of("standard", "io1", "io2", "gp2", "sc1", "st1", "gp3");
|
||||
/** The accounts behind the two non-self owner aliases DescribeImages accepts. */
|
||||
private static final String AMAZON_OWNER_ID = "137112412989";
|
||||
private static final String AWS_MARKETPLACE_OWNER_ID = "679593333241";
|
||||
@@ -195,6 +198,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
|
||||
private final StorageBackend<String, Address> addresses;
|
||||
private final StorageBackend<String, Instance> instances;
|
||||
private final StorageBackend<String, Volume> volumes;
|
||||
private final StorageBackend<String, VolumeModification> volumeModifications;
|
||||
private final StorageBackend<String, Image> registeredImages;
|
||||
private final StorageBackend<String, Snapshot> snapshots;
|
||||
private final StorageBackend<String, LaunchTemplate> launchTemplates;
|
||||
@@ -320,6 +324,8 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
|
||||
new TypeReference<Map<String, NetworkInterface>>() {}),
|
||||
storageFactory.create("ec2", "ec2-capacity-reservations.json",
|
||||
new TypeReference<Map<String, CapacityReservation>>() {}),
|
||||
storageFactory.create("ec2", "ec2-volume-modifications.json",
|
||||
new TypeReference<Map<String, VolumeModification>>() {}),
|
||||
requestContextInstance, iamService);
|
||||
}
|
||||
|
||||
@@ -436,7 +442,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
|
||||
volumes, registeredImages, snapshots, launchTemplates, vpcEndpoints,
|
||||
natGateways, spotInstanceRequests, networkAcls, managedPrefixLists, tags,
|
||||
transitGateways, transitGatewayRouteTables, transitGatewayVpcAttachments,
|
||||
transitGatewayPropagations, transitGatewayRoutes, vpcPeeringConnections, networkInterfaces, capacityReservations, requestContextInstance, null);
|
||||
transitGatewayPropagations, transitGatewayRoutes, vpcPeeringConnections, networkInterfaces, capacityReservations, new InMemoryStorage<>(), requestContextInstance, null);
|
||||
}
|
||||
|
||||
Ec2Service(EmulatorConfig config, Ec2ContainerManager containerManager,
|
||||
@@ -470,6 +476,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
|
||||
StorageBackend<String, VpcPeeringConnection> vpcPeeringConnections,
|
||||
StorageBackend<String, NetworkInterface> networkInterfaces,
|
||||
StorageBackend<String, CapacityReservation> capacityReservations,
|
||||
StorageBackend<String, VolumeModification> volumeModifications,
|
||||
jakarta.enterprise.inject.Instance<RequestContext> requestContextInstance,
|
||||
IamService iamService) {
|
||||
this.iamService = iamService;
|
||||
@@ -508,6 +515,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
|
||||
this.vpcPeeringConnections = vpcPeeringConnections;
|
||||
this.networkInterfaces = networkInterfaces;
|
||||
this.capacityReservations = capacityReservations;
|
||||
this.volumeModifications = volumeModifications;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
@@ -8214,6 +8222,19 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
|
||||
default -> true;
|
||||
};
|
||||
}
|
||||
if (resource instanceof VolumeModification mod) {
|
||||
return switch (filterName) {
|
||||
case "volume-id" -> matchesValue(values, mod.getVolumeId());
|
||||
case "modification-state" -> matchesValue(values, mod.getModificationState());
|
||||
case "target-size" -> matchesValue(values, mod.getTargetSize() != null ? String.valueOf(mod.getTargetSize()) : null);
|
||||
case "target-volume-type" -> matchesValue(values, mod.getTargetVolumeType());
|
||||
case "target-iops" -> matchesValue(values, mod.getTargetIops() != null ? String.valueOf(mod.getTargetIops()) : null);
|
||||
case "original-size" -> matchesValue(values, mod.getOriginalSize() != null ? String.valueOf(mod.getOriginalSize()) : null);
|
||||
case "original-volume-type" -> matchesValue(values, mod.getOriginalVolumeType());
|
||||
case "original-iops" -> matchesValue(values, mod.getOriginalIops() != null ? String.valueOf(mod.getOriginalIops()) : null);
|
||||
default -> true;
|
||||
};
|
||||
}
|
||||
if (resource instanceof NetworkInterface ni) {
|
||||
return switch (filterName) {
|
||||
case "network-interface-id" -> matchesValue(values, ni.getNetworkInterfaceId());
|
||||
@@ -8357,6 +8378,125 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
|
||||
volumes.delete(key(region, volumeId));
|
||||
}
|
||||
|
||||
public VolumeModification modifyVolume(String region, String volumeId, Integer size,
|
||||
String volumeType, Integer iops, Integer throughput,
|
||||
Boolean multiAttachEnabled, boolean dryRun) {
|
||||
if (volumeId == null || volumeId.isBlank()) {
|
||||
throw new AwsException("MissingParameter", "The parameter VolumeId is missing", 400);
|
||||
}
|
||||
ensureDefaultResources(region);
|
||||
Volume volume = getRequiredVolume(region, volumeId);
|
||||
|
||||
if (size != null && size <= 0) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Value (" + size + ") for parameter size is invalid.", 400);
|
||||
}
|
||||
if (size != null && size < volume.getSize()) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"New size cannot be smaller than existing size", 400);
|
||||
}
|
||||
|
||||
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 (throughput != null && !"gp3".equals(targetVolumeType)) {
|
||||
throw new AwsException("InvalidParameterCombination",
|
||||
"The parameter Throughput is not supported for " + targetVolumeType + " volumes", 400);
|
||||
}
|
||||
|
||||
if (iops != null && !"gp3".equals(targetVolumeType) && !"io1".equals(targetVolumeType) && !"io2".equals(targetVolumeType)) {
|
||||
throw new AwsException("InvalidParameterCombination",
|
||||
"The parameter iops is not supported for " + targetVolumeType + " volumes", 400);
|
||||
}
|
||||
|
||||
if (multiAttachEnabled != null && multiAttachEnabled && !"io1".equals(targetVolumeType) && !"io2".equals(targetVolumeType)) {
|
||||
throw new AwsException("InvalidParameterCombination",
|
||||
"The parameter MultiAttachEnabled is not supported for " + targetVolumeType + " volumes", 400);
|
||||
}
|
||||
|
||||
if (dryRun) {
|
||||
throw new AwsException("DryRunOperation", "Request would have succeeded, but DryRun flag is set.", 412);
|
||||
}
|
||||
|
||||
Integer originalSize = volume.getSize();
|
||||
String originalVolumeType = volume.getVolumeType();
|
||||
Integer originalIops = volume.getIops() > 0 ? volume.getIops() : null;
|
||||
Integer originalThroughput = volume.getThroughput();
|
||||
Boolean originalMultiAttachEnabled = volume.getMultiAttachEnabled();
|
||||
|
||||
int targetSize = size != null ? size : volume.getSize();
|
||||
Integer targetIops = iops != null ? iops : (volume.getIops() > 0 ? volume.getIops() : null);
|
||||
Integer targetThroughput = throughput != null ? throughput : volume.getThroughput();
|
||||
Boolean targetMultiAttach = multiAttachEnabled != null ? multiAttachEnabled : volume.getMultiAttachEnabled();
|
||||
|
||||
if ("gp3".equals(targetVolumeType)) {
|
||||
if (targetIops == null) {
|
||||
targetIops = 3000;
|
||||
}
|
||||
if (targetThroughput == null) {
|
||||
targetThroughput = 125;
|
||||
}
|
||||
} else if ("io1".equals(targetVolumeType) || "io2".equals(targetVolumeType)) {
|
||||
if (targetIops == null) {
|
||||
targetIops = 3000;
|
||||
}
|
||||
targetThroughput = null;
|
||||
} else {
|
||||
targetIops = null;
|
||||
targetThroughput = null;
|
||||
targetMultiAttach = false;
|
||||
}
|
||||
|
||||
volume.setSize(targetSize);
|
||||
volume.setVolumeType(targetVolumeType);
|
||||
volume.setIops(targetIops != null ? targetIops : 0);
|
||||
volume.setThroughput(targetThroughput);
|
||||
volume.setMultiAttachEnabled(targetMultiAttach);
|
||||
volumes.put(key(region, volumeId), volume);
|
||||
|
||||
Instant now = Instant.now();
|
||||
VolumeModification mod = new VolumeModification();
|
||||
mod.setVolumeId(volumeId);
|
||||
mod.setModificationState("completed");
|
||||
mod.setTargetSize(targetSize);
|
||||
mod.setTargetVolumeType(targetVolumeType);
|
||||
mod.setTargetIops(targetIops);
|
||||
mod.setTargetThroughput(targetThroughput);
|
||||
mod.setTargetMultiAttachEnabled(targetMultiAttach);
|
||||
mod.setOriginalSize(originalSize);
|
||||
mod.setOriginalVolumeType(originalVolumeType);
|
||||
mod.setOriginalIops(originalIops);
|
||||
mod.setOriginalThroughput(originalThroughput);
|
||||
mod.setOriginalMultiAttachEnabled(originalMultiAttachEnabled);
|
||||
mod.setProgress(100L);
|
||||
mod.setStartTime(now);
|
||||
mod.setEndTime(now);
|
||||
mod.setRegion(region);
|
||||
|
||||
volumeModifications.put(key(region, volumeId), mod);
|
||||
return mod;
|
||||
}
|
||||
|
||||
public List<VolumeModification> describeVolumesModifications(String region, List<String> volumeIds,
|
||||
Map<String, List<String>> filters) {
|
||||
if (volumeIds != null && !volumeIds.isEmpty()) {
|
||||
for (String id : volumeIds) {
|
||||
if (volumeModifications.get(key(region, id)).isEmpty()) {
|
||||
throw new AwsException("InvalidVolumeModification.NotFound",
|
||||
"Modification for volume '" + id + "' does not exist.", 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
return volumeModifications.scan(k -> true).stream()
|
||||
.filter(m -> region.equals(m.getRegion()))
|
||||
.filter(m -> volumeIds == null || volumeIds.isEmpty() || volumeIds.contains(m.getVolumeId()))
|
||||
.filter(m -> matchesFilters(m, filters, region))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public VolumeAttachment attachVolume(String region, String volumeId, String instanceId, String device) {
|
||||
ensureDefaultResources(region);
|
||||
if (volumeId == null || volumeId.isEmpty()) {
|
||||
@@ -8442,7 +8582,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
|
||||
|
||||
private Volume getRequiredVolume(String region, String volumeId) {
|
||||
return volumes.get(key(region, volumeId)).orElseThrow(() ->
|
||||
new AwsException("InvalidVolume.NotFound", "The volume '" + volumeId + "' does not exist", 400)
|
||||
new AwsException("InvalidVolume.NotFound", "The volume '" + volumeId + "' does not exist.", 400)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ public class Volume {
|
||||
private Integer throughput; // MiB/s; only meaningful for gp3 (null otherwise)
|
||||
private String snapshotId;
|
||||
private Instant createTime;
|
||||
private Boolean multiAttachEnabled;
|
||||
private String region;
|
||||
private List<Tag> tags = new ArrayList<>();
|
||||
private List<VolumeAttachment> attachments = new ArrayList<>();
|
||||
@@ -57,6 +58,9 @@ public class Volume {
|
||||
public Instant getCreateTime() { return createTime; }
|
||||
public void setCreateTime(Instant createTime) { this.createTime = createTime; }
|
||||
|
||||
public Boolean getMultiAttachEnabled() { return multiAttachEnabled; }
|
||||
public void setMultiAttachEnabled(Boolean multiAttachEnabled) { this.multiAttachEnabled = multiAttachEnabled; }
|
||||
|
||||
public String getRegion() { return region; }
|
||||
public void setRegion(String region) { this.region = region; }
|
||||
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package io.github.hectorvent.floci.services.ec2.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class VolumeModification {
|
||||
|
||||
private String volumeId;
|
||||
private String modificationState;
|
||||
private Integer targetSize;
|
||||
private Integer targetIops;
|
||||
private String targetVolumeType;
|
||||
private Integer targetThroughput;
|
||||
private Boolean targetMultiAttachEnabled;
|
||||
private Integer originalSize;
|
||||
private Integer originalIops;
|
||||
private String originalVolumeType;
|
||||
private Integer originalThroughput;
|
||||
private Boolean originalMultiAttachEnabled;
|
||||
private Long progress;
|
||||
private String statusMessage;
|
||||
private Instant startTime;
|
||||
private Instant endTime;
|
||||
private String region;
|
||||
|
||||
public VolumeModification() {}
|
||||
|
||||
public String getVolumeId() { return volumeId; }
|
||||
public void setVolumeId(String volumeId) { this.volumeId = volumeId; }
|
||||
|
||||
public String getModificationState() { return modificationState; }
|
||||
public void setModificationState(String modificationState) { this.modificationState = modificationState; }
|
||||
|
||||
public Integer getTargetSize() { return targetSize; }
|
||||
public void setTargetSize(Integer targetSize) { this.targetSize = targetSize; }
|
||||
|
||||
public Integer getTargetIops() { return targetIops; }
|
||||
public void setTargetIops(Integer targetIops) { this.targetIops = targetIops; }
|
||||
|
||||
public String getTargetVolumeType() { return targetVolumeType; }
|
||||
public void setTargetVolumeType(String targetVolumeType) { this.targetVolumeType = targetVolumeType; }
|
||||
|
||||
public Integer getTargetThroughput() { return targetThroughput; }
|
||||
public void setTargetThroughput(Integer targetThroughput) { this.targetThroughput = targetThroughput; }
|
||||
|
||||
public Boolean getTargetMultiAttachEnabled() { return targetMultiAttachEnabled; }
|
||||
public void setTargetMultiAttachEnabled(Boolean targetMultiAttachEnabled) { this.targetMultiAttachEnabled = targetMultiAttachEnabled; }
|
||||
|
||||
public Integer getOriginalSize() { return originalSize; }
|
||||
public void setOriginalSize(Integer originalSize) { this.originalSize = originalSize; }
|
||||
|
||||
public Integer getOriginalIops() { return originalIops; }
|
||||
public void setOriginalIops(Integer originalIops) { this.originalIops = originalIops; }
|
||||
|
||||
public String getOriginalVolumeType() { return originalVolumeType; }
|
||||
public void setOriginalVolumeType(String originalVolumeType) { this.originalVolumeType = originalVolumeType; }
|
||||
|
||||
public Integer getOriginalThroughput() { return originalThroughput; }
|
||||
public void setOriginalThroughput(Integer originalThroughput) { this.originalThroughput = originalThroughput; }
|
||||
|
||||
public Boolean getOriginalMultiAttachEnabled() { return originalMultiAttachEnabled; }
|
||||
public void setOriginalMultiAttachEnabled(Boolean originalMultiAttachEnabled) { this.originalMultiAttachEnabled = originalMultiAttachEnabled; }
|
||||
|
||||
public Long getProgress() { return progress; }
|
||||
public void setProgress(Long progress) { this.progress = progress; }
|
||||
|
||||
public String getStatusMessage() { return statusMessage; }
|
||||
public void setStatusMessage(String statusMessage) { this.statusMessage = statusMessage; }
|
||||
|
||||
public Instant getStartTime() { return startTime; }
|
||||
public void setStartTime(Instant startTime) { this.startTime = startTime; }
|
||||
|
||||
public Instant getEndTime() { return endTime; }
|
||||
public void setEndTime(Instant endTime) { this.endTime = endTime; }
|
||||
|
||||
public String getRegion() { return region; }
|
||||
public void setRegion(String region) { this.region = region; }
|
||||
}
|
||||
+186
@@ -0,0 +1,186 @@
|
||||
package io.github.hectorvent.floci.services.ec2;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
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.equalTo;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class Ec2ModifyVolumeIntegrationTest {
|
||||
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20250101/us-east-1/ec2/aws4_request";
|
||||
|
||||
private static String volumeId;
|
||||
private static String unmodifiedVolumeId;
|
||||
|
||||
private String createVolume(String type, int size) {
|
||||
return given().header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "CreateVolume")
|
||||
.formParam("AvailabilityZone", "us-east-1a")
|
||||
.formParam("VolumeType", type)
|
||||
.formParam("Size", String.valueOf(size))
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("CreateVolumeResponse.volumeId", startsWith("vol-"))
|
||||
.extract().path("CreateVolumeResponse.volumeId");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createInitialVolumes() {
|
||||
volumeId = createVolume("gp3", 10);
|
||||
unmodifiedVolumeId = createVolume("gp3", 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void modifyVolumeIncreasesSizeAndReportsCompletedState() {
|
||||
given().header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "ModifyVolume")
|
||||
.formParam("VolumeId", volumeId)
|
||||
.formParam("Size", "20")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("ModifyVolumeResponse.volumeModification.volumeId", equalTo(volumeId))
|
||||
.body("ModifyVolumeResponse.volumeModification.targetSize", equalTo("20"))
|
||||
.body("ModifyVolumeResponse.volumeModification.originalSize", equalTo("10"))
|
||||
.body("ModifyVolumeResponse.volumeModification.modificationState", equalTo("completed"))
|
||||
.body("ModifyVolumeResponse.volumeModification.progress", equalTo("100"))
|
||||
.body("ModifyVolumeResponse.volumeModification.startTime", notNullValue())
|
||||
.body("ModifyVolumeResponse.volumeModification.endTime", notNullValue());
|
||||
|
||||
given().header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "DescribeVolumes")
|
||||
.formParam("VolumeId.1", volumeId)
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("DescribeVolumesResponse.volumeSet.item.volumeId", equalTo(volumeId))
|
||||
.body("DescribeVolumesResponse.volumeSet.item.size", equalTo("20"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void describeVolumesModificationsReturnsCompletedModification() {
|
||||
given().header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "DescribeVolumesModifications")
|
||||
.formParam("VolumeId.1", volumeId)
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("DescribeVolumesModificationsResponse.volumeModificationSet.item.volumeId", equalTo(volumeId))
|
||||
.body("DescribeVolumesModificationsResponse.volumeModificationSet.item.targetSize", equalTo("20"))
|
||||
.body("DescribeVolumesModificationsResponse.volumeModificationSet.item.originalSize", equalTo("10"))
|
||||
.body("DescribeVolumesModificationsResponse.volumeModificationSet.item.modificationState", equalTo("completed"))
|
||||
.body("DescribeVolumesModificationsResponse.volumeModificationSet.item.progress", equalTo("100"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void modifyVolumeRejectsSizeDecrease() {
|
||||
given().header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "ModifyVolume")
|
||||
.formParam("VolumeId", volumeId)
|
||||
.formParam("Size", "15")
|
||||
.when().post("/")
|
||||
.then().statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("InvalidParameterValue"))
|
||||
.body("Response.Errors.Error.Message", equalTo("New size cannot be smaller than existing size"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void modifyVolumeRejectsUnknownVolume() {
|
||||
given().header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "ModifyVolume")
|
||||
.formParam("VolumeId", "vol-0123456789abcdef0")
|
||||
.formParam("Size", "30")
|
||||
.when().post("/")
|
||||
.then().statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("InvalidVolume.NotFound"))
|
||||
.body("Response.Errors.Error.Message", equalTo("The volume 'vol-0123456789abcdef0' does not exist."));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void describeVolumesModificationsRejectsUnmodifiedVolume() {
|
||||
given().header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "DescribeVolumesModifications")
|
||||
.formParam("VolumeId.1", unmodifiedVolumeId)
|
||||
.when().post("/")
|
||||
.then().statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("InvalidVolumeModification.NotFound"))
|
||||
.body("Response.Errors.Error.Message", equalTo("Modification for volume '" + unmodifiedVolumeId + "' does not exist."));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void describeVolumesModificationsWithoutIdsExcludesUnmodifiedVolume() {
|
||||
given().header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "DescribeVolumesModifications")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("DescribeVolumesModificationsResponse.volumeModificationSet.item.volumeId",
|
||||
equalTo(volumeId));
|
||||
|
||||
given().header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "DescribeVolumesModifications")
|
||||
.formParam("Filter.1.Name", "volume-id")
|
||||
.formParam("Filter.1.Value.1", volumeId)
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("DescribeVolumesModificationsResponse.volumeModificationSet.item.volumeId", equalTo(volumeId));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void modifyVolumeRejectsInvalidParameterCombinations() {
|
||||
String standardVolId = createVolume("standard", 10);
|
||||
|
||||
given().header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "ModifyVolume")
|
||||
.formParam("VolumeId", standardVolId)
|
||||
.formParam("Throughput", "250")
|
||||
.when().post("/")
|
||||
.then().statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("InvalidParameterCombination"))
|
||||
.body("Response.Errors.Error.Message", equalTo("The parameter Throughput is not supported for standard volumes"));
|
||||
|
||||
given().header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "ModifyVolume")
|
||||
.formParam("VolumeId", standardVolId)
|
||||
.formParam("Iops", "1000")
|
||||
.when().post("/")
|
||||
.then().statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("InvalidParameterCombination"))
|
||||
.body("Response.Errors.Error.Message", equalTo("The parameter iops is not supported for standard volumes"));
|
||||
|
||||
given().header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "ModifyVolume")
|
||||
.formParam("VolumeId", volumeId)
|
||||
.formParam("MultiAttachEnabled", "true")
|
||||
.when().post("/")
|
||||
.then().statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("InvalidParameterCombination"))
|
||||
.body("Response.Errors.Error.Message", equalTo("The parameter MultiAttachEnabled is not supported for gp3 volumes"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void modifyVolumeSupportsDryRun() {
|
||||
given().header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "ModifyVolume")
|
||||
.formParam("VolumeId", volumeId)
|
||||
.formParam("Size", "30")
|
||||
.formParam("DryRun", "true")
|
||||
.when().post("/")
|
||||
.then().statusCode(412)
|
||||
.body("Response.Errors.Error.Code", equalTo("DryRunOperation"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user