Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

fix(rds): correct DescribeDBClusters serialization for DatabaseName, NetworkType, EngineLifecycleSupport (#618)

Jay Janssenebd101d665a6
diff --git a/ministack/services/rds.py b/ministack/services/rds.py
index b8143012..463417d2 100644
--- a/ministack/services/rds.py
+++ b/ministack/services/rds.py
@@ -900,7 +900,9 @@ def _create_db_cluster(p):
"Status": "available",
"MasterUsername": master_user,
"_MasterUserPassword": master_pass,
- "DatabaseName": _p(p, "DatabaseName") or "",
+ "DatabaseName": _p(p, "DatabaseName") or None,
+ "NetworkType": _p(p, "NetworkType") or "IPV4",
+ "EngineLifecycleSupport": _p(p, "EngineLifecycleSupport") or "open-source-rds-extended-support",
"Endpoint": f"{cluster_id}.cluster-{unique_suffix}.{get_region()}.rds.amazonaws.com",
"ReaderEndpoint": f"{cluster_id}.cluster-ro-{unique_suffix}.{get_region()}.rds.amazonaws.com",
"Port": port,
@@ -2274,6 +2276,11 @@ def _cluster_xml(c):
for t in c.get("TagList", []):
tag_xml += f"<Tag><Key>{_esc(t['Key'])}</Key><Value>{_esc(t['Value'])}</Value></Tag>"
+ # AWS omits <DatabaseName> entirely when no initial database was specified;
+ # emitting an empty element would surface as "" instead of None to clients.
+ db_name = c.get("DatabaseName")
+ db_name_xml = f"<DatabaseName>{db_name}</DatabaseName>" if db_name else ""
+
return f"""<DBClusterIdentifier>{c['DBClusterIdentifier']}</DBClusterIdentifier>
<DBClusterArn>{c['DBClusterArn']}</DBClusterArn>
<Engine>{c['Engine']}</Engine>
@@ -2281,7 +2288,7 @@ def _cluster_xml(c):
<EngineMode>{c.get('EngineMode','provisioned')}</EngineMode>
<Status>{c['Status']}</Status>
<MasterUsername>{c.get('MasterUsername','admin')}</MasterUsername>
- <DatabaseName>{c.get('DatabaseName','')}</DatabaseName>
+ {db_name_xml}
<Endpoint>{c.get('Endpoint','')}</Endpoint>
<ReaderEndpoint>{c.get('ReaderEndpoint','')}</ReaderEndpoint>
<Port>{c['Port']}</Port>
@@ -2309,7 +2316,9 @@ def _cluster_xml(c):
<AssociatedRoles/>
<TagList>{tag_xml}</TagList>
<AllocatedStorage>{c.get('AllocatedStorage',1)}</AllocatedStorage>
- <ActivityStreamStatus>{c.get('ActivityStreamStatus','stopped')}</ActivityStreamStatus>"""
+ <ActivityStreamStatus>{c.get('ActivityStreamStatus','stopped')}</ActivityStreamStatus>
+ <NetworkType>{c.get('NetworkType','IPV4')}</NetworkType>
+ <EngineLifecycleSupport>{c.get('EngineLifecycleSupport','open-source-rds-extended-support')}</EngineLifecycleSupport>"""
def _snapshot_xml(s):
diff --git a/tests/test_rds.py b/tests/test_rds.py
index 759c1ad9..dbcb6f5e 100644
--- a/tests/test_rds.py
+++ b/tests/test_rds.py
@@ -42,6 +42,39 @@ def test_rds_cluster(rds):
resp = rds.describe_db_clusters(DBClusterIdentifier="test-cluster")
assert resp["DBClusters"][0]["DBClusterIdentifier"] == "test-cluster"
+def test_rds_cluster_default_field_serialization(rds):
+ """Regression: DescribeDBClusters defaults must match real AWS for
+ DatabaseName (absent/None), NetworkType ("IPV4"), and EngineLifecycleSupport
+ ("open-source-rds-extended-support") when not supplied at create time."""
+ rds.create_db_cluster(
+ DBClusterIdentifier="cluster-defaults",
+ Engine="aurora-mysql",
+ MasterUsername="root",
+ MasterUserPassword="password123",
+ )
+ cluster = rds.describe_db_clusters(DBClusterIdentifier="cluster-defaults")["DBClusters"][0]
+ # AWS returns null/absent when no initial database was specified, not "".
+ assert cluster.get("DatabaseName") is None
+ assert cluster.get("NetworkType") == "IPV4"
+ assert cluster.get("EngineLifecycleSupport") == "open-source-rds-extended-support"
+
+def test_rds_cluster_explicit_field_round_trip(rds):
+ """Explicit DatabaseName / NetworkType / EngineLifecycleSupport round-trip
+ through DescribeDBClusters."""
+ rds.create_db_cluster(
+ DBClusterIdentifier="cluster-explicit",
+ Engine="aurora-mysql",
+ MasterUsername="root",
+ MasterUserPassword="password123",
+ DatabaseName="mydb",
+ NetworkType="DUAL",
+ EngineLifecycleSupport="open-source-rds-extended-support-disabled",
+ )
+ cluster = rds.describe_db_clusters(DBClusterIdentifier="cluster-explicit")["DBClusters"][0]
+ assert cluster.get("DatabaseName") == "mydb"
+ assert cluster.get("NetworkType") == "DUAL"
+ assert cluster.get("EngineLifecycleSupport") == "open-source-rds-extended-support-disabled"
+
def test_rds_create_instance_v2(rds):
resp = rds.create_db_instance(
DBInstanceIdentifier="rds-ci-v2",