ELB: describe_instance_health() should check LB existence (#5706)
This commit is contained in:
parent
f7c504b0eb
commit
e5a1115834
@ -23,10 +23,17 @@ class CertificateNotFoundException(ELBClientError):
|
||||
|
||||
|
||||
class LoadBalancerNotFoundError(ELBClientError):
|
||||
def __init__(self, cidr):
|
||||
def __init__(self, name):
|
||||
super().__init__(
|
||||
"LoadBalancerNotFound",
|
||||
f"The specified load balancer does not exist: {cidr}",
|
||||
f"The specified load balancer does not exist: {name}",
|
||||
)
|
||||
|
||||
|
||||
class NoActiveLoadBalancerFoundError(ELBClientError):
|
||||
def __init__(self, name):
|
||||
super().__init__(
|
||||
"LoadBalancerNotFound", f"There is no ACTIVE Load Balancer named '{name}'"
|
||||
)
|
||||
|
||||
|
||||
|
@ -14,6 +14,7 @@ from .exceptions import (
|
||||
EmptyListenersError,
|
||||
InvalidSecurityGroupError,
|
||||
LoadBalancerNotFoundError,
|
||||
NoActiveLoadBalancerFoundError,
|
||||
PolicyNotFoundError,
|
||||
TooManyTagsError,
|
||||
CertificateNotFoundException,
|
||||
@ -372,8 +373,11 @@ class ELBBackend(BaseBackend):
|
||||
return policies
|
||||
|
||||
def describe_instance_health(self, lb_name, instances):
|
||||
elb = self.get_load_balancer(lb_name)
|
||||
if elb is None:
|
||||
raise NoActiveLoadBalancerFoundError(name=lb_name)
|
||||
provided_ids = [i["InstanceId"] for i in instances]
|
||||
registered_ids = self.get_load_balancer(lb_name).instance_ids
|
||||
registered_ids = elb.instance_ids
|
||||
ec2_backend = ec2_backends[self.account_id][self.region_name]
|
||||
if len(provided_ids) == 0:
|
||||
provided_ids = registered_ids
|
||||
|
@ -933,6 +933,17 @@ def test_describe_instance_health__with_instance_ids():
|
||||
instances_health[2]["State"].should.equal("OutOfService")
|
||||
|
||||
|
||||
@mock_elb
|
||||
def test_describe_instance_health_of_unknown_lb():
|
||||
elb = boto3.client("elb", region_name="us-east-1")
|
||||
|
||||
with pytest.raises(ClientError) as exc:
|
||||
elb.describe_instance_health(LoadBalancerName="what")
|
||||
err = exc.value.response["Error"]
|
||||
err["Code"].should.equal("LoadBalancerNotFound")
|
||||
err["Message"].should.equal("There is no ACTIVE Load Balancer named 'what'")
|
||||
|
||||
|
||||
@mock_elb
|
||||
def test_add_remove_tags():
|
||||
client = boto3.client("elb", region_name="us-east-1")
|
||||
|
Loading…
Reference in New Issue
Block a user