Skip to content

Commit 3686661

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Fix quota show --default command"
2 parents 4c5cea4 + 8195265 commit 3686661

3 files changed

Lines changed: 41 additions & 4 deletions

File tree

openstackclient/common/quota.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import itertools
1919
import sys
2020

21+
from openstack import exceptions as sdk_exceptions
22+
from openstack.network.v2 import quota as _quota
2123
from osc_lib.command import command
2224
from osc_lib import utils
2325
import six
@@ -251,7 +253,39 @@ def get_network_quota(self, parsed_args):
251253
project = self._get_project(parsed_args)
252254
client = self.app.client_manager.network
253255
if parsed_args.default:
254-
network_quota = client.get_quota_default(project)
256+
# TODO(dtroyer): Remove the top of this if block once the
257+
# fixed SDK QuotaDefault class is the minimum
258+
# required version. This is expected to be
259+
# SDK release 0.9.13
260+
if hasattr(_quota.QuotaDefault, 'project'):
261+
# hack 0.9.11+
262+
quotadef_obj = client._get_resource(
263+
_quota.QuotaDefault,
264+
project,
265+
)
266+
quotadef_obj.base_path = quotadef_obj.base_path % {
267+
'project': project,
268+
}
269+
try:
270+
network_quota = quotadef_obj.get(
271+
client.session,
272+
requires_id=False,
273+
)
274+
except sdk_exceptions.NotFoundException as e:
275+
raise sdk_exceptions.ResourceNotFound(
276+
message="No %s found for %s" %
277+
(_quota.QuotaDefault.__name__, project),
278+
details=e.details,
279+
response=e.response,
280+
request_id=e.request_id,
281+
url=e.url,
282+
method=e.method,
283+
http_status=e.http_status,
284+
cause=e.cause,
285+
)
286+
# end hack-around
287+
else:
288+
network_quota = client.get_quota_default(project)
255289
else:
256290
network_quota = client.get_quota(project)
257291
return network_quota

openstackclient/tests/functional/common/test_quota.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,16 @@ def test_quota_set(self):
3535
raw_output = self.openstack('quota show ' + self.PROJECT_NAME + opts)
3636
self.assertEqual("11\n11\n11\n", raw_output)
3737

38-
@testtools.skip('broken SDK testing')
3938
def test_quota_show(self):
4039
raw_output = self.openstack('quota show ' + self.PROJECT_NAME)
4140
for expected_field in self.EXPECTED_FIELDS:
4241
self.assertIn(expected_field, raw_output)
4342

44-
@testtools.skip('broken SDK testing')
4543
def test_quota_show_default_project(self):
4644
raw_output = self.openstack('quota show')
4745
for expected_field in self.EXPECTED_FIELDS:
4846
self.assertIn(expected_field, raw_output)
4947

50-
@testtools.skip('broken SDK testing')
5148
def test_quota_show_with_default_option(self):
5249
raw_output = self.openstack('quota show --default')
5350
for expected_field in self.EXPECTED_FIELDS:
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 show --default`` to fail.
6+
[Bug `1656572 <https://bugs.launchpad.net/python-openstackclient/+bug/1656572>`_]

0 commit comments

Comments
 (0)