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

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
tags/2.14.0
gengjh 6 years ago
parent
commit
267dbd292c

+ 9
- 0
novaclient/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')

+ 15
- 2
novaclient/tests/v1_1/test_shell.py View File

@@ -1123,8 +1123,21 @@ class ShellTest(utils.TestCase):
1123 1123
         self.run_command(
1124 1124
             'quota-update 97f4c221bff44578b0300df4ef119353'
1125 1125
             ' --instances=5')
1126
-        self.assert_called('PUT',
1127
-                           '/os-quota-sets/97f4c221bff44578b0300df4ef119353')
1126
+        self.assert_called(
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 1142
     def test_quota_update_fixed_ip(self):
1130 1143
         self.run_command(

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

@@ -41,7 +41,7 @@ class QuotaSetManager(base.Manager):
41 41
                volumes=None, gigabytes=None,
42 42
                ram=None, floating_ips=None, fixed_ips=None, instances=None,
43 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 46
         body = {'quota_set': {
47 47
                 'tenant_id': tenant_id,
@@ -58,7 +58,8 @@ class QuotaSetManager(base.Manager):
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:

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

@@ -31,6 +31,7 @@ from novaclient.openstack.common import timeutils
31 31
 from novaclient.openstack.common import uuidutils
32 32
 from novaclient import utils
33 33
 from novaclient.v1_1 import availability_zones
34
+from novaclient.v1_1 import quotas
34 35
 from novaclient.v1_1 import servers
35 36
 
36 37
 
@@ -2835,7 +2836,13 @@ def _quota_update(manager, identifier, args):
2835 2836
             updates[resource] = val
2836 2837
 
2837 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 2848
 @utils.arg('--tenant',
@@ -2944,6 +2951,12 @@ def do_quota_defaults(cs, args):
2944 2951
     type=int,
2945 2952
     default=None,
2946 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')
2947 2960
 def do_quota_update(cs, args):
2948 2961
     """Update the quotas for a tenant."""
2949 2962
 

Loading…
Cancel
Save