Fix 'rally task results' output for running task

* Fix disorienting message "The task {uuid} can not be found" if
trying to get results for running task to "The task {uuid} is
still running, results will become available when it is finished."
* Check correct message in unit test
* Task uuid now is set as active/default for cli after task is
started, not after it is finished

Closes-bug: #1435446

Change-Id: I90dbc26f181617a1a4dddff3cc5bcbc36e7239da
This commit is contained in:
Olga Kopylova 2015-03-22 19:46:06 +02:00
parent bcb891086c
commit 5ec0b1d0e3
2 changed files with 10 additions and 7 deletions

View File

@ -214,11 +214,11 @@ class TaskCommands(object):
print("Benchmarking... This can take a while...\n")
print("To track task status use:\n")
print("\trally task status\n\tor\n\trally task detailed\n")
if do_use:
self.use(task["uuid"])
api.Task.start(deployment, input_task, task=task,
abort_on_sla_failure=abort_on_sla_failure)
self.detailed(task_id=task["uuid"])
if do_use:
self.use(task["uuid"])
except exceptions.InvalidConfigException:
return(1)
@ -420,7 +420,6 @@ class TaskCommands(object):
:param task_id: Task uuid
"""
results = [{"key": x["key"], "result": x["data"]["raw"],
"sla": x["data"]["sla"],
"load_duration": x["data"]["load_duration"],
@ -430,7 +429,8 @@ class TaskCommands(object):
if results:
print(json.dumps(results, sort_keys=True, indent=4))
else:
print(_("The task %s can not be found") % task_id)
print(_("The task %s is still running, results will become "
"available when it is finished.") % task_id)
return(1)
@cliutils.args("--deployment", type=str, dest="deployment",

View File

@ -303,16 +303,19 @@ class TaskCommandsTestCase(test.TestCase):
mock_json.call_args[1])
mock_get.assert_called_once_with(task_id)
@mock.patch("rally.cmd.commands.task.sys.stdout")
@mock.patch("rally.cmd.commands.task.objects.Task.get")
def test_invalid_results(self, mock_get):
def test_results_no_data(self, mock_get, mock_stdout):
task_id = "foo_task_id"
data = []
mock_results = mock.Mock(return_value=data)
mock_results = mock.Mock(return_value=[])
mock_get.return_value = mock.Mock(get_results=mock_results)
result = self.task.results(task_id)
mock_get.assert_called_once_with(task_id)
self.assertEqual(1, result)
expected_out = ("The task %s is still running, results will become"
" available when it is finished." % task_id)
mock_stdout.write.assert_has_calls([mock.call(expected_out)])
@mock.patch("rally.cmd.commands.task.jsonschema.validate",
return_value=None)