Implement task cli list method

This method shows list of all tasks and their details

Change-Id: I991950823ac5e6cc5057e4e3563bd4084654a36a
This commit is contained in:
Boris Pavlovic
2013-09-19 19:25:22 +04:00
parent 86261ea868
commit 2810b88dfa
3 changed files with 19 additions and 2 deletions

View File

@@ -22,6 +22,8 @@ from __future__ import print_function
import json
import sys
import prettytable
from rally.cmd import cliutils
from rally import db
from rally.openstack.common.gettextutils import _ # noqa
@@ -64,7 +66,15 @@ class TaskCommands(object):
"""Get list of all tasks
Returns list of active tasks
"""
print(_("Not implemented"))
headers = ['uuid', 'created_at', 'status', 'failed']
table = prettytable.PrettyTable(headers)
for t in db.task_list():
r = [t['uuid'], str(t['created_at']), t['status'], t['failed']]
table.add_row(r)
print(table)
def main():

View File

@@ -5,6 +5,7 @@ jsonschema>=2.0.0
netaddr>=0.7.6
paramiko>=1.8.0
pbr>=0.5.21,<1.0
PrettyTable>=0.6,<0.8
psutil
pytest
pytest-timeout

View File

@@ -55,4 +55,10 @@ class TaskCommandsTestCase(test.BaseTestCase):
mock_db.task_get_by_uuid.assert_called_once_with(test_uuid)
def test_list(self):
self.task.list()
db_response = [
{'uuid': 'a', 'created_at': 'b', 'status': 'c', 'failed': True}
]
with mock.patch("rally.cmd.main.db") as mock_db:
mock_db.task_list = mock.MagicMock(return_value=db_response)
self.task.list()
mock_db.task_list.assert_called_once_with()