Support force update quota

Once we have additional check when update quota in
https://review.openstack.org/#/c/25887/, we need provide --force option
when run 'nova quota-update'.

Fix bug 1160749

DocImpact

Change-Id: Ib8d94d4eaa846f620abad5fb55017ac3fb0b322a
This commit is contained in:
gengjh 2013-04-08 17:30:02 +08:00
parent 5f3dbfdfdd
commit e8b665edbf
4 changed files with 42 additions and 6 deletions

View File

@ -36,7 +36,7 @@ class QuotaSetManager(base.ManagerWithFind):
tenant_id = tenant_id.tenant_id
return self._get("/os-quota-sets/%s" % (tenant_id), "quota_set")
def update(self, tenant_id, metadata_items=None,
def update(self, tenant_id, force=None, metadata_items=None,
injected_file_content_bytes=None, injected_file_path_bytes=None,
volumes=None, gigabytes=None,
ram=None, floating_ips=None, fixed_ips=None, instances=None,
@ -58,7 +58,8 @@ class QuotaSetManager(base.ManagerWithFind):
'injected_files': injected_files,
'cores': cores,
'security_groups': security_groups,
'security_group_rules': security_group_rules}}
'security_group_rules': security_group_rules,
'force': force}}
for key in body['quota_set'].keys():
if body['quota_set'][key] is None:

View File

@ -30,6 +30,7 @@ from novaclient.openstack.common import strutils
from novaclient.openstack.common import timeutils
from novaclient import utils
from novaclient.v1_1 import availability_zones
from novaclient.v1_1 import quotas
from novaclient.v1_1 import servers
@ -2703,6 +2704,10 @@ def _quota_update(manager, identifier, args):
updates[resource] = val
if updates:
force_update = getattr(args, 'force', False)
if isinstance(manager, quotas.QuotaSetManager):
manager.update(identifier, force_update, **updates)
else:
manager.update(identifier, **updates)
@ -2812,6 +2817,12 @@ def do_quota_defaults(cs, args):
type=int,
default=None,
help='New value for the "security-group-rules" quota.')
@utils.arg('--force',
dest='force',
action="store_true",
default=False,
help='Whether force update the quota even if the already used'
' and reserved exceeds the new quota')
def do_quota_update(cs, args):
"""Update the quotas for a tenant."""

View File

@ -37,6 +37,15 @@ class QuotaSetsTest(utils.TestCase):
cs.assert_called('PUT',
'/os-quota-sets/97f4c221bff44578b0300df4ef119353')
def test_force_update_quota(self):
q = cs.quotas.get('97f4c221bff44578b0300df4ef119353')
q.update(cores=2, force=True)
cs.assert_called(
'PUT', '/os-quota-sets/97f4c221bff44578b0300df4ef119353',
{'quota_set': {'force': True,
'cores': 2,
'tenant_id': '97f4c221bff44578b0300df4ef119353'}})
def test_refresh_quota(self):
q = cs.quotas.get('test')
q2 = cs.quotas.get('test')

View File

@ -1005,8 +1005,22 @@ class ShellTest(utils.TestCase):
self.run_command(
'quota-update 97f4c221bff44578b0300df4ef119353'
' --instances=5')
self.assert_called('PUT',
'/os-quota-sets/97f4c221bff44578b0300df4ef119353')
self.assert_called(
'PUT',
'/os-quota-sets/97f4c221bff44578b0300df4ef119353',
{'quota_set': {'force': False,
'instances': 5,
'tenant_id': '97f4c221bff44578b0300df4ef119353'}})
def test_quota_force_update(self):
self.run_command(
'quota-update 97f4c221bff44578b0300df4ef119353'
' --instances=5 --force')
self.assert_called(
'PUT', '/os-quota-sets/97f4c221bff44578b0300df4ef119353',
{'quota_set': {'force': True,
'instances': 5,
'tenant_id': '97f4c221bff44578b0300df4ef119353'}})
def test_quota_update_fixed_ip(self):
self.run_command(
@ -1014,7 +1028,8 @@ class ShellTest(utils.TestCase):
' --fixed-ips=5')
self.assert_called(
'PUT', '/os-quota-sets/97f4c221bff44578b0300df4ef119353',
{'quota_set': {'fixed_ips': 5,
{'quota_set': {'force': False,
'fixed_ips': 5,
'tenant_id': '97f4c221bff44578b0300df4ef119353'}})
def test_quota_class_show(self):