Add state info to tasks list
When publish fails for a task, the error message will be recorded in state info. This patch refactors the task list command to include the state info. Change-Id: I4a02fb34d7a1f2be3f0a64a808670a35a198f139 Closes-Bug: #1496685
This commit is contained in:
@@ -27,22 +27,31 @@ from mistralclient.commands.v2 import base
|
|||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def format(task=None):
|
def format_list(task=None):
|
||||||
|
return format(task, lister=True)
|
||||||
|
|
||||||
|
|
||||||
|
def format(task=None, lister=False):
|
||||||
columns = (
|
columns = (
|
||||||
'ID',
|
'ID',
|
||||||
'Name',
|
'Name',
|
||||||
'Workflow name',
|
'Workflow name',
|
||||||
'Execution ID',
|
'Execution ID',
|
||||||
'State',
|
'State',
|
||||||
|
'State info'
|
||||||
)
|
)
|
||||||
|
|
||||||
if task:
|
if task:
|
||||||
|
state_info = (task.state_info if not lister
|
||||||
|
else base.cut(task.state_info))
|
||||||
|
|
||||||
data = (
|
data = (
|
||||||
task.id,
|
task.id,
|
||||||
task.name,
|
task.name,
|
||||||
task.workflow_name,
|
task.workflow_name,
|
||||||
task.workflow_execution_id,
|
task.workflow_execution_id,
|
||||||
task.state,
|
task.state,
|
||||||
|
state_info
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
data = (tuple('<none>' for _ in range(len(columns))),)
|
data = (tuple('<none>' for _ in range(len(columns))),)
|
||||||
@@ -63,7 +72,7 @@ class List(base.MistralLister):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def _get_format_function(self):
|
def _get_format_function(self):
|
||||||
return format
|
return format_list
|
||||||
|
|
||||||
def _get_resources(self, parsed_args):
|
def _get_resources(self, parsed_args):
|
||||||
return tasks.TaskManager(self.app.client).list(
|
return tasks.TaskManager(self.app.client).list(
|
||||||
@@ -77,9 +86,8 @@ class Get(show.ShowOne):
|
|||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(Get, self).get_parser(prog_name)
|
parser = super(Get, self).get_parser(prog_name)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument('id', help='Task identifier')
|
||||||
'id',
|
|
||||||
help='Task identifier')
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
|
@@ -28,6 +28,7 @@ TASK_DICT = {
|
|||||||
'workflow_name': 'thing',
|
'workflow_name': 'thing',
|
||||||
'workflow_execution_id': '321',
|
'workflow_execution_id': '321',
|
||||||
'state': 'RUNNING',
|
'state': 'RUNNING',
|
||||||
|
'state_info': None
|
||||||
}
|
}
|
||||||
|
|
||||||
TASK_RESULT = {"test": "is", "passed": "successfully"}
|
TASK_RESULT = {"test": "is", "passed": "successfully"}
|
||||||
@@ -42,6 +43,8 @@ TASK = tasks.Task(mock, TASK_DICT)
|
|||||||
TASK_WITH_RESULT = tasks.Task(mock, TASK_WITH_RESULT_DICT)
|
TASK_WITH_RESULT = tasks.Task(mock, TASK_WITH_RESULT_DICT)
|
||||||
TASK_WITH_PUBLISHED = tasks.Task(mock, TASK_WITH_PUBLISHED_DICT)
|
TASK_WITH_PUBLISHED = tasks.Task(mock, TASK_WITH_PUBLISHED_DICT)
|
||||||
|
|
||||||
|
EXPECTED_TASK_RESULT = ('123', 'some', 'thing', '321', 'RUNNING', None)
|
||||||
|
|
||||||
|
|
||||||
class TestCLITasksV2(base.BaseCommandTest):
|
class TestCLITasksV2(base.BaseCommandTest):
|
||||||
@mock.patch('mistralclient.api.v2.tasks.TaskManager.list')
|
@mock.patch('mistralclient.api.v2.tasks.TaskManager.list')
|
||||||
@@ -50,8 +53,7 @@ class TestCLITasksV2(base.BaseCommandTest):
|
|||||||
|
|
||||||
result = self.call(task_cmd.List)
|
result = self.call(task_cmd.List)
|
||||||
|
|
||||||
self.assertEqual([('123', 'some', 'thing', '321', 'RUNNING')],
|
self.assertEqual([EXPECTED_TASK_RESULT], result[1])
|
||||||
result[1])
|
|
||||||
|
|
||||||
@mock.patch('mistralclient.api.v2.tasks.TaskManager.list')
|
@mock.patch('mistralclient.api.v2.tasks.TaskManager.list')
|
||||||
def test_list_with_workflow_execution(self, mock):
|
def test_list_with_workflow_execution(self, mock):
|
||||||
@@ -59,8 +61,7 @@ class TestCLITasksV2(base.BaseCommandTest):
|
|||||||
|
|
||||||
result = self.call(task_cmd.List, app_args=['workflow_execution'])
|
result = self.call(task_cmd.List, app_args=['workflow_execution'])
|
||||||
|
|
||||||
self.assertEqual([('123', 'some', 'thing', '321', 'RUNNING')],
|
self.assertEqual([EXPECTED_TASK_RESULT], result[1])
|
||||||
result[1])
|
|
||||||
|
|
||||||
@mock.patch('mistralclient.api.v2.tasks.TaskManager.get')
|
@mock.patch('mistralclient.api.v2.tasks.TaskManager.get')
|
||||||
def test_get(self, mock):
|
def test_get(self, mock):
|
||||||
@@ -68,8 +69,7 @@ class TestCLITasksV2(base.BaseCommandTest):
|
|||||||
|
|
||||||
result = self.call(task_cmd.Get, app_args=['id'])
|
result = self.call(task_cmd.Get, app_args=['id'])
|
||||||
|
|
||||||
self.assertEqual(('123', 'some', 'thing', '321', 'RUNNING'),
|
self.assertEqual(EXPECTED_TASK_RESULT, result[1])
|
||||||
result[1])
|
|
||||||
|
|
||||||
@mock.patch('mistralclient.api.v2.tasks.TaskManager.get')
|
@mock.patch('mistralclient.api.v2.tasks.TaskManager.get')
|
||||||
def test_get_result(self, mock):
|
def test_get_result(self, mock):
|
||||||
@@ -96,8 +96,7 @@ class TestCLITasksV2(base.BaseCommandTest):
|
|||||||
|
|
||||||
result = self.call(task_cmd.Rerun, app_args=['id'])
|
result = self.call(task_cmd.Rerun, app_args=['id'])
|
||||||
|
|
||||||
self.assertEqual(('123', 'some', 'thing', '321', 'RUNNING'),
|
self.assertEqual(EXPECTED_TASK_RESULT, result[1])
|
||||||
result[1])
|
|
||||||
|
|
||||||
@mock.patch('mistralclient.api.v2.tasks.TaskManager.rerun')
|
@mock.patch('mistralclient.api.v2.tasks.TaskManager.rerun')
|
||||||
def test_rerun_no_reset(self, mock):
|
def test_rerun_no_reset(self, mock):
|
||||||
@@ -105,5 +104,4 @@ class TestCLITasksV2(base.BaseCommandTest):
|
|||||||
|
|
||||||
result = self.call(task_cmd.Rerun, app_args=['id', '--resume'])
|
result = self.call(task_cmd.Rerun, app_args=['id', '--resume'])
|
||||||
|
|
||||||
self.assertEqual(('123', 'some', 'thing', '321', 'RUNNING'),
|
self.assertEqual(EXPECTED_TASK_RESULT, result[1])
|
||||||
result[1])
|
|
||||||
|
Reference in New Issue
Block a user