From 70962e81c375236ba90d36a7abb54837c5afad22 Mon Sep 17 00:00:00 2001 From: "geemus (Wesley Beary)" Date: Fri, 26 Mar 2010 11:16:14 -0700 Subject: [PATCH] [ec2] include default security group in mocks, and maintain same owner id --- lib/fog/aws/ec2.rb | 32 ++++++++++++++++++- .../ec2/authorize_security_group_ingress.rb | 3 +- .../aws/requests/ec2/create_security_group.rb | 2 +- lib/fog/aws/requests/ec2/run_instances.rb | 2 +- spec/slicehost/requests/create_slice_spec.rb | 1 + 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/lib/fog/aws/ec2.rb b/lib/fog/aws/ec2.rb index 71c1fd855..fb434eeac 100644 --- a/lib/fog/aws/ec2.rb +++ b/lib/fog/aws/ec2.rb @@ -76,7 +76,36 @@ module Fog :addresses => {}, :instances => {}, :key_pairs => {}, - :security_groups => {}, + :security_groups => { + 'default' => { + 'groupDescription' => 'default group', + 'groupName' => 'default', + 'ipPermissions' => [ + { + 'groups' => [{'groupName' => 'default', 'userId' => @owner_id}], + 'fromPort' => -1, + 'toPort' => -1, + 'ipProtocol' => 'icmp', + 'ipRanges' => [] + }, + { + 'groups' => [{'groupName' => 'default', 'userId' => @owner_id}], + 'fromPort' => 0, + 'toPort' => 65535, + 'ipProtocol' => 'tcp', + 'ipRanges' => [] + }, + { + 'groups' => [{'groupName' => 'default', 'userId' => @owner_id}], + 'fromPort' => 0, + 'toPort' => 65535, + 'ipProtocol' => 'udp', + 'ipRanges' => [] + } + ], + 'ownerId' => @owner_id + } + }, :snapshots => {}, :volumes => {} } @@ -91,6 +120,7 @@ module Fog def initialize(options={}) @aws_access_key_id = options[:aws_access_key_id] + @owner_id = Fog::AWS::Mock.owner_id @data = self.class.data[@aws_access_key_id] end diff --git a/lib/fog/aws/requests/ec2/authorize_security_group_ingress.rb b/lib/fog/aws/requests/ec2/authorize_security_group_ingress.rb index 648e716e7..9b6f6ba75 100644 --- a/lib/fog/aws/requests/ec2/authorize_security_group_ingress.rb +++ b/lib/fog/aws/requests/ec2/authorize_security_group_ingress.rb @@ -41,10 +41,9 @@ module Fog group['ipPermissions'] ||= [] if options['GroupName'] && options['SourceSecurityGroupName'] && options['SourceSecurityGroupOwnerId'] - owner = Fog::AWS::Mock.owner_id ['icmp', 'tcp', 'udp'].each do |protocol| group['ipPermissions'] << { - 'groups' => [{'groupName' => options['GroupName'], 'userId' => owner}], + 'groups' => [{'groupName' => options['GroupName'], 'userId' => @owner_id}], 'fromPort' => 1, 'ipRanges' => [], 'ipProtocol' => protocol, diff --git a/lib/fog/aws/requests/ec2/create_security_group.rb b/lib/fog/aws/requests/ec2/create_security_group.rb index e211d8525..22778e74c 100644 --- a/lib/fog/aws/requests/ec2/create_security_group.rb +++ b/lib/fog/aws/requests/ec2/create_security_group.rb @@ -36,7 +36,7 @@ module Fog 'groupDescription' => description, 'groupName' => name, 'ipPermissions' => [], - 'ownerId' => Fog::AWS::Mock.owner_id + 'ownerId' => @owner_id } @data[:security_groups][name] = data response.body = { diff --git a/lib/fog/aws/requests/ec2/run_instances.rb b/lib/fog/aws/requests/ec2/run_instances.rb index 3ee384b67..76411c885 100644 --- a/lib/fog/aws/requests/ec2/run_instances.rb +++ b/lib/fog/aws/requests/ec2/run_instances.rb @@ -102,7 +102,7 @@ module Fog group_set = [ (options['GroupId'] || 'default') ] instances_set = [] - owner_id = Fog::AWS::Mock.owner_id + owner_id = @owner_id reservation_id = Fog::AWS::Mock.reservation_id min_count.times do |i| diff --git a/spec/slicehost/requests/create_slice_spec.rb b/spec/slicehost/requests/create_slice_spec.rb index e51a5f1f5..3e4d97be8 100644 --- a/spec/slicehost/requests/create_slice_spec.rb +++ b/spec/slicehost/requests/create_slice_spec.rb @@ -18,6 +18,7 @@ describe 'Slicehost.create_slice' do actual['bw-out'].should be_an(Float) actual['flavor-id'].should be_an(Integer) actual['id'].should be_an(Integer) + @slice_id = actual['id'] actual['image-id'].should be_an(Integer) actual['name'].should be_an(String) actual['progress'].should be_an(Integer)