Sort by created at column in cli output

* Rally cli output, sort by created at column wherever required

Change-Id: Id2a1d9901d88f64d624cabc8d09b2ee362eb83c3
Closes-Bug: #1339613
This commit is contained in:
Rohan Kanade 2014-07-09 13:31:30 +02:00
parent 895f3cbc55
commit 9e530df605
6 changed files with 68 additions and 6 deletions

View File

@ -126,7 +126,9 @@ class DeploymentCommands(object):
r = [str(t[column]) for column in headers[:-1]] r = [str(t[column]) for column in headers[:-1]]
r.append("" if t["uuid"] != current_deploy_id else "*") r.append("" if t["uuid"] != current_deploy_id else "*")
table_rows.append(utils.Struct(**dict(zip(headers, r)))) table_rows.append(utils.Struct(**dict(zip(headers, r))))
common_cliutils.print_list(table_rows, headers) common_cliutils.print_list(table_rows, headers,
sortby_index=headers.index(
'created_at'))
else: else:
print(_("There are no deployments. " print(_("There are no deployments. "
"To create a new deployment, use:" "To create a new deployment, use:"

View File

@ -313,7 +313,9 @@ class TaskCommands(object):
headers = ['uuid', 'created_at', 'status', 'failed', 'tag'] headers = ['uuid', 'created_at', 'status', 'failed', 'tag']
task_list = task_list or db.task_list() task_list = task_list or db.task_list()
if task_list: if task_list:
common_cliutils.print_list(task_list, headers) common_cliutils.print_list(task_list, headers,
sortby_index=headers.index(
'created_at'))
else: else:
print(_("There are no tasks. To run a new task, use:" print(_("There are no tasks. To run a new task, use:"
"\nrally task start")) "\nrally task start"))

View File

@ -119,7 +119,9 @@ class VerifyCommands(object):
print ("Total results of verification:\n") print ("Total results of verification:\n")
total_fields = ['UUID', 'Deployment UUID', 'Set name', 'Tests', total_fields = ['UUID', 'Deployment UUID', 'Set name', 'Tests',
'Failures', 'Created at', 'Status'] 'Failures', 'Created at', 'Status']
common_cliutils.print_list([verification], fields=total_fields) common_cliutils.print_list([verification], fields=total_fields,
sortby_index=total_fields.index(
'Created at'))
print ("\nTests:\n") print ("\nTests:\n")
fields = ['name', 'time', 'status'] fields = ['name', 'time', 'status']

View File

@ -123,7 +123,9 @@ class DeploymentCommandsTestCase(test.TestCase):
mock_struct.assert_called_once_with(**fake_deployment) mock_struct.assert_called_once_with(**fake_deployment)
headers = ['uuid', 'created_at', 'name', 'status', 'active'] headers = ['uuid', 'created_at', 'name', 'status', 'active']
mock_print_list.assert_called_once_with([mock_struct()], headers) mock_print_list.assert_called_once_with([mock_struct()], headers,
sortby_index=headers.index(
'created_at'))
@mock.patch('rally.cmd.commands.deployment.common_cliutils.print_list') @mock.patch('rally.cmd.commands.deployment.common_cliutils.print_list')
@mock.patch('rally.cmd.commands.deployment.utils.Struct') @mock.patch('rally.cmd.commands.deployment.utils.Struct')
@ -147,7 +149,9 @@ class DeploymentCommandsTestCase(test.TestCase):
mock_struct.assert_called_once_with(**fake_deployment) mock_struct.assert_called_once_with(**fake_deployment)
headers = ['uuid', 'created_at', 'name', 'status', 'active'] headers = ['uuid', 'created_at', 'name', 'status', 'active']
mock_print_list.assert_called_once_with([mock_struct()], headers) mock_print_list.assert_called_once_with([mock_struct()], headers,
sortby_index=headers.index(
'created_at'))
@mock.patch('rally.cmd.commands.deployment.db.deployment_get') @mock.patch('rally.cmd.commands.deployment.db.deployment_get')
def test_config(self, mock_deployment): def test_config(self, mock_deployment):

View File

@ -144,7 +144,9 @@ class TaskCommandsTestCase(test.TestCase):
mock_db.task_list.assert_called_once_with() mock_db.task_list.assert_called_once_with()
headers = ['uuid', 'created_at', 'status', 'failed', 'tag'] headers = ['uuid', 'created_at', 'status', 'failed', 'tag']
mock_print_list.assert_called_once_with(db_response, headers) mock_print_list.assert_called_once_with(db_response, headers,
sortby_index=headers.index(
'created_at'))
def test_delete(self): def test_delete(self):
task_uuid = str(uuid.uuid4()) task_uuid = str(uuid.uuid4())

View File

@ -16,9 +16,11 @@
import uuid import uuid
import mock import mock
import six
from rally.cmd.commands import verify from rally.cmd.commands import verify
from rally import consts from rally import consts
from rally import objects
from tests import test from tests import test
@ -71,3 +73,51 @@ class VerifyCommandsTestCase(test.TestCase):
self.assertNotIn(wrong_set_name, consts.TEMPEST_TEST_SETS) self.assertNotIn(wrong_set_name, consts.TEMPEST_TEST_SETS)
self.assertFalse(mock_verify.called) self.assertFalse(mock_verify.called)
@mock.patch('rally.openstack.common.cliutils.print_list')
@mock.patch('rally.db.verification_list')
def test_list(self, mock_db_verification_list, mock_print_list):
fields = ['UUID', 'Deployment UUID', 'Set name', 'Tests', 'Failures',
'Created at', 'Status']
verifications = {'dummy': []}
mock_db_verification_list.return_value = verifications
self.verify.list()
mock_db_verification_list.assert_called_once()
mock_print_list.assert_called_once_with(verifications, fields,
sortby_index=fields.index(
'Created at'))
@mock.patch('rally.openstack.common.cliutils.print_list')
@mock.patch('rally.db.verification_get')
@mock.patch('rally.db.verification_result_get')
@mock.patch('rally.objects.Verification')
def test_show(self, mock_obj_verification,
mock_verification_result_get, mock_verification_get,
mock_print_list):
class Test_dummy():
data = {'test_cases': {'test_a': {'name': 'test_a', 'time': 20,
'status': 'PASS'},
'test_b': {'name': 'test_b', 'time': 20,
'status': 'SKIP'},
'test_c': {'name': 'test_c', 'time': 20,
'status': 'FAIL'}}}
verification_id = '39121186-b9a4-421d-b094-6c6b270cf9e9'
total_fields = ['UUID', 'Deployment UUID', 'Set name', 'Tests',
'Failures', 'Created at', 'Status']
fields = ['name', 'time', 'status']
verification = mock.MagicMock()
tests = Test_dummy()
mock_verification_result_get.return_value = tests
mock_verification_get.return_value = verification
mock_obj_verification.return_value = 1
values = map(objects.Verification,
six.itervalues(tests.data['test_cases']))
self.verify.show(verification_id)
mock_print_list.assert_any_call(
[verification], fields=total_fields,
sortby_index=total_fields.index('Created at'))
mock_verification_get.assert_called_once_with(verification_id)
mock_verification_result_get.assert_called_once_with(verification_id)
mock_print_list.assert_any_call(values, fields, sortby_index=0)