Add '--force; parameter to 'openstack quota set'
The compute service allows us to to force set a quota, setting a quota value that is less than the amount of the resource currently consumed. Expose this feature by way of a '--force' boolean parameter. Change-Id: I1d1ac1ac46f49f64794ffc8631e166935537966c
This commit is contained in:
parent
8c4ecbe35d
commit
b328cf74df
@ -516,6 +516,11 @@ class SetQuota(common.NetDetectionMixin, command.Command):
|
|||||||
metavar='<volume-type>',
|
metavar='<volume-type>',
|
||||||
help=_('Set quotas for a specific <volume-type>'),
|
help=_('Set quotas for a specific <volume-type>'),
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--force',
|
||||||
|
action='store_true',
|
||||||
|
help=_('Force quota update (only supported by compute)')
|
||||||
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
@ -529,6 +534,9 @@ class SetQuota(common.NetDetectionMixin, command.Command):
|
|||||||
if value is not None:
|
if value is not None:
|
||||||
compute_kwargs[k] = value
|
compute_kwargs[k] = value
|
||||||
|
|
||||||
|
if parsed_args.force:
|
||||||
|
compute_kwargs['force'] = True
|
||||||
|
|
||||||
volume_kwargs = {}
|
volume_kwargs = {}
|
||||||
for k, v in VOLUME_QUOTAS.items():
|
for k, v in VOLUME_QUOTAS.items():
|
||||||
value = getattr(parsed_args, k, None)
|
value = getattr(parsed_args, k, None)
|
||||||
|
@ -165,3 +165,47 @@ class QuotaTests(base.TestCase):
|
|||||||
# returned attributes
|
# returned attributes
|
||||||
self.assertTrue(cmd_output["key-pairs"] >= 0)
|
self.assertTrue(cmd_output["key-pairs"] >= 0)
|
||||||
self.assertTrue(cmd_output["snapshots"] >= 0)
|
self.assertTrue(cmd_output["snapshots"] >= 0)
|
||||||
|
|
||||||
|
def test_quota_set_force(self):
|
||||||
|
"""Test to set instance value by force """
|
||||||
|
json_output = json.loads(self.openstack(
|
||||||
|
'quota list -f json --detail --compute'
|
||||||
|
))
|
||||||
|
in_use = limit = None
|
||||||
|
for j in json_output:
|
||||||
|
if j["Resource"] == "instances":
|
||||||
|
in_use = j["In Use"]
|
||||||
|
limit = j["Limit"]
|
||||||
|
|
||||||
|
# Reduce count of in_use
|
||||||
|
in_use = in_use - 1
|
||||||
|
# cannot have negative instances limit
|
||||||
|
if in_use < 0:
|
||||||
|
in_use = 0
|
||||||
|
|
||||||
|
# set the limit by force now
|
||||||
|
self.openstack(
|
||||||
|
'quota set ' + self.PROJECT_NAME +
|
||||||
|
'--instances ' + str(in_use) + ' --force'
|
||||||
|
)
|
||||||
|
cmd_output = json.loads(self.openstack(
|
||||||
|
'quota show -f json ' + self.PROJECT_NAME
|
||||||
|
))
|
||||||
|
self.assertIsNotNone(cmd_output)
|
||||||
|
self.assertEqual(
|
||||||
|
in_use,
|
||||||
|
cmd_output["instances"]
|
||||||
|
)
|
||||||
|
|
||||||
|
# Set instances limit to original limit now
|
||||||
|
self.openstack(
|
||||||
|
'quota set ' + self.PROJECT_NAME + '--instances ' + str(limit)
|
||||||
|
)
|
||||||
|
cmd_output = json.loads(self.openstack(
|
||||||
|
'quota show -f json ' + self.PROJECT_NAME
|
||||||
|
))
|
||||||
|
self.assertIsNotNone(cmd_output)
|
||||||
|
self.assertEqual(
|
||||||
|
limit,
|
||||||
|
cmd_output["instances"]
|
||||||
|
)
|
||||||
|
@ -831,6 +831,56 @@ class TestQuotaSet(TestQuota):
|
|||||||
self.assertNotCalled(self.network_mock.update_quota)
|
self.assertNotCalled(self.network_mock.update_quota)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
|
def test_quota_set_with_force(self):
|
||||||
|
arglist = [
|
||||||
|
'--cores', str(compute_fakes.core_num),
|
||||||
|
'--ram', str(compute_fakes.ram_num),
|
||||||
|
'--instances', str(compute_fakes.instance_num),
|
||||||
|
'--volumes', str(volume_fakes.QUOTA['volumes']),
|
||||||
|
'--subnets', str(network_fakes.QUOTA['subnet']),
|
||||||
|
'--force',
|
||||||
|
self.projects[0].name,
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('cores', compute_fakes.core_num),
|
||||||
|
('ram', compute_fakes.ram_num),
|
||||||
|
('instances', compute_fakes.instance_num),
|
||||||
|
('volumes', volume_fakes.QUOTA['volumes']),
|
||||||
|
('subnet', network_fakes.QUOTA['subnet']),
|
||||||
|
('force', True),
|
||||||
|
('project', self.projects[0].name),
|
||||||
|
]
|
||||||
|
self.app.client_manager.network_endpoint_enabled = True
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
result = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
kwargs_compute = {
|
||||||
|
'cores': compute_fakes.core_num,
|
||||||
|
'ram': compute_fakes.ram_num,
|
||||||
|
'instances': compute_fakes.instance_num,
|
||||||
|
'force': True,
|
||||||
|
}
|
||||||
|
kwargs_volume = {
|
||||||
|
'volumes': volume_fakes.QUOTA['volumes'],
|
||||||
|
}
|
||||||
|
kwargs_network = {
|
||||||
|
'subnet': network_fakes.QUOTA['subnet'],
|
||||||
|
}
|
||||||
|
self.compute_quotas_mock.update.assert_called_once_with(
|
||||||
|
self.projects[0].id,
|
||||||
|
**kwargs_compute
|
||||||
|
)
|
||||||
|
self.volume_quotas_mock.update.assert_called_once_with(
|
||||||
|
self.projects[0].id,
|
||||||
|
**kwargs_volume
|
||||||
|
)
|
||||||
|
self.network_mock.update_quota.assert_called_once_with(
|
||||||
|
self.projects[0].id,
|
||||||
|
**kwargs_network
|
||||||
|
)
|
||||||
|
self.assertIsNone(result)
|
||||||
|
|
||||||
|
|
||||||
class TestQuotaShow(TestQuota):
|
class TestQuotaShow(TestQuota):
|
||||||
|
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- Add ``--force`` options to the ``openstack quota set``
|
||||||
|
command. The compute service allows us to to force set a quota, setting a
|
||||||
|
quota value that is less than the amount of the resource currently
|
||||||
|
consumed. Expose this feature by way of a ``--force`` boolean parameter.
|
Loading…
Reference in New Issue
Block a user