Skip to content

Commit 19723ae

Browse files
ycx516lbragstad
authored andcommitted
Client should parse string to boolean for value 'is_domain'
When we use "--property" parameter, client get lists these the value is string type, but the type of the value 'is_domain' should be boolean, so we should judge it and parse it. The patch parse string to boolean for value 'is_domain'. Co-Authored-By: Lance Bragstad <lbragstad@gmail.com> Conflict: Direct backports of this patch fail because the original tests proposed to the Victoria (master) branch included keystone ``options``. Support for ``options`` was added in: I9c3bdd741f28bf558267fb217818d947597ce13e This backport removes the ``options`` key from the expected values in the tests since feature support for ``options`` isn't going to be backported. Otherwise, the functionality of this change is fully tested like it is on later releases. Change-Id: I37c9eb854524bde3a1530bfe2e3a03810fb1a676 Task: 30039 Story: 2005246 (cherry picked from commit 533af9f)
1 parent 65411e4 commit 19723ae

3 files changed

Lines changed: 130 additions & 0 deletions

File tree

openstackclient/identity/v3/project.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ def take_action(self, parsed_args):
102102
kwargs = {}
103103
if parsed_args.property:
104104
kwargs = parsed_args.property.copy()
105+
if 'is_domain' in kwargs.keys():
106+
if kwargs['is_domain'].lower() == "true":
107+
kwargs['is_domain'] = True
108+
elif kwargs['is_domain'].lower() == "false":
109+
kwargs['is_domain'] = False
110+
elif kwargs['is_domain'].lower() == "none":
111+
kwargs['is_domain'] = None
112+
105113
kwargs['tags'] = list(set(parsed_args.tags))
106114

107115
try:

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

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,123 @@ def test_project_create_property(self):
350350
self.assertEqual(self.columns, columns)
351351
self.assertEqual(self.datalist, data)
352352

353+
def test_project_create_is_domain_false_property(self):
354+
arglist = [
355+
'--property', 'is_domain=false',
356+
self.project.name,
357+
]
358+
verifylist = [
359+
('parent', None),
360+
('enable', False),
361+
('disable', False),
362+
('name', self.project.name),
363+
('tags', []),
364+
('property', {'is_domain': 'false'}),
365+
('name', self.project.name),
366+
]
367+
368+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
369+
370+
# In base command class ShowOne in cliff, abstract method take_action()
371+
# returns a two-part tuple with a tuple of column names and a tuple of
372+
# data to be shown.
373+
columns, data = self.cmd.take_action(parsed_args)
374+
375+
# Set expected values
376+
kwargs = {
377+
'name': self.project.name,
378+
'domain': None,
379+
'description': None,
380+
'enabled': True,
381+
'parent': None,
382+
'is_domain': False,
383+
'tags': [],
384+
}
385+
self.projects_mock.create.assert_called_with(
386+
**kwargs
387+
)
388+
389+
self.assertEqual(self.columns, columns)
390+
self.assertEqual(self.datalist, data)
391+
392+
def test_project_create_is_domain_true_property(self):
393+
arglist = [
394+
'--property', 'is_domain=true',
395+
self.project.name,
396+
]
397+
verifylist = [
398+
('parent', None),
399+
('enable', False),
400+
('disable', False),
401+
('name', self.project.name),
402+
('tags', []),
403+
('property', {'is_domain': 'true'}),
404+
('name', self.project.name),
405+
]
406+
407+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
408+
409+
# In base command class ShowOne in cliff, abstract method take_action()
410+
# returns a two-part tuple with a tuple of column names and a tuple of
411+
# data to be shown.
412+
columns, data = self.cmd.take_action(parsed_args)
413+
414+
# Set expected values
415+
kwargs = {
416+
'name': self.project.name,
417+
'domain': None,
418+
'description': None,
419+
'enabled': True,
420+
'parent': None,
421+
'is_domain': True,
422+
'tags': [],
423+
}
424+
self.projects_mock.create.assert_called_with(
425+
**kwargs
426+
)
427+
428+
self.assertEqual(self.columns, columns)
429+
self.assertEqual(self.datalist, data)
430+
431+
def test_project_create_is_domain_none_property(self):
432+
arglist = [
433+
'--property', 'is_domain=none',
434+
self.project.name,
435+
]
436+
verifylist = [
437+
('parent', None),
438+
('enable', False),
439+
('disable', False),
440+
('name', self.project.name),
441+
('tags', []),
442+
('property', {'is_domain': 'none'}),
443+
('name', self.project.name),
444+
]
445+
446+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
447+
448+
# In base command class ShowOne in cliff, abstract method take_action()
449+
# returns a two-part tuple with a tuple of column names and a tuple of
450+
# data to be shown.
451+
columns, data = self.cmd.take_action(parsed_args)
452+
453+
# Set expected values
454+
kwargs = {
455+
'name': self.project.name,
456+
'domain': None,
457+
'description': None,
458+
'enabled': True,
459+
'parent': None,
460+
'is_domain': None,
461+
'tags': [],
462+
}
463+
self.projects_mock.create.assert_called_with(
464+
**kwargs
465+
)
466+
467+
self.assertEqual(self.columns, columns)
468+
self.assertEqual(self.datalist, data)
469+
353470
def test_project_create_parent(self):
354471
self.parent = identity_fakes.FakeProject.create_one_project()
355472
self.project = identity_fakes.FakeProject.create_one_project(
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
[Story `2005246 <https://storyboard.openstack.org/#!/story/2005246>`_]
5+
The `is_domain` property safely handles type checking.

0 commit comments

Comments
 (0)