X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Fbenchmark%2Fscenarios%2Favailability%2Fresult_checker%2Fresult_checker_general.py;h=4543381750ec0de7d4a2847aec526bcf9d789690;hb=f5a96ffd959b11a122c4beea1fc99c89f755678c;hp=681fbf63fbe5a12b128fbb1696e1b68555d15dcc;hpb=5d0fb5e5ed3fc324cac995994b061b6d449fc869;p=yardstick.git 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 681fbf63f..454338175 100644 --- a/yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py +++ b/yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py @@ -6,30 +6,33 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import logging -from baseresultchecker import BaseResultChecker +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__) class GeneralResultChecker(BaseResultChecker): - __result_checker__type__ = "general-result-checker" def setup(self): - LOG.debug("config:%s context:%s" % (self._config, self._context)) - host = self._context.get(self._config['host'], None) - ip = host.get("ip", None) - user = host.get("user", "root") - key_filename = host.get("key_filename", "~/.ssh/id_rsa") + LOG.debug("config:%s context:%s", self._config, self._context) + host = self._context.get(self._config.get('host', None), None) - self.connection = ssh.SSH(user, ip, key_filename=key_filename) - 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,30 +56,43 @@ class GeneralResultChecker(BaseResultChecker): def verify(self): if "parameter" in self._config: - exit_status, stdout, stderr = self.connection.execute( - self.shell_cmd, - stdin=open(self.verify_script, "r")) - LOG.debug("action script of the operation is: {0}" - .format(self.verify_script)) - LOG.debug("action parameter the of operation is: {0}" - .format(self.shell_cmd)) + if self.connection: + with open(self.verify_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + "sudo {}".format(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: - exit_status, stdout, stderr = self.connection.execute( - "/bin/bash -s ", - stdin=open(self.verify_script, "r")) - LOG.debug("action script of the operation is: {0}" - .format(self.verify_script)) + if self.connection: + with open(self.verify_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + "sudo /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) - LOG.debug("exit_status ,stdout : {0} ,{1}".format(exit_status, stdout)) + LOG.debug("exit_status ,stdout : %s ,%s", exit_status, stdout) if exit_status == 0 and stdout: self.actualResult = stdout - LOG.debug("verifying resultchecker: {0}".format(self.key)) - LOG.debug("verifying resultchecker,expected: {0}" - .format(self.expectedResult)) - LOG.debug("verifying resultchecker,actual: {0}" - .format(self.actualResult)) - LOG.debug("verifying resultchecker,condition: {0}" - .format(self.condition)) + LOG.debug("verifying resultchecker: %s", self.key) + LOG.debug("verifying resultchecker,expected: %s", + self.expectedResult) + LOG.debug("verifying resultchecker,actual: %s", self.actualResult) + LOG.debug("verifying resultchecker,condition: %s", self.condition) if (type(self.expectedResult) is int): self.actualResult = int(self.actualResult) if self.condition == Condition.EQUAL: @@ -93,16 +110,16 @@ class GeneralResultChecker(BaseResultChecker): else: self.success = False LOG.debug( - "error happened when resultchecker: {0} Invalid condition" - .format(self.key)) + "error happened when resultchecker: %s Invalid condition", + self.key) else: self.success = False LOG.debug( - "error happened when resultchecker: {0} verifying the result" - .format(self.key)) + "error happened when resultchecker: %s verifying the result", + self.key) LOG.error(stderr) LOG.debug( - "verifying resultchecker: {0},the result is : {1}" - .format(self.key, self.success)) + "verifying resultchecker: %s,the result is : %s", self.key, + self.success) return self.success