fix(rds,docdb): list DocumentDB clusters and instances in the RDS-family list form (#2623)

* fix(rds,docdb): list DocumentDB clusters and instances in the RDS-family list form

The list form of DescribeDBClusters and DescribeDBInstances answered from
one store: on the rds scope from RDS, on the docdb scope from DocumentDB,
so a DocumentDB cluster was invisible to every list while its identifier
form worked. A live account lists the whole family from either endpoint.
RdsQueryHandler now assembles the list from both stores, honouring the
db-cluster-id / db-instance-id filters in each and an engine filter across
them (case-insensitive, OR over values, refused for a name outside the
family's engine list as on AWS), and the controller sends the docdb-scope
list form there too. The identifier form keeps routing to the store that
owns the identifier. Both halves list the region the request is signed
for.

Closes #2613

* fix(rds): report and filter an Aurora member instance by its Aurora engine name

DbInstance collapsed aurora-postgresql and aurora-mysql onto the community
engine enum, so a cluster member reported Engine postgres and the engine
filter matched it as postgres, where a live account says and matches
aurora-postgresql. Keep the engine name the request gave (or the
cluster's, for a member created without one) on the instance, and read it
for both the Engine element and the filter; a record persisted before the
field existed falls back to the enum.

* fix(rds): give a persisted instance its engine name on restore

An instance written before engineIdentifier existed deserializes with it
null, and a runtime fallback to the enum would keep reporting an Aurora
member as postgres. Backfill it in restorePersistedRuntime from the state
that knows: the member's cluster for a member, the enum for a standalone
instance.

* fix(rds): never persist a guessed engine name for a member of a nameless cluster

A cluster persisted before its own engineIdentifier existed (#1829) has
none to hand down, and writing the member's enum in that case would store
postgres for what may be an Aurora member — a guess that outlives the
code able to tell. The backfill writes only what is certain: the
cluster's stored name for a member, the enum for a standalone instance;
a member of a nameless cluster is left unset.

* fix(rds,neptune): list Neptune clusters and instances in the RDS-family list form too

A live account lists a Neptune cluster from the rds, docdb and neptune
endpoints alike and selects it with engine=neptune. The list form now
merges Neptune rows the way it merges DocumentDB ones, and the neptune
scope's list form goes to the same assembly. The Neptune store is not
keyed by region, so its rows are scoped to the request's region by ARN.

* fix(rds): close the subnet-group tags test in rds.bats

---------

Co-authored-by: Priamo Germosen <6233424+pgermosen@users.noreply.github.com>
This commit is contained in:
Michal SchreiberandPriamo Germosen authored and GitHub committed 2026-08-28 09:37:29 -04:00
1 parent 7188b3ec9d
commit 3b0e31b888
14 files changed
+784 -10

No files matched your search

@@ -0,0 +1,238 @@
package io.github.hectorvent.floci.services.docdb;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import java.util.Map;
import static io.restassured.RestAssured.given;
import static io.restassured.http.ContentType.URLENC;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
/**
* The list form of DescribeDBClusters / DescribeDBInstances covers the whole RDS family.
*
* <p>A live account lists a DocumentDB cluster from {@code aws rds describe-db-clusters} and
* {@code aws docdb describe-db-clusters} alike, with or without an {@code engine} filter; both
* CLIs sign with the {@code rds} scope, and Floci accepts {@code docdb} as well.
*/
@QuarkusTest
@TestProfile(RdsFamilyListingIntegrationTest.NoContainersProfile.class)
class RdsFamilyListingIntegrationTest {
public static class NoContainersProfile implements QuarkusTestProfile {
@Override
public Map<String, String> getConfigOverrides() {
return Map.of("floci.services.rds.mock", "true",
"floci.services.docdb.mock", "true");
}
}
private static final String AURORA = "family-aurora";
private static final String DOCS = "family-docs";
private static final String DOCS_INSTANCE = "family-docs-1";
private static io.restassured.specification.RequestSpecification query(String scope, String region, String action) {
return given().header("Authorization",
"AWS4-HMAC-SHA256 Credential=test/20260615/" + region + "/" + scope + "/aws4_request, "
+ "SignedHeaders=content-type;host, Signature=test")
.contentType(URLENC)
.formParam("Action", action)
.formParam("Version", "2014-10-31");
}
private void createBoth() {
query("rds", "us-east-1", "CreateDBCluster")
.formParam("DBClusterIdentifier", AURORA)
.formParam("Engine", "aurora-postgresql")
.formParam("MasterUsername", "admin")
.formParam("MasterUserPassword", "secret99password")
.when().post("/").then().statusCode(200);
query("rds", "us-east-1", "CreateDBCluster")
.formParam("DBClusterIdentifier", DOCS)
.formParam("Engine", "docdb")
.formParam("MasterUsername", "docdbadmin")
.formParam("MasterUserPassword", "secret99password")
.when().post("/").then().statusCode(200);
query("rds", "us-east-1", "CreateDBInstance")
.formParam("DBInstanceIdentifier", DOCS_INSTANCE)
.formParam("DBInstanceClass", "db.t3.medium")
.formParam("Engine", "docdb")
.formParam("DBClusterIdentifier", DOCS)
.when().post("/").then().statusCode(200);
}
@AfterEach
void cleanUp() {
query("rds", "us-east-1", "DeleteDBInstance").formParam("DBInstanceIdentifier", DOCS_INSTANCE)
.when().post("/");
query("rds", "us-east-1", "DeleteDBCluster").formParam("DBClusterIdentifier", DOCS)
.formParam("SkipFinalSnapshot", "true").when().post("/");
query("rds", "us-east-1", "DeleteDBCluster").formParam("DBClusterIdentifier", AURORA)
.formParam("SkipFinalSnapshot", "true").when().post("/");
}
@Test
void listFormOnEitherScopeCoversBothStores() {
createBoth();
for (String scope : new String[] {"rds", "docdb"}) {
query(scope, "us-east-1", "DescribeDBClusters")
.when().post("/")
.then()
.statusCode(200)
.body(containsString("<DBClusterIdentifier>" + AURORA + "</DBClusterIdentifier>"))
.body(containsString("<DBClusterIdentifier>" + DOCS + "</DBClusterIdentifier>"));
query(scope, "us-east-1", "DescribeDBInstances")
.when().post("/")
.then()
.statusCode(200)
.body(containsString("<DBInstanceIdentifier>" + DOCS_INSTANCE + "</DBInstanceIdentifier>"));
}
}
@Test
void engineFilterSelectsAcrossBothStores() {
createBoth();
query("docdb", "us-east-1", "DescribeDBClusters")
.formParam("Filters.Filter.1.Name", "engine")
.formParam("Filters.Filter.1.Values.Value.1", "docdb")
.when().post("/")
.then()
.statusCode(200)
.body(containsString("<DBClusterIdentifier>" + DOCS + "</DBClusterIdentifier>"))
.body(not(containsString("<DBClusterIdentifier>" + AURORA + "</DBClusterIdentifier>")));
query("rds", "us-east-1", "DescribeDBClusters")
.formParam("Filters.Filter.1.Name", "engine")
.formParam("Filters.Filter.1.Values.Value.1", "aurora-postgresql")
.when().post("/")
.then()
.statusCode(200)
.body(containsString("<DBClusterIdentifier>" + AURORA + "</DBClusterIdentifier>"))
.body(not(containsString("<DBClusterIdentifier>" + DOCS + "</DBClusterIdentifier>")));
}
@Test
void unknownEngineFilterIsRefusedOnEitherScope() {
createBoth();
for (String scope : new String[] {"rds", "docdb"}) {
query(scope, "us-east-1", "DescribeDBClusters")
.formParam("Filters.Filter.1.Name", "engine")
.formParam("Filters.Filter.1.Values.Value.1", "nothing")
.when().post("/")
.then()
.statusCode(400)
.body(containsString("Unrecognized engine name: nothing"));
}
}
@Test
void auroraMemberInstancesAnswerToTheirAuroraEngineName() {
createBoth();
String member = "family-aurora-1";
query("rds", "us-east-1", "CreateDBInstance")
.formParam("DBInstanceIdentifier", member)
.formParam("DBInstanceClass", "db.t3.medium")
.formParam("Engine", "aurora-postgresql")
.formParam("DBClusterIdentifier", AURORA)
.when().post("/").then().statusCode(200)
.body(containsString("<Engine>aurora-postgresql</Engine>"));
try {
query("rds", "us-east-1", "DescribeDBInstances")
.formParam("Filters.Filter.1.Name", "engine")
.formParam("Filters.Filter.1.Values.Value.1", "aurora-postgresql")
.when().post("/")
.then()
.statusCode(200)
.body(containsString("<DBInstanceIdentifier>" + member + "</DBInstanceIdentifier>"))
.body(not(containsString("<DBInstanceIdentifier>" + DOCS_INSTANCE + "</DBInstanceIdentifier>")));
query("rds", "us-east-1", "DescribeDBInstances")
.formParam("Filters.Filter.1.Name", "engine")
.formParam("Filters.Filter.1.Values.Value.1", "postgres")
.when().post("/")
.then()
.statusCode(200)
.body(not(containsString("<DBInstanceIdentifier>" + member + "</DBInstanceIdentifier>")));
} finally {
query("rds", "us-east-1", "DeleteDBInstance").formParam("DBInstanceIdentifier", member)
.when().post("/");
}
}
@Test
void identifierFormStillFaultsForAnUnknownClusterOnEitherScope() {
createBoth();
for (String scope : new String[] {"rds", "docdb"}) {
query(scope, "us-east-1", "DescribeDBClusters")
.formParam("DBClusterIdentifier", "family-absent")
.when().post("/")
.then()
.statusCode(404)
.body(containsString("DBClusterNotFoundFault"));
}
}
@Test
void bothHalvesOfTheListingFollowTheSignedRegionAwayFromTheDefault() {
// both stores keyed by the region the request was signed for, not the configured default:
// records created under eu-west-1 show up there and nowhere else
String aurora = "family-west-aurora";
String docs = "family-west-docs";
query("rds", "eu-west-1", "CreateDBCluster")
.formParam("DBClusterIdentifier", aurora)
.formParam("Engine", "aurora-postgresql")
.formParam("MasterUsername", "admin")
.formParam("MasterUserPassword", "secret99password")
.when().post("/").then().statusCode(200);
query("docdb", "eu-west-1", "CreateDBCluster")
.formParam("DBClusterIdentifier", docs)
.formParam("Engine", "docdb")
.formParam("MasterUsername", "docdbadmin")
.formParam("MasterUserPassword", "secret99password")
.when().post("/").then().statusCode(200);
try {
for (String scope : new String[] {"rds", "docdb"}) {
query(scope, "eu-west-1", "DescribeDBClusters")
.when().post("/")
.then()
.statusCode(200)
.body(containsString("<DBClusterIdentifier>" + aurora + "</DBClusterIdentifier>"))
.body(containsString("<DBClusterIdentifier>" + docs + "</DBClusterIdentifier>"));
query(scope, "us-east-1", "DescribeDBClusters")
.when().post("/")
.then()
.statusCode(200)
.body(not(containsString("<DBClusterIdentifier>" + aurora + "</DBClusterIdentifier>")))
.body(not(containsString("<DBClusterIdentifier>" + docs + "</DBClusterIdentifier>")));
}
// an ARN filter naming the other region's cluster finds nothing either
query("rds", "us-east-1", "DescribeDBClusters")
.formParam("Filters.Filter.1.Name", "db-cluster-id")
.formParam("Filters.Filter.1.Values.Value.1",
"arn:aws:rds:eu-west-1:000000000000:cluster:" + docs)
.when().post("/")
.then()
.statusCode(200)
.body(not(containsString("<DBClusterIdentifier>" + docs + "</DBClusterIdentifier>")));
} finally {
query("rds", "eu-west-1", "DeleteDBCluster").formParam("DBClusterIdentifier", docs)
.formParam("SkipFinalSnapshot", "true").when().post("/");
query("rds", "eu-west-1", "DeleteDBCluster").formParam("DBClusterIdentifier", aurora)
.formParam("SkipFinalSnapshot", "true").when().post("/");
}
}
@Test
void listingIsScopedToTheSignedRegion() {
createBoth();
query("rds", "eu-west-1", "DescribeDBClusters")
.when().post("/")
.then()
.statusCode(200)
.body(not(containsString("<DBClusterIdentifier>" + DOCS + "</DBClusterIdentifier>")))
.body(not(containsString("<DBClusterIdentifier>" + AURORA + "</DBClusterIdentifier>")));
}
}
@@ -0,0 +1,39 @@
package io.github.hectorvent.floci.services.neptune;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.neptune.model.NeptuneCluster;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
class NeptuneQueryHandlerRowsTest {
private static NeptuneCluster cluster(String id, String region) {
NeptuneCluster c = new NeptuneCluster();
c.setDbClusterIdentifier(id);
c.setStatus("available");
c.setDbClusterArn("arn:aws:rds:" + region + ":000000000000:cluster:" + id);
return c;
}
@Test
void rowsForTheFamilyListingAreScopedToTheRequestRegionByArn() {
// the Neptune store is not keyed by region: the request's region has to be read off the ARN
NeptuneService service = mock(NeptuneService.class);
when(service.listDbClusters(isNull())).thenReturn(List.of(
cluster("east", "us-east-1"), cluster("west", "eu-west-1")));
NeptuneQueryHandler handler = new NeptuneQueryHandler(service, mock(EmulatorConfig.class));
List<String> rows = handler.clusterRowsXml(null, "us-east-1");
assertEquals(1, rows.size(), rows.toString());
assertTrue(rows.getFirst().contains("<DBClusterIdentifier>east</DBClusterIdentifier>"), rows.getFirst());
assertTrue(rows.getFirst().contains("<Engine>neptune</Engine>"), rows.getFirst());
}
}
@@ -2,8 +2,11 @@ package io.github.hectorvent.floci.services.rds;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.rds.model.DatabaseEngine;
import io.github.hectorvent.floci.services.rds.model.DbCluster;
import io.github.hectorvent.floci.services.rds.model.DbClusterParameterGroup;
import io.github.hectorvent.floci.services.docdb.DocDbQueryHandler;
import io.github.hectorvent.floci.services.neptune.NeptuneQueryHandler;
import io.github.hectorvent.floci.services.rds.model.DbInstance;
import io.github.hectorvent.floci.services.rds.model.DbInstanceStatus;
import io.github.hectorvent.floci.services.rds.model.DbParameterGroup;
@@ -34,6 +37,8 @@ import static org.mockito.Mockito.*;
class RdsQueryHandlerTest {
private RdsService service;
private DocDbQueryHandler docDbHandler;
private NeptuneQueryHandler neptuneHandler;
private RdsQueryHandler handler;
@BeforeEach
@@ -45,7 +50,9 @@ class RdsQueryHandlerTest {
when(config.services()).thenReturn(servicesConfig);
when(servicesConfig.rds()).thenReturn(rdsConfig);
when(config.defaultAvailabilityZone()).thenReturn("us-east-1a");
handler = new RdsQueryHandler(service, config);
docDbHandler = mock(DocDbQueryHandler.class);
neptuneHandler = mock(NeptuneQueryHandler.class);
handler = new RdsQueryHandler(service, config, docDbHandler, neptuneHandler);
}
// ──────────────────────────── DBInstances XML tag ────────────────────────────
@@ -2027,4 +2034,190 @@ class RdsQueryHandlerTest {
verify(service).createDbSubnetGroup("tagged", "d", List.of("subnet-aaa", "subnet-bbb"), null,
java.util.Map.of("Name", "tagged", "env", "tst"));
}
// ──────────────────────────── RDS-family listing ────────────────────────────
@Test
void describeDbClusters_listFormIncludesDocumentDbClusters() {
DbCluster aurora = makeCluster("aurora");
when(service.listDbClusters(null, null)).thenReturn(List.of(aurora));
when(docDbHandler.clusterRowsXml(null)).thenReturn(List.of(
"<DBClusterIdentifier>docs</DBClusterIdentifier><Engine>docdb</Engine>"));
String body = (String) handler.handle("DescribeDBClusters", params()).getEntity();
assertTrue(body.contains("<DBClusterIdentifier>aurora</DBClusterIdentifier>"), body);
assertTrue(body.contains("<DBClusterIdentifier>docs</DBClusterIdentifier>"), body);
}
@Test
void describeDbClusters_identifierFormNeverConsultsDocumentDb() {
when(service.listDbClusters("aurora", null)).thenReturn(List.of(makeCluster("aurora")));
MultivaluedMap<String, String> p = params();
p.add("DBClusterIdentifier", "aurora");
assertEquals(200, handler.handle("DescribeDBClusters", p).getStatus());
verify(docDbHandler, never()).clusterRowsXml(any());
}
@Test
void describeDbClusters_engineFilterSelectsAcrossBothStores() {
DbCluster aurora = makeCluster("aurora");
aurora.setEngineIdentifier("aurora-postgresql");
when(service.listDbClusters(null, null)).thenReturn(List.of(aurora));
when(docDbHandler.clusterRowsXml(null)).thenReturn(List.of(
"<DBClusterIdentifier>docs</DBClusterIdentifier><Engine>docdb</Engine>"));
MultivaluedMap<String, String> p = params();
p.add("Filters.Filter.1.Name", "engine");
p.add("Filters.Filter.1.Values.Value.1", "docdb");
String body = (String) handler.handle("DescribeDBClusters", p).getEntity();
assertFalse(body.contains("<DBClusterIdentifier>aurora</DBClusterIdentifier>"), body);
assertTrue(body.contains("<DBClusterIdentifier>docs</DBClusterIdentifier>"), body);
p = params();
p.add("Filters.Filter.1.Name", "engine");
p.add("Filters.Filter.1.Values.Value.1", "Aurora-PostgreSQL");
body = (String) handler.handle("DescribeDBClusters", p).getEntity();
assertTrue(body.contains("<DBClusterIdentifier>aurora</DBClusterIdentifier>"), body);
assertFalse(body.contains("<DBClusterIdentifier>docs</DBClusterIdentifier>"), body);
verify(docDbHandler, times(1)).clusterRowsXml(any());
}
@Test
void describeDbClusters_idFilterReachesDocumentDbToo() {
when(service.listDbClusters("docs", null)).thenReturn(List.of());
when(docDbHandler.clusterRowsXml("docs")).thenReturn(List.of(
"<DBClusterIdentifier>docs</DBClusterIdentifier><Engine>docdb</Engine>"));
MultivaluedMap<String, String> p = params();
p.add("Filters.Filter.1.Name", "db-cluster-id");
p.add("Filters.Filter.1.Values.Value.1", "docs");
String body = (String) handler.handle("DescribeDBClusters", p).getEntity();
assertTrue(body.contains("<DBClusterIdentifier>docs</DBClusterIdentifier>"), body);
}
@Test
void describeDbInstances_listFormIncludesDocumentDbInstancesAndHonoursEngineFilter() {
DbInstance postgres = makeInstance("pg");
postgres.setEngine(DatabaseEngine.POSTGRES);
when(service.listDbInstances(null, null)).thenReturn(List.of(postgres));
when(docDbHandler.instanceRowsXml(null)).thenReturn(List.of(
"<DBInstanceIdentifier>docs-1</DBInstanceIdentifier><Engine>docdb</Engine>"));
String body = (String) handler.handle("DescribeDBInstances", params()).getEntity();
assertTrue(body.contains("<DBInstanceIdentifier>pg</DBInstanceIdentifier>"), body);
assertTrue(body.contains("<DBInstanceIdentifier>docs-1</DBInstanceIdentifier>"), body);
MultivaluedMap<String, String> p = params();
p.add("Filters.Filter.1.Name", "engine");
p.add("Filters.Filter.1.Values.Value.1", "postgres");
body = (String) handler.handle("DescribeDBInstances", p).getEntity();
assertTrue(body.contains("<DBInstanceIdentifier>pg</DBInstanceIdentifier>"), body);
assertFalse(body.contains("<DBInstanceIdentifier>docs-1</DBInstanceIdentifier>"), body);
p = params();
p.add("DBInstanceIdentifier", "pg");
when(service.listDbInstances("pg", null)).thenReturn(List.of(postgres));
handler.handle("DescribeDBInstances", p);
verify(docDbHandler, times(1)).instanceRowsXml(any());
}
@Test
void describeDbClusters_engineFilterIsValidatedAgainstTheFamilysEngineNames() {
when(service.listDbClusters(null, null)).thenReturn(List.of(makeCluster("aurora")));
when(docDbHandler.clusterRowsXml(null)).thenReturn(List.of());
MultivaluedMap<String, String> p = params();
p.add("Filters.Filter.1.Name", "engine");
p.add("Filters.Filter.1.Values.Value.1", "nothing");
Response response = handler.handle("DescribeDBClusters", p);
assertEquals(400, response.getStatus());
String body = (String) response.getEntity();
assertTrue(body.contains("<Code>InvalidParameterValue</Code>"), body);
assertTrue(body.contains("Unrecognized engine name: nothing"), body);
// an engine Floci cannot create is still a name AWS knows: an empty list, not a fault
p = params();
p.add("Filters.Filter.1.Name", "engine");
p.add("Filters.Filter.1.Values.Value.1", "oracle-ee");
response = handler.handle("DescribeDBClusters", p);
assertEquals(200, response.getStatus());
assertFalse(((String) response.getEntity()).contains("<DBClusterIdentifier>"), (String) response.getEntity());
p = params();
p.add("Filters.Filter.1.Name", "engine");
p.add("Filters.Filter.1.Values.Value.1", "bogus");
response = handler.handle("DescribeDBInstances", p);
assertEquals(400, response.getStatus());
assertTrue(((String) response.getEntity()).contains("Unrecognized engine name: bogus"));
}
@Test
void describeDbInstances_auroraMemberIsFilteredAndReportedByItsAuroraEngineName() {
DbInstance member = makeInstance("member");
member.setEngine(DatabaseEngine.POSTGRES);
member.setEngineIdentifier("aurora-postgresql");
DbInstance legacy = makeInstance("legacy");
legacy.setEngine(DatabaseEngine.POSTGRES);
when(service.listDbInstances(null, null)).thenReturn(List.of(member, legacy));
when(docDbHandler.instanceRowsXml(null)).thenReturn(List.of());
MultivaluedMap<String, String> p = params();
p.add("Filters.Filter.1.Name", "engine");
p.add("Filters.Filter.1.Values.Value.1", "aurora-postgresql");
String body = (String) handler.handle("DescribeDBInstances", p).getEntity();
assertTrue(body.contains("<DBInstanceIdentifier>member</DBInstanceIdentifier>"), body);
assertTrue(body.contains("<Engine>aurora-postgresql</Engine>"), body);
assertFalse(body.contains("<DBInstanceIdentifier>legacy</DBInstanceIdentifier>"), body);
p = params();
p.add("Filters.Filter.1.Name", "engine");
p.add("Filters.Filter.1.Values.Value.1", "postgres");
body = (String) handler.handle("DescribeDBInstances", p).getEntity();
assertFalse(body.contains("<DBInstanceIdentifier>member</DBInstanceIdentifier>"), body);
assertTrue(body.contains("<DBInstanceIdentifier>legacy</DBInstanceIdentifier>"), body);
assertTrue(body.contains("<Engine>postgres</Engine>"), body);
}
@Test
void describeDbClusters_listFormIncludesNeptuneClustersAndTheEngineFilterSelectsThem() {
when(service.listDbClusters(null, null)).thenReturn(List.of(makeCluster("aurora")));
when(docDbHandler.clusterRowsXml(null)).thenReturn(List.of(
"<DBClusterIdentifier>docs</DBClusterIdentifier><Engine>docdb</Engine>"));
when(neptuneHandler.clusterRowsXml(null, null)).thenReturn(List.of(
"<DBClusterIdentifier>graph</DBClusterIdentifier><Engine>neptune</Engine>"));
String body = (String) handler.handle("DescribeDBClusters", params()).getEntity();
assertTrue(body.contains("<DBClusterIdentifier>aurora</DBClusterIdentifier>"), body);
assertTrue(body.contains("<DBClusterIdentifier>docs</DBClusterIdentifier>"), body);
assertTrue(body.contains("<DBClusterIdentifier>graph</DBClusterIdentifier>"), body);
MultivaluedMap<String, String> p = params();
p.add("Filters.Filter.1.Name", "engine");
p.add("Filters.Filter.1.Values.Value.1", "neptune");
body = (String) handler.handle("DescribeDBClusters", p).getEntity();
assertFalse(body.contains("<DBClusterIdentifier>aurora</DBClusterIdentifier>"), body);
assertFalse(body.contains("<DBClusterIdentifier>docs</DBClusterIdentifier>"), body);
assertTrue(body.contains("<DBClusterIdentifier>graph</DBClusterIdentifier>"), body);
verify(docDbHandler, times(1)).clusterRowsXml(any());
p = params();
p.add("DBClusterIdentifier", "aurora");
handler.handle("DescribeDBClusters", p);
verify(neptuneHandler, times(2)).clusterRowsXml(any(), any());
}
@Test
void describeDbInstances_listFormIncludesNeptuneInstances() {
when(service.listDbInstances(null, null)).thenReturn(List.of());
when(docDbHandler.instanceRowsXml(null)).thenReturn(List.of());
when(neptuneHandler.instanceRowsXml(null, null)).thenReturn(List.of(
"<DBInstanceIdentifier>graph-1</DBInstanceIdentifier><Engine>neptune</Engine>"));
String body = (String) handler.handle("DescribeDBInstances", params()).getEntity();
assertTrue(body.contains("<DBInstanceIdentifier>graph-1</DBInstanceIdentifier>"), body);
}
}
@@ -4938,4 +4938,73 @@ class RdsServiceTest {
assertEquals(Map.of("Name", "tagged", "env", "stg", "extra", "yes"),
rdsService.getDbSubnetGroup("tagged", "us-east-1").getTags());
}
@Test
void createDbInstanceKeepsTheEngineNameTheRequestGave() {
rdsService.createDbCluster("aurora", "aurora-postgresql", null, "admin", "secret99password",
null, false, null);
rdsService.createDbInstance("member", "aurora-postgresql", "16",
"admin", "password", null, "db.t3.medium",
20, false, null, null, "aurora", null, false);
rdsService.createDbInstance("member-2", null, "16",
"admin", "password", null, "db.t3.medium",
20, false, null, null, "aurora", null, false);
rdsService.createDbInstance("plain", "postgres", "13",
"admin", "password", "dbname", "db.t3.micro",
20, false, null, null, null, null, false);
assertEquals("aurora-postgresql", rdsService.getDbInstance("member").getEngineIdentifier());
// a member created without Engine takes the cluster's
assertEquals("aurora-postgresql", rdsService.getDbInstance("member-2").getEngineIdentifier());
assertEquals("postgres", rdsService.getDbInstance("plain").getEngineIdentifier());
}
@Test
void restoreGivesAPersistedAuroraMemberItsClusterEngineName() {
// A member written by a floci that predates engineIdentifier carries only the enum, which
// says postgres for an aurora-postgresql cluster. The cluster still knows, and the restore
// reads it there, so the member is reported and filtered as aurora-postgresql.
InMemoryStorage<String, DbInstance> instances = new InMemoryStorage<>();
InMemoryStorage<String, DbCluster> clusters = new InMemoryStorage<>();
RdsService service = newService(containerManager, proxyManager, instances, clusters,
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>());
service.createDbCluster("aurora", "aurora-postgresql", null, "admin", "secret99password",
null, false, null);
DbInstance legacyMember = new DbInstance();
legacyMember.setDbInstanceIdentifier("legacy-member");
legacyMember.setEngine(DatabaseEngine.POSTGRES);
legacyMember.setDbClusterIdentifier("aurora");
legacyMember.setDbInstanceArn("arn:aws:rds:us-east-1:123456789012:db:legacy-member");
legacyMember.setStatus(DbInstanceStatus.AVAILABLE);
instances.put("us-east-1::legacy-member", legacyMember);
DbInstance legacyStandalone = new DbInstance();
legacyStandalone.setDbInstanceIdentifier("legacy-plain");
legacyStandalone.setEngine(DatabaseEngine.MARIADB);
legacyStandalone.setDbInstanceArn("arn:aws:rds:us-east-1:123456789012:db:legacy-plain");
legacyStandalone.setStatus(DbInstanceStatus.AVAILABLE);
instances.put("us-east-1::legacy-plain", legacyStandalone);
// a member of a cluster that predates the field itself: nothing certain to write, so
// nothing is written — the enum would persist postgres for what may be Aurora
DbCluster nameless = new DbCluster();
nameless.setDbClusterIdentifier("old-cluster");
nameless.setEngine(DatabaseEngine.POSTGRES);
nameless.setStatus(DbInstanceStatus.AVAILABLE);
nameless.setDbClusterArn("arn:aws:rds:us-east-1:123456789012:cluster:old-cluster");
clusters.put("us-east-1::old-cluster", nameless);
DbInstance orphanedMember = new DbInstance();
orphanedMember.setDbInstanceIdentifier("old-member");
orphanedMember.setEngine(DatabaseEngine.POSTGRES);
orphanedMember.setDbClusterIdentifier("old-cluster");
orphanedMember.setDbInstanceArn("arn:aws:rds:us-east-1:123456789012:db:old-member");
orphanedMember.setStatus(DbInstanceStatus.AVAILABLE);
instances.put("us-east-1::old-member", orphanedMember);
service.restorePersistedRuntime();
assertEquals("aurora-postgresql", service.getDbInstance("legacy-member").getEngineIdentifier());
assertEquals("mariadb", service.getDbInstance("legacy-plain").getEngineIdentifier());
assertNull(service.getDbInstance("old-member").getEngineIdentifier());
}
}