mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|rds] Mock DB snapshot requests.
Relevant tests pass; no longer pending
This commit is contained in:
parent
b55ce59976
commit
b18e5efa03
6 changed files with 85 additions and 14 deletions
|
@ -65,7 +65,8 @@ module Fog
|
|||
hash[region] = Hash.new do |region_hash, key|
|
||||
region_hash[key] = {
|
||||
:servers => {},
|
||||
:security_groups => {}
|
||||
:security_groups => {},
|
||||
:snapshots => {}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,9 +27,45 @@ module Fog
|
|||
class Mock
|
||||
|
||||
def create_db_snapshot(identifier, name)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
response = Excon::Response.new
|
||||
if data[:snapshots][name]
|
||||
raise Fog::AWS::RDS::IndentifierTaken.new
|
||||
end
|
||||
|
||||
server_data = data[:servers][identifier]
|
||||
unless server_data
|
||||
raise Fog::AWS::RDS::NotFound.new("DBInstance #{identifier} not found")
|
||||
end
|
||||
|
||||
# TODO: raise an error if the server isn't in 'available' state
|
||||
|
||||
snapshot_data = {
|
||||
'Status' => 'creating',
|
||||
#'SnapshotType' => 'manual', # In a newer RDS version
|
||||
'DBInstanceIdentifier' => identifier,
|
||||
'DBSnapshotIdentifier' => name,
|
||||
'InstanceCreateTime' => Time.now
|
||||
}
|
||||
# Copy attributes from server
|
||||
%w(Engine EngineVersion AvailabilityZone AllocatedStorage MasterUsername InstanceCreateTime).each do |key|
|
||||
snapshot_data[key] = server_data[key]
|
||||
end
|
||||
snapshot_data['Port'] = server_data['Endpoint']['Port']
|
||||
|
||||
self.data[:snapshots][name] = snapshot_data
|
||||
|
||||
# TODO: put the server in 'modifying' state
|
||||
|
||||
response.body = {
|
||||
"ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id },
|
||||
"CreateDBSnapshotResult"=> {"DBSnapshot"=> snapshot_data.dup}
|
||||
}
|
||||
response.status = 200
|
||||
# SnapshotCreateTime is not part of the response.
|
||||
self.data[:snapshots][name]['SnapshotCreateTime'] = Time.now
|
||||
response
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -34,8 +34,7 @@ module Fog
|
|||
response = Excon::Response.new
|
||||
|
||||
unless skip_snapshot
|
||||
# I don't know how to mock snapshot_identifier
|
||||
Fog::Logger.warning("snapshot_identifier is not mocked [light_black](#{caller.first})[/]")
|
||||
create_db_snapshot(identifier, snapshot_identifier)
|
||||
end
|
||||
|
||||
if server_set = self.data[:servers].delete(identifier)
|
||||
|
|
|
@ -12,11 +12,11 @@ module Fog
|
|||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
def delete_db_snapshot(group_name)
|
||||
def delete_db_snapshot(name)
|
||||
|
||||
request({
|
||||
'Action' => 'DeleteDBSnapshot',
|
||||
'DBSnapshotIdentifier' => group_name,
|
||||
'DBSnapshotIdentifier' => name,
|
||||
|
||||
:parser => Fog::Parsers::AWS::RDS::DeleteDBSnapshot.new
|
||||
})
|
||||
|
@ -26,8 +26,19 @@ module Fog
|
|||
|
||||
class Mock
|
||||
|
||||
def delete_db_snapshot(group_name)
|
||||
Fog::Mock.not_implemented
|
||||
def delete_db_snapshot(name)
|
||||
# TODO: raise error if snapshot isn't 'available'
|
||||
response = Excon::Response.new
|
||||
snapshot_data = self.data[:snapshots].delete(name)
|
||||
|
||||
raise Fog::AWS::RDS::NotFound.new("DBSnapshtoNotFound => #{name} not found") unless snapshot_data
|
||||
|
||||
response.status = 200
|
||||
response.body = {
|
||||
"ResponseMetadata"=> { "RequestId"=> Fog::AWS::Mock.request_id },
|
||||
"DeleteDBSnapshotResult"=> {"DBSnapshot"=> snapshot_data}
|
||||
}
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -33,7 +33,33 @@ module Fog
|
|||
class Mock
|
||||
|
||||
def describe_db_snapshots(opts={})
|
||||
Fog::Mock.not_implemented
|
||||
response = Excon::Response.new
|
||||
snapshots = self.data[:snapshots].values
|
||||
if opts[:identifier]
|
||||
snapshots.select!{|snapshot| snapshot['DBInstanceIdentifier'] == opts[:identifier]}
|
||||
end
|
||||
|
||||
if opts[:snapshot_id]
|
||||
snapshots.select!{|snapshot| snapshot['DBSnapshotIdentifier'] == opts[:snapshot_id]}
|
||||
end
|
||||
|
||||
snapshots.each do |snapshot|
|
||||
case snapshot['Status']
|
||||
when 'creating'
|
||||
if Time.now - snapshot['SnapshotCreateTime'] > Fog::Mock.delay
|
||||
snapshot['Status'] = 'available'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Build response
|
||||
response.status = 200
|
||||
response.body = {
|
||||
"ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id },
|
||||
"DescribeDBSnapshotsResult" => { "DBSnapshots" => snapshots }
|
||||
}
|
||||
response
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -58,8 +58,6 @@ Shindo.tests('AWS::RDS | instance requests', ['aws', 'rds']) do
|
|||
server.reload.wait_for { state == 'rebooting' }
|
||||
server.reload.wait_for { state == 'available'}
|
||||
|
||||
pending if Fog.mocking?
|
||||
|
||||
tests("#create_db_snapshot").formats(AWS::RDS::Formats::CREATE_DB_SNAPSHOT) do
|
||||
body = Fog::AWS[:rds].create_db_snapshot(@db_instance_id, @db_snapshot_id).body
|
||||
returns('creating'){ body['CreateDBSnapshotResult']['DBSnapshot']['Status']}
|
||||
|
@ -72,6 +70,8 @@ Shindo.tests('AWS::RDS | instance requests', ['aws', 'rds']) do
|
|||
|
||||
server.reload.wait_for { state == 'available' }
|
||||
|
||||
pending if Fog.mocking?
|
||||
|
||||
tests( "#create read replica").formats(AWS::RDS::Formats::CREATE_READ_REPLICA) do
|
||||
Fog::AWS[:rds].create_db_instance_read_replica(@db_replica_id, @db_instance_id).body
|
||||
end
|
||||
|
@ -114,8 +114,6 @@ Shindo.tests('AWS::RDS | instance requests', ['aws', 'rds']) do
|
|||
end
|
||||
|
||||
tests('failure') do
|
||||
pending if Fog.mocking?
|
||||
|
||||
tests "deleting nonexisting instance" do
|
||||
raises(Fog::AWS::RDS::NotFound) {Fog::AWS[:rds].delete_db_instance('doesnexist', 'irrelevant')}
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue