diff --git a/tripleo_common/actions/plan.py b/tripleo_common/actions/plan.py index 077642d56..15363d818 100644 --- a/tripleo_common/actions/plan.py +++ b/tripleo_common/actions/plan.py @@ -185,12 +185,16 @@ class ListRolesAction(base.TripleOAction): Parses roles_data.yaml and returns the names of all available roles. :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 """ - def __init__(self, container=constants.DEFAULT_CONTAINER_NAME): + def __init__(self, container=constants.DEFAULT_CONTAINER_NAME, + detail=False): super(ListRolesAction, self).__init__() self.container = container + self.detail = detail def run(self, context): try: @@ -203,7 +207,10 @@ class ListRolesAction(base.TripleOAction): LOG.exception(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): diff --git a/tripleo_common/tests/actions/test_plan.py b/tripleo_common/tests/actions/test_plan.py index 4967926c1..5205bc543 100644 --- a/tripleo_common/tests/actions/test_plan.py +++ b/tripleo_common/tests/actions/test_plan.py @@ -235,10 +235,10 @@ class DeletePlanActionTest(base.TestCase): swift.delete_container.assert_called_with(self.container_name) -class RoleListActionTest(base.TestCase): +class ListRolesActionTest(base.TestCase): def setUp(self): - super(RoleListActionTest, self).setUp() + super(ListRolesActionTest, self).setUp() self.container = 'overcloud' self.ctx = mock.MagicMock() @@ -257,6 +257,31 @@ class RoleListActionTest(base.TestCase): expected = ['MyController', 'Compute', 'CustomRole'] 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') def test_no_roles_data_file(self, get_obj_client_mock):