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

[ec2] fix gaps in mocking revealed by new shindo tests

This commit is contained in:
geemus 2010-05-24 17:41:01 -07:00
parent 063b0b42d1
commit 4577e2d093
6 changed files with 92 additions and 55 deletions

View file

@ -96,40 +96,42 @@ module Fog
def self.data def self.data
@data ||= Hash.new do |hash, key| @data ||= Hash.new do |hash, key|
owner_id = Fog::AWS::Mock.owner_id
hash[key] = { hash[key] = {
:deleted_at => {}, :deleted_at => {},
:addresses => {}, :addresses => {},
:instances => {}, :instances => {},
:key_pairs => {}, :key_pairs => {},
:limits => { :addresses => 5 }, :limits => { :addresses => 5 },
:owner_id => owner_id,
:security_groups => { :security_groups => {
'default' => { 'default' => {
'groupDescription' => 'default group', 'groupDescription' => 'default group',
'groupName' => 'default', 'groupName' => 'default',
'ipPermissions' => [ 'ipPermissions' => [
{ {
'groups' => [{'groupName' => 'default', 'userId' => @owner_id}], 'groups' => [{'groupName' => 'default', 'userId' => owner_id}],
'fromPort' => -1, 'fromPort' => -1,
'toPort' => -1, 'toPort' => -1,
'ipProtocol' => 'icmp', 'ipProtocol' => 'icmp',
'ipRanges' => [] 'ipRanges' => []
}, },
{ {
'groups' => [{'groupName' => 'default', 'userId' => @owner_id}], 'groups' => [{'groupName' => 'default', 'userId' => owner_id}],
'fromPort' => 0, 'fromPort' => 0,
'toPort' => 65535, 'toPort' => 65535,
'ipProtocol' => 'tcp', 'ipProtocol' => 'tcp',
'ipRanges' => [] 'ipRanges' => []
}, },
{ {
'groups' => [{'groupName' => 'default', 'userId' => @owner_id}], 'groups' => [{'groupName' => 'default', 'userId' => owner_id}],
'fromPort' => 0, 'fromPort' => 0,
'toPort' => 65535, 'toPort' => 65535,
'ipProtocol' => 'udp', 'ipProtocol' => 'udp',
'ipRanges' => [] 'ipRanges' => []
} }
], ],
'ownerId' => @owner_id 'ownerId' => owner_id
} }
}, },
:snapshots => {}, :snapshots => {},
@ -146,8 +148,8 @@ module Fog
def initialize(options={}) def initialize(options={})
@aws_access_key_id = options[:aws_access_key_id] @aws_access_key_id = options[:aws_access_key_id]
@owner_id = Fog::AWS::Mock.owner_id
@data = self.class.data[@aws_access_key_id] @data = self.class.data[@aws_access_key_id]
@owner_id = @data[:owner_id]
end end
end end

View file

@ -37,32 +37,47 @@ module Fog
def authorize_security_group_ingress(options = {}) def authorize_security_group_ingress(options = {})
response = Excon::Response.new response = Excon::Response.new
group = @data[:security_groups][options['GroupName']] group = @data[:security_groups][options['GroupName']]
group['ipPermissions'] ||= []
if options['GroupName'] && options['SourceSecurityGroupName'] && options['SourceSecurityGroupOwnerId'] if group
['icmp', 'tcp', 'udp'].each do |protocol| group['ipPermissions'] ||= []
if options['GroupName'] && options['SourceSecurityGroupName'] && options['SourceSecurityGroupOwnerId']
['tcp', 'udp'].each do |protocol|
group['ipPermissions'] << {
'groups' => [{'groupName' => options['GroupName'], 'userId' => @owner_id}],
'fromPort' => 1,
'ipRanges' => [],
'ipProtocol' => protocol,
'toPort' => 65535
}
end
group['ipPermissions'] << { group['ipPermissions'] << {
'groups' => [{'groupName' => options['GroupName'], 'userId' => @owner_id}], 'groups' => [{'groupName' => options['GroupName'], 'userId' => @owner_id}],
'fromPort' => 1, 'fromPort' => -1,
'ipRanges' => [], 'ipRanges' => [],
'ipProtocol' => protocol, 'ipProtocol' => 'icmp',
'toPort' => 65535 'toPort' => -1
} }
else
group['ipPermissions'] << {
'groups' => [],
'fromPort' => options['FromPort'],
'ipRanges' => [],
'ipProtocol' => options['IpProtocol'],
'toPort' => options['ToPort']
}
if options['CidrIp']
group['ipPermissions'].last['ipRanges'] << { 'cidrIp' => options['CidrIp'] }
end
end end
else response.status = 200
group['ipPermissions'] << { response.body = {
'groups' => [], 'requestId' => Fog::AWS::Mock.request_id,
'fromPort' => options['FromPort'], 'return' => true
'ipRanges' => [{ 'cidrIp' => options['CidrIp'] }],
'ipProtocol' => options['IpProtocol'],
'toPort' => options['ToPort']
} }
else
response.status = 400
raise(Excon::Errors.status_error({:expects => 200}, response))
end end
response.status = 200
response.body = {
'requestId' => Fog::AWS::Mock.request_id,
'return' => true
}
response response
end end

View file

@ -31,8 +31,8 @@ module Fog
response = Excon::Response.new response = Excon::Response.new
unless @data[:security_groups][name] unless @data[:security_groups][name]
data = { data = {
'groupDescription' => description, 'groupDescription' => CGI.escape(description).gsub('%20', '+'),
'groupName' => name, 'groupName' => CGI.escape(name).gsub('%20', '+'),
'ipPermissions' => [], 'ipPermissions' => [],
'ownerId' => @owner_id 'ownerId' => @owner_id
} }

View file

@ -44,11 +44,16 @@ module Fog
availability_zone_info = zones.values availability_zone_info = zones.values
end end
response.status = 200 if zone_name.length == 0 || zone_name.length == availability_zone_info.length
response.body = { response.status = 200
'requestId' => Fog::AWS::Mock.request_id, response.body = {
'availabilityZoneInfo' => availability_zone_info 'requestId' => Fog::AWS::Mock.request_id,
} 'availabilityZoneInfo' => availability_zone_info
}
else
response.status = 400
raise(Excon::Errors.status_error({:expects => 200}, response))
end
response response
end end

View file

@ -41,11 +41,16 @@ module Fog
region_info = regions.values region_info = regions.values
end end
response.status = 200 if region_name.length == 0 || region_name.length == region_info.length
response.body = { response.status = 200
'requestId' => Fog::AWS::Mock.request_id, response.body = {
'regionInfo' => region_info 'requestId' => Fog::AWS::Mock.request_id,
} 'regionInfo' => region_info
}
else
response.status = 400
raise(Excon::Errors.status_error({:expects => 200}, response))
end
response response
end end

View file

@ -35,28 +35,38 @@ module Fog
class Mock class Mock
def revoke_security_group_ingress(options = {}) def revoke_security_group_ingress(options = {})
if options['GroupName'] && options['SourceSecurityGroupName'] && options['SourceSecurityGroupOwnerId'] response = Excon::Response.new
raise MockNotImplemented.new("Contributions welcome!") group = @data[:security_groups][options['GroupName']]
else if group
response = Excon::Response.new if options['GroupName'] && options['SourceSecurityGroupName'] && options['SourceSecurityGroupOwnerId']
group = @data[:security_groups][options['GroupName']] group['ipPermissions'].delete_if {|permission|
permission['groups'].first['groupName'] == options['GroupName']
ingress = group['ipPermissions'].select {|permission| }
permission['fromPort'] == options['FromPort'] && else
permission['ipProtocol'] == options['IpProtocol'] && ingress = group['ipPermissions'].select {|permission|
permission['toPort'] == options['ToPort'] && permission['fromPort'] == options['FromPort'] &&
permission['ipRanges'].first['cidrIp'] == options['CidrIp'] permission['ipProtocol'] == options['IpProtocol'] &&
}.first permission['toPort'] == options['ToPort'] &&
(
group['ipPermissions'].delete(ingress) permission['ipRanges'].empty? ||
(
permission['ipRanges'].first &&
permission['ipRanges'].first['cidrIp'] == options['CidrIp']
)
)
}.first
group['ipPermissions'].delete(ingress)
end
response.status = 200 response.status = 200
response.body = { response.body = {
'requestId' => Fog::AWS::Mock.request_id, 'requestId' => Fog::AWS::Mock.request_id,
'return' => true 'return' => true
} }
response else
response.status = 400
raise(Excon::Errors.status_error({:expects => 200}, response))
end end
response
end end
end end