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 ##############################################################################
12 from yardstick.benchmark.core.task import Task
13 from yardstick.common.utils import cliargs
14 from yardstick.common.utils import write_json_to_file
15 from yardstick.cmd.commands import change_osloobj_to_paras
17 output_file_default = "/tmp/yardstick.out"
20 LOG = logging.getLogger(__name__)
23 class TaskCommands(object): # pragma: no cover
26 Set of commands to manage benchmark tasks.
30 @cliargs("inputfile", type=str, help="path to task or suite file", nargs=1)
31 @cliargs("--task-args", dest="task_args",
32 help="Input task args (dict in json). These args are used"
33 "to render input task that is jinja2 template.")
34 @cliargs("--task-args-file", dest="task_args_file",
35 help="Path to the file with input task args (dict in "
36 "json/yaml). These args are used to render input"
37 "task that is jinja2 template.")
38 @cliargs("--keep-deploy", help="keep context deployed in cloud",
40 @cliargs("--parse-only", help="parse the config file and exit",
42 @cliargs("--render-only", help="Render the tasks files, store the result "
43 "in the directory given and exit", type=str, dest="render_only")
44 @cliargs("--output-file", help="file where output is stored, default %s" %
45 output_file_default, default=output_file_default)
46 @cliargs("--suite", help="process test suite file instead of a task file",
48 def do_start(self, args, **kwargs):
49 param = change_osloobj_to_paras(args)
50 self.output_file = param.output_file
52 LOG.info('Task START')
54 result = Task().start(param, **kwargs)
55 except Exception as e: # pylint: disable=broad-except
56 self._write_error_data(e)
57 LOG.info('Task FAILED')
60 if result.get('result', {}).get('criteria') == 'PASS':
61 LOG.info('Task SUCCESS')
63 LOG.info('Task FAILED')
64 # exit without backtrace
65 raise SystemExit(self.EXIT_TEST_FAILED)
67 def _write_error_data(self, error):
68 data = {'status': 2, 'result': str(error)}
69 write_json_to_file(self.output_file, data)