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.

Conflicts:
    octavia/tests/functional/api/v2/test_l7rule.py

Story: 2005374
Task: 36023

Change-Id: I4e8007ff98f585ce6622f7128ecdd53cdfa926a7
(cherry picked from commit e4e7b4a880)
(cherry picked from commit 55b04f279b)
(cherry picked from commit e0913562de)
This commit is contained in:
Michael Johnson 2019-05-31 13:09:42 -07:00 committed by Carlos Goncalves
parent 189938ee63
commit 431d9c9b95
2 changed files with 7 additions and 0 deletions

View File

@ -198,6 +198,11 @@ class L7RuleController(base.BaseController):
l7rule = l7rule_.rule
context = pecan.request.context.get('octavia_context')
db_l7rule = self._get_db_l7rule(context.session, id)
# Handle the invert unset
if l7rule.invert is None:
l7rule.invert = False
new_l7rule = db_l7rule.to_dict()
new_l7rule.update(l7rule.to_dict())
new_l7rule = data_models.L7Rule.from_dict(new_l7rule)

View File

@ -104,6 +104,8 @@ def regex(regex):
# L7 rules must be internally consistent.
def l7rule_data(l7rule):
"""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 not l7rule.key:
raise exceptions.InvalidL7Rule(msg='L7 rule type requires a key')