ELBv2 modify_rule changes listener rule partially (#1073)
* modify_rule changes listener rule partially * fix syntax * fix outdated code * fix outdated code
This commit is contained in:
parent
bd98996a19
commit
b6cc208534
@ -174,3 +174,12 @@ class InvalidTargetGroupNameError(ELBClientError):
|
|||||||
super(InvalidTargetGroupNameError, self).__init__(
|
super(InvalidTargetGroupNameError, self).__init__(
|
||||||
"ValidationError", msg
|
"ValidationError", msg
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidModifyRuleArgumentsError(ELBClientError):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super(InvalidModifyRuleArgumentsError, self).__init__(
|
||||||
|
"ValidationError",
|
||||||
|
"Either conditions or actions must be specified"
|
||||||
|
)
|
||||||
|
@ -23,7 +23,8 @@ from .exceptions import (
|
|||||||
InvalidDescribeRulesRequest,
|
InvalidDescribeRulesRequest,
|
||||||
RuleNotFoundError,
|
RuleNotFoundError,
|
||||||
DuplicatePriorityError,
|
DuplicatePriorityError,
|
||||||
InvalidTargetGroupNameError
|
InvalidTargetGroupNameError,
|
||||||
|
InvalidModifyRuleArgumentsError
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -429,12 +430,15 @@ class ELBv2Backend(BaseBackend):
|
|||||||
raise ListenerNotFoundError()
|
raise ListenerNotFoundError()
|
||||||
|
|
||||||
def modify_rule(self, rule_arn, conditions, actions):
|
def modify_rule(self, rule_arn, conditions, actions):
|
||||||
|
# if conditions or actions is empty list, do not update the attributes
|
||||||
|
if not conditions and not actions:
|
||||||
|
raise InvalidModifyRuleArgumentsError()
|
||||||
rules = self.describe_rules(listener_arn=None, rule_arns=[rule_arn])
|
rules = self.describe_rules(listener_arn=None, rule_arns=[rule_arn])
|
||||||
if not rules:
|
if not rules:
|
||||||
raise RuleNotFoundError()
|
raise RuleNotFoundError()
|
||||||
rule = rules[0]
|
rule = rules[0]
|
||||||
|
|
||||||
# validate conditions
|
if conditions:
|
||||||
for condition in conditions:
|
for condition in conditions:
|
||||||
field = condition['field']
|
field = condition['field']
|
||||||
if field not in ['path-pattern', 'host-header']:
|
if field not in ['path-pattern', 'host-header']:
|
||||||
@ -447,12 +451,12 @@ class ELBv2Backend(BaseBackend):
|
|||||||
raise InvalidConditionValueError(
|
raise InvalidConditionValueError(
|
||||||
"The '%s' field contains too many values; the limit is '1'" % field
|
"The '%s' field contains too many values; the limit is '1'" % field
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: check pattern of value for 'host-header'
|
# TODO: check pattern of value for 'host-header'
|
||||||
# TODO: check pattern of value for 'path-pattern'
|
# TODO: check pattern of value for 'path-pattern'
|
||||||
|
|
||||||
# validate Actions
|
# validate Actions
|
||||||
target_group_arns = [target_group.arn for target_group in self.target_groups.values()]
|
target_group_arns = [target_group.arn for target_group in self.target_groups.values()]
|
||||||
|
if actions:
|
||||||
for i, action in enumerate(actions):
|
for i, action in enumerate(actions):
|
||||||
index = i + 1
|
index = i + 1
|
||||||
action_type = action['type']
|
action_type = action['type']
|
||||||
@ -466,7 +470,9 @@ class ELBv2Backend(BaseBackend):
|
|||||||
# TODO: check for error 'TooManyRules'
|
# TODO: check for error 'TooManyRules'
|
||||||
|
|
||||||
# modify rule
|
# modify rule
|
||||||
|
if conditions:
|
||||||
rule.conditions = conditions
|
rule.conditions = conditions
|
||||||
|
if actions:
|
||||||
rule.actions = actions
|
rule.actions = actions
|
||||||
return [rule]
|
return [rule]
|
||||||
|
|
||||||
|
@ -731,7 +731,7 @@ def test_handle_listener_rules():
|
|||||||
RuleArns=[first_rule['RuleArn']]
|
RuleArns=[first_rule['RuleArn']]
|
||||||
)
|
)
|
||||||
|
|
||||||
# modify rule
|
# modify rule partially
|
||||||
new_host = 'new.example.com'
|
new_host = 'new.example.com'
|
||||||
new_path_pattern = 'new_path'
|
new_path_pattern = 'new_path'
|
||||||
modified_rule = conn.modify_rule(
|
modified_rule = conn.modify_rule(
|
||||||
@ -743,15 +743,15 @@ def test_handle_listener_rules():
|
|||||||
{
|
{
|
||||||
'Field': 'path-pattern',
|
'Field': 'path-pattern',
|
||||||
'Values': [ new_path_pattern ]
|
'Values': [ new_path_pattern ]
|
||||||
}],
|
|
||||||
Actions=[{
|
|
||||||
'TargetGroupArn': target_group.get('TargetGroupArn'),
|
|
||||||
'Type': 'forward'
|
|
||||||
}]
|
}]
|
||||||
|
|
||||||
)['Rules'][0]
|
)['Rules'][0]
|
||||||
|
|
||||||
rules = conn.describe_rules(ListenerArn=http_listener_arn)
|
rules = conn.describe_rules(ListenerArn=http_listener_arn)
|
||||||
modified_rule.should.equal(rules['Rules'][0])
|
obtained_rule = rules['Rules'][0]
|
||||||
|
modified_rule.should.equal(obtained_rule)
|
||||||
|
obtained_rule['Conditions'][0]['Values'][0].should.equal(new_host)
|
||||||
|
obtained_rule['Conditions'][1]['Values'][0].should.equal(new_path_pattern)
|
||||||
|
obtained_rule['Actions'][0]['TargetGroupArn'].should.equal(target_group.get('TargetGroupArn'))
|
||||||
|
|
||||||
# modify priority
|
# modify priority
|
||||||
conn.set_rule_priorities(
|
conn.set_rule_priorities(
|
||||||
|
Loading…
Reference in New Issue
Block a user