Bugfix: Local Openstack Operation in HA test frameworks
[yardstick.git] / yardstick / benchmark / scenarios / availability / util.py
1 ##############################################################################
2 # Copyright (c) 2016 Juan Qiu
3 # juan_ qiu@tongji.edu.cn
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 ##############################################################################
9 import logging
10 import subprocess
11 import traceback
12
13 LOG = logging.getLogger(__name__)
14
15
16 def buildshellparams(param, remote=True):
17     i = 0
18     values = []
19     result = '/bin/bash -s' if remote else ''
20     for key in param.keys():
21         values.append(param[key])
22         result += " {%d}" % i
23         i = i + 1
24     return result
25
26
27 def execute_shell_command(command):
28     """execute shell script with error handling"""
29     exitcode = 0
30     output = []
31     try:
32         LOG.debug("the command is: %s", command)
33         output = subprocess.check_output(command, shell=True)
34     except Exception:
35         exitcode = -1
36         output = traceback.format_exc()
37         LOG.error("exec command '%s' error:\n ", command)
38         LOG.error(traceback.format_exc())
39
40     return exitcode, output