Parse roles from roles_data.yaml directly
roles_data.yaml is the source of truth for the roles available in a deployment. Change-Id: I599bf5675caa4650a8eb647e8c50e0fc64fdc923 Implements blueprint: get-roles-action
This commit is contained in:
parent
e56cccf739
commit
c824b58a22
@ -0,0 +1,6 @@
|
||||
---
|
||||
fixes:
|
||||
- The tripleo.role.list action now returns the list of roles based
|
||||
directly on the data from roles_data.yaml in the deployment
|
||||
plan. (See blueprint `get-roles-actions
|
||||
<https://blueprints.launchpad.net/tripleo/+spec/get-roles-action>`__)
|
@ -314,8 +314,7 @@ class DeletePlanAction(base.TripleOAction):
|
||||
class ListRolesAction(base.TripleOAction):
|
||||
"""Returns a deployment plan's roles
|
||||
|
||||
Parses overcloud.yaml and returns the Heat resources where
|
||||
type = OS::Heat::ResourceGroup
|
||||
Parses roles_data.yaml and returns the names of all available roles.
|
||||
|
||||
:param container: name of the Swift container / plan name
|
||||
:return: list of roles in the container's deployment plan
|
||||
@ -327,24 +326,16 @@ class ListRolesAction(base.TripleOAction):
|
||||
|
||||
def run(self, context):
|
||||
try:
|
||||
mc = self.get_workflow_client(context)
|
||||
mistral_env = mc.environments.get(self.container)
|
||||
template_name = mistral_env.variables['template']
|
||||
|
||||
oc = self.get_object_client(context)
|
||||
resources = yaml.safe_load(
|
||||
oc.get_object(self.container, template_name)[1])['resources']
|
||||
except Exception as mistral_err:
|
||||
err_msg = ("Error retrieving deployment plan: %s"
|
||||
% mistral_err)
|
||||
roles_data = yaml.safe_load(oc.get_object(
|
||||
self.container, constants.OVERCLOUD_J2_ROLES_NAME)[1])
|
||||
except Exception as err:
|
||||
err_msg = ("Error retrieving roles data from deployment plan: %s"
|
||||
% err)
|
||||
LOG.exception(err_msg)
|
||||
return mistral_workflow_utils.Result(error=err_msg)
|
||||
|
||||
roles = []
|
||||
for resource, details in resources.items():
|
||||
if details['type'] == constants.RESOURCE_GROUP_TYPE:
|
||||
roles.append(resource)
|
||||
return roles
|
||||
return [role['name'] for role in roles_data]
|
||||
|
||||
|
||||
class ExportPlanAction(base.TripleOAction):
|
||||
|
@ -81,6 +81,24 @@ notresources:
|
||||
"""
|
||||
|
||||
|
||||
ROLES_DATA_YAML_CONTENTS = """
|
||||
- name: MyController
|
||||
CountDefault: 1
|
||||
ServicesDefault:
|
||||
- OS::TripleO::Services::CACerts
|
||||
|
||||
- name: Compute
|
||||
HostnameFormatDefault: '%stackname%-novacompute-%index%'
|
||||
ServicesDefault:
|
||||
- OS::TripleO::Services::NovaCompute
|
||||
- OS::TripleO::Services::DummyService
|
||||
|
||||
- name: CustomRole
|
||||
ServicesDefault:
|
||||
- OS::TripleO::Services::Kernel
|
||||
"""
|
||||
|
||||
|
||||
class CreateContainerActionTest(base.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
@ -467,47 +485,33 @@ class RoleListActionTest(base.TestCase):
|
||||
self.ctx = mock.MagicMock()
|
||||
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
@mock.patch(
|
||||
'tripleo_common.actions.base.TripleOAction.get_workflow_client')
|
||||
def test_run(self, workflow_client_mock, get_obj_client_mock):
|
||||
|
||||
# setup mistral
|
||||
mistral = mock.MagicMock()
|
||||
env_item = mock.Mock()
|
||||
mistral.environments.get.return_value = env_item
|
||||
workflow_client_mock.return_value = mistral
|
||||
|
||||
env_item.variables = {
|
||||
'template': 'overcloud.yaml',
|
||||
'environments': [
|
||||
{'path': 'overcloud-resource-registry-puppet.yaml'}
|
||||
]
|
||||
}
|
||||
env_item.name = self.container
|
||||
env_item.description = None
|
||||
env_item.created_at = '2016-06-30 15:51:09'
|
||||
env_item.updated_at = None
|
||||
env_item.scope = 'private'
|
||||
env_item.id = '4b5e97d0-2f7a-4cdd-ab7c-71331cce477d'
|
||||
def test_run(self, get_obj_client_mock):
|
||||
|
||||
# setup swift
|
||||
swift = mock.MagicMock()
|
||||
swift.get_object.return_value = ({}, RESOURCES_YAML_CONTENTS)
|
||||
swift.get_object.return_value = ({}, ROLES_DATA_YAML_CONTENTS)
|
||||
get_obj_client_mock.return_value = swift
|
||||
|
||||
template_name = workflow_client_mock().environments.get(
|
||||
self.container).variables['template']
|
||||
|
||||
# Test
|
||||
action = plan.ListRolesAction()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
# verify
|
||||
expected = ['Compute', 'Controller']
|
||||
result.sort()
|
||||
expected = ['MyController', 'Compute', 'CustomRole']
|
||||
self.assertEqual(expected, result)
|
||||
self.assertEqual('overcloud.yaml', template_name)
|
||||
swift.get_object.assert_called_with(self.container, template_name)
|
||||
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
def test_no_roles_data_file(self, get_obj_client_mock):
|
||||
|
||||
swift = mock.MagicMock()
|
||||
swift.get_object.side_effect = swiftexceptions.ClientException("404")
|
||||
get_obj_client_mock.return_value = swift
|
||||
|
||||
action = plan.ListRolesAction()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
error_str = ('Error retrieving roles data from deployment plan: 404')
|
||||
self.assertEqual(result.error, error_str)
|
||||
|
||||
|
||||
class ExportPlanActionTest(base.TestCase):
|
||||
|
Loading…
x
Reference in New Issue
Block a user