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