Browse Source

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
tags/2.14.0
gengjh 6 years ago
parent
commit
e8b665edbf
4 changed files with 42 additions and 6 deletions
  1. 3
    2
      novaclient/v1_1/quotas.py
  2. 12
    1
      novaclient/v1_1/shell.py
  3. 9
    0
      tests/v1_1/test_quotas.py
  4. 18
    3
      tests/v1_1/test_shell.py

+ 3
- 2
novaclient/v1_1/quotas.py View File

@@ -36,7 +36,7 @@ class QuotaSetManager(base.ManagerWithFind):
36 36
             tenant_id = tenant_id.tenant_id
37 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 40
                injected_file_content_bytes=None, injected_file_path_bytes=None,
41 41
                volumes=None, gigabytes=None,
42 42
                ram=None, floating_ips=None, fixed_ips=None, instances=None,
@@ -58,7 +58,8 @@ class QuotaSetManager(base.ManagerWithFind):
58 58
                 'injected_files': injected_files,
59 59
                 'cores': cores,
60 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 64
         for key in body['quota_set'].keys():
64 65
             if body['quota_set'][key] is None:

+ 12
- 1
novaclient/v1_1/shell.py View File

@@ -30,6 +30,7 @@ from novaclient.openstack.common import strutils
30 30
 from novaclient.openstack.common import timeutils
31 31
 from novaclient import utils
32 32
 from novaclient.v1_1 import availability_zones
33
+from novaclient.v1_1 import quotas
33 34
 from novaclient.v1_1 import servers
34 35
 
35 36
 
@@ -2703,7 +2704,11 @@ def _quota_update(manager, identifier, args):
2703 2704
             updates[resource] = val
2704 2705
 
2705 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 2714
 @utils.arg('--tenant',
@@ -2812,6 +2817,12 @@ def do_quota_defaults(cs, args):
2812 2817
     type=int,
2813 2818
     default=None,
2814 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')
2815 2826
 def do_quota_update(cs, args):
2816 2827
     """Update the quotas for a tenant."""
2817 2828
 

+ 9
- 0
tests/v1_1/test_quotas.py View File

@@ -37,6 +37,15 @@ class QuotaSetsTest(utils.TestCase):
37 37
         cs.assert_called('PUT',
38 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 49
     def test_refresh_quota(self):
41 50
         q = cs.quotas.get('test')
42 51
         q2 = cs.quotas.get('test')

+ 18
- 3
tests/v1_1/test_shell.py View File

@@ -1005,8 +1005,22 @@ class ShellTest(utils.TestCase):
1005 1005
         self.run_command(
1006 1006
             'quota-update 97f4c221bff44578b0300df4ef119353'
1007 1007
             ' --instances=5')
1008
-        self.assert_called('PUT',
1009
-                           '/os-quota-sets/97f4c221bff44578b0300df4ef119353')
1008
+        self.assert_called(
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 1025
     def test_quota_update_fixed_ip(self):
1012 1026
         self.run_command(
@@ -1014,7 +1028,8 @@ class ShellTest(utils.TestCase):
1014 1028
             ' --fixed-ips=5')
1015 1029
         self.assert_called(
1016 1030
             'PUT', '/os-quota-sets/97f4c221bff44578b0300df4ef119353',
1017
-            {'quota_set': {'fixed_ips': 5,
1031
+            {'quota_set': {'force': False,
1032
+                           'fixed_ips': 5,
1018 1033
                            'tenant_id': '97f4c221bff44578b0300df4ef119353'}})
1019 1034
 
1020 1035
     def test_quota_class_show(self):

Loading…
Cancel
Save