Merge "User provided pwd has to be merged for get_passwords workflow"

This commit is contained in:
Jenkins 2017-01-18 21:57:50 +00:00 committed by Gerrit Code Review
commit cce40e6932
4 changed files with 131 additions and 5 deletions

View File

@ -77,6 +77,7 @@ mistral.actions =
tripleo.parameters.update = tripleo_common.actions.parameters:UpdateParametersAction
tripleo.parameters.update_role = tripleo_common.actions.parameters:UpdateRoleParametersAction
tripleo.parameters.generate_passwords = tripleo_common.actions.parameters:GeneratePasswordsAction
tripleo.parameters.get_passwords = tripleo_common.actions.parameters:GetPasswordsAction
tripleo.plan.create = tripleo_common.actions.plan:CreatePlanAction
tripleo.plan.update = tripleo_common.actions.plan:UpdatePlanAction
tripleo.plan.create_container = tripleo_common.actions.plan:CreateContainerAction

View File

@ -181,3 +181,32 @@ class GeneratePasswordsAction(base.TripleOAction):
wc.environments.update(**env_kwargs)
return wf_env.variables['passwords']
class GetPasswordsAction(base.TripleOAction):
"""Get passwords from the environment
This method returns the list passwords which are used for the deployment.
It will return a merged list of user provided passwords and generated
passwords, giving priority to the user provided passwords.
"""
def __init__(self, container=constants.DEFAULT_CONTAINER_NAME):
self.container = container
def run(self):
wc = self.get_workflow_client()
try:
wf_env = wc.environments.get(self.container)
except Exception:
msg = "Error retrieving mistral environment: %s" % self.container
LOG.exception(msg)
return mistral_workflow_utils.Result(error=msg)
parameter_defaults = wf_env.variables.get('parameter_defaults', {})
passwords = wf_env.variables.get('passwords', {})
for name in constants.PASSWORD_PARAMETER_NAMES:
if name in parameter_defaults:
passwords[name] = parameter_defaults[name]
return passwords

View File

@ -335,3 +335,99 @@ class GeneratePasswordsActionTest(base.TestCase):
existing_passwords["AdminPassword"] = "ExistingPasswordInHeat"
# ensure old passwords used and no new generation
self.assertEqual(existing_passwords, result)
class GetPasswordsActionTest(base.TestCase):
@mock.patch('tripleo_common.actions.base.TripleOAction.'
'get_orchestration_client')
@mock.patch('tripleo_common.actions.base.TripleOAction.'
'get_workflow_client')
@mock.patch('mistral.context.ctx')
def test_password_from_parameter_defaults(self, mock_ctx,
mock_get_workflow_client,
mock_get_orchestration_client):
mock_ctx.return_value = mock.MagicMock()
mock_mistral = mock.MagicMock()
mock_env = mock.MagicMock()
mock_env.name = constants.DEFAULT_CONTAINER_NAME
mock_env.variables = {
"parameter_defaults": _EXISTING_PASSWORDS,
}
mock_mistral.environments.get.return_value = mock_env
mock_get_workflow_client.return_value = mock_mistral
mock_orchestration = mock.MagicMock()
mock_get_orchestration_client.return_value = mock_orchestration
action = parameters.GetPasswordsAction()
result = action.run()
# ensure old passwords used and no new generation
self.assertEqual(_EXISTING_PASSWORDS, result)
@mock.patch('tripleo_common.actions.base.TripleOAction.'
'get_orchestration_client')
@mock.patch('tripleo_common.actions.base.TripleOAction.'
'get_workflow_client')
@mock.patch('mistral.context.ctx')
def test_password_from_generated_passwords(self, mock_ctx,
mock_get_workflow_client,
mock_get_orchestration_client):
mock_ctx.return_value = mock.MagicMock()
mock_mistral = mock.MagicMock()
mock_env = mock.MagicMock()
mock_env.name = constants.DEFAULT_CONTAINER_NAME
mock_env.variables = {
"parameter_defaults": {},
"passwords": _EXISTING_PASSWORDS,
}
mock_mistral.environments.get.return_value = mock_env
mock_get_workflow_client.return_value = mock_mistral
mock_orchestration = mock.MagicMock()
mock_get_orchestration_client.return_value = mock_orchestration
action = parameters.GetPasswordsAction()
result = action.run()
# ensure old passwords used and no new generation
self.assertEqual(_EXISTING_PASSWORDS, result)
@mock.patch('tripleo_common.actions.base.TripleOAction.'
'get_orchestration_client')
@mock.patch('tripleo_common.actions.base.TripleOAction.'
'get_workflow_client')
@mock.patch('mistral.context.ctx')
def test_password_merging_passwords(self, mock_ctx,
mock_get_workflow_client,
mock_get_orchestration_client):
parameter_defaults = _EXISTING_PASSWORDS.copy()
passwords = {"AdminPassword": parameter_defaults.pop("AdminPassword")}
mock_ctx.return_value = mock.MagicMock()
mock_mistral = mock.MagicMock()
mock_env = mock.MagicMock()
mock_env.name = constants.DEFAULT_CONTAINER_NAME
mock_env.variables = {
"parameter_defaults": parameter_defaults,
"passwords": passwords
}
mock_mistral.environments.get.return_value = mock_env
mock_get_workflow_client.return_value = mock_mistral
mock_orchestration = mock.MagicMock()
mock_get_orchestration_client.return_value = mock_orchestration
action = parameters.GetPasswordsAction()
result = action.run()
# ensure old passwords used and no new generation
self.assertEqual(_EXISTING_PASSWORDS, result)

View File

@ -246,11 +246,11 @@ workflows:
verify_environment_exists:
action: mistral.environments_get name=<% $.container %>
on-success: get_or_generate_passwords
on-success: get_environement_passwords
on-error: verify_environment_set_status_failed
get_or_generate_passwords:
action: tripleo.parameters.generate_passwords container=<% $.container %>
get_environement_passwords:
action: tripleo.parameters.get_passwords container=<% $.container %>
on-success: get_passwords_set_status_success
on-error: get_passwords_set_status_failed
@ -258,13 +258,13 @@ workflows:
on-success: notify_zaqar
publish:
status: SUCCESS
message: <% task(get_or_generate_passwords).result %>
message: <% task(get_environement_passwords).result %>
get_passwords_set_status_failed:
on-success: notify_zaqar
publish:
status: FAILED
message: <% task(get_or_generate_passwords).result %>
message: <% task(get_environement_passwords).result %>
verify_container_set_status_failed:
on-success: notify_zaqar