Add an action and workflow to update a plan

This should be used when the plan files are updated in swift to
ensure that the Mistral environment keeps in sync.

Closes-Bug: #1621462
Change-Id: I35be5ed5062bb26ca31b55d049780a1423c2ce46
This commit is contained in:
Dougal Matthews
2016-09-09 10:20:08 +00:00
parent 5cdae308be
commit dba588673d
3 changed files with 89 additions and 0 deletions

View File

@@ -89,6 +89,7 @@ mistral.actions =
tripleo.parameters.reset = tripleo_common.actions.parameters:ResetParametersAction
tripleo.parameters.update = tripleo_common.actions.parameters:UpdateParametersAction
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
tripleo.plan.delete = tripleo_common.actions.plan:DeletePlanAction
tripleo.plan.list = tripleo_common.actions.plan:ListPlansAction

View File

@@ -103,6 +103,60 @@ class CreatePlanAction(base.TripleOAction):
return mistral_workflow_utils.Result(error=error_text)
class UpdatePlanAction(base.TripleOAction):
"""Update a plan
Given a container, update the Mistral environment with the same name,
parses the capabilities map file and sets the initial plan template
and environment files if they have changed since the plan was originally
created.
"""
def __init__(self, container):
super(UpdatePlanAction, self).__init__()
self.container = container
def run(self):
swift = self._get_object_client()
mistral = self._get_workflow_client()
error_text = None
try:
mapobject = swift.get_object(self.container,
'capabilities-map.yaml')[1]
mapfile = yaml.safe_load(mapobject)
mistral_env = mistral.environments.get(self.container)
# We always want the root template to match whatever is in the
# capabilities map, so update that regardless.
mistral_env.variables['root_template'] = mapfile['root_template']
# Check to see if the root environment is already listed, if it
# isn't - add it.
# TODO(d0ugal): Users could get into a situation where they have
# an old root environment still added and they
# then have two after the new one is added.
root_env = {'path': mapfile['root_environment']}
if root_env not in mistral_env.variables['environments']:
mistral_env.variables['environments'].insert(0, root_env)
mistral.environments.update(
name=self.container,
variables=mistral_env.variables,
)
except yaml.YAMLError as yaml_err:
error_text = "Error parsing the yaml file: %s" % yaml_err
except swiftexceptions.ClientException as obj_err:
error_text = "File missing from container: %s" % obj_err
except KeyError as key_err:
error_text = ("capabilities-map.yaml missing key: "
"%s" % key_err)
if error_text:
return mistral_workflow_utils.Result(error=error_text)
class ListPlansAction(base.TripleOAction):
"""Lists deployment plans

View File

@@ -40,6 +40,40 @@ workflows:
message: <% $.message or '' %>
execution: <% execution() %>
update_deployment_plan:
input:
- container
- queue_name: tripleo
tasks:
update_plan:
action: tripleo.plan.update container=<% $.container %>
on-success: set_status_success
on-error: set_status_failed
set_status_success:
on-success: notify_zaqar
publish:
status: SUCCESS
message: <% task(update_plan).result %>
set_status_failed:
on-success: notify_zaqar
publish:
status: FAILED
message: <% task(update_plan).result %>
notify_zaqar:
action: zaqar.queue_post
input:
queue_name: <% $.queue_name %>
messages:
body:
type: tripleo.plan_management.v1.update_deployment_plan
payload:
status: <% $.status %>
message: <% $.message or '' %>
execution: <% execution() %>
create_default_deployment_plan:
type: direct
input: