Skip to content

Commit 77214c5

Browse files
author
jiaxi
committed
Fix quota set failed problem
When using the command: openstack quota set, the compute quota below can't be set successfully,the value of compute quota stay unchanged, 'fixed-ips', 'floating-ips', 'injected-files', 'key-pairs'. What's more,I add a TODO comment in the code for two reason. 1. volume quota set works fine for the moment. 2. To indicate that this issue about volume needs discuss and report another bug, if it's confirmed. This bug is only about compute quota. Change-Id: Ic1028d561f5a0030cf65ac18fc117bf01e945478 Partial-Bug: #1420104
1 parent 8175ce5 commit 77214c5

3 files changed

Lines changed: 109 additions & 1 deletion

File tree

openstackclient/common/quota.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,13 @@ def take_action(self, parsed_args):
9797

9898
compute_kwargs = {}
9999
for k, v in COMPUTE_QUOTAS.items():
100-
value = getattr(parsed_args, v, None)
100+
value = getattr(parsed_args, k, None)
101101
if value is not None:
102102
compute_kwargs[k] = value
103103

104104
volume_kwargs = {}
105105
for k, v in VOLUME_QUOTAS.items():
106+
# TODO(jiaxi): Should use k or v needs discuss
106107
value = getattr(parsed_args, v, None)
107108
if value is not None:
108109
if parsed_args.volume_type:
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
import copy
14+
15+
from openstackclient.common import quota
16+
from openstackclient.tests.compute.v2 import fakes as compute_fakes
17+
from openstackclient.tests import fakes
18+
19+
20+
class FakeQuotaResource(fakes.FakeResource):
21+
22+
_keys = {'property': 'value'}
23+
24+
def set_keys(self, args):
25+
self._keys.update(args)
26+
27+
def unset_keys(self, keys):
28+
for key in keys:
29+
self._keys.pop(key, None)
30+
31+
def get_keys(self):
32+
return self._keys
33+
34+
35+
class TestQuota(compute_fakes.TestComputev2):
36+
37+
def setUp(self):
38+
super(TestQuota, self).setUp()
39+
self.quotas_mock = self.app.client_manager.compute.quotas
40+
self.quotas_mock.reset_mock()
41+
42+
43+
class TestQuotaSet(TestQuota):
44+
45+
def setUp(self):
46+
super(TestQuotaSet, self).setUp()
47+
48+
self.quotas_mock.find.return_value = FakeQuotaResource(
49+
None,
50+
copy.deepcopy(compute_fakes.QUOTA),
51+
loaded=True,
52+
)
53+
54+
self.quotas_mock.update.return_value = FakeQuotaResource(
55+
None,
56+
copy.deepcopy(compute_fakes.QUOTA),
57+
loaded=True,
58+
)
59+
60+
self.cmd = quota.SetQuota(self.app, None)
61+
62+
def test_quota_set(self):
63+
arglist = [
64+
'--floating-ips', str(compute_fakes.floating_ip_num),
65+
'--fixed-ips', str(compute_fakes.fix_ip_num),
66+
'--injected-files', str(compute_fakes.injected_file_num),
67+
'--key-pairs', str(compute_fakes.key_pair_num),
68+
compute_fakes.project_name,
69+
]
70+
verifylist = [
71+
('floating_ips', compute_fakes.floating_ip_num),
72+
('fixed_ips', compute_fakes.fix_ip_num),
73+
('injected_files', compute_fakes.injected_file_num),
74+
('key_pairs', compute_fakes.key_pair_num),
75+
('project', compute_fakes.project_name),
76+
]
77+
78+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
79+
80+
self.cmd.take_action(parsed_args)
81+
82+
kwargs = {
83+
'floating_ips': compute_fakes.floating_ip_num,
84+
'fixed_ips': compute_fakes.fix_ip_num,
85+
'injected_files': compute_fakes.injected_file_num,
86+
'key_pairs': compute_fakes.key_pair_num,
87+
}
88+
89+
self.quotas_mock.update.assert_called_with('project_test', **kwargs)

openstackclient/tests/compute/v2/fakes.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@
6262
'vcpus': flavor_vcpus,
6363
}
6464

65+
floating_ip_num = 100
66+
fix_ip_num = 100
67+
injected_file_num = 100
68+
key_pair_num = 100
69+
project_name = 'project_test'
70+
QUOTA = {
71+
'project': project_name,
72+
'floating-ips': floating_ip_num,
73+
'fix-ips': fix_ip_num,
74+
'injected-files': injected_file_num,
75+
'key-pairs': key_pair_num,
76+
}
77+
78+
QUOTA_columns = tuple(sorted(QUOTA))
79+
QUOTA_data = tuple(QUOTA[x] for x in sorted(QUOTA))
80+
6581

6682
class FakeComputev2Client(object):
6783
def __init__(self, **kwargs):
@@ -73,6 +89,8 @@ def __init__(self, **kwargs):
7389
self.extensions.resource_class = fakes.FakeResource(None, {})
7490
self.flavors = mock.Mock()
7591
self.flavors.resource_class = fakes.FakeResource(None, {})
92+
self.quotas = mock.Mock()
93+
self.quotas.resource_class = fakes.FakeResource(None, {})
7694
self.auth_token = kwargs['token']
7795
self.management_url = kwargs['endpoint']
7896

0 commit comments

Comments
 (0)