Add parent project filter for listing projects
This patch introduces a new option --parent into project list, to specify a parent project to filter projects which has the given project as their parent. Depends-on: https://review.opendev.org/#/c/677101 Change-Id: I6725262cf040e0ec6ceca9cf0462ce59224049c6
This commit is contained in:
parent
6f60f833e8
commit
7c1b6a799e
@ -102,6 +102,7 @@ List projects
|
|||||||
|
|
||||||
openstack project list
|
openstack project list
|
||||||
[--domain <domain>]
|
[--domain <domain>]
|
||||||
|
[--parent <parent>]
|
||||||
[--user <user>]
|
[--user <user>]
|
||||||
[--my-projects]
|
[--my-projects]
|
||||||
[--long]
|
[--long]
|
||||||
@ -115,6 +116,12 @@ List projects
|
|||||||
|
|
||||||
.. versionadded:: 3
|
.. versionadded:: 3
|
||||||
|
|
||||||
|
.. option:: --parent <parent>
|
||||||
|
|
||||||
|
Filter projects whose parent is :option:`\<parent\> <--parent>` (name or ID)
|
||||||
|
|
||||||
|
.. versionadded:: 3
|
||||||
|
|
||||||
.. option:: --user <user>
|
.. option:: --user <user>
|
||||||
|
|
||||||
Filter projects by :option:`\<user\> <--user>` (name or ID)
|
Filter projects by :option:`\<user\> <--user>` (name or ID)
|
||||||
|
@ -185,6 +185,11 @@ class ListProject(command.Lister):
|
|||||||
metavar='<domain>',
|
metavar='<domain>',
|
||||||
help=_('Filter projects by <domain> (name or ID)'),
|
help=_('Filter projects by <domain> (name or ID)'),
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--parent',
|
||||||
|
metavar='<parent>',
|
||||||
|
help=_('Filter projects whose parent is <parent> (name or ID)'),
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--user',
|
'--user',
|
||||||
metavar='<user>',
|
metavar='<user>',
|
||||||
@ -226,6 +231,11 @@ class ListProject(command.Lister):
|
|||||||
parsed_args.domain).id
|
parsed_args.domain).id
|
||||||
kwargs['domain'] = domain_id
|
kwargs['domain'] = domain_id
|
||||||
|
|
||||||
|
if parsed_args.parent:
|
||||||
|
parent_id = common.find_project(identity_client,
|
||||||
|
parsed_args.parent).id
|
||||||
|
kwargs['parent'] = parent_id
|
||||||
|
|
||||||
if parsed_args.user:
|
if parsed_args.user:
|
||||||
if parsed_args.domain:
|
if parsed_args.domain:
|
||||||
user_id = utils.find_resource(identity_client.users,
|
user_id = utils.find_resource(identity_client.users,
|
||||||
|
@ -645,6 +645,28 @@ class TestProjectList(TestProject):
|
|||||||
self.assertEqual(self.columns, columns)
|
self.assertEqual(self.columns, columns)
|
||||||
self.assertEqual(self.datalist, tuple(data))
|
self.assertEqual(self.datalist, tuple(data))
|
||||||
|
|
||||||
|
def test_project_list_parent(self):
|
||||||
|
self.parent = identity_fakes.FakeProject.create_one_project()
|
||||||
|
self.project = identity_fakes.FakeProject.create_one_project(
|
||||||
|
attrs={'domain_id': self.domain.id, 'parent_id': self.parent.id})
|
||||||
|
|
||||||
|
arglist = [
|
||||||
|
'--parent', self.parent.id,
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('parent', self.parent.id),
|
||||||
|
]
|
||||||
|
|
||||||
|
self.projects_mock.get.return_value = self.parent
|
||||||
|
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
self.projects_mock.list.assert_called_with(parent=self.parent.id)
|
||||||
|
|
||||||
|
self.assertEqual(self.columns, columns)
|
||||||
|
self.assertEqual(self.datalist, tuple(data))
|
||||||
|
|
||||||
def test_project_list_sort(self):
|
def test_project_list_sort(self):
|
||||||
self.projects_mock.list.return_value = self.projects
|
self.projects_mock.list.return_value = self.projects
|
||||||
|
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Add ``--parent`` option to ``project list`` command to filter projects
|
||||||
|
by the specified parent project.
|
Loading…
Reference in New Issue
Block a user