diff --git a/lib/fog/aws/parsers/elb/describe_load_balancers.rb b/lib/fog/aws/parsers/elb/describe_load_balancers.rb index 36485d537..4144cf528 100644 --- a/lib/fog/aws/parsers/elb/describe_load_balancers.rb +++ b/lib/fog/aws/parsers/elb/describe_load_balancers.rb @@ -95,9 +95,12 @@ module Fog when 'BackendServerDescriptions' @in_backend_server_descriptions = false + when 'InstancePort' if @in_backend_server_descriptions - @backend_server_description[name] = value + @backend_server_description[name] = value.to_i + elsif @in_listeners + @listener_description['Listener'][name] = value.to_i end when 'CanonicalHostedZoneName', 'CanonicalHostedZoneNameID', 'LoadBalancerName', 'DNSName', 'Scheme' @@ -111,7 +114,7 @@ module Fog @in_policy_names = false when 'Protocol', 'SSLCertificateId', 'InstanceProtocol' @listener_description['Listener'][name] = value - when 'LoadBalancerPort', 'InstancePort' + when 'LoadBalancerPort' @listener_description['Listener'][name] = value.to_i when 'Instances' diff --git a/lib/fog/aws/requests/elb/create_load_balancer.rb b/lib/fog/aws/requests/elb/create_load_balancer.rb index dad4585fc..4cedb7fe4 100644 --- a/lib/fog/aws/requests/elb/create_load_balancer.rb +++ b/lib/fog/aws/requests/elb/create_load_balancer.rb @@ -65,9 +65,6 @@ module Fog certificate_ids = Fog::AWS::IAM::Mock.data[@aws_access_key_id][:server_certificates].map {|n, c| c['Arn'] } - instance_ports = listeners.map{|l| l["InstancePort"] } - backend_server_descriptions = instance_ports.map {|port| {'InstancePort' => port } } - listeners = [*listeners].map do |listener| if listener['SSLCertificateId'] and !certificate_ids.include? listener['SSLCertificateId'] raise Fog::AWS::IAM::NotFound.new('CertificateNotFound') @@ -89,7 +86,11 @@ module Fog self.data[:load_balancers][lb_name] = { 'AvailabilityZones' => availability_zones, - 'BackendServerDescriptions' => backend_server_descriptions, + 'BackendServerDescriptions' => [], + # Hack to facilitate not updating the local data structure + # (BackendServerDescriptions) until we do a subsequent + # describe as that is how AWS behaves. + 'BackendServerDescriptionsRemote' => [], 'Subnets' => options[:subnet_ids] || [], 'Scheme' => options[:scheme].nil? ? 'internet-facing' : options[:scheme], 'SecurityGroups' => options[:security_groups].nil? ? [] : options[:security_groups], diff --git a/lib/fog/aws/requests/elb/describe_load_balancers.rb b/lib/fog/aws/requests/elb/describe_load_balancers.rb index 5bef70695..9f23180a5 100644 --- a/lib/fog/aws/requests/elb/describe_load_balancers.rb +++ b/lib/fog/aws/requests/elb/describe_load_balancers.rb @@ -106,6 +106,7 @@ module Fog 'LoadBalancerDescriptions' => load_balancers.map do |lb| lb['Instances'] = lb['Instances'].map { |i| i['InstanceId'] } lb['Policies'] = lb['Policies'].reject { |name, policies| name == 'Proper' } + lb['BackendServerDescriptions'] = lb.delete('BackendServerDescriptionsRemote') lb end } diff --git a/lib/fog/aws/requests/elb/set_load_balancer_policies_for_backend_server.rb b/lib/fog/aws/requests/elb/set_load_balancer_policies_for_backend_server.rb index e48a0474d..9319360f2 100644 --- a/lib/fog/aws/requests/elb/set_load_balancer_policies_for_backend_server.rb +++ b/lib/fog/aws/requests/elb/set_load_balancer_policies_for_backend_server.rb @@ -42,10 +42,12 @@ module Fog end end - # Update backend policies - description = load_balancer['BackendServerDescriptions'].find{|d| d["InstancePort"] == instance_port } || {} + # Update backend policies: + description = load_balancer['BackendServerDescriptionsRemote'].find{|d| d["InstancePort"] == instance_port } || {} description["InstancePort"] = instance_port description["PolicyNames"] = policy_names + load_balancer['BackendServerDescriptionsRemote'].delete_if{|d| d["InstancePort"] == instance_port } + load_balancer['BackendServerDescriptionsRemote'] << description Excon::Response.new.tap do |response| response.status = 200 diff --git a/lib/fog/xml/sax_parser_connection.rb b/lib/fog/xml/sax_parser_connection.rb index 11f95edf5..a5065bc3d 100644 --- a/lib/fog/xml/sax_parser_connection.rb +++ b/lib/fog/xml/sax_parser_connection.rb @@ -26,12 +26,15 @@ module Fog # Prepare the SAX parser data_stream = Nokogiri::XML::SAX::PushParser.new(parser) + response_string = "" params[:response_block] = lambda do |chunk, remaining, total| + response_string << chunk if ENV['DEBUG_RESPONSE'] data_stream << chunk end # Make request which read chunks into parser response = @excon.request(params) + Fog::Logger.debug "\n#{response_string}" if ENV['DEBUG_RESPONSE'] # Cease parsing and override response.body with parsed data data_stream.finish diff --git a/tests/aws/models/elb/model_tests.rb b/tests/aws/models/elb/model_tests.rb index 89e17bb79..8c8441912 100644 --- a/tests/aws/models/elb/model_tests.rb +++ b/tests/aws/models/elb/model_tests.rb @@ -284,8 +284,7 @@ Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do tests('backend server descriptions') do tests('default') do - returns(1) { elb.backend_server_descriptions.size } - returns(80) { elb.backend_server_descriptions.first.instance_port } + returns(0) { elb.backend_server_descriptions.size } end tests('with a backend policy') do @@ -293,7 +292,7 @@ Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do port = 80 Fog::AWS[:elb].create_load_balancer_policy(elb.id, policy, 'ProxyProtocolPolicyType', { "ProxyProtocol" => true }) Fog::AWS[:elb].set_load_balancer_policies_for_backend_server(elb.id, port, [policy]).body - + elb.reload returns([policy]) { elb.backend_server_descriptions.get(port).policy_names } end end diff --git a/tests/aws/parsers/elb/describe_load_balancers.rb b/tests/aws/parsers/elb/describe_load_balancers.rb new file mode 100644 index 000000000..115dbeffa --- /dev/null +++ b/tests/aws/parsers/elb/describe_load_balancers.rb @@ -0,0 +1,65 @@ +require 'fog/xml' +require 'fog/aws/parsers/elb/describe_load_balancers' + +DESCRIBE_LOAD_BALANCERS_RESULT = <<-EOF + + + + + + 2013-08-01T15:47:20.930Z + fog-test-elb + + 30 + TCP:80 + 10 + 5 + 2 + + + + + + HTTP + 80 + HTTP + 80 + + + + + + + + + + + us-east-1a + + fog-test-elb-1965660309.us-east-1.elb.amazonaws.com + Z3DZXE0Q79N41H + internet-facing + + amazon-elb + amazon-elb-sg + + fog-test-elb-1965660309.us-east-1.elb.amazonaws.com + + + + + + + a6ea2117-fac1-11e2-abd3-1740ab4ef14e + + +EOF + +Shindo.tests('AWS::ELB | parsers | describe_load_balancers', ['aws', 'elb', 'parser']) do + tests('parses the xml').formats(AWS::ELB::Formats::DESCRIBE_LOAD_BALANCERS) do + parser = Nokogiri::XML::SAX::Parser.new(Fog::Parsers::AWS::ELB::DescribeLoadBalancers.new) + parser.parse(DESCRIBE_LOAD_BALANCERS_RESULT) + parser.document.response + end +end diff --git a/tests/aws/requests/elb/helper.rb b/tests/aws/requests/elb/helper.rb index c78f58550..1f9e113bb 100644 --- a/tests/aws/requests/elb/helper.rb +++ b/tests/aws/requests/elb/helper.rb @@ -8,6 +8,7 @@ class AWS LOAD_BALANCER = { "AvailabilityZones" => Array, + "BackendServerDescriptions" => Array, "CanonicalHostedZoneName" => String, "CanonicalHostedZoneNameID" => String, "CreatedTime" => Time, @@ -25,7 +26,7 @@ class AWS } }], "LoadBalancerName" => String, - "Policies" => {"LBCookieStickinessPolicies" => Array, "AppCookieStickinessPolicies" => Array}, + "Policies" => {"LBCookieStickinessPolicies" => Array, "AppCookieStickinessPolicies" => Array, "OtherPolicies" => Array}, "Scheme" => String, "SecurityGroups" => [Fog::Nullable::String], "SourceSecurityGroup" => {"GroupName" => String, "OwnerAlias" => String}, diff --git a/tests/aws/requests/elb/load_balancer_tests.rb b/tests/aws/requests/elb/load_balancer_tests.rb index 17ad5e033..a101fd7b2 100644 --- a/tests/aws/requests/elb/load_balancer_tests.rb +++ b/tests/aws/requests/elb/load_balancer_tests.rb @@ -3,6 +3,10 @@ Shindo.tests('AWS::ELB | load_balancer_tests', ['aws', 'elb']) do @key_name = 'fog-test' tests('success') do + if (Fog::AWS[:iam].get_server_certificate(@key_name) rescue nil) + Fog::AWS[:iam].delete_server_certificate(@key_name) + end + @certificate = Fog::AWS[:iam].upload_server_certificate(AWS::IAM::SERVER_CERT_PUBLIC_KEY, AWS::IAM::SERVER_CERT_PRIVATE_KEY, @key_name).body['Certificate'] tests("#create_load_balancer").formats(AWS::ELB::Formats::CREATE_LOAD_BALANCER) do