diff --git a/moto/rds/models.py b/moto/rds/models.py index f4ad42687..37c7f3f30 100644 --- a/moto/rds/models.py +++ b/moto/rds/models.py @@ -1385,6 +1385,15 @@ class RDSBackend(BaseBackend): return self.database_snapshots.pop(db_snapshot_identifier) + def promote_read_replica(self, db_kwargs): + database_id = db_kwargs["db_instance_identifier"] + database = self.databases.get(database_id) + if database.is_replica: + database.is_replica = False + database.update(db_kwargs) + + return database + def create_db_instance_read_replica(self, db_kwargs): database_id = db_kwargs["db_instance_identifier"] source_database_id = db_kwargs["source_db_identifier"] diff --git a/moto/rds/responses.py b/moto/rds/responses.py index b16ab47e7..814e9d828 100644 --- a/moto/rds/responses.py +++ b/moto/rds/responses.py @@ -295,6 +295,14 @@ class RDSResponse(BaseResponse): template = self.response_template(DESCRIBE_SNAPSHOTS_TEMPLATE) return template.render(snapshots=snapshots) + def promote_read_replica(self): + db_instance_identifier = self._get_param("DBInstanceIdentifier") + db_kwargs = self._get_db_kwargs() + database = self.backend.promote_read_replica(db_kwargs) + database = self.backend.modify_db_instance(db_instance_identifier, db_kwargs) + template = self.response_template(PROMOTE_REPLICA_TEMPLATE) + return template.render(database=database) + def delete_db_snapshot(self): db_snapshot_identifier = self._get_param("DBSnapshotIdentifier") snapshot = self.backend.delete_db_snapshot(db_snapshot_identifier) @@ -704,6 +712,15 @@ MODIFY_DATABASE_TEMPLATE = """ + + {{ database.to_xml() }} + + + 8e8c0d64-be21-11d3-a71c-13dc2f771e41 + +""" + REBOOT_DATABASE_TEMPLATE = """ {{ database.to_xml() }} diff --git a/tests/test_rds/test_rds.py b/tests/test_rds/test_rds.py index 67567772b..006903788 100644 --- a/tests/test_rds/test_rds.py +++ b/tests/test_rds/test_rds.py @@ -656,6 +656,34 @@ def test_describe_db_snapshots(): snapshots.should.have.length_of(2) +@mock_rds +def test_promote_read_replica(): + conn = boto3.client("rds", region_name="us-west-2") + conn.create_db_instance( + DBInstanceIdentifier="db-primary-1", + AllocatedStorage=10, + Engine="postgres", + DBName="staging-postgres", + DBInstanceClass="db.m1.small", + MasterUsername="root", + MasterUserPassword="hunter2", + Port=1234, + DBSecurityGroups=["my_sg"], + ) + + conn.create_db_instance_read_replica( + DBInstanceIdentifier="db-replica-1", + SourceDBInstanceIdentifier="db-primary-1", + DBInstanceClass="db.m1.small", + ) + conn.promote_read_replica(DBInstanceIdentifier="db-replica-1") + + replicas = conn.describe_db_instances(DBInstanceIdentifier="db-primary-1").get( + "ReadReplicaDBInstanceIdentifiers" + ) + assert replicas is None + + @mock_rds def test_delete_db_snapshot(): conn = boto3.client("rds", region_name="us-west-2")