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

[aws|elasticache] refactor for whitespace / readability

This commit is contained in:
Benton Roberts 2011-09-02 12:49:21 -04:00 committed by geemus
parent 5b66328a70
commit bd98aa44d5
5 changed files with 101 additions and 36 deletions

View file

@ -1,6 +1,6 @@
module Fog
module AWS
class ACS < Fog::Service
class Elasticache < Fog::Service
class IdentifierTaken < Fog::Errors::Error; end
@ -63,7 +63,9 @@ module Fog
@path = options[:path] || '/'
@port = options[:port] || 443
@scheme = options[:scheme] || 'https'
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", options[:persistent])
@connection = Fog::Connection.new(
"#{@scheme}://#{@host}:#{@port}#{@path}", options[:persistent]
)
end
def reload
@ -101,11 +103,11 @@ module Fog
if match = error.message.match(/<Code>(.*)<\/Code>/m)
case match[1]
when 'CacheSecurityGroupNotFound'
raise Fog::AWS::ACS::NotFound
raise Fog::AWS::Elasticache::NotFound
when 'CacheSecurityGroupAlreadyExists'
raise Fog::AWS::ACS::IdentifierTaken
raise Fog::AWS::Elasticache::IdentifierTaken
when 'InvalidParameterValue'
raise Fog::AWS::ACS::InvalidInstance
raise Fog::AWS::Elasticache::InvalidInstance
else
raise
end

View file

@ -2,7 +2,7 @@ require 'fog/core/model'
module Fog
module AWS
class ACS
class Elasticache
class SecurityGroup < Fog::Model
@ -30,15 +30,19 @@ module Fog
def authorize_ec2_group(group_name, group_owner_id=owner_id)
requires :id
requires :owner_id if group_owner_id.nil?
data = connection.authorize_cache_security_group_ingress(id, group_name, group_owner_id).body['CacheSecurityGroup']
merge_attributes(data)
data = connection.authorize_cache_security_group_ingress(
id, group_name, group_owner_id
)
merge_attributes(data.body['CacheSecurityGroup'])
end
def revoke_ec2_group(group_name, group_owner_id=owner_id)
requires :id
requires :owner_id if group_owner_id.nil?
data = connection.revoke_cache_security_group_ingress(id, group_name, group_owner_id).body['CacheSecurityGroup']
merge_attributes(data)
data = connection.revoke_cache_security_group_ingress(
id, group_name, group_owner_id
)
merge_attributes(data.body['CacheSecurityGroup'])
end
end

View file

@ -9,13 +9,17 @@ module Fog
model Fog::AWS::Elasticache::SecurityGroup
def all
data = connection.describe_cache_security_groups.body['CacheSecurityGroups']
load(data)
load(
connection.describe_cache_security_groups.body['CacheSecurityGroups']
)
end
def get(identity)
data = connection.describe_cache_security_groups('CacheSecurityGroupName' => identity).body['CacheSecurityGroups'].first
new(data)
new(
connection.describe_cache_security_groups(
'CacheSecurityGroupName' => identity
).body['CacheSecurityGroups'].first
)
rescue Fog::AWS::Elasticache::NotFound
nil
end

View file

@ -4,17 +4,27 @@ Shindo.tests('AWS::Elasticache | security groups', ['aws', 'elasticache']) do
pending if Fog.mocking?
model_tests(AWS[:elasticache].security_groups, {:id => group_name, :description => description}, false) do
model_tests(
AWS[:elasticache].security_groups,
{:id => group_name, :description => description}, false
) do
# An EC2 group to authorize
ec2_group = Fog::Compute.new(:provider => 'AWS').security_groups.create(:name => 'fog-test-elasticache', :description => 'fog test')
ec2_group = Fog::Compute.new(:provider => 'AWS').security_groups.create(
:name => 'fog-test-elasticache', :description => 'fog test'
)
# Reload to get the instance owner_id
@instance.reload
tests('#authorize_ec2_group') do
@instance.authorize_ec2_group(ec2_group.name)
returns('authorizing') { @instance.ec2_groups.detect{|g| g['EC2SecurityGroupName'] == ec2_group.name}['Status'] }
returns('authorizing') do
group = @instance.ec2_groups.detect do |g|
g['EC2SecurityGroupName'] == ec2_group.name
end
group['Status']
end
returns(false, 'not ready') { @instance.ready? }
end
@ -22,12 +32,21 @@ Shindo.tests('AWS::Elasticache | security groups', ['aws', 'elasticache']) do
tests('#revoke_ec2_group') do
@instance.revoke_ec2_group(ec2_group.name)
returns('revoking') { @instance.ec2_groups.detect{|g| g['EC2SecurityGroupName'] == ec2_group.name}['Status'] }
returns('revoking') do
group = @instance.ec2_groups.detect do |g|
g['EC2SecurityGroupName'] == ec2_group.name
end
group.['Status']
end
returns(false, 'not ready') { @instance.ready? }
end
ec2_group.destroy
end
collection_tests(AWS[:elasticache].security_groups, {:id => group_name, :description => description}, false)
collection_tests(
AWS[:elasticache].security_groups,
{:id => group_name, :description => description}, false
)
end

View file

