Elbv2.create rule links target group to lb (#6452)

* Link loadbalancer arn to target group when creating a forward rule so target groups can be found by loadbalancer arn

* add test for describe_target_groups by loadbalancer arn when creating listener rule after listener creation

* Linting

---------

Co-authored-by: Bert Blommers <info@bertblommers.nl>
This commit is contained in:
Florian Weyandt 2023-09-15 09:39:17 +02:00 committed by GitHub
parent d88d5afda6
commit 6831c42284
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -822,6 +822,13 @@ class ELBv2Backend(BaseBackend):
raise PriorityInUseError() raise PriorityInUseError()
self._validate_actions(fake_actions) self._validate_actions(fake_actions)
for action in fake_actions:
if action.type == "forward":
found_arns = self._get_target_group_arns_from(action_data=action.data)
for arn in found_arns:
target_group = self.target_groups[arn]
target_group.load_balancer_arns.append(listener.load_balancer_arn)
arn = listener_arn.replace(":listener/", ":listener-rule/") arn = listener_arn.replace(":listener/", ":listener-rule/")
arn += f"/{mock_random.get_random_hex(16)}" arn += f"/{mock_random.get_random_hex(16)}"

View File

@ -518,3 +518,10 @@ def test_create_rule_action_forward_target_group():
assert rule["Priority"] == "99" assert rule["Priority"] == "99"
assert rule["Conditions"] == [] assert rule["Conditions"] == []
assert rule["Actions"][0] == action assert rule["Actions"][0] == action
# assert describe_target_group by loadbalancer_arn response
load_balancer_arn = conn.describe_listeners(ListenerArns=[http_listener_arn])[
"Listeners"
][0]["LoadBalancerArn"]
response = conn.describe_target_groups(LoadBalancerArn=load_balancer_arn)
assert len(response.get("TargetGroups")) == 1