Enhances Roles List
This patch enhances the ListRolesAction by adding a detail argument that toggles whether the names or all role data will be returned. Change-Id: Ib1755bcf5c1361a3e5616014bf063f69e49687c6 Implements: blueprint tripleo-common-enhance-list-roles-action
This commit is contained in:
parent
c82bf420dc
commit
9bd54ab664
@ -185,12 +185,16 @@ class ListRolesAction(base.TripleOAction):
|
|||||||
Parses roles_data.yaml and returns the names of all available roles.
|
Parses roles_data.yaml and returns the names of all available roles.
|
||||||
|
|
||||||
:param container: name of the Swift container / plan name
|
:param container: name of the Swift container / plan name
|
||||||
|
:param detail: if false(default), displays role names only. if true,
|
||||||
|
returns all roles data
|
||||||
:return: list of roles in the container's deployment plan
|
:return: list of roles in the container's deployment plan
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, container=constants.DEFAULT_CONTAINER_NAME):
|
def __init__(self, container=constants.DEFAULT_CONTAINER_NAME,
|
||||||
|
detail=False):
|
||||||
super(ListRolesAction, self).__init__()
|
super(ListRolesAction, self).__init__()
|
||||||
self.container = container
|
self.container = container
|
||||||
|
self.detail = detail
|
||||||
|
|
||||||
def run(self, context):
|
def run(self, context):
|
||||||
try:
|
try:
|
||||||
@ -203,7 +207,10 @@ class ListRolesAction(base.TripleOAction):
|
|||||||
LOG.exception(err_msg)
|
LOG.exception(err_msg)
|
||||||
return actions.Result(error=err_msg)
|
return actions.Result(error=err_msg)
|
||||||
|
|
||||||
return [role['name'] for role in roles_data]
|
if self.detail:
|
||||||
|
return roles_data
|
||||||
|
else:
|
||||||
|
return [role['name'] for role in roles_data]
|
||||||
|
|
||||||
|
|
||||||
class ExportPlanAction(base.TripleOAction):
|
class ExportPlanAction(base.TripleOAction):
|
||||||
|
@ -235,10 +235,10 @@ class DeletePlanActionTest(base.TestCase):
|
|||||||
swift.delete_container.assert_called_with(self.container_name)
|
swift.delete_container.assert_called_with(self.container_name)
|
||||||
|
|
||||||
|
|
||||||
class RoleListActionTest(base.TestCase):
|
class ListRolesActionTest(base.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(RoleListActionTest, self).setUp()
|
super(ListRolesActionTest, self).setUp()
|
||||||
self.container = 'overcloud'
|
self.container = 'overcloud'
|
||||||
self.ctx = mock.MagicMock()
|
self.ctx = mock.MagicMock()
|
||||||
|
|
||||||
@ -257,6 +257,31 @@ class RoleListActionTest(base.TestCase):
|
|||||||
expected = ['MyController', 'Compute', 'CustomRole']
|
expected = ['MyController', 'Compute', 'CustomRole']
|
||||||
self.assertEqual(expected, result)
|
self.assertEqual(expected, result)
|
||||||
|
|
||||||
|
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||||
|
def test_run_show_detail(self, get_obj_client_mock):
|
||||||
|
# setup swift
|
||||||
|
swift = mock.MagicMock()
|
||||||
|
swift.get_object.return_value = ({}, ROLES_DATA_YAML_CONTENTS)
|
||||||
|
get_obj_client_mock.return_value = swift
|
||||||
|
|
||||||
|
# Test
|
||||||
|
action = plan.ListRolesAction(detail=True)
|
||||||
|
result = action.run(self.ctx)
|
||||||
|
|
||||||
|
# verify
|
||||||
|
expected = [
|
||||||
|
{u'CountDefault': 1,
|
||||||
|
u'ServicesDefault': [u'OS::TripleO::Services::CACerts'],
|
||||||
|
u'name': u'MyController'},
|
||||||
|
{u'HostnameFormatDefault': u'%stackname%-novacompute-%index%',
|
||||||
|
u'ServicesDefault': [u'OS::TripleO::Services::NovaCompute',
|
||||||
|
u'OS::TripleO::Services::DummyService'],
|
||||||
|
u'name': u'Compute'},
|
||||||
|
{u'ServicesDefault': [u'OS::TripleO::Services::Kernel'],
|
||||||
|
u'name': u'CustomRole'}]
|
||||||
|
|
||||||
|
self.assertEqual(expected, result)
|
||||||
|
|
||||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||||
def test_no_roles_data_file(self, get_obj_client_mock):
|
def test_no_roles_data_file(self, get_obj_client_mock):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user