summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgengjh <gengjh@cn.ibm.com>2013-06-15 10:07:49 +0800
committergengjh <gengjh@cn.ibm.com>2013-06-18 21:04:57 +0800
commit267dbd292c5681daaa5659f8f2ce644a80a54a08 (patch)
tree870182f1a073fb3faf18f504e919b04cbee8faee
parentf41b76cf1b8def8f8e3f60918fa26d1c13fe7730 (diff)
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
Notes
Notes (review): Verified+2: Jenkins Code-Review+2: Kevin L. Mitchell <kevin.mitchell@rackspace.com> Approved+1: Yun Mao <yunmao@gmail.com> Code-Review+2: Yun Mao <yunmao@gmail.com> Submitted-by: Jenkins Submitted-at: Tue, 18 Jun 2013 18:12:43 +0000 Reviewed-on: https://review.openstack.org/33150 Project: openstack/python-novaclient Branch: refs/heads/master
-rw-r--r--novaclient/tests/v1_1/test_quotas.py9
-rw-r--r--novaclient/tests/v1_1/test_shell.py17
-rw-r--r--novaclient/v1_1/quotas.py5
-rw-r--r--novaclient/v1_1/shell.py15
4 files changed, 41 insertions, 5 deletions
diff --git a/novaclient/tests/v1_1/test_quotas.py b/novaclient/tests/v1_1/test_quotas.py
index a4d68f8..ce1c038 100644
--- a/novaclient/tests/v1_1/test_quotas.py
+++ b/novaclient/tests/v1_1/test_quotas.py
@@ -37,6 +37,15 @@ class QuotaSetsTest(utils.TestCase):
37 cs.assert_called('PUT', 37 cs.assert_called('PUT',
38 '/os-quota-sets/97f4c221bff44578b0300df4ef119353') 38 '/os-quota-sets/97f4c221bff44578b0300df4ef119353')
39 39
40 def test_force_update_quota(self):
41 q = cs.quotas.get('97f4c221bff44578b0300df4ef119353')
42 q.update(cores=2, force=True)
43 cs.assert_called(
44 'PUT', '/os-quota-sets/97f4c221bff44578b0300df4ef119353',
45 {'quota_set': {'force': True,
46 'cores': 2,
47 'tenant_id': '97f4c221bff44578b0300df4ef119353'}})
48
40 def test_refresh_quota(self): 49 def test_refresh_quota(self):
41 q = cs.quotas.get('test') 50 q = cs.quotas.get('test')
42 q2 = cs.quotas.get('test') 51 q2 = cs.quotas.get('test')
diff --git a/novaclient/tests/v1_1/test_shell.py b/novaclient/tests/v1_1/test_shell.py
index e9adfda..01fde3a 100644
--- a/novaclient/tests/v1_1/test_shell.py
+++ b/novaclient/tests/v1_1/test_shell.py
@@ -1123,8 +1123,21 @@ class ShellTest(utils.TestCase):
1123 self.run_command( 1123 self.run_command(
1124 'quota-update 97f4c221bff44578b0300df4ef119353' 1124 'quota-update 97f4c221bff44578b0300df4ef119353'
1125 ' --instances=5') 1125 ' --instances=5')
1126 self.assert_called('PUT', 1126 self.assert_called(
1127 '/os-quota-sets/97f4c221bff44578b0300df4ef119353') 1127 'PUT',
1128 '/os-quota-sets/97f4c221bff44578b0300df4ef119353',
1129 {'quota_set': {'instances': 5,
1130 'tenant_id': '97f4c221bff44578b0300df4ef119353'}})
1131
1132 def test_quota_force_update(self):
1133 self.run_command(
1134 'quota-update 97f4c221bff44578b0300df4ef119353'
1135 ' --instances=5 --force')
1136 self.assert_called(
1137 'PUT', '/os-quota-sets/97f4c221bff44578b0300df4ef119353',
1138 {'quota_set': {'force': True,
1139 'instances': 5,
1140 'tenant_id': '97f4c221bff44578b0300df4ef119353'}})
1128 1141
1129 def test_quota_update_fixed_ip(self): 1142 def test_quota_update_fixed_ip(self):
1130 self.run_command( 1143 self.run_command(
diff --git a/novaclient/v1_1/quotas.py b/novaclient/v1_1/quotas.py
index 19f7d71..e174c6f 100644
--- a/novaclient/v1_1/quotas.py
+++ b/novaclient/v1_1/quotas.py
@@ -41,7 +41,7 @@ class QuotaSetManager(base.Manager):
41 volumes=None, gigabytes=None, 41 volumes=None, gigabytes=None,
42 ram=None, floating_ips=None, fixed_ips=None, instances=None, 42 ram=None, floating_ips=None, fixed_ips=None, instances=None,
43 injected_files=None, cores=None, key_pairs=None, 43 injected_files=None, cores=None, key_pairs=None,
44 security_groups=None, security_group_rules=None): 44 security_groups=None, security_group_rules=None, force=None):
45 45
46 body = {'quota_set': { 46 body = {'quota_set': {
47 'tenant_id': tenant_id, 47 'tenant_id': tenant_id,
@@ -58,7 +58,8 @@ class QuotaSetManager(base.Manager):
58 'injected_files': injected_files, 58 'injected_files': injected_files,
59 'cores': cores, 59 'cores': cores,
60 'security_groups': security_groups, 60 'security_groups': security_groups,
61 'security_group_rules': security_group_rules}} 61 'security_group_rules': security_group_rules,
62 'force': force}}
62 63
63 for key in body['quota_set'].keys(): 64 for key in body['quota_set'].keys():
64 if body['quota_set'][key] is None: 65 if body['quota_set'][key] is None:
diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py
index 0bdabe4..fa854e3 100644
--- a/novaclient/v1_1/shell.py
+++ b/novaclient/v1_1/shell.py
@@ -31,6 +31,7 @@ from novaclient.openstack.common import timeutils
31from novaclient.openstack.common import uuidutils 31from novaclient.openstack.common import uuidutils
32from novaclient import utils 32from novaclient import utils
33from novaclient.v1_1 import availability_zones 33from novaclient.v1_1 import availability_zones
34from novaclient.v1_1 import quotas
34from novaclient.v1_1 import servers 35from novaclient.v1_1 import servers
35 36
36 37
@@ -2835,7 +2836,13 @@ def _quota_update(manager, identifier, args):
2835 updates[resource] = val 2836 updates[resource] = val
2836 2837
2837 if updates: 2838 if updates:
2838 manager.update(identifier, **updates) 2839 # default value of force is None to make sure this client
2840 # will be compatibile with old nova server
2841 force_update = getattr(args, 'force', None)
2842 if isinstance(manager, quotas.QuotaSetManager):
2843 manager.update(identifier, force=force_update, **updates)
2844 else:
2845 manager.update(identifier, **updates)
2839 2846
2840 2847
2841@utils.arg('--tenant', 2848@utils.arg('--tenant',
@@ -2944,6 +2951,12 @@ def do_quota_defaults(cs, args):
2944 type=int, 2951 type=int,
2945 default=None, 2952 default=None,
2946 help='New value for the "security-group-rules" quota.') 2953 help='New value for the "security-group-rules" quota.')
2954@utils.arg('--force',
2955 dest='force',
2956 action="store_true",
2957 default=None,
2958 help='Whether force update the quota even if the already used'
2959 ' and reserved exceeds the new quota')
2947def do_quota_update(cs, args): 2960def do_quota_update(cs, args):
2948 """Update the quotas for a tenant.""" 2961 """Update the quotas for a tenant."""
2949 2962