1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[aws|rds] Mocking better supports reboot state

Also cleanup some whitespace
This commit is contained in:
Aaron Suggs 2012-08-03 14:18:52 -04:00
parent c5fc9f29c8
commit 3faa90219e
4 changed files with 21 additions and 22 deletions

View file

@ -80,30 +80,30 @@ module Fog
end
end
end
def self.reset
@data = nil
end
def initialize(options={})
@use_iam_profile = options[:use_iam_profile]
@region = options[:region] || 'us-east-1'
unless ['ap-northeast-1', 'ap-southeast-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1'].include?(@region)
raise ArgumentError, "Unknown region: #{@region.inspect}"
end
end
def data
self.class.data[@region][@aws_access_key_id]
end
def reset_data
self.class.data[@region].delete(@aws_access_key_id)
end
def setup_credentials(options)
@aws_access_key_id = options[:aws_access_key_id]
end

View file

@ -56,16 +56,14 @@ module Fog
"Address"=> Fog::AWS::Mock.rds_address(server["DBInstanceIdentifier"],region) }
server["PendingModifiedValues"] = {}
end
when "rebooting" # I don't know how to show rebooting just once before it changes to available
# it applies pending modified values
unless server["PendingModifiedValues"].empty?
when "rebooting"
if Time.now - self.data[:reboot_time] >= Fog::Mock.delay
# apply pending modified values
server.merge!(server["PendingModifiedValues"])
server["PendingModifiedValues"] = {}
self.data[:tmp] ||= Time.now + Fog::Mock.delay * 2
if self.data[:tmp] <= Time.now
server["DBInstanceStatus"] = 'available'
self.data.delete(:tmp)
end
server["DBInstanceStatus"] = 'available'
self.data.delete(:reboot_time)
end
when "modifying"
# TODO there are some fields that only applied after rebooting

View file

@ -26,18 +26,19 @@ module Fog
def reboot_db_instance(instance_identifier)
response = Excon::Response.new
if self.data[:servers][instance_identifier]
if self.data[:servers][instance_identifier]["DBInstanceStatus"] != "available"
if server = self.data[:servers][instance_identifier]
if server["DBInstanceStatus"] != "available"
raise Fog::AWS::RDS::NotFound.new("DBInstance #{instance_identifier} not available for rebooting")
else
self.data[:servers][instance_identifier]["DBInstanceStatus"] = 'rebooting'
server["DBInstanceStatus"] = 'rebooting'
self.data[:reboot_time] = Time.now
response.status = 200
response.body = {
"ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id },
"RebootDBInstanceResult" => { "DBInstance" => self.data[:servers][instance_identifier] }
"RebootDBInstanceResult" => { "DBInstance" => server }
}
response
end
else
raise Fog::AWS::RDS::NotFound.new("DBInstance #{instance_identifier} not found")

View file

@ -42,7 +42,7 @@ Shindo.tests('AWS::RDS | instance requests', ['aws', 'rds']) do
body
end
server.reload.wait_for { state == 'modifying' }
server.reload.wait_for { state == 'modifying' } unless Fog.mocking?
server.reload.wait_for { state == 'available' }
tests 'new storage' do