mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|acs] Improve security group tests
This commit is contained in:
parent
83f1a6adeb
commit
580d49e8ff
3 changed files with 35 additions and 8 deletions
|
@ -2,6 +2,8 @@ module Fog
|
||||||
module AWS
|
module AWS
|
||||||
class ACS < Fog::Service
|
class ACS < Fog::Service
|
||||||
|
|
||||||
|
class IdentifierTaken < Fog::Errors::Error; end
|
||||||
|
|
||||||
requires :aws_access_key_id, :aws_secret_access_key
|
requires :aws_access_key_id, :aws_secret_access_key
|
||||||
recognizes :region, :host, :path, :port, :scheme, :persistent
|
recognizes :region, :host, :path, :port, :scheme, :persistent
|
||||||
|
|
||||||
|
@ -101,7 +103,7 @@ module Fog
|
||||||
when 'CacheSecurityGroupNotFound'
|
when 'CacheSecurityGroupNotFound'
|
||||||
raise Fog::AWS::ACS::NotFound
|
raise Fog::AWS::ACS::NotFound
|
||||||
when 'CacheSecurityGroupAlreadyExists'
|
when 'CacheSecurityGroupAlreadyExists'
|
||||||
raise Fog::AWS::ACS::IndentifierTaken
|
raise Fog::AWS::ACS::IdentifierTaken
|
||||||
when 'InvalidParameterValue'
|
when 'InvalidParameterValue'
|
||||||
raise Fog::AWS::ACE::InvalidInstance
|
raise Fog::AWS::ACE::InvalidInstance
|
||||||
else
|
else
|
||||||
|
|
|
@ -8,11 +8,11 @@ module Fog
|
||||||
|
|
||||||
identity :id, :aliases => 'CacheSecurityGroupName'
|
identity :id, :aliases => 'CacheSecurityGroupName'
|
||||||
attribute :description, :aliases => 'CacheSecurityGroupDescription'
|
attribute :description, :aliases => 'CacheSecurityGroupDescription'
|
||||||
attribute :ec2_security_group, :aliases => 'EC2SecurityGroups', :type => :array
|
attribute :ec2_groups, :aliases => 'EC2SecurityGroups', :type => :array
|
||||||
attribute :owner_id, :aliases => 'OwnerId'
|
attribute :owner_id, :aliases => 'OwnerId'
|
||||||
|
|
||||||
def ready?
|
def ready?
|
||||||
ec2_security_groups.all?{|ingress| ingress['Status'] == 'authorized'}
|
ec2_groups.all?{|ingress| ingress['Status'] == 'authorized'}
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
@ -28,11 +28,17 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
def authorize_ec2_group(group_name, group_owner_id=owner_id)
|
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
|
end
|
||||||
|
|
||||||
def revoke_ec2_group(group_name, group_owner_id=owner_id)
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,9 +5,28 @@ Shindo.tests('AWS::ACS | security groups', ['aws', 'acs']) do
|
||||||
pending if Fog.mocking?
|
pending if Fog.mocking?
|
||||||
|
|
||||||
model_tests(AWS[:acs].security_groups, {:id => group_name, :description => description}, false) do
|
model_tests(AWS[:acs].security_groups, {:id => group_name, :description => description}, false) do
|
||||||
# TODO:
|
|
||||||
# test authorize_ec2_group
|
# An EC2 group to authorize
|
||||||
# test revoke_ec2_group
|
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
|
end
|
||||||
|
|
||||||
collection_tests(AWS[:acs].security_groups, {:id => group_name, :description => description}, false)
|
collection_tests(AWS[:acs].security_groups, {:id => group_name, :description => description}, false)
|
||||||
|
|
Loading…
Add table
Reference in a new issue