diff --git a/moto/elb/responses.py b/moto/elb/responses.py index be9c8ad8b..8a7902f37 100644 --- a/moto/elb/responses.py +++ b/moto/elb/responses.py @@ -177,6 +177,14 @@ class ELBResponse(BaseResponse): template = self.response_template(MODIFY_ATTRIBUTES_TEMPLATE) return template.render(attributes=load_balancer.attributes) + def describe_instance_health(self): + load_balancer_name = self.querystring.get('LoadBalancerName')[0] + instance_ids = [value[0] for key, value in self.querystring.items() if "Instances.member" in key] + if len(instance_ids) == 0: + instance_ids = self.elb_backend.describe_load_balancers(load_balancer_name)[0].instance_ids + template = self.response_template(DESCRIBE_INSTANCE_HEALTH_TEMPLATE) + return template.render(instance_ids=instance_ids) + CREATE_LOAD_BALANCER_TEMPLATE = """ tests.us-east-1.elb.amazonaws.com @@ -364,7 +372,7 @@ MODIFY_ATTRIBUTES_TEMPLATE = """ + + + {% for instance_id in instance_ids %} + + N/A + {{ instance_id }} + InService + N/A + + {% endfor %} + + + + 1549581b-12b7-11e3-895e-1334aEXAMPLE + +""" diff --git a/tests/test_elb/test_elb.py b/tests/test_elb/test_elb.py index 3f31e9d49..3c8f3f22f 100644 --- a/tests/test_elb/test_elb.py +++ b/tests/test_elb/test_elb.py @@ -199,6 +199,7 @@ def test_deregister_instances(): balancer.instances.should.have.length_of(1) balancer.instances[0].id.should.equal(instance_id2) + @mock_elb def test_default_attributes(): conn = boto.connect_elb() @@ -226,6 +227,7 @@ def test_cross_zone_load_balancing_attribute(): attributes = lb.get_attributes(force=True) attributes.cross_zone_load_balancing.enabled.should.be.false + @mock_elb def test_connection_draining_attribute(): conn = boto.connect_elb() @@ -251,6 +253,7 @@ def test_connection_draining_attribute(): attributes = lb.get_attributes(force=True) attributes.connection_draining.enabled.should.be.false + @mock_elb def test_access_log_attribute(): conn = boto.connect_elb() @@ -275,6 +278,7 @@ def test_access_log_attribute(): attributes = lb.get_attributes(force=True) attributes.access_log.enabled.should.be.false + @mock_elb def test_connection_settings_attribute(): conn = boto.connect_elb() @@ -294,3 +298,31 @@ def test_connection_settings_attribute(): attributes.connecting_settings.idle_timeout.should.equal(60) +@mock_ec2 +@mock_elb +def test_describe_instance_health(): + ec2_conn = boto.connect_ec2() + reservation = ec2_conn.run_instances('ami-1234abcd', 2) + instance_id1 = reservation.instances[0].id + instance_id2 = reservation.instances[1].id + + conn = boto.connect_elb() + zones = ['us-east-1a', 'us-east-1b'] + ports = [(80, 8080, 'http'), (443, 8443, 'tcp')] + lb = conn.create_load_balancer('my-lb', zones, ports) + + instances_health = conn.describe_instance_health('my-lb') + instances_health.should.be.empty + + lb.register_instances([instance_id1, instance_id2]) + + instances_health = conn.describe_instance_health('my-lb') + instances_health.should.have.length_of(2) + for instance_health in instances_health: + instance_health.instance_id.should.be.within([instance_id1, instance_id2]) + instance_health.state.should.equal('InService') + + instances_health = conn.describe_instance_health('my-lb', [instance_id1]) + instances_health.should.have.length_of(1) + instances_health[0].instance_id.should.equal(instance_id1) + instances_health[0].state.should.equal('InService')