diff --git a/lib/fog/aws/models/rds/security_group.rb b/lib/fog/aws/models/rds/security_group.rb index 5960177be..49bb843b1 100644 --- a/lib/fog/aws/models/rds/security_group.rb +++ b/lib/fog/aws/models/rds/security_group.rb @@ -29,8 +29,9 @@ module Fog # group_owner_id defaults to the current owner_id def authorize_ec2_security_group(group_name, group_owner_id=owner_id) + key = group_name.match(/^sg-/) ? 'EC2SecurityGroupId' : 'EC2SecurityGroupName' authorize_ingress({ - 'EC2SecurityGroupName' => group_name, + key => group_name, 'EC2SecurityGroupOwnerId' => group_owner_id }) end @@ -56,8 +57,9 @@ module Fog # group_owner_id defaults to the current owner_id def revoke_ec2_security_group(group_name, group_owner_id=owner_id) + key = group_name.match(/^sg-/) ? 'EC2SecurityGroupId' : 'EC2SecurityGroupName' revoke_ingress({ - 'EC2SecurityGroupName' => group_name, + key => group_name, 'EC2SecurityGroupOwnerId' => group_owner_id }) end diff --git a/lib/fog/aws/rds.rb b/lib/fog/aws/rds.rb index 91768cc56..7692a2507 100644 --- a/lib/fog/aws/rds.rb +++ b/lib/fog/aws/rds.rb @@ -164,7 +164,7 @@ module Fog @data = nil end - attr_accessor :region + attr_accessor :region, :aws_access_key_id def initialize(options={}) @use_iam_profile = options[:use_iam_profile] diff --git a/lib/fog/aws/requests/rds/authorize_db_security_group_ingress.rb b/lib/fog/aws/requests/rds/authorize_db_security_group_ingress.rb index b39ba07ab..a721555c6 100644 --- a/lib/fog/aws/requests/rds/authorize_db_security_group_ingress.rb +++ b/lib/fog/aws/requests/rds/authorize_db_security_group_ingress.rb @@ -15,8 +15,8 @@ module Fog # * response<~Excon::Response>: # * body<~Hash>: def authorize_db_security_group_ingress(name, opts={}) - unless opts.key?('CIDRIP') || (opts.key?('EC2SecurityGroupName') && opts.key?('EC2SecurityGroupOwnerId')) - raise ArgumentError, 'Must specify CIDRIP, or both EC2SecurityGroupName and EC2SecurityGroupOwnerId' + unless opts.key?('CIDRIP') || ((opts.key?('EC2SecurityGroupName') || opts.key?('EC2SecurityGroupId')) && opts.key?('EC2SecurityGroupOwnerId')) + raise ArgumentError, 'Must specify CIDRIP, or one of EC2SecurityGroupName or EC2SecurityGroupId, and EC2SecurityGroupOwnerId' end request({ @@ -29,8 +29,13 @@ module Fog class Mock def authorize_db_security_group_ingress(name, opts = {}) - unless opts.key?('CIDRIP') || (opts.key?('EC2SecurityGroupName') && opts.key?('EC2SecurityGroupOwnerId')) - raise ArgumentError, 'Must specify CIDRIP, or both EC2SecurityGroupName and EC2SecurityGroupOwnerId' + unless opts.key?('CIDRIP') || ((opts.key?('EC2SecurityGroupName') || opts.key?('EC2SecurityGroupId')) && opts.key?('EC2SecurityGroupOwnerId')) + raise ArgumentError, 'Must specify CIDRIP, or one of EC2SecurityGroupName or EC2SecurityGroupId, and EC2SecurityGroupOwnerId' + end + + if ec2_security_group_id = opts.delete("EC2SecurityGroupId") + ec2_security_group = (Fog::Compute::AWS::Mock.data[self.region][self.aws_access_key_id][:security_groups] || {}).values.detect { |sg| sg['groupId'] == ec2_security_group_id } + opts['EC2SecurityGroupName'] = ec2_security_group['groupName'] end response = Excon::Response.new @@ -42,7 +47,7 @@ module Fog end sec_group['IPRanges'] << opts.merge({"Status" => 'authorizing'}) else - if sec_group['EC2SecurityGroups'].find{|h| h['EC2SecurityGroupName'] == opts['EC2SecurityGroupName']} + if sec_group['EC2SecurityGroups'].find{|h| h['EC2SecurityGroupName'] == opts['EC2SecurityGroupName'] || h['EC2SecurityGroupId'] == opts['EC2SecurityGroupId']} raise Fog::AWS::RDS::AuthorizationAlreadyExists.new("AuthorizationAlreadyExists => #{opts['EC2SecurityGroupName']} is alreay defined") end sec_group['EC2SecurityGroups'] << opts.merge({"Status" => 'authorizing'}) diff --git a/lib/fog/aws/requests/rds/create_db_subnet_group.rb b/lib/fog/aws/requests/rds/create_db_subnet_group.rb index 0c4d37c1f..46c189cc5 100644 --- a/lib/fog/aws/requests/rds/create_db_subnet_group.rb +++ b/lib/fog/aws/requests/rds/create_db_subnet_group.rb @@ -31,15 +31,14 @@ module Fog end # collection = Fog::Compute::AWS.new(:aws_access_key_id => 'mock key', :aws_secret_access_key => 'mock secret') - collection = Fog::Compute[:aws] - collection.region = @region + compute_data = Fog::Compute::AWS::Mock.data[self.region][self.aws_access_key_id] subnets = subnet_ids.map do |snid| - subnet = collection.subnets.get(snid) + subnet = compute_data[:subnets].detect { |s| s['subnetId'] == snid } raise Fog::AWS::RDS::NotFound.new("InvalidSubnet => The subnet '#{snid}' was not found") if subnet.nil? subnet end - vpc_id = subnets.first.vpc_id + vpc_id = subnets.first['vpcId'] data = { 'DBSubnetGroupName' => name, diff --git a/lib/fog/aws/requests/rds/delete_db_subnet_group.rb b/lib/fog/aws/requests/rds/delete_db_subnet_group.rb index 1b1fbf597..c63366650 100644 --- a/lib/fog/aws/requests/rds/delete_db_subnet_group.rb +++ b/lib/fog/aws/requests/rds/delete_db_subnet_group.rb @@ -26,6 +26,8 @@ module Fog raise Fog::AWS::RDS::NotFound.new("DBSubnetGroupNotFound => The subnet group '#{name}' doesn't exists") end + self.data[:subnet_groups].delete(name) + response.body = { 'ResponseMetadata'=>{ 'RequestId'=> Fog::AWS::Mock.request_id }, 'return' => true, diff --git a/lib/fog/aws/requests/rds/revoke_db_security_group_ingress.rb b/lib/fog/aws/requests/rds/revoke_db_security_group_ingress.rb index a3174f199..8be4bb657 100644 --- a/lib/fog/aws/requests/rds/revoke_db_security_group_ingress.rb +++ b/lib/fog/aws/requests/rds/revoke_db_security_group_ingress.rb @@ -15,8 +15,8 @@ module Fog # * response<~Excon::Response>: # * body<~Hash>: def revoke_db_security_group_ingress(name, opts={}) - unless opts.key?('CIDRIP') || (opts.key?('EC2SecurityGroupName') && opts.key?('EC2SecurityGroupOwnerId')) - raise ArgumentError, 'Must specify CIDRIP, or both EC2SecurityGroupName and EC2SecurityGroupOwnerId' + unless opts.key?('CIDRIP') || ((opts.key?('EC2SecurityGroupName') || opts.key?('EC2SecurityGroupId')) && opts.key?('EC2SecurityGroupOwnerId')) + raise ArgumentError, 'Must specify CIDRIP, or one of EC2SecurityGroupName or EC2SecurityGroupId, and EC2SecurityGroupOwnerId' end request({ @@ -29,8 +29,13 @@ module Fog class Mock def revoke_db_security_group_ingress(name, opts = {}) - unless opts.key?('CIDRIP') || (opts.key?('EC2SecurityGroupName') && opts.key?('EC2SecurityGroupOwnerId')) - raise ArgumentError, 'Must specify CIDRIP, or both EC2SecurityGroupName and EC2SecurityGroupOwnerId' + unless opts.key?('CIDRIP') || ((opts.key?('EC2SecurityGroupName') || opts.key?('EC2SecurityGroupId')) && opts.key?('EC2SecurityGroupOwnerId')) + raise ArgumentError, 'Must specify CIDRIP, or one of EC2SecurityGroupName or EC2SecurityGroupId, and EC2SecurityGroupOwnerId' + end + + if ec2_security_group_id = opts.delete("EC2SecurityGroupId") + ec2_security_group = (Fog::Compute::AWS::Mock.data[self.region][self.aws_access_key_id][:security_groups] || {}).values.detect { |sg| sg['groupId'] == ec2_security_group_id } + opts['EC2SecurityGroupName'] = ec2_security_group['groupName'] end response = Excon::Response.new diff --git a/tests/models/rds/security_group_tests.rb b/tests/models/rds/security_group_tests.rb index cf42f6be8..de555e2aa 100644 --- a/tests/models/rds/security_group_tests.rb +++ b/tests/models/rds/security_group_tests.rb @@ -6,9 +6,9 @@ Shindo.tests("AWS::RDS | security_group", ['aws', 'rds']) do tests("#description").returns('fog test') { @instance.description } - tests("#authorize_ec2_security_group").succeeds do - @ec2_sec_group = Fog::Compute[:aws].security_groups.create(:name => 'fog-test', :description => 'fog test') + @ec2_sec_group = Fog::Compute[:aws].security_groups.create(:name => uniq_id("fog-rds-test"), :description => 'fog test') + tests("#authorize_ec2_security_group('#{@ec2_sec_group.name}')").succeeds do @instance.authorize_ec2_security_group(@ec2_sec_group.name) returns('authorizing') do @instance.ec2_security_groups.find{|h| h['EC2SecurityGroupName'] == @ec2_sec_group.name}['Status'] @@ -17,9 +17,7 @@ Shindo.tests("AWS::RDS | security_group", ['aws', 'rds']) do @instance.wait_for { ready? } - tests("#revoke_ec2_security_group").succeeds do - pending if Fog.mocking? - + tests("#revoke_ec2_security_group('#{@ec2_sec_group.name}')").succeeds do @instance.revoke_ec2_security_group(@ec2_sec_group.name) returns('revoking') do @@ -29,9 +27,35 @@ Shindo.tests("AWS::RDS | security_group", ['aws', 'rds']) do @instance.wait_for { ready? } returns(false) { @instance.ec2_security_groups.any?{|h| h['EC2SecurityGroupName'] == @ec2_sec_group.name} } - @ec2_sec_group.destroy end + @instance.wait_for { ready? } + + tests("#authorize_ec2_security_group('#{@ec2_sec_group.group_id}')").succeeds do + @instance.authorize_ec2_security_group(@ec2_sec_group.group_id) + returns('authorizing') do + @instance.ec2_security_groups.find{|h| h['EC2SecurityGroupName'] == @ec2_sec_group.name}['Status'] + end + end + + @instance.wait_for { ready? } + + tests("#revoke_ec2_security_group('#{@ec2_sec_group.group_id}')").succeeds do + @instance.revoke_ec2_security_group(@ec2_sec_group.group_id) + + returns('revoking') do + @instance.ec2_security_groups.find{|h| h['EC2SecurityGroupName'] == @ec2_sec_group.name}['Status'] + end + + @instance.wait_for { ready? } + + returns(false) { @instance.ec2_security_groups.any?{|h| h['EC2SecurityGroupId'] == @ec2_sec_group.group_id} } + end + + @instance.wait_for { ready? } + + @ec2_sec_group.destroy + tests("#authorize_cidrip").succeeds do @cidr = '127.0.0.1/32' @instance.authorize_cidrip(@cidr)