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.common.utils import read_json_from_file
18 from yardstick.cmd.commands import change_osloobj_to_paras
20 output_file_default = "/tmp/yardstick.out"
23 class TaskCommands(object):
26 Set of commands to manage benchmark tasks.
29 @cliargs("inputfile", type=str, help="path to task or suite file", nargs=1)
30 @cliargs("--task-args", dest="task_args",
31 help="Input task args (dict in json). These args are used"
32 "to render input task that is jinja2 template.")
33 @cliargs("--task-args-file", dest="task_args_file",
34 help="Path to the file with input task args (dict in "
35 "json/yaml). These args are used to render input"
36 "task that is jinja2 template.")
37 @cliargs("--keep-deploy", help="keep context deployed in cloud",
39 @cliargs("--parse-only", help="parse the config file and exit",
41 @cliargs("--output-file", help="file where output is stored, default %s" %
42 output_file_default, default=output_file_default)
43 @cliargs("--suite", help="process test suite file instead of a task file",
45 def do_start(self, args, **kwargs):
46 param = change_osloobj_to_paras(args)
47 self.output_file = param.output_file
49 self._init_result_file()
52 Task().start(param, **kwargs)
54 except Exception as e:
55 self._write_error_data(e)
57 def _init_result_file(self):
58 data = {'status': 0, 'result': []}
59 write_json_to_file(self.output_file, data)
62 result = read_json_from_file(self.output_file).get('result')
63 data = {'status': 1, 'result': result}
64 write_json_to_file(self.output_file, data)
66 def _write_error_data(self, error):
67 data = {'status': 2, 'result': str(error)}
68 write_json_to_file(self.output_file, data)