Browse Source

Print proper status in task results

If there are no results for task, `rally task results` prints message that
task is in failed status, but it can be not true(tasks in running state do
not have results).

Change-Id: I66b606bd89bdad0478cce35d8d68a736bc6eb34d
Closes-Bug: #1539096
changes/42/289942/6
Andrey Kurilin 5 years ago
committed by Andrey Kurilin
parent
commit
b8e858d6b6
2 changed files with 23 additions and 17 deletions
  1. +10
    -8
      rally/cli/commands/task.py
  2. +13
    -9
      tests/unit/cli/commands/test_task.py

+ 10
- 8
rally/cli/commands/task.py View File

@ -451,19 +451,21 @@ class TaskCommands(object):
:param task_id: Task uuid
"""
task = api.Task.get(task_id)
finished_statuses = (consts.TaskStatus.FINISHED,
consts.TaskStatus.ABORTED)
if task["status"] not in finished_statuses:
print(_("Task status is %s. Results available when it is one "
"of %s.") % (task["status"], ", ".join(finished_statuses)))
return 1
results = [{"key": x["key"], "result": x["data"]["raw"],
"sla": x["data"]["sla"],
"load_duration": x["data"]["load_duration"],
"full_duration": x["data"]["full_duration"]}
for x in api.Task.get(task_id).get_results()]
for x in task.get_results()]
if results:
print(json.dumps(results, sort_keys=True, indent=4))
else:
print(_("The task %s marked as '%s'. Results "
"available when it is '%s' .") % (
task_id, consts.TaskStatus.FAILED, consts.TaskStatus.FINISHED))
return(1)
print(json.dumps(results, sort_keys=True, indent=4))
@cliutils.args("--deployment", dest="deployment", type=str,
metavar="<uuid>", required=False,


+ 13
- 9
tests/unit/cli/commands/test_task.py View File

@ -364,8 +364,9 @@ class TaskCommandsTestCase(test.TestCase):
"load_duration": x["data"]["load_duration"],
"full_duration": x["data"]["full_duration"],
"sla": x["data"]["sla"]}, data)
mock_results = mock.Mock(return_value=data)
mock_task_get.return_value = mock.Mock(get_results=mock_results)
fake_task = fakes.FakeTask({"status": consts.TaskStatus.FINISHED})
fake_task.get_results = mock.MagicMock(return_value=data)
mock_task_get.return_value = fake_task
self.task.results(task_id)
self.assertEqual(1, mock_json_dumps.call_count)
@ -379,15 +380,18 @@ class TaskCommandsTestCase(test.TestCase):
@mock.patch("rally.cli.commands.task.api.Task.get")
def test_results_no_data(self, mock_task_get, mock_stdout):
task_id = "foo_task_id"
mock_results = mock.Mock(return_value=[])
mock_task_get.return_value = mock.Mock(get_results=mock_results)
fake_task = fakes.FakeTask({"status": consts.TaskStatus.FAILED})
mock_task_get.return_value = fake_task
self.assertEqual(1, self.task.results(task_id))
result = self.task.results(task_id)
mock_task_get.assert_called_once_with(task_id)
self.assertEqual(1, result)
expected_out = ("The task %s marked as '%s'. Results "
"available when it is '%s' .") % (
task_id, consts.TaskStatus.FAILED, consts.TaskStatus.FINISHED)
expected_out = ("Task status is %s. Results "
"available when it is one of %s.") % (
consts.TaskStatus.FAILED,
", ".join((consts.TaskStatus.FINISHED,
consts.TaskStatus.ABORTED)))
mock_stdout.write.assert_has_calls([mock.call(expected_out)])
@mock.patch("rally.cli.commands.task.jsonschema.validate",


Loading…
Cancel
Save