Skip to content

Commit

Permalink
Merge "Adding duration header"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Jan 16, 2015
2 parents ebec66f + e6fd7b6 commit b3ea58b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 7 additions & 4 deletions rally/cmd/commands/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,8 @@ def list(self, deployment=None, all_deployments=False, status=None):
"""

filters = {}
headers = ["uuid", "deployment_name", "created_at", "status",
"failed", "tag"]
headers = ["uuid", "deployment_name", "created_at", "duration",
"status", "failed", "tag"]

if status in consts.TaskStatus:
filters.setdefault("status", status)
Expand All @@ -468,11 +468,14 @@ def list(self, deployment=None, all_deployments=False, status=None):
if not all_deployments:
filters.setdefault("deployment", deployment)

task_list = objects.Task.list(**filters)
task_list = map(lambda x: x.to_dict(), objects.Task.list(**filters))

for x in task_list:
x["duration"] = x["updated_at"] - x["created_at"]

if task_list:
common_cliutils.print_list(
map(lambda x: x.to_dict(), task_list),
task_list,
headers, sortby_index=headers.index("created_at"))
else:
if status:
Expand Down
8 changes: 5 additions & 3 deletions tests/unit/cmd/commands/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# under the License.

import copy
import datetime as date

import mock

Expand Down Expand Up @@ -489,7 +490,8 @@ def test_report_exceptions(self, mock_open, mock_json_load,
return_value="123456789")
@mock.patch("rally.cmd.commands.task.objects.Task.list",
return_value=[fakes.FakeTask(uuid="a",
created_at="b",
created_at=date.datetime.now(),
updated_at=date.datetime.now(),
status="c",
failed=True,
tag="d",
Expand All @@ -501,8 +503,8 @@ def test_list(self, mock_objects_list, mock_default, mock_print_list):
deployment=mock_default.return_value,
status=consts.TaskStatus.RUNNING)

headers = ["uuid", "deployment_name", "created_at", "status",
"failed", "tag"]
headers = ["uuid", "deployment_name", "created_at", "duration",
"status", "failed", "tag"]
mock_print_list.assert_called_once_with(
mock_objects_list.return_value, headers,
sortby_index=headers.index('created_at'))
Expand Down

0 comments on commit b3ea58b

Please sign in to comment.