summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgengjh <gengjh@cn.ibm.com>2013-04-08 17:30:02 +0800
committergengjh <gengjh@cn.ibm.com>2013-04-11 17:11:08 +0800
commite8b665edbfcd86488f75ed0b79dafdedbf8f5950 (patch)
tree4c7fc2abb26f1c173890d6a125775b25e8a74eaa
parent5f3dbfdfdd9c9f05aea6833f6d7b749ceeac685b (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'. Fix bug 1160749 DocImpact Change-Id: Ib8d94d4eaa846f620abad5fb55017ac3fb0b322a
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: Thu, 11 Apr 2013 20:43:48 +0000 Reviewed-on: https://review.openstack.org/26365 Project: openstack/python-novaclient Branch: refs/heads/master
-rw-r--r--novaclient/v1_1/quotas.py5
-rw-r--r--novaclient/v1_1/shell.py13
-rw-r--r--tests/v1_1/test_quotas.py9
-rw-r--r--tests/v1_1/test_shell.py21
4 files changed, 42 insertions, 6 deletions
diff --git a/novaclient/v1_1/quotas.py b/novaclient/v1_1/quotas.py
index d0cdf02..c5ef0df 100644
--- a/novaclient/v1_1/quotas.py
+++ b/novaclient/v1_1/quotas.py
@@ -36,7 +36,7 @@ class QuotaSetManager(base.ManagerWithFind):
36 tenant_id = tenant_id.tenant_id 36 tenant_id = tenant_id.tenant_id
37 return self._get("/os-quota-sets/%s" % (tenant_id), "quota_set") 37 return self._get("/os-quota-sets/%s" % (tenant_id), "quota_set")
38 38
39 def update(self, tenant_id, metadata_items=None, 39 def update(self, tenant_id, force=None, metadata_items=None,
40 injected_file_content_bytes=None, injected_file_path_bytes=None, 40 injected_file_content_bytes=None, injected_file_path_bytes=None,
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,
@@ -58,7 +58,8 @@ class QuotaSetManager(base.ManagerWithFind):
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 4a0194c..55cbe51 100644
--- a/novaclient/v1_1/shell.py
+++ b/novaclient/v1_1/shell.py
@@ -30,6 +30,7 @@ from novaclient.openstack.common import strutils
30from novaclient.openstack.common import timeutils 30from novaclient.openstack.common import timeutils
31from novaclient import utils 31from novaclient import utils
32from novaclient.v1_1 import availability_zones 32from novaclient.v1_1 import availability_zones
33from novaclient.v1_1 import quotas
33from novaclient.v1_1 import servers 34from novaclient.v1_1 import servers
34 35
35 36
@@ -2703,7 +2704,11 @@ def _quota_update(manager, identifier, args):
2703 updates[resource] = val 2704 updates[resource] = val
2704 2705
2705 if updates: 2706 if updates:
2706 manager.update(identifier, **updates) 2707 force_update = getattr(args, 'force', False)
2708 if isinstance(manager, quotas.QuotaSetManager):
2709 manager.update(identifier, force_update, **updates)
2710 else:
2711 manager.update(identifier, **updates)
2707 2712
2708 2713
2709@utils.arg('--tenant', 2714@utils.arg('--tenant',
@@ -2812,6 +2817,12 @@ def do_quota_defaults(cs, args):
2812 type=int, 2817 type=int,
2813 default=None, 2818 default=None,
2814 help='New value for the "security-group-rules" quota.') 2819 help='New value for the "security-group-rules" quota.')
2820@utils.arg('--force',
2821 dest='force',
2822 action="store_true",
2823 default=False,
2824 help='Whether force update the quota even if the already used'
2825 ' and reserved exceeds the new quota')
2815def do_quota_update(cs, args): 2826def do_quota_update(cs, args):
2816 """Update the quotas for a tenant.""" 2827 """Update the quotas for a tenant."""
2817 2828
diff --git a/tests/v1_1/test_quotas.py b/tests/v1_1/test_quotas.py
index 85a7a57..c7aa64c 100644
--- a/tests/v1_1/test_quotas.py
+++ b/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/tests/v1_1/test_shell.py b/tests/v1_1/test_shell.py
index bf5c812..3de8408 100644
--- a/tests/v1_1/test_shell.py
+++ b/tests/v1_1/test_shell.py
@@ -1005,8 +1005,22 @@ class ShellTest(utils.TestCase):
1005 self.run_command( 1005 self.run_command(
1006 'quota-update 97f4c221bff44578b0300df4ef119353' 1006 'quota-update 97f4c221bff44578b0300df4ef119353'
1007 ' --instances=5') 1007 ' --instances=5')
1008 self.assert_called('PUT', 1008 self.assert_called(
1009 '/os-quota-sets/97f4c221bff44578b0300df4ef119353') 1009 'PUT',
1010 '/os-quota-sets/97f4c221bff44578b0300df4ef119353',
1011 {'quota_set': {'force': False,
1012 'instances': 5,
1013 'tenant_id': '97f4c221bff44578b0300df4ef119353'}})
1014
1015 def test_quota_force_update(self):
1016 self.run_command(
1017 'quota-update 97f4c221bff44578b0300df4ef119353'
1018 ' --instances=5 --force')
1019 self.assert_called(
1020 'PUT', '/os-quota-sets/97f4c221bff44578b0300df4ef119353',
1021 {'quota_set': {'force': True,
1022 'instances': 5,
1023 'tenant_id': '97f4c221bff44578b0300df4ef119353'}})
1010 1024
1011 def test_quota_update_fixed_ip(self): 1025 def test_quota_update_fixed_ip(self):
1012 self.run_command( 1026 self.run_command(
@@ -1014,7 +1028,8 @@ class ShellTest(utils.TestCase):
1014 ' --fixed-ips=5') 1028 ' --fixed-ips=5')
1015 self.assert_called( 1029 self.assert_called(
1016 'PUT', '/os-quota-sets/97f4c221bff44578b0300df4ef119353', 1030 'PUT', '/os-quota-sets/97f4c221bff44578b0300df4ef119353',
1017 {'quota_set': {'fixed_ips': 5, 1031 {'quota_set': {'force': False,
1032 'fixed_ips': 5,
1018 'tenant_id': '97f4c221bff44578b0300df4ef119353'}}) 1033 'tenant_id': '97f4c221bff44578b0300df4ef119353'}})
1019 1034
1020 def test_quota_class_show(self): 1035 def test_quota_class_show(self):