mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(dms): accept explicit default subnet group on CreateReplicationInstance (#5820)
* fix(dms): accept explicit default subnet group on CreateReplicationInstance CreateReplicationInstance with ReplicationSubnetGroupIdentifier=default (any case) returned ResourceNotFoundFault because only stored groups were consulted. AWS creates the default group on first use, so naming it explicitly is one way it comes into existence. It is now accepted whenever the region has default subnets, and the instance then makes it listed, keeping the rule that default is listed only once an instance uses it. * fix(dms): resolve the instance subnet group only after create validations CreateReplicationInstance resolved ReplicationSubnetGroupIdentifier=default before the duplicate-identifier, ResourceIdentifier and tag checks. Resolving default reads the region's subnets, which seeds its default VPC, so a request rejected by a later check still left a default VPC and subnets behind. The group is now resolved after every other check has passed, just before the instance is stored; successful requests behave as before.
This commit is contained in:
1 parent
0be4581d4e
commit
20b7a3673e
4 files changed
+120
-11
No files matched your search
@@ -205,6 +205,34 @@ class DmsIntegrationTest {
|
||||
.body("ReplicationSubnetGroups[0].VpcId", equalTo("vpc-default-ap-southeast-2"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Naming {@code default} explicitly is how an instance brings it into use, so it is accepted
|
||||
* before it is listed, and listed afterwards. Own region for the same reason as above.
|
||||
*/
|
||||
@Test
|
||||
void createInstanceNamingDefaultExplicitlyBringsTheDefaultGroupIntoUse() {
|
||||
String region = "ca-central-1";
|
||||
dms("CreateReplicationInstance", region)
|
||||
.body("{\"ReplicationInstanceIdentifier\":\"tf-explicit-default\","
|
||||
+ "\"ReplicationInstanceClass\":\"dms.t3.micro\","
|
||||
+ "\"ReplicationSubnetGroupIdentifier\":\"Default\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ReplicationInstance.ReplicationSubnetGroup.ReplicationSubnetGroupIdentifier",
|
||||
equalTo("default"));
|
||||
|
||||
dms("DescribeReplicationSubnetGroups", region)
|
||||
.body("{\"Filters\":[{\"Name\":\"replication-subnet-group-id\",\"Values\":[\"default\"]}]}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ReplicationSubnetGroups", hasSize(1))
|
||||
.body("ReplicationSubnetGroups[0].VpcId", equalTo("vpc-default-ca-central-1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeRejectsMaxRecordsOutsideTheDocumentedRange() {
|
||||
for (int outOfRange : new int[] {19, 101}) {
|
||||
|
||||
@@ -9,6 +9,7 @@ import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.dms.model.DmsResource;
|
||||
import io.github.hectorvent.floci.services.dms.model.ReplicationSubnetGroup;
|
||||
import io.github.hectorvent.floci.services.dms.model.ResourceTag;
|
||||
import io.github.hectorvent.floci.services.ec2.Ec2Service;
|
||||
@@ -210,6 +211,53 @@ class DmsServiceTest {
|
||||
assertEquals("ResourceNotFoundFault", notFound.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createInstanceNamingDefaultExplicitlyBringsTheDefaultGroupIntoUse() {
|
||||
useDefaultVpc();
|
||||
|
||||
DmsResource instance = service.createReplicationInstance(instanceRequest("Default"), REGION);
|
||||
|
||||
assertEquals("default", instance.getAttributes()
|
||||
.path("ReplicationSubnetGroup").path("ReplicationSubnetGroupIdentifier").asText());
|
||||
List<ReplicationSubnetGroup> described =
|
||||
service.describeReplicationSubnetGroups(filterRequest("default"), REGION).items();
|
||||
assertEquals(1, described.size());
|
||||
assertEquals(List.of("subnet-a", "subnet-b"), described.getFirst().getSubnetIds());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createInstanceNamingDefaultFaultsWhenTheRegionHasNoDefaultSubnets() {
|
||||
AwsException notFound = assertThrows(AwsException.class,
|
||||
() -> service.createReplicationInstance(instanceRequest("default"), REGION));
|
||||
assertEquals("ResourceNotFoundFault", notFound.getErrorCode());
|
||||
assertTrue(service.describeReplicationSubnetGroups(mapper.createObjectNode(), REGION).items().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectedCreateNamingDefaultNeverReadsTheRegionsSubnets() {
|
||||
useDefaultVpc();
|
||||
ObjectNode first = instanceRequest("default");
|
||||
first.remove("ReplicationSubnetGroupIdentifier");
|
||||
service.createReplicationInstance(first, REGION);
|
||||
|
||||
ObjectNode duplicate = instanceRequest("default");
|
||||
ObjectNode badResourceId = instanceRequest("default");
|
||||
badResourceId.put("ReplicationInstanceIdentifier", "bad-resource-id");
|
||||
badResourceId.put("ResourceIdentifier", "1-starts-with-a-digit");
|
||||
ObjectNode badTag = instanceRequest("default");
|
||||
badTag.put("ReplicationInstanceIdentifier", "bad-tag");
|
||||
badTag.putArray("Tags").addObject().put("Key", "aws:reserved").put("Value", "v");
|
||||
|
||||
assertEquals("ResourceAlreadyExistsFault", assertThrows(AwsException.class,
|
||||
() -> service.createReplicationInstance(duplicate, REGION)).getErrorCode());
|
||||
assertEquals("InvalidParameterValueException", assertThrows(AwsException.class,
|
||||
() -> service.createReplicationInstance(badResourceId, REGION)).getErrorCode());
|
||||
assertEquals("InvalidParameterValueException", assertThrows(AwsException.class,
|
||||
() -> service.createReplicationInstance(badTag, REGION)).getErrorCode());
|
||||
// Reading the region's subnets is what seeds its default VPC in the real Ec2Service.
|
||||
verify(ec2Service, never()).describeSubnets(eq(REGION), eq(List.of()), anyMap());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeOfMissingGroupFaults() {
|
||||
AwsException notFound = assertThrows(AwsException.class,
|
||||
@@ -616,6 +664,14 @@ class DmsServiceTest {
|
||||
service.createReplicationInstance(request, REGION);
|
||||
}
|
||||
|
||||
private ObjectNode instanceRequest(String subnetGroup) {
|
||||
ObjectNode request = mapper.createObjectNode();
|
||||
request.put("ReplicationInstanceIdentifier", "names-default");
|
||||
request.put("ReplicationInstanceClass", "dms.t3.micro");
|
||||
request.put("ReplicationSubnetGroupIdentifier", subnetGroup);
|
||||
return request;
|
||||
}
|
||||
|
||||
private void useDefaultVpc() {
|
||||
Subnet a = subnet("subnet-a");
|
||||
Subnet b = subnet("subnet-b");
|
||||
|
||||
Reference in new issue
Block a user