feat: transition elbv2 state to active
on first describe (#3937)
* refactor: parameterize state in elbv2 template response * feat: transition load balancer to active on first describe Closes #3936
This commit is contained in:
parent
31cf3c4252
commit
867cf078de
@ -381,6 +381,7 @@ class FakeLoadBalancer(CloudFormationModel):
|
||||
vpc_id,
|
||||
arn,
|
||||
dns_name,
|
||||
state,
|
||||
scheme="internet-facing",
|
||||
):
|
||||
self.name = name
|
||||
@ -393,6 +394,7 @@ class FakeLoadBalancer(CloudFormationModel):
|
||||
self.tags = {}
|
||||
self.arn = arn
|
||||
self.dns_name = dns_name
|
||||
self.state = state
|
||||
|
||||
self.stack = "ipv4"
|
||||
self.attrs = {
|
||||
@ -419,6 +421,10 @@ class FakeLoadBalancer(CloudFormationModel):
|
||||
if key in self.tags:
|
||||
del self.tags[key]
|
||||
|
||||
def activate(self):
|
||||
if self.state == "provisioning":
|
||||
self.state = "active"
|
||||
|
||||
def delete(self, region):
|
||||
""" Not exposed as part of the ELB API - used for CloudFormation. """
|
||||
elbv2_backends[region].delete_load_balancer(self.arn)
|
||||
@ -517,6 +523,8 @@ class ELBv2Backend(BaseBackend):
|
||||
):
|
||||
vpc_id = None
|
||||
subnets = []
|
||||
state = "provisioning"
|
||||
|
||||
if not subnet_ids:
|
||||
raise SubnetNotFoundError()
|
||||
for subnet_id in subnet_ids:
|
||||
@ -542,6 +550,7 @@ class ELBv2Backend(BaseBackend):
|
||||
subnets=subnets,
|
||||
vpc_id=vpc_id,
|
||||
dns_name=dns_name,
|
||||
state=state,
|
||||
)
|
||||
self.load_balancers[arn] = new_load_balancer
|
||||
return new_load_balancer
|
||||
@ -740,6 +749,8 @@ Member must satisfy regular expression pattern: {}".format(
|
||||
arns = arns or []
|
||||
names = names or []
|
||||
if not arns and not names:
|
||||
for balancer in balancers:
|
||||
balancer.activate()
|
||||
return balancers
|
||||
|
||||
matched_balancers = []
|
||||
@ -747,6 +758,7 @@ Member must satisfy regular expression pattern: {}".format(
|
||||
|
||||
for arn in arns:
|
||||
for balancer in balancers:
|
||||
balancer.activate()
|
||||
if balancer.arn == arn:
|
||||
matched_balancer = balancer
|
||||
if matched_balancer is None:
|
||||
@ -756,6 +768,7 @@ Member must satisfy regular expression pattern: {}".format(
|
||||
|
||||
for name in names:
|
||||
for balancer in balancers:
|
||||
balancer.activate()
|
||||
if balancer.name == name:
|
||||
matched_balancer = balancer
|
||||
if matched_balancer is None:
|
||||
|
@ -706,7 +706,7 @@ CREATE_LOAD_BALANCER_TEMPLATE = """<CreateLoadBalancerResponse xmlns="http://ela
|
||||
</SecurityGroups>
|
||||
<DNSName>{{ load_balancer.dns_name }}</DNSName>
|
||||
<State>
|
||||
<Code>provisioning</Code>
|
||||
<Code>{{ load_balancer.state }}</Code>
|
||||
</State>
|
||||
<Type>application</Type>
|
||||
</member>
|
||||
@ -877,7 +877,7 @@ DESCRIBE_LOAD_BALANCERS_TEMPLATE = """<DescribeLoadBalancersResponse xmlns="http
|
||||
</SecurityGroups>
|
||||
<DNSName>{{ load_balancer.dns_name }}</DNSName>
|
||||
<State>
|
||||
<Code>provisioning</Code>
|
||||
<Code>{{ load_balancer.state }}</Code>
|
||||
</State>
|
||||
<Type>application</Type>
|
||||
<IpAddressType>ipv4</IpAddressType>
|
||||
|
@ -52,6 +52,7 @@ def test_create_load_balancer():
|
||||
]
|
||||
)
|
||||
lb.get("CreatedTime").tzinfo.should_not.be.none
|
||||
lb.get("State").get("Code").should.equal("provisioning")
|
||||
|
||||
# Ensure the tags persisted
|
||||
response = conn.describe_tags(ResourceArns=[lb.get("LoadBalancerArn")])
|
||||
@ -89,6 +90,7 @@ def test_describe_load_balancers():
|
||||
response.get("LoadBalancers").should.have.length_of(1)
|
||||
lb = response.get("LoadBalancers")[0]
|
||||
lb.get("LoadBalancerName").should.equal("my-lb")
|
||||
lb.get("State").get("Code").should.equal("active")
|
||||
|
||||
response = conn.describe_load_balancers(
|
||||
LoadBalancerArns=[lb.get("LoadBalancerArn")]
|
||||
|
Loading…
Reference in New Issue
Block a user