Merge "Add "published_global" field to the task execution REST resource"

This commit is contained in:
Zuul 2019-09-03 14:04:32 +00:00 committed by Gerrit Code Review
commit dc246bf808
5 changed files with 74 additions and 20 deletions

View File

@ -476,3 +476,29 @@ class GetReport(command.Command):
)
self.print_report(report_json)
class GetPublished(command.Command):
"""Show workflow global published variables."""
def get_parser(self, prog_name):
parser = super(GetPublished, self).get_parser(prog_name)
parser.add_argument(
'id',
help='Workflow ID')
return parser
def take_action(self, parsed_args):
mistral_client = self.app.client_manager.workflow_engine
res = mistral_client.executions.get(parsed_args.id)
published = res.published_global \
if hasattr(res, 'published_global') else None
try:
published = jsonutils.loads(published)
published = jsonutils.dumps(published, indent=4) + "\n"
except Exception:
LOG.debug("Task result is not JSON.")
self.app.stdout.write(published or "\n")

View File

@ -148,15 +148,22 @@ class GetPublished(command.Command):
def take_action(self, parsed_args):
mistral_client = self.app.client_manager.workflow_engine
result = mistral_client.tasks.get(parsed_args.id).published
res = mistral_client.tasks.get(parsed_args.id)
published = res.published
published_glob = res.published_global \
if hasattr(res, 'published_global') else None
try:
result = jsonutils.loads(result)
result = jsonutils.dumps(result, indent=4) + "\n"
published = jsonutils.loads(published)
published = jsonutils.dumps(published, indent=4) + "\n"
if published_glob:
published_glob = jsonutils.loads(published_glob)
published += jsonutils.dumps(published_glob, indent=4) + "\n"
except Exception:
LOG.debug("Task result is not JSON.")
self.app.stdout.write(result or "\n")
self.app.stdout.write(published or "\n")
class Rerun(command.ShowOne):

View File

@ -730,6 +730,8 @@ class MistralShell(app.App):
mistralclient.commands.v2.executions.GetOutput,
'execution-get-report':
mistralclient.commands.v2.executions.GetReport,
'execution-get-published':
mistralclient.commands.v2.executions.GetPublished,
'task-list': mistralclient.commands.v2.tasks.List,
'task-get': mistralclient.commands.v2.tasks.Get,
'task-get-published': mistralclient.commands.v2.tasks.GetPublished,

View File

@ -22,26 +22,27 @@ import pkg_resources as pkg
import six
import sys
from oslo_serialization import jsonutils
from mistralclient.api.v2 import executions
from mistralclient.commands.v2 import executions as execution_cmd
from mistralclient.tests.unit import base
EXEC = executions.Execution(
mock,
{
'id': '123',
'workflow_id': '123e4567-e89b-12d3-a456-426655440000',
'workflow_name': 'some',
'workflow_namespace': '',
'root_execution_id': '',
'description': '',
'state': 'RUNNING',
'state_info': None,
'created_at': '1',
'updated_at': '1',
'task_execution_id': None
}
)
EXEC_DICT = {
'id': '123',
'workflow_id': '123e4567-e89b-12d3-a456-426655440000',
'workflow_name': 'some',
'workflow_namespace': '',
'root_execution_id': '',
'description': '',
'state': 'RUNNING',
'state_info': None,
'created_at': '1',
'updated_at': '1',
'task_execution_id': None
}
EXEC = executions.Execution(mock, EXEC_DICT)
SUB_WF_EXEC = executions.Execution(
mock,
@ -88,6 +89,12 @@ SUB_WF_EX_RESULT = (
'1'
)
EXEC_PUBLISHED = {"bar1": "val1", "var2": 2}
EXEC_WITH_PUBLISHED_DICT = EXEC_DICT.copy()
EXEC_WITH_PUBLISHED_DICT.update(
{'published_global': jsonutils.dumps(EXEC_PUBLISHED)})
EXEC_WITH_PUBLISHED = executions.Execution(mock, EXEC_WITH_PUBLISHED_DICT)
class TestCLIExecutionsV2(base.BaseCommandTest):
@ -326,3 +333,13 @@ class TestCLIExecutionsV2(base.BaseCommandTest):
[mock.call('id1', force=False), mock.call('id2', force=False)],
self.client.executions.delete.call_args_list
)
def test_get_published(self):
self.client.executions.get.return_value = EXEC_WITH_PUBLISHED
self.call(execution_cmd.GetPublished, app_args=['id'])
self.assertDictEqual(
EXEC_PUBLISHED,
jsonutils.loads(self.app.stdout.write.call_args[0][0])
)

View File

@ -68,6 +68,8 @@ openstack.workflow_engine.v2 =
workflow_execution_show = mistralclient.commands.v2.executions:Get
workflow_execution_input_show = mistralclient.commands.v2.executions:GetInput
workflow_execution_output_show = mistralclient.commands.v2.executions:GetOutput
workflow_execution_report_show = mistralclient.commands.v2.executions:GetReport
workflow_execution_published_show = mistralclient.commands.v2.executions:GetPublished
task_execution_list = mistralclient.commands.v2.tasks:List
task_execution_show = mistralclient.commands.v2.tasks:Get