Make all existing ELB endpoints compatible with boto3
This commit is contained in:
parent
8093505e89
commit
1d8252feea
@ -220,9 +220,14 @@ class ELBResponse(BaseResponse):
|
||||
return template.render(instance_ids=instance_ids)
|
||||
|
||||
|
||||
CREATE_LOAD_BALANCER_TEMPLATE = """<CreateLoadBalancerResult xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
|
||||
CREATE_LOAD_BALANCER_TEMPLATE = """<CreateLoadBalancerResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
|
||||
<CreateLoadBalancerResult>
|
||||
<DNSName>tests.us-east-1.elb.amazonaws.com</DNSName>
|
||||
</CreateLoadBalancerResult>"""
|
||||
</CreateLoadBalancerResult>
|
||||
<ResponseMetadata>
|
||||
<RequestId>1549581b-12b7-11e3-895e-1334aEXAMPLE</RequestId>
|
||||
</ResponseMetadata>
|
||||
</CreateLoadBalancerResponse>"""
|
||||
|
||||
CREATE_LOAD_BALANCER_LISTENERS_TEMPLATE = """<CreateLoadBalancerListenersResponse xmlns="http://elasticloadbalancing.amazon aws.com/doc/2012-06-01/">
|
||||
<CreateLoadBalancerListenersResult/>
|
||||
@ -231,8 +236,12 @@ CREATE_LOAD_BALANCER_LISTENERS_TEMPLATE = """<CreateLoadBalancerListenersRespons
|
||||
</ResponseMetadata>
|
||||
</CreateLoadBalancerListenersResponse>"""
|
||||
|
||||
DELETE_LOAD_BALANCER_TEMPLATE = """<DeleteLoadBalancerResult xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
|
||||
</DeleteLoadBalancerResult>"""
|
||||
DELETE_LOAD_BALANCER_TEMPLATE = """<DeleteLoadBalancerResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
|
||||
<DeleteLoadBalancerResult/>
|
||||
<ResponseMetadata>
|
||||
<RequestId>1549581b-12b7-11e3-895e-1334aEXAMPLE</RequestId>
|
||||
</ResponseMetadata>
|
||||
</DeleteLoadBalancerResponse>"""
|
||||
|
||||
DESCRIBE_LOAD_BALANCERS_TEMPLATE = """<DescribeLoadBalancersResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
|
||||
<DescribeLoadBalancersResult>
|
||||
@ -345,7 +354,8 @@ DESCRIBE_LOAD_BALANCERS_TEMPLATE = """<DescribeLoadBalancersResponse xmlns="http
|
||||
</ResponseMetadata>
|
||||
</DescribeLoadBalancersResponse>"""
|
||||
|
||||
CONFIGURE_HEALTH_CHECK_TEMPLATE = """<ConfigureHealthCheckResult xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
|
||||
CONFIGURE_HEALTH_CHECK_TEMPLATE = """<ConfigureHealthCheckResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
|
||||
<ConfigureHealthCheckResult>
|
||||
<HealthCheck>
|
||||
<Interval>{{ check.interval }}</Interval>
|
||||
<Target>{{ check.target }}</Target>
|
||||
@ -353,9 +363,14 @@ CONFIGURE_HEALTH_CHECK_TEMPLATE = """<ConfigureHealthCheckResult xmlns="http://e
|
||||
<Timeout>{{ check.timeout }}</Timeout>
|
||||
<UnhealthyThreshold>{{ check.unhealthy_threshold }}</UnhealthyThreshold>
|
||||
</HealthCheck>
|
||||
</ConfigureHealthCheckResult>"""
|
||||
</ConfigureHealthCheckResult>
|
||||
<ResponseMetadata>
|
||||
<RequestId>f9880f01-7852-629d-a6c3-3ae2-666a409287e6dc0c</RequestId>
|
||||
</ResponseMetadata>
|
||||
</ConfigureHealthCheckResponse>"""
|
||||
|
||||
REGISTER_INSTANCES_TEMPLATE = """<RegisterInstancesWithLoadBalancerResult xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
|
||||
REGISTER_INSTANCES_TEMPLATE = """<RegisterInstancesWithLoadBalancerResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
|
||||
<RegisterInstancesWithLoadBalancerResult>
|
||||
<Instances>
|
||||
{% for instance_id in load_balancer.instance_ids %}
|
||||
<member>
|
||||
@ -363,9 +378,14 @@ REGISTER_INSTANCES_TEMPLATE = """<RegisterInstancesWithLoadBalancerResult xmlns=
|
||||
</member>
|
||||
{% endfor %}
|
||||
</Instances>
|
||||
</RegisterInstancesWithLoadBalancerResult>"""
|
||||
</RegisterInstancesWithLoadBalancerResult>
|
||||
<ResponseMetadata>
|
||||
<RequestId>f9880f01-7852-629d-a6c3-3ae2-666a409287e6dc0c</RequestId>
|
||||
</ResponseMetadata>
|
||||
</RegisterInstancesWithLoadBalancerResponse>"""
|
||||
|
||||
DEREGISTER_INSTANCES_TEMPLATE = """<DeregisterInstancesWithLoadBalancerResult xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
|
||||
DEREGISTER_INSTANCES_TEMPLATE = """<DeregisterInstancesFromLoadBalancerResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
|
||||
<DeregisterInstancesFromLoadBalancerResult>
|
||||
<Instances>
|
||||
{% for instance_id in load_balancer.instance_ids %}
|
||||
<member>
|
||||
@ -373,7 +393,11 @@ DEREGISTER_INSTANCES_TEMPLATE = """<DeregisterInstancesWithLoadBalancerResult xm
|
||||
</member>
|
||||
{% endfor %}
|
||||
</Instances>
|
||||
</DeregisterInstancesWithLoadBalancerResult>"""
|
||||
</DeregisterInstancesFromLoadBalancerResult>
|
||||
<ResponseMetadata>
|
||||
<RequestId>f9880f01-7852-629d-a6c3-3ae2-666a409287e6dc0c</RequestId>
|
||||
</ResponseMetadata>
|
||||
</DeregisterInstancesFromLoadBalancerResponse>"""
|
||||
|
||||
SET_LOAD_BALANCER_SSL_CERTIFICATE = """<SetLoadBalancerListenerSSLCertificateResponse xmlns="http://elasticloadbalan cing.amazonaws.com/doc/2012-06-01/">
|
||||
<SetLoadBalancerListenerSSLCertificateResult/>
|
||||
|
@ -1,4 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
import boto3
|
||||
import boto
|
||||
import boto.ec2.elb
|
||||
from boto.ec2.elb import HealthCheck
|
||||
@ -73,6 +74,22 @@ def test_create_load_balancer_with_certificate():
|
||||
listener.ssl_certificate_id.should.equal('arn:aws:iam:123456789012:server-certificate/test-cert')
|
||||
|
||||
|
||||
@mock_elb
|
||||
def test_create_and_delete_boto3_support():
|
||||
client = boto3.client('elb', region_name='us-east-1')
|
||||
|
||||
client.create_load_balancer(
|
||||
LoadBalancerName='my-lb',
|
||||
Listeners=[{'Protocol':'tcp', 'LoadBalancerPort':80, 'InstancePort':8080}],
|
||||
AvailabilityZones=['us-east-1a', 'us-east-1b']
|
||||
)
|
||||
list(client.describe_load_balancers()['LoadBalancerDescriptions']).should.have.length_of(1)
|
||||
|
||||
client.delete_load_balancer(
|
||||
LoadBalancerName='my-lb'
|
||||
)
|
||||
list(client.describe_load_balancers()['LoadBalancerDescriptions']).should.have.length_of(0)
|
||||
|
||||
@mock_elb
|
||||
def test_add_listener():
|
||||
conn = boto.connect_elb()
|
||||
@ -110,6 +127,31 @@ def test_delete_listener():
|
||||
balancer.listeners.should.have.length_of(1)
|
||||
|
||||
|
||||
@mock_elb
|
||||
def test_create_and_delete_listener_boto3_support():
|
||||
client = boto3.client('elb', region_name='us-east-1')
|
||||
|
||||
client.create_load_balancer(
|
||||
LoadBalancerName='my-lb',
|
||||
Listeners=[{'Protocol':'http', 'LoadBalancerPort':80, 'InstancePort':8080}],
|
||||
AvailabilityZones=['us-east-1a', 'us-east-1b']
|
||||
)
|
||||
list(client.describe_load_balancers()['LoadBalancerDescriptions']).should.have.length_of(1)
|
||||
|
||||
client.create_load_balancer_listeners(
|
||||
LoadBalancerName='my-lb',
|
||||
Listeners=[{'Protocol':'tcp', 'LoadBalancerPort':443, 'InstancePort':8443}]
|
||||
)
|
||||
balancer = client.describe_load_balancers()['LoadBalancerDescriptions'][0]
|
||||
list(balancer['ListenerDescriptions']).should.have.length_of(2)
|
||||
balancer['ListenerDescriptions'][0]['Listener']['Protocol'].should.equal('HTTP')
|
||||
balancer['ListenerDescriptions'][0]['Listener']['LoadBalancerPort'].should.equal(80)
|
||||
balancer['ListenerDescriptions'][0]['Listener']['InstancePort'].should.equal(8080)
|
||||
balancer['ListenerDescriptions'][1]['Listener']['Protocol'].should.equal('TCP')
|
||||
balancer['ListenerDescriptions'][1]['Listener']['LoadBalancerPort'].should.equal(443)
|
||||
balancer['ListenerDescriptions'][1]['Listener']['InstancePort'].should.equal(8443)
|
||||
|
||||
|
||||
@mock_elb
|
||||
def test_set_sslcertificate():
|
||||
conn = boto.connect_elb()
|
||||
@ -183,6 +225,34 @@ def test_create_health_check():
|
||||
health_check.timeout.should.equal(23)
|
||||
|
||||
|
||||
@mock_elb
|
||||
def test_create_health_check_boto3():
|
||||
client = boto3.client('elb', region_name='us-east-1')
|
||||
|
||||
client.create_load_balancer(
|
||||
LoadBalancerName='my-lb',
|
||||
Listeners=[{'Protocol':'http', 'LoadBalancerPort':80, 'InstancePort':8080}],
|
||||
AvailabilityZones=['us-east-1a', 'us-east-1b']
|
||||
)
|
||||
client.configure_health_check(
|
||||
LoadBalancerName='my-lb',
|
||||
HealthCheck={
|
||||
'Target': 'HTTP:8080/health',
|
||||
'Interval': 20,
|
||||
'Timeout': 23,
|
||||
'HealthyThreshold': 3,
|
||||
'UnhealthyThreshold': 5
|
||||
}
|
||||
)
|
||||
|
||||
balancer = client.describe_load_balancers()['LoadBalancerDescriptions'][0]
|
||||
balancer['HealthCheck']['Target'].should.equal('HTTP:8080/health')
|
||||
balancer['HealthCheck']['Interval'].should.equal(20)
|
||||
balancer['HealthCheck']['Timeout'].should.equal(23)
|
||||
balancer['HealthCheck']['HealthyThreshold'].should.equal(3)
|
||||
balancer['HealthCheck']['UnhealthyThreshold'].should.equal(5)
|
||||
|
||||
|
||||
@mock_ec2
|
||||
@mock_elb
|
||||
def test_register_instances():
|
||||
@ -202,6 +272,32 @@ def test_register_instances():
|
||||
set(instance_ids).should.equal(set([instance_id1, instance_id2]))
|
||||
|
||||
|
||||
@mock_ec2
|
||||
@mock_elb
|
||||
def test_register_instances_boto3():
|
||||
ec2 = boto3.resource('ec2', region_name='us-east-1')
|
||||
response = ec2.create_instances(ImageId='ami-1234abcd', MinCount=2, MaxCount=2)
|
||||
instance_id1 = response[0].id
|
||||
instance_id2 = response[1].id
|
||||
|
||||
client = boto3.client('elb', region_name='us-east-1')
|
||||
client.create_load_balancer(
|
||||
LoadBalancerName='my-lb',
|
||||
Listeners=[{'Protocol':'http', 'LoadBalancerPort':80, 'InstancePort':8080}],
|
||||
AvailabilityZones=['us-east-1a', 'us-east-1b']
|
||||
)
|
||||
client.register_instances_with_load_balancer(
|
||||
LoadBalancerName='my-lb',
|
||||
Instances=[
|
||||
{'InstanceId': instance_id1},
|
||||
{'InstanceId': instance_id2}
|
||||
]
|
||||
)
|
||||
balancer = client.describe_load_balancers()['LoadBalancerDescriptions'][0]
|
||||
instance_ids = [instance['InstanceId'] for instance in balancer['Instances']]
|
||||
set(instance_ids).should.equal(set([instance_id1, instance_id2]))
|
||||
|
||||
|
||||
@mock_ec2
|
||||
@mock_elb
|
||||
def test_deregister_instances():
|
||||
@ -223,6 +319,42 @@ def test_deregister_instances():
|
||||
balancer.instances.should.have.length_of(1)
|
||||
balancer.instances[0].id.should.equal(instance_id2)
|
||||
|
||||
@mock_ec2
|
||||
@mock_elb
|
||||
def test_deregister_instances_boto3():
|
||||
ec2 = boto3.resource('ec2', region_name='us-east-1')
|
||||
response = ec2.create_instances(ImageId='ami-1234abcd', MinCount=2, MaxCount=2)
|
||||
instance_id1 = response[0].id
|
||||
instance_id2 = response[1].id
|
||||
|
||||
client = boto3.client('elb', region_name='us-east-1')
|
||||
client.create_load_balancer(
|
||||
LoadBalancerName='my-lb',
|
||||
Listeners=[{'Protocol':'http', 'LoadBalancerPort':80, 'InstancePort':8080}],
|
||||
AvailabilityZones=['us-east-1a', 'us-east-1b']
|
||||
)
|
||||
client.register_instances_with_load_balancer(
|
||||
LoadBalancerName='my-lb',
|
||||
Instances=[
|
||||
{'InstanceId': instance_id1},
|
||||
{'InstanceId': instance_id2}
|
||||
]
|
||||
)
|
||||
|
||||
balancer = client.describe_load_balancers()['LoadBalancerDescriptions'][0]
|
||||
balancer['Instances'].should.have.length_of(2)
|
||||
|
||||
client.deregister_instances_from_load_balancer(
|
||||
LoadBalancerName='my-lb',
|
||||
Instances=[
|
||||
{'InstanceId': instance_id1}
|
||||
]
|
||||
)
|
||||
|
||||
balancer = client.describe_load_balancers()['LoadBalancerDescriptions'][0]
|
||||
balancer['Instances'].should.have.length_of(1)
|
||||
balancer['Instances'][0]['InstanceId'].should.equal(instance_id2)
|
||||
|
||||
|
||||
@mock_elb
|
||||
def test_default_attributes():
|
||||
|
Loading…
Reference in New Issue
Block a user