RDS: promote_read_replica (#5739)
This commit is contained in:
parent
8f074b0799
commit
4eb3944b1d
@ -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"]
|
||||
|
@ -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 = """<ModifyDBInstanceResponse xmlns="http://rds.amazon
|
||||
</ResponseMetadata>
|
||||
</ModifyDBInstanceResponse>"""
|
||||
|
||||
PROMOTE_REPLICA_TEMPLATE = """<PromoteReadReplicaResponse xmlns="http://rds.amazonaws.com/doc/2014-09-01/">
|
||||
<PromoteReadReplicaResult>
|
||||
{{ database.to_xml() }}
|
||||
</PromoteReadReplicaResult>
|
||||
<ResponseMetadata>
|
||||
<RequestId>8e8c0d64-be21-11d3-a71c-13dc2f771e41</RequestId>
|
||||
</ResponseMetadata>
|
||||
</PromoteReadReplicaResponse>"""
|
||||
|
||||
REBOOT_DATABASE_TEMPLATE = """<RebootDBInstanceResponse xmlns="http://rds.amazonaws.com/doc/2014-09-01/">
|
||||
<RebootDBInstanceResult>
|
||||
{{ database.to_xml() }}
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user