Skip to content

Commit 74162fa

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Support quota show for current project"
2 parents a0a29df + 27024d7 commit 74162fa

5 files changed

Lines changed: 46 additions & 17 deletions

File tree

doc/source/command-objects/quota.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ quota
44

55
Resource quotas appear in multiple APIs, OpenStackClient presents them as a single object with multiple properties.
66

7-
Compute v2, Block Storage v1
7+
Block Storage v1, Compute v2, Network v2
88

99
quota set
1010
---------
@@ -129,14 +129,14 @@ Set quotas for class
129129
quota show
130130
----------
131131

132-
Show quotas for project
132+
Show quotas for project or class
133133

134134
.. program:: quota show
135135
.. code:: bash
136136
137137
os quota show
138138
[--default]
139-
<project>
139+
[<project>]
140140
141141
142142
.. option:: --default
@@ -146,13 +146,13 @@ Show quotas for project
146146
.. _quota_show-project:
147147
.. describe:: <project>
148148

149-
Show quotas for class
149+
Show quotas for this project (name or ID)
150150

151151
.. code:: bash
152152
153153
os quota show
154154
--class
155-
<class>
155+
[<class>]
156156
157157
.. option:: --class
158158

@@ -161,4 +161,4 @@ Show quotas for project
161161
.. _quota_show-class:
162162
.. describe:: <class>
163163

164-
Class to show
164+
Show quotas for this class (name or ID)

functional/tests/common/test_quota.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ def test_quota_show(self):
3636
raw_output = self.openstack('quota show ' + self.PROJECT_NAME)
3737
for expected_field in self.EXPECTED_FIELDS:
3838
self.assertIn(expected_field, raw_output)
39+
40+
def test_quota_show_default_project(self):
41+
raw_output = self.openstack('quota show')
42+
for expected_field in self.EXPECTED_FIELDS:
43+
self.assertIn(expected_field, raw_output)

openstackclient/common/quota.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ def get_parser(self, prog_name):
145145
parser.add_argument(
146146
'project',
147147
metavar='<project/class>',
148-
help='Show this project or class (name/ID)',
148+
nargs='?',
149+
help='Show quotas for this project or class (name or ID)',
149150
)
150151
type_group = parser.add_mutually_exclusive_group()
151152
type_group.add_argument(
@@ -164,12 +165,22 @@ def get_parser(self, prog_name):
164165
)
165166
return parser
166167

168+
def _get_project(self, parsed_args):
169+
if parsed_args.project is not None:
170+
identity_client = self.app.client_manager.identity
171+
project = utils.find_resource(
172+
identity_client.projects,
173+
parsed_args.project,
174+
).id
175+
elif self.app.client_manager.auth_ref:
176+
# Get the project from the current auth
177+
project = self.app.client_manager.auth_ref.project_id
178+
else:
179+
project = None
180+
return project
181+
167182
def get_compute_volume_quota(self, client, parsed_args):
168-
identity_client = self.app.client_manager.identity
169-
project = utils.find_resource(
170-
identity_client.projects,
171-
parsed_args.project,
172-
).id
183+
project = self._get_project(parsed_args)
173184

174185
try:
175186
if parsed_args.quota_class:
@@ -189,11 +200,7 @@ def get_network_quota(self, parsed_args):
189200
if parsed_args.quota_class or parsed_args.default:
190201
return {}
191202
if self.app.client_manager.is_network_endpoint_enabled():
192-
identity_client = self.app.client_manager.identity
193-
project = utils.find_resource(
194-
identity_client.projects,
195-
parsed_args.project,
196-
).id
203+
project = self._get_project(parsed_args)
197204
return self.app.client_manager.network.get_quota(project)
198205
else:
199206
return {}

openstackclient/tests/common/test_quota.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def setUp(self):
5959
self.service_catalog_mock = \
6060
self.app.client_manager.auth_ref.service_catalog
6161
self.service_catalog_mock.reset_mock()
62+
self.app.client_manager.auth_ref.project_id = identity_fakes.project_id
6263

6364

6465
class TestQuotaSet(TestQuota):
@@ -304,3 +305,13 @@ def test_quota_show_with_class(self):
304305
identity_fakes.project_id)
305306
self.volume_quotas_class_mock.get.assert_called_with(
306307
identity_fakes.project_id)
308+
309+
def test_quota_show_no_project(self):
310+
parsed_args = self.check_parser(self.cmd, [], [])
311+
312+
self.cmd.take_action(parsed_args)
313+
314+
self.quotas_mock.get.assert_called_with(identity_fakes.project_id)
315+
self.volume_quotas_mock.get.assert_called_with(
316+
identity_fakes.project_id)
317+
self.network.get_quota.assert_called_with(identity_fakes.project_id)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
fixes:
3+
- The ``quota show`` command ``<project/class>`` argument is now
4+
optional. If not specified, the user's current project is used.
5+
This allows non-admin users to show quotas for their current project.
6+
[Bug `1572733 <https://bugs.launchpad.net/bugs/1572733>`_]

0 commit comments

Comments
 (0)