Skip to content

Commit 4679a4c

Browse files
committed
Fix --parents and --children options in project show
Options "--parents" and "--children" don't work in "project show" command, fix the issue and add related unit and functional tests. Change-Id: Id9965267a037442f1077f8e1929d0527981f643d Closes-Bug: #1499657
1 parent 2966bd0 commit 4679a4c

4 files changed

Lines changed: 46 additions & 32 deletions

File tree

openstackclient/identity/v3/project.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,13 +336,18 @@ def take_action(self, parsed_args):
336336
project = utils.find_resource(
337337
identity_client.projects,
338338
project_str,
339-
domain_id=domain.id,
340-
parents_as_list=parsed_args.parents,
341-
subtree_as_list=parsed_args.children)
339+
domain_id=domain.id)
342340
else:
343341
project = utils.find_resource(
344342
identity_client.projects,
345-
project_str,
343+
project_str)
344+
345+
if parsed_args.parents or parsed_args.children:
346+
# NOTE(RuiChen): utils.find_resource() can't pass kwargs,
347+
# if id query hit the result at first, so call
348+
# identity manager.get() with kwargs directly.
349+
project = identity_client.projects.get(
350+
project.id,
346351
parents_as_list=parsed_args.parents,
347352
subtree_as_list=parsed_args.children)
348353

openstackclient/tests/functional/identity/v3/test_project.py

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

13+
import json
14+
1315
from tempest.lib.common.utils import data_utils
1416

1517
from openstackclient.tests.functional.identity.v3 import common
@@ -111,3 +113,14 @@ def test_project_show(self):
111113
'name': self.project_name})
112114
items = self.parse_show(raw_output)
113115
self.assert_show_fields(items, self.PROJECT_FIELDS)
116+
117+
def test_project_show_with_parents_children(self):
118+
json_output = json.loads(self.openstack(
119+
'project show '
120+
'--parents --children -f json '
121+
'--domain %(domain)s '
122+
'%(name)s' % {'domain': self.domain_name,
123+
'name': self.project_name}))
124+
for attr_name in (self.PROJECT_FIELDS + ['parents', 'subtree']):
125+
self.assertIn(attr_name, json_output)
126+
self.assertEqual(self.project_name, json_output.get('name'))

openstackclient/tests/unit/identity/v3/test_project.py

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#
1515

1616
import mock
17+
from mock import call
1718

1819
from osc_lib import exceptions
1920
from osc_lib import utils
@@ -763,8 +764,6 @@ def setUp(self):
763764

764765
def test_project_show(self):
765766

766-
self.projects_mock.get.side_effect = [Exception("Not found"),
767-
self.project]
768767
self.projects_mock.get.return_value = self.project
769768

770769
arglist = [
@@ -790,11 +789,7 @@ def test_project_show(self):
790789
# data to be shown.
791790
columns, data = self.cmd.take_action(parsed_args)
792791

793-
self.projects_mock.get.assert_called_with(
794-
self.project.id,
795-
parents_as_list=False,
796-
subtree_as_list=False,
797-
)
792+
self.projects_mock.get.assert_called_once_with(self.project.id)
798793

799794
collist = (
800795
'description',
@@ -824,8 +819,6 @@ def test_project_show_parents(self):
824819
'parents': [{'project': {'id': self.project.parent_id}}]
825820
}
826821
)
827-
self.projects_mock.get.side_effect = [Exception("Not found"),
828-
self.project]
829822
self.projects_mock.get.return_value = self.project
830823

831824
arglist = [
@@ -849,11 +842,12 @@ def test_project_show_parents(self):
849842
}
850843

851844
columns, data = self.cmd.take_action(parsed_args)
852-
self.projects_mock.get.assert_called_with(
853-
self.project.id,
854-
parents_as_list=True,
855-
subtree_as_list=False,
856-
)
845+
846+
self.projects_mock.get.assert_has_calls([call(self.project.id),
847+
call(self.project.id,
848+
parents_as_list=True,
849+
subtree_as_list=False,
850+
)])
857851

858852
collist = (
859853
'description',
@@ -885,8 +879,6 @@ def test_project_show_subtree(self):
885879
'subtree': [{'project': {'id': 'children-id'}}]
886880
}
887881
)
888-
self.projects_mock.get.side_effect = [Exception("Not found"),
889-
self.project]
890882
self.projects_mock.get.return_value = self.project
891883

892884
arglist = [
@@ -910,11 +902,11 @@ def test_project_show_subtree(self):
910902
}
911903

912904
columns, data = self.cmd.take_action(parsed_args)
913-
self.projects_mock.get.assert_called_with(
914-
self.project.id,
915-
parents_as_list=False,
916-
subtree_as_list=True,
917-
)
905+
self.projects_mock.get.assert_has_calls([call(self.project.id),
906+
call(self.project.id,
907+
parents_as_list=False,
908+
subtree_as_list=True,
909+
)])
918910

919911
collist = (
920912
'description',
@@ -947,8 +939,6 @@ def test_project_show_parents_and_children(self):
947939
'subtree': [{'project': {'id': 'children-id'}}]
948940
}
949941
)
950-
self.projects_mock.get.side_effect = [Exception("Not found"),
951-
self.project]
952942
self.projects_mock.get.return_value = self.project
953943

954944
arglist = [
@@ -973,11 +963,11 @@ def test_project_show_parents_and_children(self):
973963
}
974964

975965
columns, data = self.cmd.take_action(parsed_args)
976-
self.projects_mock.get.assert_called_with(
977-
self.project.id,
978-
parents_as_list=True,
979-
subtree_as_list=True,
980-
)
966+
self.projects_mock.get.assert_has_calls([call(self.project.id),
967+
call(self.project.id,
968+
parents_as_list=True,
969+
subtree_as_list=True,
970+
)])
981971

982972
collist = (
983973
'description',
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
fixes:
3+
- |
4+
Options ``--parents`` and ``--children`` don't work in ``project show``
5+
command, fix the issue.
6+
[Bug `1499657 <https://bugs.launchpad.net/python-openstackclient/+bug/1499657>`_]

0 commit comments

Comments
 (0)