diff options
Diffstat (limited to 'yardstick/benchmark/scenarios')
3 files changed, 104 insertions, 40 deletions
diff --git a/yardstick/benchmark/scenarios/availability/operation/operation_general.py b/yardstick/benchmark/scenarios/availability/operation/operation_general.py index 49c63cc75..6ec8601af 100644 --- a/yardstick/benchmark/scenarios/availability/operation/operation_general.py +++ b/yardstick/benchmark/scenarios/availability/operation/operation_general.py @@ -14,7 +14,8 @@ from yardstick.benchmark.scenarios.availability.operation.baseoperation \ BaseOperation import yardstick.ssh as ssh -from yardstick.benchmark.scenarios.availability.util import buildshellparams +from yardstick.benchmark.scenarios.availability.util \ + import buildshellparams, execute_shell_command LOG = logging.getLogger(__name__) @@ -25,24 +26,29 @@ class GeneralOperaion(BaseOperation): def setup(self): LOG.debug("config:%s context:%s", self._config, self._context) - host = self._context.get(self._config['host'], None) + host = self._context.get(self._config.get('host', None), None) - self.connection = ssh.SSH.from_node(host, defaults={"user": "root"}) - self.connection.wait(timeout=600) - LOG.debug("ssh host success!") + self.connection = None + if host: + self.connection = ssh.SSH.from_node( + host, defaults={"user": "root"}) + self.connection.wait(timeout=600) + LOG.debug("ssh host success!") self.key = self._config['key'] self.operation_key = self._config['operation_key'] if "action_parameter" in self._config: actionParameter = self._config['action_parameter'] - str = buildshellparams(actionParameter) + str = buildshellparams( + actionParameter, True if self.connection else False) l = list(item for item in actionParameter.values()) self.action_param = str.format(*l) if "rollback_parameter" in self._config: rollbackParameter = self._config['rollback_parameter'] - str = buildshellparams(rollbackParameter) + str = buildshellparams( + rollbackParameter, True if self.connection else False) l = list(item for item in rollbackParameter.values()) self.rollback_param = str.format(*l) @@ -55,15 +61,25 @@ class GeneralOperaion(BaseOperation): def run(self): if "action_parameter" in self._config: - with open(self.action_script, "r") as stdin_file: - exit_status, stdout, stderr = self.connection.execute( - self.action_param, - stdin=stdin_file) + if self.connection: + with open(self.action_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + self.action_param, + stdin=stdin_file) + else: + exit_status, stdout = \ + execute_shell_command( + "/bin/bash {0} {1}".format( + self.action_script, self.action_param)) else: - with open(self.action_script, "r") as stdin_file: - exit_status, stdout, stderr = self.connection.execute( - "/bin/sh -s ", - stdin=stdin_file) + if self.connection: + with open(self.action_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + "/bin/sh -s ", + stdin=stdin_file) + else: + exit_status, stdout = execute_shell_command( + "/bin/bash {0}".format(self.action_script)) if exit_status == 0: LOG.debug("success,the operation's output is: %s", stdout) @@ -74,12 +90,22 @@ class GeneralOperaion(BaseOperation): def rollback(self): if "rollback_parameter" in self._config: - with open(self.rollback_script, "r") as stdin_file: - exit_status, stdout, stderr = self.connection.execute( - self.rollback_param, - stdin=stdin_file) + if self.connection: + with open(self.rollback_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + self.rollback_param, + stdin=stdin_file) + else: + exit_status, stdout = \ + execute_shell_command( + "/bin/bash {0} {1}".format( + self.rollback_script, self.rollback_param)) else: - with open(self.rollback_script, "r") as stdin_file: - exit_status, stdout, stderr = self.connection.execute( - "/bin/sh -s ", - stdin=stdin_file) + if self.connection: + with open(self.rollback_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + "/bin/sh -s ", + stdin=stdin_file) + else: + exit_status, stdout = execute_shell_command( + "/bin/bash {0}".format(self.rollback_script)) diff --git a/yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py b/yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py index ff6017b88..0f2e382ae 100644 --- a/yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py +++ b/yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py @@ -9,13 +9,13 @@ from __future__ import absolute_import import logging - from yardstick.benchmark.scenarios.availability.result_checker \ .baseresultchecker import \ BaseResultChecker from yardstick.benchmark.scenarios.availability import Condition import yardstick.ssh as ssh -from yardstick.benchmark.scenarios.availability.util import buildshellparams +from yardstick.benchmark.scenarios.availability.util \ + import buildshellparams, execute_shell_command LOG = logging.getLogger(__name__) @@ -25,11 +25,14 @@ class GeneralResultChecker(BaseResultChecker): def setup(self): LOG.debug("config:%s context:%s", self._config, self._context) - host = self._context.get(self._config['host'], None) + host = self._context.get(self._config.get('host', None), None) - self.connection = ssh.SSH.from_node(host, defaults={"user": "root"}) - self.connection.wait(timeout=600) - LOG.debug("ssh host success!") + self.connection = None + if host: + self.connection = ssh.SSH.from_node( + host, defaults={"user": "root"}) + self.connection.wait(timeout=600) + LOG.debug("ssh host success!") self.key = self._config['key'] self.resultchecker_key = self._config['checker_key'] @@ -41,7 +44,8 @@ class GeneralResultChecker(BaseResultChecker): self.key = self._config['key'] if "parameter" in self._config: parameter = self._config['parameter'] - str = buildshellparams(parameter) + str = buildshellparams( + parameter, True if self.connection else False) l = list(item for item in parameter.values()) self.shell_cmd = str.format(*l) @@ -52,19 +56,32 @@ class GeneralResultChecker(BaseResultChecker): def verify(self): if "parameter" in self._config: - with open(self.verify_script, "r") as stdin_file: - exit_status, stdout, stderr = self.connection.execute( - self.shell_cmd, - stdin=stdin_file) + if self.connection: + with open(self.verify_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + self.shell_cmd, + stdin=stdin_file) + else: + exit_status, stdout = \ + execute_shell_command( + "/bin/bash {0} {1}".format( + self.verify_script, + self.rollback_param)) + LOG.debug("action script of the operation is: %s", self.verify_script) LOG.debug("action parameter the of operation is: %s", self.shell_cmd) else: - with open(self.verify_script, "r") as stdin_file: - exit_status, stdout, stderr = self.connection.execute( - "/bin/bash -s ", - stdin=stdin_file) + if self.connection: + with open(self.verify_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + "/bin/bash -s ", + stdin=stdin_file) + else: + exit_status, stdout = execute_shell_command( + "/bin/bash {0}".format(self.verify_script)) + LOG.debug("action script of the operation is: %s", self.verify_script) diff --git a/yardstick/benchmark/scenarios/availability/util.py b/yardstick/benchmark/scenarios/availability/util.py index 2addef8ef..eadbfa53b 100644 --- a/yardstick/benchmark/scenarios/availability/util.py +++ b/yardstick/benchmark/scenarios/availability/util.py @@ -6,14 +6,35 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +import logging +import subprocess +import traceback +LOG = logging.getLogger(__name__) -def buildshellparams(param): + +def buildshellparams(param, remote=True): i = 0 values = [] - result = '/bin/bash -s' + result = '/bin/bash -s' if remote else '' for key in param.keys(): values.append(param[key]) result += " {%d}" % i i = i + 1 return result + + +def execute_shell_command(command): + """execute shell script with error handling""" + exitcode = 0 + output = [] + try: + LOG.debug("the command is: %s", command) + output = subprocess.check_output(command, shell=True) + except Exception: + exitcode = -1 + output = traceback.format_exc() + LOG.error("exec command '%s' error:\n ", command) + LOG.error(traceback.format_exc()) + + return exitcode, output |