ELBv2: Fix LoadBalancerNotFound being thrown for listener rules (#4921)
This commit is contained in:
parent
fdba9e4dbe
commit
131c448756
@ -305,6 +305,7 @@ class FakeListenerRule(CloudFormationModel):
|
||||
self.conditions = conditions
|
||||
self.actions = actions
|
||||
self.priority = priority
|
||||
self.tags = {}
|
||||
|
||||
@property
|
||||
def physical_resource_id(self):
|
||||
|
@ -2,7 +2,7 @@ from moto.core.exceptions import RESTError
|
||||
from moto.core.utils import amzn_request_id
|
||||
from moto.core.responses import BaseResponse
|
||||
from .models import elbv2_backends
|
||||
from .exceptions import DuplicateTagKeysError
|
||||
from .exceptions import DuplicateTagKeysError, RuleNotFoundError
|
||||
from .exceptions import LoadBalancerNotFoundError
|
||||
from .exceptions import TargetGroupNotFoundError
|
||||
from .exceptions import ListenerNotFoundError
|
||||
@ -467,6 +467,22 @@ class ELBV2Response(BaseResponse):
|
||||
resource = self.elbv2_backend.load_balancers.get(arn)
|
||||
if not resource:
|
||||
raise LoadBalancerNotFoundError()
|
||||
elif ":listener-rule" in arn:
|
||||
lb_arn = arn.replace(":listener-rule", ":loadbalancer").rsplit("/", 2)[
|
||||
0
|
||||
]
|
||||
balancer = self.elbv2_backend.load_balancers.get(lb_arn)
|
||||
if not balancer:
|
||||
raise LoadBalancerNotFoundError()
|
||||
listener_arn = arn.replace(":listener-rule", ":listener").rsplit(
|
||||
"/", 1
|
||||
)[0]
|
||||
listener = balancer.listeners.get(listener_arn)
|
||||
if not listener:
|
||||
raise ListenerNotFoundError()
|
||||
resource = listener.rules.get(arn)
|
||||
if not resource:
|
||||
raise RuleNotFoundError()
|
||||
elif ":listener" in arn:
|
||||
lb_arn, _, _ = arn.replace(":listener", ":loadbalancer").rpartition("/")
|
||||
balancer = self.elbv2_backend.load_balancers.get(lb_arn)
|
||||
|
@ -117,6 +117,10 @@ def test_create_rule_condition(condition):
|
||||
response = conn.describe_rules(RuleArns=[rule["RuleArn"]])
|
||||
response["Rules"].should.equal([rule])
|
||||
|
||||
# assert describe_tags response
|
||||
response = conn.describe_tags(ResourceArns=[rule["RuleArn"]])
|
||||
response["TagDescriptions"].should.have.length_of(1)
|
||||
|
||||
|
||||
@mock_elbv2
|
||||
@mock_ec2
|
||||
|
Loading…
Reference in New Issue
Block a user