From 580d49e8ff4c2a0d6782c790083167a8dfa8dd34 Mon Sep 17 00:00:00 2001 From: Aaron Suggs Date: Thu, 14 Jul 2011 10:45:52 -0400 Subject: [PATCH] [aws|acs] Improve security group tests --- lib/fog/aws/acs.rb | 4 +++- lib/fog/aws/models/acs/security_group.rb | 14 +++++++++---- tests/aws/models/acs/security_groups.rb | 25 +++++++++++++++++++++--- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/lib/fog/aws/acs.rb b/lib/fog/aws/acs.rb index 7195cd939..f7e9911a8 100644 --- a/lib/fog/aws/acs.rb +++ b/lib/fog/aws/acs.rb @@ -2,6 +2,8 @@ module Fog module AWS class ACS < Fog::Service + class IdentifierTaken < Fog::Errors::Error; end + requires :aws_access_key_id, :aws_secret_access_key recognizes :region, :host, :path, :port, :scheme, :persistent @@ -101,7 +103,7 @@ module Fog when 'CacheSecurityGroupNotFound' raise Fog::AWS::ACS::NotFound when 'CacheSecurityGroupAlreadyExists' - raise Fog::AWS::ACS::IndentifierTaken + raise Fog::AWS::ACS::IdentifierTaken when 'InvalidParameterValue' raise Fog::AWS::ACE::InvalidInstance else diff --git a/lib/fog/aws/models/acs/security_group.rb b/lib/fog/aws/models/acs/security_group.rb index 7357518a6..8f74a8de9 100644 --- a/lib/fog/aws/models/acs/security_group.rb +++ b/lib/fog/aws/models/acs/security_group.rb @@ -8,11 +8,11 @@ module Fog identity :id, :aliases => 'CacheSecurityGroupName' attribute :description, :aliases => 'CacheSecurityGroupDescription' - attribute :ec2_security_group, :aliases => 'EC2SecurityGroups', :type => :array + attribute :ec2_groups, :aliases => 'EC2SecurityGroups', :type => :array attribute :owner_id, :aliases => 'OwnerId' def ready? - ec2_security_groups.all?{|ingress| ingress['Status'] == 'authorized'} + ec2_groups.all?{|ingress| ingress['Status'] == 'authorized'} end def destroy @@ -28,11 +28,17 @@ module Fog end def authorize_ec2_group(group_name, group_owner_id=owner_id) - connection.authorize_ec2_security_group(id, group_name, group_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) end def revoke_ec2_group(group_name, group_owner_id=owner_id) - connection.revoke_ec2_security_group(id, group_name, group_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) end end diff --git a/tests/aws/models/acs/security_groups.rb b/tests/aws/models/acs/security_groups.rb index efe9a6258..4f2773355 100644 --- a/tests/aws/models/acs/security_groups.rb +++ b/tests/aws/models/acs/security_groups.rb @@ -5,9 +5,28 @@ Shindo.tests('AWS::ACS | security groups', ['aws', 'acs']) do pending if Fog.mocking? model_tests(AWS[:acs].security_groups, {:id => group_name, :description => description}, false) do - # TODO: - # test authorize_ec2_group - # test revoke_ec2_group + + # An EC2 group to authorize + ec2_group = Fog::Compute.new(:provider => 'AWS').security_groups.create(:name => 'fog-test-acs', :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(false, 'not ready') { @instance.ready? } + end + + @instance.wait_for { ready? } + + 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(false, 'not ready') { @instance.ready? } + end + + ec2_group.destroy end collection_tests(AWS[:acs].security_groups, {:id => group_name, :description => description}, false)