summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-04-25 21:15:43 +0000
committerGerrit Code Review <review@openstack.org>2016-04-25 21:15:43 +0000
commit74162fa31a3c34ee08472f24318f1c326b493330 (patch)
tree2630dafbee9dd36ef2681b05abd7f270c8c00bfd
parenta0a29df3e67b29880e62e1974dde18a4993f2aa1 (diff)
parent27024d70af4756cb6e4b210b025ed7427541f773 (diff)
downloadpython-openstackclient-74162fa31a3c34ee08472f24318f1c326b493330.tar.gz
Merge "Support quota show for current project"
-rw-r--r--doc/source/command-objects/quota.rst12
-rw-r--r--functional/tests/common/test_quota.py5
-rw-r--r--openstackclient/common/quota.py29
-rw-r--r--openstackclient/tests/common/test_quota.py11
-rw-r--r--releasenotes/notes/bug-1572733-874b37a7fa8292d0.yaml6
5 files changed, 46 insertions, 17 deletions
diff --git a/doc/source/command-objects/quota.rst b/doc/source/command-objects/quota.rst
index 98e6df33..9e09bd48 100644
--- a/doc/source/command-objects/quota.rst
+++ b/doc/source/command-objects/quota.rst
@@ -4,7 +4,7 @@ quota
Resource quotas appear in multiple APIs, OpenStackClient presents them as a single object with multiple properties.
-Compute v2, Block Storage v1
+Block Storage v1, Compute v2, Network v2
quota set
---------
@@ -129,14 +129,14 @@ Set quotas for class
quota show
----------
-Show quotas for project
+Show quotas for project or class
.. program:: quota show
.. code:: bash
os quota show
[--default]
- <project>
+ [<project>]
.. option:: --default
@@ -146,13 +146,13 @@ Show quotas for project
.. _quota_show-project:
.. describe:: <project>
- Show quotas for class
+ Show quotas for this project (name or ID)
.. code:: bash
os quota show
--class
- <class>
+ [<class>]
.. option:: --class
@@ -161,4 +161,4 @@ Show quotas for project
.. _quota_show-class:
.. describe:: <class>
- Class to show
+ Show quotas for this class (name or ID)
diff --git a/functional/tests/common/test_quota.py b/functional/tests/common/test_quota.py
index 62b43a34..22549efe 100644
--- a/functional/tests/common/test_quota.py
+++ b/functional/tests/common/test_quota.py
@@ -36,3 +36,8 @@ class QuotaTests(test.TestCase):
raw_output = self.openstack('quota show ' + self.PROJECT_NAME)
for expected_field in self.EXPECTED_FIELDS:
self.assertIn(expected_field, raw_output)
+
+ def test_quota_show_default_project(self):
+ raw_output = self.openstack('quota show')
+ for expected_field in self.EXPECTED_FIELDS:
+ self.assertIn(expected_field, raw_output)
diff --git a/openstackclient/common/quota.py b/openstackclient/common/quota.py
index b3d4c3b6..b497a44d 100644
--- a/openstackclient/common/quota.py
+++ b/openstackclient/common/quota.py
@@ -145,7 +145,8 @@ class ShowQuota(command.ShowOne):
parser.add_argument(
'project',
metavar='<project/class>',
- help='Show this project or class (name/ID)',
+ nargs='?',
+ help='Show quotas for this project or class (name or ID)',
)
type_group = parser.add_mutually_exclusive_group()
type_group.add_argument(
@@ -164,12 +165,22 @@ class ShowQuota(command.ShowOne):
)
return parser
+ def _get_project(self, parsed_args):
+ if parsed_args.project is not None:
+ identity_client = self.app.client_manager.identity
+ project = utils.find_resource(
+ identity_client.projects,
+ parsed_args.project,
+ ).id
+ elif self.app.client_manager.auth_ref:
+ # Get the project from the current auth
+ project = self.app.client_manager.auth_ref.project_id
+ else:
+ project = None
+ return project
+
def get_compute_volume_quota(self, client, parsed_args):
- identity_client = self.app.client_manager.identity
- project = utils.find_resource(
- identity_client.projects,
- parsed_args.project,
- ).id
+ project = self._get_project(parsed_args)
try:
if parsed_args.quota_class:
@@ -189,11 +200,7 @@ class ShowQuota(command.ShowOne):
if parsed_args.quota_class or parsed_args.default:
return {}
if self.app.client_manager.is_network_endpoint_enabled():
- identity_client = self.app.client_manager.identity
- project = utils.find_resource(
- identity_client.projects,
- parsed_args.project,
- ).id
+ project = self._get_project(parsed_args)
return self.app.client_manager.network.get_quota(project)
else:
return {}
diff --git a/openstackclient/tests/common/test_quota.py b/openstackclient/tests/common/test_quota.py
index edf29c9b..ba7ee469 100644
--- a/openstackclient/tests/common/test_quota.py
+++ b/openstackclient/tests/common/test_quota.py
@@ -59,6 +59,7 @@ class TestQuota(compute_fakes.TestComputev2):
self.service_catalog_mock = \
self.app.client_manager.auth_ref.service_catalog
self.service_catalog_mock.reset_mock()
+ self.app.client_manager.auth_ref.project_id = identity_fakes.project_id
class TestQuotaSet(TestQuota):
@@ -304,3 +305,13 @@ class TestQuotaShow(TestQuota):
identity_fakes.project_id)
self.volume_quotas_class_mock.get.assert_called_with(
identity_fakes.project_id)
+
+ def test_quota_show_no_project(self):
+ parsed_args = self.check_parser(self.cmd, [], [])
+
+ self.cmd.take_action(parsed_args)
+
+ self.quotas_mock.get.assert_called_with(identity_fakes.project_id)
+ self.volume_quotas_mock.get.assert_called_with(
+ identity_fakes.project_id)
+ self.network.get_quota.assert_called_with(identity_fakes.project_id)
diff --git a/releasenotes/notes/bug-1572733-874b37a7fa8292d0.yaml b/releasenotes/notes/bug-1572733-874b37a7fa8292d0.yaml
new file mode 100644
index 00000000..3ddf4937
--- /dev/null
+++ b/releasenotes/notes/bug-1572733-874b37a7fa8292d0.yaml
@@ -0,0 +1,6 @@
+---
+fixes:
+ - The ``quota show`` command ``<project/class>`` argument is now
+ optional. If not specified, the user's current project is used.
+ This allows non-admin users to show quotas for their current project.
+ [Bug `1572733 <https://bugs.launchpad.net/bugs/1572733>`_]