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) 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): def take_action(self, parsed_args):
mistral_client = self.app.client_manager.workflow_engine 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: try:
result = jsonutils.loads(result) published = jsonutils.loads(published)
result = jsonutils.dumps(result, indent=4) + "\n" 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: except Exception:
LOG.debug("Task result is not JSON.") 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): class Rerun(command.ShowOne):

View File

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

View File

@ -22,26 +22,27 @@ import pkg_resources as pkg
import six import six
import sys import sys
from oslo_serialization import jsonutils
from mistralclient.api.v2 import executions from mistralclient.api.v2 import executions
from mistralclient.commands.v2 import executions as execution_cmd from mistralclient.commands.v2 import executions as execution_cmd
from mistralclient.tests.unit import base from mistralclient.tests.unit import base
EXEC = executions.Execution( EXEC_DICT = {
mock, 'id': '123',
{ 'workflow_id': '123e4567-e89b-12d3-a456-426655440000',
'id': '123', 'workflow_name': 'some',
'workflow_id': '123e4567-e89b-12d3-a456-426655440000', 'workflow_namespace': '',
'workflow_name': 'some', 'root_execution_id': '',
'workflow_namespace': '', 'description': '',
'root_execution_id': '', 'state': 'RUNNING',
'description': '', 'state_info': None,
'state': 'RUNNING', 'created_at': '1',
'state_info': None, 'updated_at': '1',
'created_at': '1', 'task_execution_id': None
'updated_at': '1', }
'task_execution_id': None
} EXEC = executions.Execution(mock, EXEC_DICT)
)
SUB_WF_EXEC = executions.Execution( SUB_WF_EXEC = executions.Execution(
mock, mock,
@ -88,6 +89,12 @@ SUB_WF_EX_RESULT = (
'1' '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): class TestCLIExecutionsV2(base.BaseCommandTest):
@ -326,3 +333,13 @@ class TestCLIExecutionsV2(base.BaseCommandTest):
[mock.call('id1', force=False), mock.call('id2', force=False)], [mock.call('id1', force=False), mock.call('id2', force=False)],
self.client.executions.delete.call_args_list 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_show = mistralclient.commands.v2.executions:Get
workflow_execution_input_show = mistralclient.commands.v2.executions:GetInput workflow_execution_input_show = mistralclient.commands.v2.executions:GetInput
workflow_execution_output_show = mistralclient.commands.v2.executions:GetOutput 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_list = mistralclient.commands.v2.tasks:List
task_execution_show = mistralclient.commands.v2.tasks:Get task_execution_show = mistralclient.commands.v2.tasks:Get