Fix l7rule API handling of None updates
The current l7rule API does not properly handle
clearing/reseting values on update.
This patch corrects this to appropriately handle None/null updates
to the l7rule parameters.
Story: 2005374
Task: 36023
Change-Id: I4e8007ff98f585ce6622f7128ecdd53cdfa926a7
(cherry picked from commit e4e7b4a880
)
This commit is contained in:
parent
a680a19e18
commit
55b04f279b
@ -192,6 +192,11 @@ class L7RuleController(base.BaseController):
|
|||||||
context = pecan.request.context.get('octavia_context')
|
context = pecan.request.context.get('octavia_context')
|
||||||
db_l7rule = self._get_db_l7rule(context.session, id,
|
db_l7rule = self._get_db_l7rule(context.session, id,
|
||||||
show_deleted=False)
|
show_deleted=False)
|
||||||
|
|
||||||
|
# Handle the invert unset
|
||||||
|
if l7rule.invert is None:
|
||||||
|
l7rule.invert = False
|
||||||
|
|
||||||
new_l7rule = db_l7rule.to_dict()
|
new_l7rule = db_l7rule.to_dict()
|
||||||
new_l7rule.update(l7rule.to_dict())
|
new_l7rule.update(l7rule.to_dict())
|
||||||
new_l7rule = data_models.L7Rule.from_dict(new_l7rule)
|
new_l7rule = data_models.L7Rule.from_dict(new_l7rule)
|
||||||
|
@ -107,6 +107,8 @@ def regex(regex):
|
|||||||
# L7 rules must be internally consistent.
|
# L7 rules must be internally consistent.
|
||||||
def l7rule_data(l7rule):
|
def l7rule_data(l7rule):
|
||||||
"""Raises an error if the l7rule given is invalid in some way."""
|
"""Raises an error if the l7rule given is invalid in some way."""
|
||||||
|
if not l7rule.value:
|
||||||
|
raise exceptions.InvalidL7Rule(msg=_('L7 rule type requires a value'))
|
||||||
if l7rule.type == constants.L7RULE_TYPE_HEADER:
|
if l7rule.type == constants.L7RULE_TYPE_HEADER:
|
||||||
if not l7rule.key:
|
if not l7rule.key:
|
||||||
raise exceptions.InvalidL7Rule(msg='L7 rule type requires a key')
|
raise exceptions.InvalidL7Rule(msg='L7 rule type requires a key')
|
||||||
|
@ -1004,6 +1004,18 @@ class TestL7Rule(base.BaseAPITest):
|
|||||||
self._test_bad_cases_with_ssl_rule_types(
|
self._test_bad_cases_with_ssl_rule_types(
|
||||||
is_create=False, rule_id=api_l7rule.get('id'))
|
is_create=False, rule_id=api_l7rule.get('id'))
|
||||||
|
|
||||||
|
def test_update_invert_none(self):
|
||||||
|
api_l7rule = self.create_l7rule(
|
||||||
|
self.l7policy_id, constants.L7RULE_TYPE_PATH,
|
||||||
|
constants.L7RULE_COMPARE_TYPE_STARTS_WITH,
|
||||||
|
'/api', tags=['old_tag'], invert=True).get(self.root_tag)
|
||||||
|
self.set_lb_status(self.lb_id)
|
||||||
|
new_l7rule = {'invert': None}
|
||||||
|
response = self.put(self.l7rule_path.format(
|
||||||
|
l7rule_id=api_l7rule.get('id')),
|
||||||
|
self._build_body(new_l7rule)).json.get(self.root_tag)
|
||||||
|
self.assertFalse(response.get('invert'))
|
||||||
|
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
api_l7rule = self.create_l7rule(
|
api_l7rule = self.create_l7rule(
|
||||||
self.l7policy_id, constants.L7RULE_TYPE_PATH,
|
self.l7policy_id, constants.L7RULE_TYPE_PATH,
|
||||||
|
Loading…
Reference in New Issue
Block a user