Skip to content

Commit d0741d7

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add '--force; parameter to 'openstack quota set'"
2 parents 1d8781a + b328cf7 commit d0741d7

4 files changed

Lines changed: 108 additions & 0 deletions

File tree

openstackclient/common/quota.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,11 @@ def get_parser(self, prog_name):
525525
metavar='<volume-type>',
526526
help=_('Set quotas for a specific <volume-type>'),
527527
)
528+
parser.add_argument(
529+
'--force',
530+
action='store_true',
531+
help=_('Force quota update (only supported by compute)')
532+
)
528533
return parser
529534

530535
def take_action(self, parsed_args):
@@ -538,6 +543,9 @@ def take_action(self, parsed_args):
538543
if value is not None:
539544
compute_kwargs[k] = value
540545

546+
if parsed_args.force:
547+
compute_kwargs['force'] = True
548+
541549
volume_kwargs = {}
542550
for k, v in VOLUME_QUOTAS.items():
543551
value = getattr(parsed_args, k, None)

openstackclient/tests/functional/common/test_quota.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,47 @@ def test_quota_set_class(self):
165165
# returned attributes
166166
self.assertTrue(cmd_output["key-pairs"] >= 0)
167167
self.assertTrue(cmd_output["snapshots"] >= 0)
168+
169+
def test_quota_set_force(self):
170+
"""Test to set instance value by force """
171+
json_output = json.loads(self.openstack(
172+
'quota list -f json --detail --compute'
173+
))
174+
in_use = limit = None
175+
for j in json_output:
176+
if j["Resource"] == "instances":
177+
in_use = j["In Use"]
178+
limit = j["Limit"]
179+
180+
# Reduce count of in_use
181+
in_use = in_use - 1
182+
# cannot have negative instances limit
183+
if in_use < 0:
184+
in_use = 0
185+
186+
# set the limit by force now
187+
self.openstack(
188+
'quota set ' + self.PROJECT_NAME +
189+
'--instances ' + str(in_use) + ' --force'
190+
)
191+
cmd_output = json.loads(self.openstack(
192+
'quota show -f json ' + self.PROJECT_NAME
193+
))
194+
self.assertIsNotNone(cmd_output)
195+
self.assertEqual(
196+
in_use,
197+
cmd_output["instances"]
198+
)
199+
200+
# Set instances limit to original limit now
201+
self.openstack(
202+
'quota set ' + self.PROJECT_NAME + '--instances ' + str(limit)
203+
)
204+
cmd_output = json.loads(self.openstack(
205+
'quota show -f json ' + self.PROJECT_NAME
206+
))
207+
self.assertIsNotNone(cmd_output)
208+
self.assertEqual(
209+
limit,
210+
cmd_output["instances"]
211+
)

openstackclient/tests/unit/common/test_quota.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,56 @@ def test_quota_set_with_class(self):
900900
self.assertNotCalled(self.network_mock.update_quota)
901901
self.assertIsNone(result)
902902

903+
def test_quota_set_with_force(self):
904+
arglist = [
905+
'--cores', str(compute_fakes.core_num),
906+
'--ram', str(compute_fakes.ram_num),
907+
'--instances', str(compute_fakes.instance_num),
908+
'--volumes', str(volume_fakes.QUOTA['volumes']),
909+
'--subnets', str(network_fakes.QUOTA['subnet']),
910+
'--force',
911+
self.projects[0].name,
912+
]
913+
verifylist = [
914+
('cores', compute_fakes.core_num),
915+
('ram', compute_fakes.ram_num),
916+
('instances', compute_fakes.instance_num),
917+
('volumes', volume_fakes.QUOTA['volumes']),
918+
('subnet', network_fakes.QUOTA['subnet']),
919+
('force', True),
920+
('project', self.projects[0].name),
921+
]
922+
self.app.client_manager.network_endpoint_enabled = True
923+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
924+
925+
result = self.cmd.take_action(parsed_args)
926+
927+
kwargs_compute = {
928+
'cores': compute_fakes.core_num,
929+
'ram': compute_fakes.ram_num,
930+
'instances': compute_fakes.instance_num,
931+
'force': True,
932+
}
933+
kwargs_volume = {
934+
'volumes': volume_fakes.QUOTA['volumes'],
935+
}
936+
kwargs_network = {
937+
'subnet': network_fakes.QUOTA['subnet'],
938+
}
939+
self.compute_quotas_mock.update.assert_called_once_with(
940+
self.projects[0].id,
941+
**kwargs_compute
942+
)
943+
self.volume_quotas_mock.update.assert_called_once_with(
944+
self.projects[0].id,
945+
**kwargs_volume
946+
)
947+
self.network_mock.update_quota.assert_called_once_with(
948+
self.projects[0].id,
949+
**kwargs_network
950+
)
951+
self.assertIsNone(result)
952+
903953

904954
class TestQuotaShow(TestQuota):
905955

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
features:
3+
- Add ``--force`` options to the ``openstack quota set``
4+
command. The compute service allows us to to force set a quota, setting a
5+
quota value that is less than the amount of the resource currently
6+
consumed. Expose this feature by way of a ``--force`` boolean parameter.

0 commit comments

Comments
 (0)