RDS: Can't delete DBCluster with active DBInstances (#6998)
This commit is contained in:
parent
e57aa67239
commit
6e9960895e
@ -82,6 +82,14 @@ class InvalidDBClusterStateFaultError(RDSClientError):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class DBClusterToBeDeletedHasActiveMembers(RDSClientError):
|
||||||
|
def __init__(self) -> None:
|
||||||
|
super().__init__(
|
||||||
|
"InvalidDBClusterStateFault",
|
||||||
|
"Cluster cannot be deleted, it still contains DB instances in non-deleting state.",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class InvalidDBInstanceStateError(RDSClientError):
|
class InvalidDBInstanceStateError(RDSClientError):
|
||||||
def __init__(self, database_identifier: str, istate: str):
|
def __init__(self, database_identifier: str, istate: str):
|
||||||
estate = (
|
estate = (
|
||||||
|
@ -19,6 +19,7 @@ from .exceptions import (
|
|||||||
DBClusterNotFoundError,
|
DBClusterNotFoundError,
|
||||||
DBClusterSnapshotAlreadyExistsError,
|
DBClusterSnapshotAlreadyExistsError,
|
||||||
DBClusterSnapshotNotFoundError,
|
DBClusterSnapshotNotFoundError,
|
||||||
|
DBClusterToBeDeletedHasActiveMembers,
|
||||||
DBInstanceNotFoundError,
|
DBInstanceNotFoundError,
|
||||||
DBSnapshotNotFoundError,
|
DBSnapshotNotFoundError,
|
||||||
DBSecurityGroupNotFoundError,
|
DBSecurityGroupNotFoundError,
|
||||||
@ -2344,7 +2345,8 @@ class RDSBackend(BaseBackend):
|
|||||||
raise InvalidParameterValue(
|
raise InvalidParameterValue(
|
||||||
"Can't delete Cluster with protection enabled"
|
"Can't delete Cluster with protection enabled"
|
||||||
)
|
)
|
||||||
|
if cluster.cluster_members:
|
||||||
|
raise DBClusterToBeDeletedHasActiveMembers()
|
||||||
global_id = cluster.global_cluster_identifier or ""
|
global_id = cluster.global_cluster_identifier or ""
|
||||||
if global_id in self.global_clusters:
|
if global_id in self.global_clusters:
|
||||||
self.remove_from_global_cluster(global_id, cluster_identifier)
|
self.remove_from_global_cluster(global_id, cluster_identifier)
|
||||||
|
@ -89,3 +89,42 @@ def test_add_instance_to_serverless_cluster():
|
|||||||
err = exc.value.response["Error"]
|
err = exc.value.response["Error"]
|
||||||
assert err["Code"] == "InvalidParameterValue"
|
assert err["Code"] == "InvalidParameterValue"
|
||||||
assert err["Message"] == "Instances cannot be added to Aurora Serverless clusters."
|
assert err["Message"] == "Instances cannot be added to Aurora Serverless clusters."
|
||||||
|
|
||||||
|
|
||||||
|
@mock_rds
|
||||||
|
def test_delete_db_cluster_fails_if_cluster_contains_db_instances():
|
||||||
|
cluster_identifier = "test-cluster"
|
||||||
|
instance_identifier = "test-instance"
|
||||||
|
client = boto3.client("rds", "us-east-1")
|
||||||
|
client.create_db_cluster(
|
||||||
|
DBClusterIdentifier=cluster_identifier,
|
||||||
|
Engine="aurora-postgresql",
|
||||||
|
MasterUsername="test-user",
|
||||||
|
MasterUserPassword="password",
|
||||||
|
)
|
||||||
|
client.create_db_instance(
|
||||||
|
DBClusterIdentifier=cluster_identifier,
|
||||||
|
Engine="aurora-postgresql",
|
||||||
|
DBInstanceIdentifier=instance_identifier,
|
||||||
|
DBInstanceClass="db.t4g.medium",
|
||||||
|
)
|
||||||
|
with pytest.raises(ClientError) as exc:
|
||||||
|
client.delete_db_cluster(
|
||||||
|
DBClusterIdentifier=cluster_identifier,
|
||||||
|
SkipFinalSnapshot=True,
|
||||||
|
)
|
||||||
|
err = exc.value.response["Error"]
|
||||||
|
assert err["Code"] == "InvalidDBClusterStateFault"
|
||||||
|
assert (
|
||||||
|
err["Message"]
|
||||||
|
== "Cluster cannot be deleted, it still contains DB instances in non-deleting state."
|
||||||
|
)
|
||||||
|
client.delete_db_instance(
|
||||||
|
DBInstanceIdentifier=instance_identifier,
|
||||||
|
SkipFinalSnapshot=True,
|
||||||
|
)
|
||||||
|
cluster = client.delete_db_cluster(
|
||||||
|
DBClusterIdentifier=cluster_identifier,
|
||||||
|
SkipFinalSnapshot=True,
|
||||||
|
).get("DBCluster")
|
||||||
|
assert cluster["DBClusterIdentifier"] == cluster_identifier
|
||||||
|
Loading…
Reference in New Issue
Block a user