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'.

Since the change in nova server has been merged, we need re-enable the
changes in nova client side.

Fix bug 1160749

Change-Id: Iceb67c5816312fafed8a68e48a8a136c03d0bb5b
This commit is contained in:
gengjh 2013-06-15 10:07:49 +08:00
parent f41b76cf1b
commit 267dbd292c
4 changed files with 41 additions and 5 deletions

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

@ -1123,8 +1123,21 @@ 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': {'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(

View File

@ -41,7 +41,7 @@ class QuotaSetManager(base.Manager):
volumes=None, gigabytes=None,
ram=None, floating_ips=None, fixed_ips=None, instances=None,
injected_files=None, cores=None, key_pairs=None,
security_groups=None, security_group_rules=None):
security_groups=None, security_group_rules=None, force=None):
body = {'quota_set': {
'tenant_id': tenant_id,
@ -58,7 +58,8 @@ class QuotaSetManager(base.Manager):
'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

@ -31,6 +31,7 @@ from novaclient.openstack.common import timeutils
from novaclient.openstack.common import uuidutils
from novaclient import utils
from novaclient.v1_1 import availability_zones
from novaclient.v1_1 import quotas
from novaclient.v1_1 import servers
@ -2835,7 +2836,13 @@ def _quota_update(manager, identifier, args):
updates[resource] = val
if updates:
manager.update(identifier, **updates)
# default value of force is None to make sure this client
# will be compatibile with old nova server
force_update = getattr(args, 'force', None)
if isinstance(manager, quotas.QuotaSetManager):
manager.update(identifier, force=force_update, **updates)
else:
manager.update(identifier, **updates)
@utils.arg('--tenant',
@ -2944,6 +2951,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=None,
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."""