Adds "unset" action to the listener command

This patch adds "openstack loadbalancer listener unset" action to the
octavia client. This allows the user to unset the name, description,
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: I153967b69a1766cf1fa5033bc77d580d05aaceac
This commit is contained in:
Michael Johnson 2019-04-04 11:30:00 -07:00
parent 52529d7df1
commit 29449fc5a0
3 changed files with 202 additions and 0 deletions

View File

@ -414,6 +414,107 @@ class SetListener(command.Command):
listener_id, json=body)
class UnsetListener(command.Command):
"""Clear listener settings"""
def get_parser(self, prog_name):
parser = super(UnsetListener, self).get_parser(prog_name)
parser.add_argument(
'listener',
metavar="<listener>",
help="Listener to modify (name or ID)."
)
parser.add_argument(
'--name',
action='store_true',
help="Clear the listener name."
)
parser.add_argument(
'--description',
action='store_true',
help="Clear the description of this listener."
)
parser.add_argument(
'--connection-limit',
action='store_true',
help="Reset the connection limit to the API default."
)
parser.add_argument(
'--default-pool',
dest='default_pool_id',
action='store_true',
help="Clear the default pool from the listener."
)
parser.add_argument(
'--default-tls-container-ref',
action='store_true',
help="Remove the default TLS container reference from the "
"listener."
)
parser.add_argument(
'--sni-container-refs',
action='store_true',
help="Remove the TLS SNI container references from the listener."
)
parser.add_argument(
'--insert-headers',
action='store_true',
help="Clear the insert headers from the listener."
)
parser.add_argument(
'--timeout-client-data',
action='store_true',
help="Reset the client data timeout to the API default."
)
parser.add_argument(
'--timeout-member-connect',
action='store_true',
help="Reset the member connect timeout to the API default."
)
parser.add_argument(
'--timeout-member-data',
action='store_true',
help="Reset the member data timeout to the API default."
)
parser.add_argument(
'--timeout-tcp-inspect',
action='store_true',
help="Reset the TCP inspection timeout to the API default."
)
parser.add_argument(
'--client-ca-tls-container-ref',
action='store_true',
help="Clear the client CA TLS container reference from the "
"listener."
)
parser.add_argument(
'--client-authentication',
action='store_true',
help="Reset the client authentication setting to the API default."
)
parser.add_argument(
'--client-crl-container-ref',
action='store_true',
help="Clear the client CRL container reference from the listener."
)
return parser
def take_action(self, parsed_args):
unset_args = v2_utils.get_unsets(parsed_args)
if not len(unset_args):
return
listener_id = v2_utils.get_resource_id(
self.app.client_manager.load_balancer.listener_list,
'listeners', parsed_args.listener)
body = {'listener': unset_args}
self.app.client_manager.load_balancer.listener_set(
listener_id, json=body)
class ShowListenerStats(command.ShowOne):
"""Shows the current statistics for a listener."""

View File

@ -287,3 +287,103 @@ class TestListenerStatsShow(TestListener):
self.cmd.take_action(parsed_args)
self.api_mock.listener_stats_show.assert_called_with(
listener_id=self._listener.id)
class TestListenerUnset(TestListener):
PARAMETERS = ('name', 'description', 'connection_limit', 'default_pool_id',
'default_tls_container_ref', 'sni_container_refs',
'insert_headers', 'timeout_client_data',
'timeout_member_connect', 'timeout_member_data',
'timeout_tcp_inspect', 'client_ca_tls_container_ref',
'client_authentication', 'client_crl_container_ref')
def setUp(self):
super(TestListenerUnset, self).setUp()
self.cmd = listener.UnsetListener(self.app, None)
def test_listener_unset_name(self):
self._test_listener_unset_param('name')
def test_listener_unset_description(self):
self._test_listener_unset_param('description')
def test_listener_unset_connection_limit(self):
self._test_listener_unset_param('connection_limit')
def test_listener_unset_default_pool(self):
self._test_listener_unset_param('default_pool')
def test_listener_unset_default_tls_container_ref(self):
self._test_listener_unset_param('default_tls_container_ref')
def test_listener_unset_sni_container_refs(self):
self._test_listener_unset_param('sni_container_refs')
def test_listener_unset_insert_headers(self):
self._test_listener_unset_param('insert_headers')
def test_listener_unset_timeout_client_data(self):
self._test_listener_unset_param('timeout_client_data')
def test_listener_unset_timeout_member_connect(self):
self._test_listener_unset_param('timeout_member_connect')
def test_listener_unset_timeout_member_data(self):
self._test_listener_unset_param('timeout_member_data')
def test_listener_unset_timeout_tcp_inspect(self):
self._test_listener_unset_param('timeout_tcp_inspect')
def test_listener_unset_client_ca_tls_container_ref(self):
self._test_listener_unset_param('client_ca_tls_container_ref')
def test_listener_unset_client_authentication(self):
self._test_listener_unset_param('client_authentication')
def test_listener_unset_client_crl_container_ref(self):
self._test_listener_unset_param('client_crl_container_ref')
def _test_listener_unset_param(self, param):
self.api_mock.listener_set.reset_mock()
arg_param = param.replace('_', '-') if '_' in param else param
arglist = [self._listener.id, '--%s' % arg_param]
# Handle the special rename case of default_pool rename
if param == 'default_pool':
param = 'default_pool_id'
ref_body = {'listener': {param: None}}
verifylist = [
('listener', self._listener.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.listener_set.assert_called_once_with(
self._listener.id, json=ref_body)
def test_listener_unset_all(self):
self.api_mock.listener_set.reset_mock()
ref_body = {'listener': {x: None for x in self.PARAMETERS}}
arglist = [self._listener.id]
for ref_param in self.PARAMETERS:
# Handle the special rename case of default_pool rename
if ref_param == 'default_pool_id':
ref_param = 'default_pool'
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 = [('listener', self._listener.id)] + verifylist
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
self.api_mock.listener_set.assert_called_once_with(
self._listener.id, json=ref_body)
def test_listener_unset_none(self):
self.api_mock.listener_set.reset_mock()
arglist = [self._listener.id]
verifylist = list(zip(self.PARAMETERS, [False]*len(self.PARAMETERS)))
verifylist = [('listener', self._listener.id)] + verifylist
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
self.api_mock.listener_set.assert_not_called()

View File

@ -42,6 +42,7 @@ openstack.load_balancer.v2 =
loadbalancer_listener_show = octaviaclient.osc.v2.listener:ShowListener
loadbalancer_listener_delete = octaviaclient.osc.v2.listener:DeleteListener
loadbalancer_listener_set = octaviaclient.osc.v2.listener:SetListener
loadbalancer_listener_unset = octaviaclient.osc.v2.listener:UnsetListener
loadbalancer_listener_stats_show = octaviaclient.osc.v2.listener:ShowListenerStats
loadbalancer_pool_create = octaviaclient.osc.v2.pool:CreatePool
loadbalancer_pool_list = octaviaclient.osc.v2.pool:ListPool