Adds "unset" action to the l7rule command
This patch adds "openstack loadbalancer l7rule unset" action to the octavia client. This allows the user to unset the invert, key, etc. setings. This is a patch in a chain adding "unset" to all of the octavia commands. A follow on patch will include the release note. Change-Id: I4931c024392889e75c9f428a0c7a6053e8a1abf4
This commit is contained in:
parent
3d9d888f3a
commit
3bb83c0ec5
|
@ -1,4 +1,6 @@
|
|||
# Copyright 2017 GoDaddy
|
||||
# Copyright 2019 Red Hat, Inc. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
|
@ -266,3 +268,46 @@ class SetL7Rule(command.Command):
|
|||
l7policy_id=l7policy_id,
|
||||
json=body
|
||||
)
|
||||
|
||||
|
||||
class UnsetL7Rule(command.Command):
|
||||
"""Clear l7rule settings"""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(UnsetL7Rule, self).get_parser(prog_name)
|
||||
|
||||
parser.add_argument(
|
||||
'l7policy',
|
||||
metavar='<l7policy>',
|
||||
help="L7policy to update (name or ID)."
|
||||
)
|
||||
parser.add_argument(
|
||||
'l7rule_id',
|
||||
metavar='<l7rule_id>',
|
||||
help="l7rule to update."
|
||||
)
|
||||
parser.add_argument(
|
||||
'--invert',
|
||||
action='store_true',
|
||||
help="Reset the l7rule invert to the API default."
|
||||
)
|
||||
parser.add_argument(
|
||||
'--key',
|
||||
action='store_true',
|
||||
help="Clear the l7rule key."
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
unset_args = v2_utils.get_unsets(parsed_args)
|
||||
if not len(unset_args):
|
||||
return
|
||||
|
||||
policy_id = v2_utils.get_resource_id(
|
||||
self.app.client_manager.load_balancer.l7policy_list,
|
||||
'l7policies', parsed_args.l7policy)
|
||||
|
||||
body = {'rule': unset_args}
|
||||
|
||||
self.app.client_manager.load_balancer.l7rule_set(
|
||||
l7policy_id=policy_id, l7rule_id=parsed_args.l7rule_id, json=body)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# Copyright 2019 Red Hat, Inc. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
|
@ -185,3 +187,56 @@ class TestL7RuleSet(TestL7Rule):
|
|||
l7rule_id=self._l7ru.id,
|
||||
l7policy_id=self._l7po.id,
|
||||
json={'rule': {'admin_state_up': False}})
|
||||
|
||||
|
||||
class TestL7RuleUnset(TestL7Rule):
|
||||
PARAMETERS = ('invert', 'key')
|
||||
|
||||
def setUp(self):
|
||||
super(TestL7RuleUnset, self).setUp()
|
||||
self.cmd = l7rule.UnsetL7Rule(self.app, None)
|
||||
|
||||
def test_l7rule_unset_invert(self):
|
||||
self._test_l7rule_unset_param('invert')
|
||||
|
||||
def test_l7rule_unset_key(self):
|
||||
self._test_l7rule_unset_param('key')
|
||||
|
||||
def _test_l7rule_unset_param(self, param):
|
||||
self.api_mock.l7rule_set.reset_mock()
|
||||
arg_param = param.replace('_', '-') if '_' in param else param
|
||||
arglist = [self._l7po.id, self._l7ru.id, '--%s' % arg_param]
|
||||
ref_body = {'rule': {param: None}}
|
||||
verifylist = [
|
||||
('l7rule_id', self._l7ru.id),
|
||||
]
|
||||
for ref_param in self.PARAMETERS:
|
||||
verifylist.append((ref_param, param == ref_param))
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.api_mock.l7rule_set.assert_called_once_with(
|
||||
l7policy_id=self._l7po.id, l7rule_id=self._l7ru.id, json=ref_body)
|
||||
|
||||
def test_l7rule_unset_all(self):
|
||||
self.api_mock.l7rule_set.reset_mock()
|
||||
ref_body = {'rule': {x: None for x in self.PARAMETERS}}
|
||||
arglist = [self._l7po.id, self._l7ru.id]
|
||||
for ref_param in self.PARAMETERS:
|
||||
arg_param = (ref_param.replace('_', '-') if '_' in ref_param else
|
||||
ref_param)
|
||||
arglist.append('--%s' % arg_param)
|
||||
verifylist = list(zip(self.PARAMETERS, [True]*len(self.PARAMETERS)))
|
||||
verifylist = [('l7rule_id', self._l7ru.id)] + verifylist
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.api_mock.l7rule_set.assert_called_once_with(
|
||||
l7policy_id=self._l7po.id, l7rule_id=self._l7ru.id, json=ref_body)
|
||||
|
||||
def test_l7rule_unset_none(self):
|
||||
self.api_mock.l7rule_set.reset_mock()
|
||||
arglist = [self._l7po.id, self._l7ru.id]
|
||||
verifylist = list(zip(self.PARAMETERS, [False]*len(self.PARAMETERS)))
|
||||
verifylist = [('l7rule_id', self._l7ru.id)] + verifylist
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.api_mock.l7rule_set.assert_not_called()
|
||||
|
|
|
@ -67,6 +67,7 @@ openstack.load_balancer.v2 =
|
|||
loadbalancer_l7rule_show = octaviaclient.osc.v2.l7rule:ShowL7Rule
|
||||
loadbalancer_l7rule_delete = octaviaclient.osc.v2.l7rule:DeleteL7Rule
|
||||
loadbalancer_l7rule_set = octaviaclient.osc.v2.l7rule:SetL7Rule
|
||||
loadbalancer_l7rule_unset = octaviaclient.osc.v2.l7rule:UnsetL7Rule
|
||||
loadbalancer_healthmonitor_create = octaviaclient.osc.v2.health_monitor:CreateHealthMonitor
|
||||
loadbalancer_healthmonitor_list = octaviaclient.osc.v2.health_monitor:ListHealthMonitor
|
||||
loadbalancer_healthmonitor_show = octaviaclient.osc.v2.health_monitor:ShowHealthMonitor
|
||||
|
|
Loading…
Reference in New Issue