Use kwargs to pass in data and error to Mistral Result

This standardises how we create mistral.workflow.utils.Result instances.
Previously we used a combination of passing empty strings or None values
to pass errors only. Using kwargs makes this clearer and cleaner. This
is also means we use the Result class in the same way as the builtin
Mistral actions.

Change-Id: Ic94c0513b1fba030de70263ac1df32b4ab130e9a
This commit is contained in:
Dougal Matthews 2016-09-23 10:20:04 +01:00
parent 6239c4c2e7
commit b771918bba
5 changed files with 19 additions and 44 deletions

View File

@ -67,10 +67,7 @@ class RegisterOrUpdateNodes(base.TripleOAction):
ramdisk_name=self.ramdisk_name)
except Exception as err:
LOG.exception("Error registering nodes with ironic.")
return mistral_workflow_utils.Result(
"",
err.message
)
return mistral_workflow_utils.Result(error=err)
class ConfigureBootAction(base.TripleOAction):
@ -133,7 +130,7 @@ class ConfigureBootAction(base.TripleOAction):
LOG.debug("Configuring boot option for Node %s", self.node_uuid)
except Exception as err:
LOG.exception("Error configuring node boot options with Ironic.")
return mistral_workflow_utils.Result("", err)
return mistral_workflow_utils.Result(error=err)
class ConfigureRootDeviceAction(base.TripleOAction):
@ -288,6 +285,5 @@ class UpdateNodeCapability(base.TripleOAction):
except Exception as err:
LOG.exception("Error updating node capability in ironic.")
return mistral_workflow_utils.Result(
"",
"%s: %s" % (type(err).__name__, str(err))
error="%s: %s" % (type(err).__name__, str(err))
)

View File

@ -121,10 +121,7 @@ class OrchestrationDeployAction(base.TripleOAction):
if body_json['deploy_status_code'] != 0:
error = "Heat deployment failed for '%s'" % self.name
return mistral_workflow_utils.Result(
body_json,
error
)
return mistral_workflow_utils.Result(data=body_json, error=error)
class DeployStackAction(templates.ProcessTemplatesAction):

View File

@ -48,10 +48,7 @@ class GetCapabilitiesAction(base.TripleOAction):
err_msg = (
"Error parsing capabilities-map.yaml.")
LOG.exception(err_msg)
return mistral_workflow_utils.Result(
None,
err_msg
)
return mistral_workflow_utils.Result(error=err_msg)
try:
container_files = swift_client.get_container(self.container)
container_file_list = [entry['name'] for entry
@ -59,10 +56,7 @@ class GetCapabilitiesAction(base.TripleOAction):
except Exception as swift_err:
err_msg = ("Error retrieving plan files: %s" % swift_err)
LOG.exception(err_msg)
return mistral_workflow_utils.Result(
None,
err_msg
)
return mistral_workflow_utils.Result(error=err_msg)
try:
mistral_client = self._get_workflow_client()
mistral_env = mistral_client.environments.get(self.container)
@ -70,10 +64,7 @@ class GetCapabilitiesAction(base.TripleOAction):
err_msg = ("Error retrieving mistral "
"environment. %s" % mistral_err)
LOG.exception(err_msg)
return mistral_workflow_utils.Result(
None,
err_msg
)
return mistral_workflow_utils.Result(error=err_msg)
selected_envs = [item['path'] for item in
mistral_env.variables['environments']
@ -175,10 +166,7 @@ class UpdateCapabilitiesAction(base.TripleOAction):
"Error retrieving mistral "
"environment. %s" % mistral_err)
LOG.exception(err_msg)
return mistral_workflow_utils.Result(
None,
err_msg
)
return mistral_workflow_utils.Result(error=err_msg)
for k, v in self.environments.items():
found = False
@ -203,8 +191,5 @@ class UpdateCapabilitiesAction(base.TripleOAction):
err_msg = (
"Error retrieving mistral environment. %s" % mistral_err)
LOG.exception(err_msg)
return mistral_workflow_utils.Result(
None,
err_msg
)
return mistral_workflow_utils.Result(error=err_msg)
return mistral_env.variables

View File

@ -50,10 +50,7 @@ class CreateContainerAction(base.TripleOAction):
oc.get_account()[1]]:
result_string = ("A container with the name %s already"
" exists.") % self.container
return mistral_workflow_utils.Result(
None,
result_string
)
return mistral_workflow_utils.Result(error=result_string)
oc.put_container(self.container, headers=default_container_headers)
@ -86,7 +83,7 @@ class CreatePlanAction(base.TripleOAction):
else:
message = ("Unable to create plan. The Mistral environment "
"already exists")
return mistral_workflow_utils.Result(None, message)
return mistral_workflow_utils.Result(error=message)
try:
# parses capabilities to get root_template, root_environment
@ -281,7 +278,7 @@ class ListRolesAction(base.TripleOAction):
err_msg = ("Error retrieving deployment plan: %s"
% mistral_err)
LOG.exception(err_msg)
return mistral_workflow_utils.Result(None, err_msg)
return mistral_workflow_utils.Result(error=err_msg)
roles = []
for resource, details in resources.items():

View File

@ -83,11 +83,11 @@ class Enabled(base.TripleOAction):
return_value = {'stderr': ''}
if self._validations_enabled():
return_value['stdout'] = 'Validations are enabled'
mistral_result = (return_value, None)
mistral_result = {"data": return_value}
else:
return_value['stdout'] = 'Validations are disabled'
mistral_result = (None, return_value)
return mistral_workflow_utils.Result(*mistral_result)
mistral_result = {"error": return_value}
return mistral_workflow_utils.Result(**mistral_result)
class ListValidationsAction(base.TripleOAction):
@ -132,15 +132,15 @@ class RunValidationAction(base.TripleOAction):
identity_file,
self.plan)
return_value = {'stdout': stdout, 'stderr': stderr}
mistral_result = (return_value, None)
mistral_result = {"data": return_value}
except mistralclient_api.APIException as e:
return_value = {'stdout': '', 'stderr': e.error_message}
mistral_result = (None, return_value)
mistral_result = {"error": return_value}
except ProcessExecutionError as e:
return_value = {'stdout': e.stdout, 'stderr': e.stderr}
# Indicates to Mistral there was a failure
mistral_result = (None, return_value)
mistral_result = {"error": return_value}
finally:
if identity_file:
utils.cleanup_identity_file(identity_file)
return mistral_workflow_utils.Result(*mistral_result)
return mistral_workflow_utils.Result(**mistral_result)