ELBv2 - Store default action when modifying listener (#4589)

This commit is contained in:
Bert Blommers 2021-11-17 20:36:20 -01:00 committed by GitHub
parent a912fc4cac
commit 17f2a13573
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 1 deletions

View File

@ -1423,6 +1423,7 @@ Member must satisfy regular expression pattern: {}".format(
if default_actions is not None and default_actions != []:
# Is currently not validated
listener.default_actions = default_actions
listener._default_rule[0].actions = default_actions
return listener

View File

@ -607,7 +607,7 @@ class ELBV2Response(BaseResponse):
protocol = self._get_param("Protocol")
ssl_policy = self._get_param("SslPolicy")
certificates = self._get_list_prefix("Certificates.member")
default_actions = self._get_list_prefix("DefaultActions.member")
default_actions = self._get_params().get("DefaultActions", [])
# Should really move SSL Policies to models
if ssl_policy is not None and ssl_policy not in [

View File

@ -521,3 +521,52 @@ def test_create_target_group_with_target_type(target_type):
group.should.have.key("TargetType").equal(target_type)
group.shouldnt.have.key("Protocol")
group.shouldnt.have.key("VpcId")
@mock_elbv2
@mock_ec2
def test_delete_target_group_after_modifying_listener():
client = boto3.client("elbv2", region_name="us-east-1")
response, vpc, _, _, _, conn = create_load_balancer()
load_balancer_arn = response.get("LoadBalancers")[0].get("LoadBalancerArn")
response = client.create_target_group(
Name="a-target", Protocol="HTTP", Port=8080, VpcId=vpc.id,
)
target_group_arn1 = response.get("TargetGroups")[0]["TargetGroupArn"]
response = client.create_target_group(
Name="a-target-2", Protocol="HTTPS", Port=8081, VpcId=vpc.id,
)
target_group_arn2 = response.get("TargetGroups")[0]["TargetGroupArn"]
response = conn.create_listener(
LoadBalancerArn=load_balancer_arn,
Protocol="HTTP",
Port=80,
DefaultActions=[{"Type": "forward", "TargetGroupArn": target_group_arn1}],
)
listener_arn = response["Listeners"][0].get("ListenerArn")
client.modify_listener(
ListenerArn=listener_arn,
DefaultActions=[{"Type": "forward", "TargetGroupArn": target_group_arn2,}],
)
response = conn.describe_listeners(LoadBalancerArn=load_balancer_arn)
default_actions = response["Listeners"][0]["DefaultActions"]
default_actions.should.equal(
[{"Type": "forward", "TargetGroupArn": target_group_arn2}]
)
# Target Group 1 can now be deleted, as the LB points to group 2
client.delete_target_group(TargetGroupArn=target_group_arn1)
# Sanity check - we're still pointing to group 2
response = conn.describe_listeners(LoadBalancerArn=load_balancer_arn)
default_actions = response["Listeners"][0]["DefaultActions"]
default_actions.should.equal(
[{"Type": "forward", "TargetGroupArn": target_group_arn2}]
)