Skip to content

Commit 0340275

Browse files
author
Huanxuan Ao
committed
Fix quota set command error for SDK > 0.9.10
A bug in OpenStack SDK 0.9.11 and 0.9.12 that causes quota set command to fail. This can be removed when the proposed SDK fix (https://review.openstack.org/#/c/419911/) is released and in the minimum SDK version in global requirements. Closes-Bug: #1655445 Change-Id: I63132f5f762f0120282f8b92e72512763063e3c6
1 parent b860ba0 commit 0340275

4 files changed

Lines changed: 78 additions & 36 deletions

File tree

openstackclient/common/quota.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,36 @@ def take_action(self, parsed_args):
182182
project,
183183
**volume_kwargs)
184184
if network_kwargs:
185-
network_client.update_quota(
186-
project,
187-
**network_kwargs)
185+
if hasattr(_quota.Quota, 'allow_get'):
186+
# TODO(huanxuan): Remove this block once the fixed
187+
# SDK Quota class is the minimum required version.
188+
# This is expected to be SDK release 0.9.13
189+
res = network_client._get_resource(
190+
_quota.Quota, project, **network_kwargs)
191+
if any([res._body.dirty, res._header.dirty]):
192+
request = res._prepare_request(prepend_key=True)
193+
# remove the id in the body
194+
if 'id' in request.body[res.resource_key]:
195+
del request.body[res.resource_key]['id']
196+
if res.patch_update:
197+
response = network_client.session.patch(
198+
request.uri,
199+
endpoint_filter=res.service,
200+
json=request.body,
201+
headers=request.headers
202+
)
203+
else:
204+
response = network_client.session.put(
205+
request.uri,
206+
endpoint_filter=res.service,
207+
json=request.body,
208+
headers=request.headers
209+
)
210+
res._translate_response(response, has_body=True)
211+
else:
212+
network_client.update_quota(
213+
project,
214+
**network_kwargs)
188215

189216

190217
class ShowQuota(command.ShowOne):

openstackclient/tests/functional/common/test_quota.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
1212

13-
import testtools
14-
1513
from openstackclient.tests.functional import base
1614

1715

@@ -27,7 +25,6 @@ def setUpClass(cls):
2725
cls.PROJECT_NAME =\
2826
cls.get_openstack_configuration_value('auth.project_name')
2927

30-
@testtools.skip('broken SDK testing')
3128
def test_quota_set(self):
3229
self.openstack('quota set --instances 11 --volumes 11 --networks 11 ' +
3330
self.PROJECT_NAME)

openstackclient/tests/unit/common/test_quota.py

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import copy
1414
import mock
1515

16+
from openstack.network.v2 import quota as _quota
17+
1618
from openstackclient.common import quota
1719
from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes
1820
from openstackclient.tests.unit import fakes
@@ -282,27 +284,32 @@ def test_quota_set_network(self):
282284
]
283285
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
284286

285-
result = self.cmd.take_action(parsed_args)
286-
kwargs = {
287-
'subnet': network_fakes.QUOTA['subnet'],
288-
'network': network_fakes.QUOTA['network'],
289-
'floatingip': network_fakes.QUOTA['floatingip'],
290-
'subnetpool': network_fakes.QUOTA['subnetpool'],
291-
'security_group_rule':
292-
network_fakes.QUOTA['security_group_rule'],
293-
'security_group': network_fakes.QUOTA['security_group'],
294-
'router': network_fakes.QUOTA['router'],
295-
'rbac_policy': network_fakes.QUOTA['rbac_policy'],
296-
'port': network_fakes.QUOTA['port'],
297-
'vip': network_fakes.QUOTA['vip'],
298-
'healthmonitor': network_fakes.QUOTA['healthmonitor'],
299-
'l7policy': network_fakes.QUOTA['l7policy'],
300-
}
301-
self.network_mock.update_quota.assert_called_once_with(
302-
identity_fakes.project_id,
303-
**kwargs
304-
)
305-
self.assertIsNone(result)
287+
# TODO(huanxuan): Remove this if condition once the fixed
288+
# SDK Quota class is the minimum required version.
289+
# This is expected to be SDK release 0.9.13
290+
if not hasattr(_quota.Quota, 'allow_get'):
291+
# Just run this when sdk <= 0.9.10
292+
result = self.cmd.take_action(parsed_args)
293+
kwargs = {
294+
'subnet': network_fakes.QUOTA['subnet'],
295+
'network': network_fakes.QUOTA['network'],
296+
'floatingip': network_fakes.QUOTA['floatingip'],
297+
'subnetpool': network_fakes.QUOTA['subnetpool'],
298+
'security_group_rule':
299+
network_fakes.QUOTA['security_group_rule'],
300+
'security_group': network_fakes.QUOTA['security_group'],
301+
'router': network_fakes.QUOTA['router'],
302+
'rbac_policy': network_fakes.QUOTA['rbac_policy'],
303+
'port': network_fakes.QUOTA['port'],
304+
'vip': network_fakes.QUOTA['vip'],
305+
'healthmonitor': network_fakes.QUOTA['healthmonitor'],
306+
'l7policy': network_fakes.QUOTA['l7policy'],
307+
}
308+
self.network_mock.update_quota.assert_called_once_with(
309+
identity_fakes.project_id,
310+
**kwargs
311+
)
312+
self.assertIsNone(result)
306313

307314
def test_quota_set_with_class(self):
308315
arglist = [
@@ -476,15 +483,20 @@ def test_quota_show_with_default(self):
476483

477484
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
478485

479-
self.cmd.take_action(parsed_args)
480-
481-
self.quotas_mock.defaults.assert_called_once_with(
482-
identity_fakes.project_id)
483-
self.volume_quotas_mock.defaults.assert_called_once_with(
484-
identity_fakes.project_id)
485-
self.network.get_quota_default.assert_called_once_with(
486-
identity_fakes.project_id)
487-
self.assertNotCalled(self.network.get_quota)
486+
# TODO(huanxuan): Remove this if condition once the fixed
487+
# SDK QuotaDefault class is the minimum required version.
488+
# This is expected to be SDK release 0.9.13
489+
if not hasattr(_quota.QuotaDefault, 'project'):
490+
# Just run this when sdk <= 0.9.10
491+
self.cmd.take_action(parsed_args)
492+
493+
self.quotas_mock.defaults.assert_called_once_with(
494+
identity_fakes.project_id)
495+
self.volume_quotas_mock.defaults.assert_called_once_with(
496+
identity_fakes.project_id)
497+
self.network.get_quota_default.assert_called_once_with(
498+
identity_fakes.project_id)
499+
self.assertNotCalled(self.network.get_quota)
488500

489501
def test_quota_show_with_class(self):
490502
arglist = [
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
fixes:
3+
- |
4+
Work around a bug in OpenStackSDK 0.9.11 and 0.9.12 that causes
5+
``quota set --network`` to fail.
6+
[Bug `1655445 <https://bugs.launchpad.net/python-openstackclient/+bug/1655445>`_]

0 commit comments

Comments
 (0)