1
0
Fork 0
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:
Wesley Beary 2015-08-03 15:43:58 -05:00
commit 2ca24dcbdf
5 changed files with 52 additions and 26 deletions

View file

@ -87,9 +87,14 @@ module Fog
def promote_read_replica def promote_read_replica
requires :id requires :id
service.promote_read_replica(id)
data = service.promote_read_replica(id).body["PromoteReadReplicaResult"]["DBInstance"]
merge_attributes(data)
end end
alias promote promote_read_replica
def modify(immediately, options) def modify(immediately, options)
options[:security_group_names] ||= options['DBSecurityGroups'] options[:security_group_names] ||= options['DBSecurityGroups']
params = self.class.new(options).attributes_to_params params = self.class.new(options).attributes_to_params

View file

@ -77,7 +77,7 @@ module Fog
response.status = 200 response.status = 200
response.body = { response.body = {
"ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id }, "ResponseMetadata" => { "RequestId" => Fog::AWS::Mock.request_id },
"DescribeDBInstancesResult" => { "DBInstances" => server_set } "DescribeDBInstancesResult" => { "DBInstances" => server_set }
} }
response response

View file

@ -35,11 +35,12 @@ module Fog
response = Excon::Response.new response = Excon::Response.new
snapshots = self.data[:snapshots].values snapshots = self.data[:snapshots].values
if opts[:identifier] if opts[:identifier]
snapshots = snapshots.select{|snapshot| snapshot['DBInstanceIdentifier'] == opts[:identifier]} snapshots = snapshots.select { |snapshot| snapshot['DBInstanceIdentifier'] == opts[:identifier] }
end end
if opts[:snapshot_id] 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? raise Fog::AWS::RDS::NotFound.new("DBSnapshot #{opts[:snapshot_id]} not found") if snapshots.empty?
end end

View file

@ -25,34 +25,43 @@ module Fog
params['BackupRetentionPeriod'] = backup_retention_period if backup_retention_period params['BackupRetentionPeriod'] = backup_retention_period if backup_retention_period
params['PreferredBackupWindow'] = preferred_backup_window if preferred_backup_window params['PreferredBackupWindow'] = preferred_backup_window if preferred_backup_window
request({ request({
'Action' => 'PromoteReadReplica', 'Action' => 'PromoteReadReplica',
'DBInstanceIdentifier' => identifier, 'DBInstanceIdentifier' => identifier,
:parser => Fog::Parsers::AWS::RDS::PromoteReadReplica.new :parser => Fog::Parsers::AWS::RDS::PromoteReadReplica.new
}.merge(params)) }.merge(params))
end end
end end
class Mock class Mock
def promote_read_replica(identifier, backup_retention_period = nil, preferred_backup_window = nil) def promote_read_replica(identifier, backup_retention_period = nil, preferred_backup_window = nil)
if self.data[:servers][identifier] server = self.data[:servers][identifier]
data = { server || raise(Fog::AWS::RDS::NotFound.new("DBInstance #{identifier} not found"))
'BackupRetentionPeriod' => backup_retention_period || 1,
'PreferredBackupWindow' => preferred_backup_window || '08:00-08:30',
'DBInstanceIdentifier' => identifier,
}
db_instance = self.data[:servers][identifier].merge(data) if server["ReadReplicaSourceDBInstanceIdentifier"].nil?
raise(Fog::AWS::RDS::Error.new("InvalidDBInstanceState => DB Instance is not a read replica."))
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")
end 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 end
end end

View file

@ -87,8 +87,9 @@ Shindo.tests("AWS::RDS | server", ['aws', 'rds']) do
@instance.wait_for { state == 'rebooting' } @instance.wait_for { state == 'rebooting' }
@instance.wait_for { ready? } @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')) replica = @instance_with_final_snapshot.create_read_replica(uniq_id('fog-replica'))
@instance_with_final_snapshot.reload @instance_with_final_snapshot.reload
returns([replica.id]) { @instance_with_final_snapshot.read_replica_identifiers } 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 # FinalDBSnapshotIdentifier can not be specified when deleting a replica instance
raises(Fog::AWS::RDS::Error) { replica.destroy("foobar") } raises(Fog::AWS::RDS::Error) { replica.destroy("foobar") }
replica.destroy
end 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 test("Destroying with a final snapshot") do
final_snapshot_id = uniq_id('fog-test-snapshot') final_snapshot_id = uniq_id('fog-test-snapshot')