@ -6,7 +6,9 @@ Shindo.tests('AWS::Elasticache | security group requests', ['aws', 'elasticache'
name = 'fog-test'
description = 'Fog Test Group'
tests('#create_cache_security_group').formats(AWS::Elasticache::Formats::SINGLE_SECURITY_GROUP) do
tests(
'#create_cache_security_group'
).formats(AWS::Elasticache::Formats::SINGLE_SECURITY_GROUP) do
body = AWS[:elasticache].create_cache_security_group(name, description).body
group = body['CacheSecurityGroup']
returns(name) { group['CacheSecurityGroupName'] }
@ -15,45 +17,77 @@ Shindo.tests('AWS::Elasticache | security group requests', ['aws', 'elasticache'
body
end
tests('#describe_cache_security_groups without options').formats(AWS::Elasticache::Formats::DESCRIBE_SECURITY_GROUPS) do
tests(
'#describe_cache_security_groups without options'
).formats(AWS::Elasticache::Formats::DESCRIBE_SECURITY_GROUPS) do
body = AWS[:elasticache].describe_cache_security_groups.body
returns(true, "has #{name}") do
body['CacheSecurityGroups'].any? {|group| group['CacheSecurityGroupName'] == name }
body['CacheSecurityGroups'].any? do |group|
group['CacheSecurityGroupName'] == name
end
end
body
end
tests('#describe_cache_security_groups with name').formats(AWS::Elasticache::Formats::DESCRIBE_SECURITY_GROUPS) do
body = AWS[:elasticache].describe_cache_security_groups('CacheSecurityGroupName' => name).body
tests(
'#describe_cache_security_groups with name'
).formats(AWS::Elasticache::Formats::DESCRIBE_SECURITY_GROUPS) do
body = AWS[:elasticache].describe_cache_security_groups(
'CacheSecurityGroupName' => name
).body
returns(1, "size of 1") { body['CacheSecurityGroups'].size }
returns(name, "has #{name}") { body['CacheSecurityGroups'].first['CacheSecurityGroupName'] }
returns(name, "has #{name}") do
body['CacheSecurityGroups'].first['CacheSecurityGroupName']
end
body
end
tests('authorization') do
ec2_group = Fog::Compute.new(:provider => 'AWS').security_groups.create(:name => 'fog-test-elasticache', :description => 'Fog Test Elasticache')
ec2_group = Fog::Compute.new(:provider => 'AWS').security_groups.create(
:name => 'fog-test-elasticache', :description => 'Fog Test Elasticache'
)
# Reload to get the owner_id
ec2_group.reload
tests('#authorize_cache_security_group_ingress').formats(AWS::Elasticache::Formats::SINGLE_SECURITY_GROUP) do
body = AWS[:elasticache].authorize_cache_security_group_ingress(name, ec2_group.name, ec2_group.owner_id).body
tests(
'#authorize_cache_security_group_ingress'
).formats(AWS::Elasticache::Formats::SINGLE_SECURITY_GROUP) do
body = AWS[:elasticache].authorize_cache_security_group_ingress(
name, ec2_group.name, ec2_group.owner_id
).body
group = body['CacheSecurityGroup']
expected_ec2_groups = [{'Status' => 'authorizing', 'EC2SecurityGroupName' => ec2_group.name, 'EC2SecurityGroupOwnerId' => ec2_group.owner_id}]
returns(expected_ec2_groups, 'has correct EC2 groups') { group['EC2SecurityGroups'] }
expected_ec2_groups = [{
'Status' => 'authorizing', 'EC2SecurityGroupName' => ec2_group.name,
'EC2SecurityGroupOwnerId' => ec2_group.owner_id
}]
returns(expected_ec2_groups, 'has correct EC2 groups') do
group['EC2SecurityGroups']
end
body
end
# Wait for the state to be active
Fog.wait_for do
group = AWS[:elasticache].describe_cache_security_groups('CacheSecurityGroupName' => name).body['CacheSecurityGroups'].first
group = AWS[:elasticache].describe_cache_security_groups(
'CacheSecurityGroupName' => name
).body['CacheSecurityGroups'].first
group['EC2SecurityGroups'].all? {|ec2| ec2['Status'] == 'authorized'}
end
tests('#revoke_cache_security_group_ingress').formats(AWS::Elasticache::Formats::SINGLE_SECURITY_GROUP) do
body = AWS[:elasticache].revoke_cache_security_group_ingress(name, ec2_group.name, ec2_group.owner_id).body
tests(
'#revoke_cache_security_group_ingress'
).formats(AWS::Elasticache::Formats::SINGLE_SECURITY_GROUP) do
body = AWS[:elasticache].revoke_cache_security_group_ingress(
name, ec2_group.name, ec2_group.owner_id
).body
group = body['CacheSecurityGroup']
expected_ec2_groups = [{'Status' => 'revoking', 'EC2SecurityGroupName' => ec2_group.name, 'EC2SecurityGroupOwnerId' => ec2_group.owner_id}]
returns(expected_ec2_groups, 'has correct EC2 groups') { group['EC2SecurityGroups'] }
expected_ec2_groups = [{
'Status' => 'revoking', 'EC2SecurityGroupName' => ec2_group.name,
'EC2SecurityGroupOwnerId' => ec2_group.owner_id
}]
returns(expected_ec2_groups, 'has correct EC2 groups') do
group['EC2SecurityGroups']
end
body
end
@ -61,7 +95,9 @@ Shindo.tests('AWS::Elasticache | security group requests', ['aws', 'elasticache'
ec2_group.destroy
end
tests('#delete_cache_security_group').formats(AWS::Elasticache::Formats::BASIC) do
tests(
'#delete_cache_security_group'
).formats(AWS::Elasticache::Formats::BASIC) do
body = AWS[:elasticache].delete_cache_security_group(name).body
end
end