From 4ee99f4ac6cd484b73d42357b11077a743b2fef1 Mon Sep 17 00:00:00 2001 From: David Faber Date: Tue, 29 Oct 2013 16:17:43 -0700 Subject: [PATCH 1/2] Fix parser typo that caused failure in #describe_internet_gateways when the gateway had tags --- lib/fog/aws/parsers/compute/describe_internet_gateways.rb | 2 +- tests/aws/requests/compute/internet_gateway_tests.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/fog/aws/parsers/compute/describe_internet_gateways.rb b/lib/fog/aws/parsers/compute/describe_internet_gateways.rb index 10d76f318..28169c395 100644 --- a/lib/fog/aws/parsers/compute/describe_internet_gateways.rb +++ b/lib/fog/aws/parsers/compute/describe_internet_gateways.rb @@ -26,7 +26,7 @@ module Fog if @in_tag_set case name when 'item' - @vpc['tagSet'][@tag['key']] = @tag['value'] + @internet_gateway['tagSet'][@tag['key']] = @tag['value'] @tag = {} when 'key', 'value' @tag[name] = value diff --git a/tests/aws/requests/compute/internet_gateway_tests.rb b/tests/aws/requests/compute/internet_gateway_tests.rb index c21e831fe..92d5ce898 100644 --- a/tests/aws/requests/compute/internet_gateway_tests.rb +++ b/tests/aws/requests/compute/internet_gateway_tests.rb @@ -26,6 +26,11 @@ Shindo.tests('Fog::Compute[:aws] | internet_gateway requests', ['aws']) do tests('#describe_internet_gateways').formats(@internet_gateways_format) do Fog::Compute[:aws].describe_internet_gateways.body end + + tests('#describe_internet_gateways with tags').formats(@internet_gateways_format) do + Fog::Compute[:aws].create_tags @igw_id, {"environment" => "production"} + Fog::Compute[:aws].describe_internet_gateways.body + end tests("#attach_internet_gateway('#{@igw_id}, #{@vpc_id}')").formats(AWS::Compute::Formats::BASIC) do Fog::Compute[:aws].attach_internet_gateway(@igw_id, @vpc_id).body From 01d156c16bd4f1a75dcb5a5c5049d12341e2f845 Mon Sep 17 00:00:00 2001 From: David Faber Date: Tue, 29 Oct 2013 17:55:43 -0700 Subject: [PATCH 2/2] Add support to #create_tags mock for internet gateways --- lib/fog/aws/compute.rb | 1 - lib/fog/aws/requests/compute/create_internet_gateway.rb | 9 +++++---- lib/fog/aws/requests/compute/create_tags.rb | 2 ++ lib/fog/aws/requests/compute/delete_internet_gateway.rb | 2 +- .../aws/requests/compute/describe_internet_gateways.rb | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/fog/aws/compute.rb b/lib/fog/aws/compute.rb index c503fb636..124202293 100644 --- a/lib/fog/aws/compute.rb +++ b/lib/fog/aws/compute.rb @@ -223,7 +223,6 @@ module Fog :subnets => [], :vpcs => [], :dhcp_options => [], - :internet_gateways => [], :route_tables => [], :account_attributes => [ { diff --git a/lib/fog/aws/requests/compute/create_internet_gateway.rb b/lib/fog/aws/requests/compute/create_internet_gateway.rb index 34263e939..503d8bd11 100644 --- a/lib/fog/aws/requests/compute/create_internet_gateway.rb +++ b/lib/fog/aws/requests/compute/create_internet_gateway.rb @@ -33,16 +33,17 @@ module Fog class Mock def create_internet_gateway() - self.data[:internet_gateways].push({ - 'internetGatewayId' => Fog::AWS::Mock.request_id, + gateway_id = Fog::AWS::Mock.internet_gateway_id + self.data[:internet_gateways][gateway_id] = { + 'internetGatewayId' => gateway_id, 'attachmentSet' => {}, 'tagSet' => {} - }) + } Excon::Response.new( :status => 200, :body => { 'requestId' => Fog::AWS::Mock.request_id, - 'internetGatewaySet' => self.data[:internet_gateways] + 'internetGatewaySet' => [self.data[:internet_gateways][gateway_id]] } ) end diff --git a/lib/fog/aws/requests/compute/create_tags.rb b/lib/fog/aws/requests/compute/create_tags.rb index 354036057..35c8173d6 100644 --- a/lib/fog/aws/requests/compute/create_tags.rb +++ b/lib/fog/aws/requests/compute/create_tags.rb @@ -53,6 +53,8 @@ module Fog 'snapshot' when /^vol\-[a-z0-9]{8}$/i 'volume' + when /^igw\-[a-z0-9]{8}$/i + 'internet_gateway' end if type && ((type == 'image' && visible_images[resource_id]) || self.data[:"#{type}s"][resource_id]) { 'resourceId' => resource_id, 'resourceType' => type } diff --git a/lib/fog/aws/requests/compute/delete_internet_gateway.rb b/lib/fog/aws/requests/compute/delete_internet_gateway.rb index e7b385a05..271b4a4f7 100644 --- a/lib/fog/aws/requests/compute/delete_internet_gateway.rb +++ b/lib/fog/aws/requests/compute/delete_internet_gateway.rb @@ -30,7 +30,7 @@ module Fog Excon::Response.new.tap do |response| if internet_gateway_id response.status = 200 - self.data[:internet_gateways].reject! { |v| v['internetGatewayId'] == internet_gateway_id } + self.data[:internet_gateways].delete(internet_gateway_id) response.body = { 'requestId' => Fog::AWS::Mock.request_id, diff --git a/lib/fog/aws/requests/compute/describe_internet_gateways.rb b/lib/fog/aws/requests/compute/describe_internet_gateways.rb index 987a599da..a2d7fa51f 100644 --- a/lib/fog/aws/requests/compute/describe_internet_gateways.rb +++ b/lib/fog/aws/requests/compute/describe_internet_gateways.rb @@ -40,7 +40,7 @@ module Fog class Mock def describe_internet_gateways(filters = {}) - internet_gateways = self.data[:internet_gateways] + internet_gateways = self.data[:internet_gateways].values if filters['internet-gateway-id'] internet_gateways = internet_gateways.reject {|internet_gateway| internet_gateway['internetGatewayId'] != filters['internet-gateway-id']}