Browse Source

Adds "unset" action to the quota command

This patch adds "openstack loadbalancer quota unset" action to the
octavia client. This allows the user to reset the quota to the default
value.

Change-Id: If95cc0c91df4c6831d91995ca0cf849986be951e
changes/88/662588/1
Michael Johnson 2 years ago
parent
commit
8d791ec69e
4 changed files with 129 additions and 0 deletions
  1. +55
    -0
      octaviaclient/osc/v2/quota.py
  2. +67
    -0
      octaviaclient/tests/unit/osc/v2/test_quota.py
  3. +6
    -0
      releasenotes/notes/Add-unset-commands-15490df414a70df0.yaml
  4. +1
    -0
      setup.cfg

+ 55
- 0
octaviaclient/osc/v2/quota.py View File

@ -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
@ -183,3 +185,56 @@ class ResetQuota(command.Command):
self.app.client_manager.load_balancer.quota_reset(
project_id=project_id)
class UnsetQuota(command.Command):
"""Clear quota settings"""
def get_parser(self, prog_name):
parser = super(UnsetQuota, self).get_parser(prog_name)
parser.add_argument(
'project',
metavar='<project>',
help="Name or UUID of the project."
)
parser.add_argument(
'--loadbalancer',
action='store_true',
help="Reset the load balancer quota to the default."
)
parser.add_argument(
'--listener',
action='store_true',
help="Reset the listener quota to the default."
)
parser.add_argument(
'--pool',
action='store_true',
help="Reset the pool quota to the default."
)
parser.add_argument(
'--member',
action='store_true',
help="Reset the member quota to the default."
)
parser.add_argument(
'--healthmonitor',
action='store_true',
help="Reset the health monitor quota to the default."
)
return parser
def take_action(self, parsed_args):
unset_args = v2_utils.get_unsets(parsed_args)
if not len(unset_args):
return
project_id = v2_utils.get_resource_id(
self.app.client_manager.identity,
'project', parsed_args.project)
body = {'quota': unset_args}
self.app.client_manager.load_balancer.quota_set(
project_id, json=body)

+ 67
- 0
octaviaclient/tests/unit/osc/v2/test_quota.py View File

@ -198,3 +198,70 @@ class TestQuotaReset(TestQuota):
self.cmd.take_action(parsed_args)
self.api_mock.quota_reset.assert_called_with(
project_id=qt_reset.project_id)
class TestQuotaUnset(TestQuota):
PARAMETERS = ('loadbalancer', 'listener', 'pool',
'member', 'healthmonitor')
def setUp(self):
super(TestQuotaUnset, self).setUp()
self.cmd = quota.UnsetQuota(self.app, None)
def test_quota_unset_loadbalancer(self):
self._test_quota_unset_param('loadbalancer')
def test_quota_unset_listener(self):
self._test_quota_unset_param('listener')
def test_quota_unset_pool(self):
self._test_quota_unset_param('pool')
def test_quota_unset_health_monitor(self):
self._test_quota_unset_param('healthmonitor')
def test_quota_unset_member(self):
self._test_quota_unset_param('member')
@mock.patch('octaviaclient.osc.v2.utils.get_resource_id')
def _test_quota_unset_param(self, param, mock_get_resource):
self.api_mock.quota_set.reset_mock()
mock_get_resource.return_value = self._qt.project_id
arg_param = param.replace('_', '-') if '_' in param else param
arglist = [self._qt.project_id, '--%s' % arg_param]
ref_body = {'quota': {param: None}}
verifylist = [
('project', self._qt.project_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.quota_set.assert_called_once_with(
self._qt.project_id, json=ref_body)
@mock.patch('octaviaclient.osc.v2.utils.get_resource_id')
def test_quota_unset_all(self, mock_get_resource):
self.api_mock.quota_set.reset_mock()
mock_get_resource.return_value = self._qt.project_id
ref_body = {'quota': {x: None for x in self.PARAMETERS}}
arglist = [self._qt.project_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 = [('project', self._qt.project_id)] + verifylist
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
self.api_mock.quota_set.assert_called_once_with(
self._qt.project_id, json=ref_body)
def test_quota_unset_none(self):
self.api_mock.quota_set.reset_mock()
arglist = [self._qt.project_id]
verifylist = list(zip(self.PARAMETERS, [False]*len(self.PARAMETERS)))
verifylist = [('project', self._qt.project_id)] + verifylist
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
self.api_mock.quota_set.assert_not_called()

+ 6
- 0
releasenotes/notes/Add-unset-commands-15490df414a70df0.yaml View File

@ -0,0 +1,6 @@
---
features:
- |
The loadbalancer commands now have unset actions. These will either clear
the field back to None or it will reset the value to the API default
value.

+ 1
- 0
setup.cfg View File

@ -79,6 +79,7 @@ openstack.load_balancer.v2 =
loadbalancer_quota_defaults_show = octaviaclient.osc.v2.quota:ShowQuotaDefaults
loadbalancer_quota_reset = octaviaclient.osc.v2.quota:ResetQuota
loadbalancer_quota_set = octaviaclient.osc.v2.quota:SetQuota
loadbalancer_quota_unset = octaviaclient.osc.v2.quota:UnsetQuota
loadbalancer_amphora_list = octaviaclient.osc.v2.amphora:ListAmphora
loadbalancer_amphora_show = octaviaclient.osc.v2.amphora:ShowAmphora
loadbalancer_amphora_configure = octaviaclient.osc.v2.amphora:ConfigureAmphora


Loading…
Cancel
Save