Print task information when creating task from CLI
Summary line is printed when task has been created but not started, detailed information is printed once the task has completed. Change-Id: I8a3cbb81d7fccffe158517d3023ad47d28d7ebc1 Trello: https://trello.com/c/wJbH8DqG
This commit is contained in:
parent
de35f19279
commit
e4832ed29e
@ -120,7 +120,10 @@ class TaskCommands(object):
|
||||
with open(task) as task_file:
|
||||
config_dict = json.load(task_file)
|
||||
try:
|
||||
api.start_task(deploy_id, config_dict)
|
||||
task = api.create_task(deploy_id)
|
||||
self.list(task_list=[task])
|
||||
api.start_task(deploy_id, config_dict, task=task)
|
||||
self.detailed(task_id=task['uuid'])
|
||||
except exceptions.InvalidArgumentsException:
|
||||
print(_("Reason: %s") % sys.exc_info()[1])
|
||||
|
||||
@ -246,13 +249,15 @@ class TaskCommands(object):
|
||||
else:
|
||||
print(_("Wrong value for --pretty=%s") % pretty)
|
||||
|
||||
def list(self):
|
||||
def list(self, task_list=None):
|
||||
"""Print a list of all tasks."""
|
||||
|
||||
headers = ['uuid', 'created_at', 'status', 'failed']
|
||||
table = prettytable.PrettyTable(headers)
|
||||
|
||||
for t in db.task_list():
|
||||
task_list = task_list or db.task_list()
|
||||
|
||||
for t in task_list:
|
||||
r = [t['uuid'], str(t['created_at']), t['status'], t['failed']]
|
||||
table.add_row(r)
|
||||
|
||||
|
@ -66,7 +66,18 @@ def recreate_deploy(deploy_uuid):
|
||||
deployment.update_endpoint(endpoint)
|
||||
|
||||
|
||||
def start_task(deploy_uuid, config):
|
||||
def create_task(deploy_uuid):
|
||||
"""Create a task without starting it.
|
||||
|
||||
Task is a list of benchmarks that will be called one by one, results of
|
||||
execution will be stored in DB.
|
||||
|
||||
:param deploy_uuid: UUID of the deployment
|
||||
"""
|
||||
return objects.Task(deployment_uuid=deploy_uuid)
|
||||
|
||||
|
||||
def start_task(deploy_uuid, config, task=None):
|
||||
"""Start a task.
|
||||
|
||||
Task is a list of benchmarks that will be called one by one, results of
|
||||
@ -76,8 +87,7 @@ def start_task(deploy_uuid, config):
|
||||
:param config: a dict with a task configuration
|
||||
"""
|
||||
deployment = objects.Deployment.get(deploy_uuid)
|
||||
task = objects.Task(deployment_uuid=deploy_uuid)
|
||||
|
||||
task = task or objects.Task(deployment_uuid=deploy_uuid)
|
||||
tester = engine.TestEngine(config, task)
|
||||
deployer = deploy.EngineFactory.get_engine(deployment['config']['name'],
|
||||
deployment)
|
||||
|
@ -26,14 +26,22 @@ class TaskCommandsTestCase(test.BaseTestCase):
|
||||
super(TaskCommandsTestCase, self).setUp()
|
||||
self.task = main.TaskCommands()
|
||||
|
||||
@mock.patch('rally.cmd.main.TaskCommands.detailed')
|
||||
@mock.patch('rally.orchestrator.api.create_task',
|
||||
return_value=dict(uuid='fc1a9bbe-1ead-4740-92b5-0feecf421634',
|
||||
created_at='2014-01-14 09:14:45.395822',
|
||||
status='init',
|
||||
failed=False))
|
||||
@mock.patch('rally.cmd.main.api.start_task')
|
||||
@mock.patch('rally.cmd.main.open',
|
||||
mock.mock_open(read_data='{"some": "json"}'),
|
||||
create=True)
|
||||
def test_start(self, mock_api):
|
||||
def test_start(self, mock_api, mock_create_task,
|
||||
mock_task_detailed):
|
||||
deploy_id = str(uuid.uuid4())
|
||||
self.task.start(deploy_id, 'path_to_config.json')
|
||||
mock_api.assert_called_once_with(deploy_id, {'some': 'json'})
|
||||
mock_api.assert_called_once_with(deploy_id, {u'some': u'json'},
|
||||
task=mock_create_task.return_value)
|
||||
|
||||
def test_abort(self):
|
||||
test_uuid = str(uuid.uuid4())
|
||||
|
@ -80,6 +80,12 @@ class APITestCase(test.TestCase):
|
||||
'endpoint': self.endpoint,
|
||||
}
|
||||
|
||||
@mock.patch('rally.objects.Task')
|
||||
def test_create_task(self, mock_task):
|
||||
deployment_uuid = uuid.uuid4()
|
||||
api.create_task(deployment_uuid)
|
||||
mock_task.assert_called_once_with(deployment_uuid=deployment_uuid)
|
||||
|
||||
@mock.patch('rally.benchmark.engine.osclients')
|
||||
@mock.patch('rally.benchmark.engine.runner.ScenarioRunner')
|
||||
@mock.patch('rally.objects.deploy.db.deployment_get')
|
||||
|
Loading…
x
Reference in New Issue
Block a user