mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #2012 from mikehale/aws-elb-parser-fix
Aws elb parser fix
This commit is contained in:
commit
db5d9f0813
9 changed files with 91 additions and 12 deletions
|
@ -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'
|
||||
|
|
|
@ -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],
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
65
tests/aws/parsers/elb/describe_load_balancers.rb
Normal file
65
tests/aws/parsers/elb/describe_load_balancers.rb
Normal file
|
@ -0,0 +1,65 @@
|
|||
require 'fog/xml'
|
||||
require 'fog/aws/parsers/elb/describe_load_balancers'
|
||||
|
||||
DESCRIBE_LOAD_BALANCERS_RESULT = <<-EOF
|
||||
<DescribeLoadBalancersResponse
|
||||
xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
|
||||
<DescribeLoadBalancersResult>
|
||||
<LoadBalancerDescriptions>
|
||||
<member>
|
||||
<SecurityGroups/>
|
||||
<CreatedTime>2013-08-01T15:47:20.930Z</CreatedTime>
|
||||
<LoadBalancerName>fog-test-elb</LoadBalancerName>
|
||||
<HealthCheck>
|
||||
<Interval>30</Interval>
|
||||
<Target>TCP:80</Target>
|
||||
<HealthyThreshold>10</HealthyThreshold>
|
||||
<Timeout>5</Timeout>
|
||||
<UnhealthyThreshold>2</UnhealthyThreshold>
|
||||
</HealthCheck>
|
||||
<ListenerDescriptions>
|
||||
<member>
|
||||
<PolicyNames/>
|
||||
<Listener>
|
||||
<Protocol>HTTP</Protocol>
|
||||
<LoadBalancerPort>80</LoadBalancerPort>
|
||||
<InstanceProtocol>HTTP</InstanceProtocol>
|
||||
<InstancePort>80</InstancePort>
|
||||
</Listener>
|
||||
</member>
|
||||
</ListenerDescriptions>
|
||||
<Instances/>
|
||||
<Policies>
|
||||
<AppCookieStickinessPolicies/>
|
||||
<OtherPolicies/>
|
||||
<LBCookieStickinessPolicies/>
|
||||
</Policies>
|
||||
<AvailabilityZones>
|
||||
<member>us-east-1a</member>
|
||||
</AvailabilityZones>
|
||||
<CanonicalHostedZoneName>fog-test-elb-1965660309.us-east-1.elb.amazonaws.com</CanonicalHostedZoneName>
|
||||
<CanonicalHostedZoneNameID>Z3DZXE0Q79N41H</CanonicalHostedZoneNameID>
|
||||
<Scheme>internet-facing</Scheme>
|
||||
<SourceSecurityGroup>
|
||||
<OwnerAlias>amazon-elb</OwnerAlias>
|
||||
<GroupName>amazon-elb-sg</GroupName>
|
||||
</SourceSecurityGroup>
|
||||
<DNSName>fog-test-elb-1965660309.us-east-1.elb.amazonaws.com</DNSName>
|
||||
<BackendServerDescriptions/>
|
||||
<Subnets/>
|
||||
</member>
|
||||
</LoadBalancerDescriptions>
|
||||
</DescribeLoadBalancersResult>
|
||||
<ResponseMetadata>
|
||||
<RequestId>a6ea2117-fac1-11e2-abd3-1740ab4ef14e</RequestId>
|
||||
</ResponseMetadata>
|
||||
</DescribeLoadBalancersResponse>
|
||||
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
|
|
@ -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},
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue