mirror of
https://github.com/fog/fog-aws.git
synced 2022-11-09 13:50:52 -05:00
Merge pull request #158 from engineyard/rds-promote-modifying
update #promote_read_replica mock
This commit is contained in:
commit
2ca24dcbdf
5 changed files with 52 additions and 26 deletions
|
@ -87,9 +87,14 @@ module Fog
|
|||
|
||||
def promote_read_replica
|
||||
requires :id
|
||||
service.promote_read_replica(id)
|
||||
|
||||
data = service.promote_read_replica(id).body["PromoteReadReplicaResult"]["DBInstance"]
|
||||
|
||||
merge_attributes(data)
|
||||
end
|
||||
|
||||
alias promote promote_read_replica
|
||||
|
||||
def modify(immediately, options)
|
||||
options[:security_group_names] ||= options['DBSecurityGroups']
|
||||
params = self.class.new(options).attributes_to_params
|
||||
|
|
|
@ -77,7 +77,7 @@ module Fog
|
|||
|
||||
response.status = 200
|
||||
response.body = {
|
||||
"ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id },
|
||||
"ResponseMetadata" => { "RequestId" => Fog::AWS::Mock.request_id },
|
||||
"DescribeDBInstancesResult" => { "DBInstances" => server_set }
|
||||
}
|
||||
response
|
||||
|
|
|
@ -35,11 +35,12 @@ module Fog
|
|||
response = Excon::Response.new
|
||||
snapshots = self.data[:snapshots].values
|
||||
if opts[:identifier]
|
||||
snapshots = snapshots.select{|snapshot| snapshot['DBInstanceIdentifier'] == opts[:identifier]}
|
||||
snapshots = snapshots.select { |snapshot| snapshot['DBInstanceIdentifier'] == opts[:identifier] }
|
||||
|
||||
end
|
||||
|
||||
if opts[:snapshot_id]
|
||||
snapshots = snapshots.select{|snapshot| snapshot['DBSnapshotIdentifier'] == opts[:snapshot_id]}
|
||||
snapshots = snapshots.select { |snapshot| snapshot['DBSnapshotIdentifier'] == opts[:snapshot_id] }
|
||||
raise Fog::AWS::RDS::NotFound.new("DBSnapshot #{opts[:snapshot_id]} not found") if snapshots.empty?
|
||||
end
|
||||
|
||||
|
|
|
@ -25,34 +25,43 @@ module Fog
|
|||
params['BackupRetentionPeriod'] = backup_retention_period if backup_retention_period
|
||||
params['PreferredBackupWindow'] = preferred_backup_window if preferred_backup_window
|
||||
request({
|
||||
'Action' => 'PromoteReadReplica',
|
||||
'Action' => 'PromoteReadReplica',
|
||||
'DBInstanceIdentifier' => identifier,
|
||||
:parser => Fog::Parsers::AWS::RDS::PromoteReadReplica.new
|
||||
:parser => Fog::Parsers::AWS::RDS::PromoteReadReplica.new
|
||||
}.merge(params))
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def promote_read_replica(identifier, backup_retention_period = nil, preferred_backup_window = nil)
|
||||
if self.data[:servers][identifier]
|
||||
data = {
|
||||
'BackupRetentionPeriod' => backup_retention_period || 1,
|
||||
'PreferredBackupWindow' => preferred_backup_window || '08:00-08:30',
|
||||
'DBInstanceIdentifier' => identifier,
|
||||
}
|
||||
server = self.data[:servers][identifier]
|
||||
server || raise(Fog::AWS::RDS::NotFound.new("DBInstance #{identifier} not found"))
|
||||
|
||||
db_instance = self.data[:servers][identifier].merge(data)
|
||||
|
||||
response = Excon::Response.new
|
||||
response.body = {
|
||||
"ResponseMetadata" => { "RequestId" => Fog::AWS::Mock.request_id },
|
||||
"PromoteReadReplicaResult" => { "DBInstance" => db_instance }
|
||||
}
|
||||
response.status = 200
|
||||
response
|
||||
else
|
||||
raise Fog::AWS::RDS::NotFound.new("DBInstance #{identifier} not found")
|
||||
if server["ReadReplicaSourceDBInstanceIdentifier"].nil?
|
||||
raise(Fog::AWS::RDS::Error.new("InvalidDBInstanceState => DB Instance is not a read replica."))
|
||||
end
|
||||
|
||||
self.data[:modify_time] = Time.now
|
||||
|
||||
data = {
|
||||
'BackupRetentionPeriod' => backup_retention_period || 1,
|
||||
'PreferredBackupWindow' => preferred_backup_window || '08:00-08:30',
|
||||
'DBInstanceIdentifier' => identifier,
|
||||
'DBInstanceStatus' => "modifying",
|
||||
'PendingModifiedValues' => {
|
||||
'ReadReplicaSourceDBInstanceIdentifier' => nil,
|
||||
}
|
||||
}
|
||||
|
||||
server.merge!(data)
|
||||
|
||||
response = Excon::Response.new
|
||||
response.body = {
|
||||
"ResponseMetadata" => { "RequestId" => Fog::AWS::Mock.request_id },
|
||||
"PromoteReadReplicaResult" => { "DBInstance" => server }
|
||||
}
|
||||
response.status = 200
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -87,8 +87,9 @@ Shindo.tests("AWS::RDS | server", ['aws', 'rds']) do
|
|||
@instance.wait_for { state == 'rebooting' }
|
||||
@instance.wait_for { ready? }
|
||||
|
||||
tests('#create_read_replica').succeeds do
|
||||
replica = nil
|
||||
|
||||
tests('#create_read_replica').succeeds do
|
||||
replica = @instance_with_final_snapshot.create_read_replica(uniq_id('fog-replica'))
|
||||
@instance_with_final_snapshot.reload
|
||||
returns([replica.id]) { @instance_with_final_snapshot.read_replica_identifiers }
|
||||
|
@ -98,10 +99,20 @@ Shindo.tests("AWS::RDS | server", ['aws', 'rds']) do
|
|||
|
||||
# FinalDBSnapshotIdentifier can not be specified when deleting a replica instance
|
||||
raises(Fog::AWS::RDS::Error) { replica.destroy("foobar") }
|
||||
|
||||
replica.destroy
|
||||
end
|
||||
|
||||
tests('#promote_read_replica').succeeds do
|
||||
replica.promote.wait_for { state != "modifying" }
|
||||
|
||||
replica.read_replica_source == nil
|
||||
end
|
||||
|
||||
tests('#promote_read_replica', 'master').raises(Fog::AWS::RDS::Error) {
|
||||
@instance_with_final_snapshot.promote
|
||||
}
|
||||
|
||||
replica && replica.destroy
|
||||
|
||||
test("Destroying with a final snapshot") do
|
||||
final_snapshot_id = uniq_id('fog-test-snapshot')
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue