1 #############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
10 """ Handler for yardstick command 'task' """
11 from __future__ import print_function
12 from __future__ import absolute_import
14 from yardstick.benchmark.core.task import Task
15 from yardstick.common.utils import cliargs
16 from yardstick.common.utils import write_json_to_file
17 from yardstick.cmd.commands import change_osloobj_to_paras
19 output_file_default = "/tmp/yardstick.out"
22 class TaskCommands(object): # pragma: no cover
25 Set of commands to manage benchmark tasks.
28 @cliargs("inputfile", type=str, help="path to task or suite file", nargs=1)
29 @cliargs("--task-args", dest="task_args",
30 help="Input task args (dict in json). These args are used"
31 "to render input task that is jinja2 template.")
32 @cliargs("--task-args-file", dest="task_args_file",
33 help="Path to the file with input task args (dict in "
34 "json/yaml). These args are used to render input"
35 "task that is jinja2 template.")
36 @cliargs("--keep-deploy", help="keep context deployed in cloud",
38 @cliargs("--parse-only", help="parse the config file and exit",
40 @cliargs("--output-file", help="file where output is stored, default %s" %
41 output_file_default, default=output_file_default)
42 @cliargs("--suite", help="process test suite file instead of a task file",
44 def do_start(self, args, **kwargs):
45 param = change_osloobj_to_paras(args)
46 self.output_file = param.output_file
49 Task().start(param, **kwargs)
50 except Exception as e:
51 self._write_error_data(e)
54 def _write_error_data(self, error):
55 data = {'status': 2, 'result': str(error)}
56 write_json_to_file(self.output_file, data)