diff --git a/lib/fog/aws/models/rds/server.rb b/lib/fog/aws/models/rds/server.rb index e0d22a8de..890722cfe 100644 --- a/lib/fog/aws/models/rds/server.rb +++ b/lib/fog/aws/models/rds/server.rb @@ -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 diff --git a/lib/fog/aws/requests/rds/describe_db_instances.rb b/lib/fog/aws/requests/rds/describe_db_instances.rb index 2bc663e5d..1ad8d5be4 100644 --- a/lib/fog/aws/requests/rds/describe_db_instances.rb +++ b/lib/fog/aws/requests/rds/describe_db_instances.rb @@ -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 diff --git a/lib/fog/aws/requests/rds/describe_db_snapshots.rb b/lib/fog/aws/requests/rds/describe_db_snapshots.rb index 1ab314d9e..8988cc33a 100644 --- a/lib/fog/aws/requests/rds/describe_db_snapshots.rb +++ b/lib/fog/aws/requests/rds/describe_db_snapshots.rb @@ -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 diff --git a/lib/fog/aws/requests/rds/promote_read_replica.rb b/lib/fog/aws/requests/rds/promote_read_replica.rb index a398b0628..76f083118 100644 --- a/lib/fog/aws/requests/rds/promote_read_replica.rb +++ b/lib/fog/aws/requests/rds/promote_read_replica.rb @@ -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 diff --git a/tests/models/rds/server_tests.rb b/tests/models/rds/server_tests.rb index 2005e3b93..0da179cc6 100644 --- a/tests/models/rds/server_tests.rb +++ b/tests/models/rds/server_tests.rb @@ -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')