1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd 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 ##############################################################################
17 from oslo_utils import encodeutils
20 class Yardstick(object):
21 """Create and represent separate yardstick installation.
24 yardstick = yardstick()
25 output = yardstick("runner list")
29 def __init__(self, fake=False):
31 self.args = ["yardstick"]
32 self.env = copy.deepcopy(os.environ)
37 def __call__(self, cmd, getjson=False, report_path=None, raw=False,
38 suffix=None, extension=None, keep_old=False,
40 """Call yardstick in the shell
42 :param cmd: yardstick command
43 :param getjson: in cases, when yardstick prints JSON, you can catch output
46 :param report_path: if present, yardstick command and its output will be
47 written to file with passed file name
48 :param raw: don't write command itself to report file. Only output
52 if not isinstance(cmd, list):
55 output = encodeutils.safe_decode(subprocess.check_output(
56 self.args + cmd, stderr=subprocess.STDOUT, env=self.env))
59 return json.loads(output)
61 except subprocess.CalledProcessError as e: