1 ##############################################################################
2 # Copyright (c) 2016 Juan Qiu and others
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 from __future__ import absolute_import
12 from yardstick.benchmark.scenarios.availability.result_checker \
13 .baseresultchecker import \
15 from yardstick.benchmark.scenarios.availability import Condition
16 import yardstick.ssh as ssh
17 from yardstick.benchmark.scenarios.availability.util \
18 import buildshellparams, execute_shell_command
20 LOG = logging.getLogger(__name__)
23 class GeneralResultChecker(BaseResultChecker):
24 __result_checker__type__ = "general-result-checker"
27 LOG.debug("config:%s context:%s", self._config, self._context)
28 host = self._context.get(self._config.get('host', None), None)
30 self.connection = None
32 self.connection = ssh.SSH.from_node(
33 host, defaults={"user": "root"})
34 self.connection.wait(timeout=600)
35 LOG.debug("ssh host success!")
37 self.key = self._config['key']
38 self.resultchecker_key = self._config['checker_key']
39 self.type = self._config['checker_type']
40 self.condition = self._config['condition']
41 self.expectedResult = self._config['expectedValue']
42 self.actualResult = object()
44 self.key = self._config['key']
45 if "parameter" in self._config:
46 parameter = self._config['parameter']
47 str = buildshellparams(
48 parameter, True if self.connection else False)
49 l = list(item for item in parameter.values())
50 self.shell_cmd = str.format(*l)
52 self.resultchecker_cfgs = BaseResultChecker.resultchecker_cfgs.get(
53 self.resultchecker_key)
54 self.verify_script = self.get_script_fullpath(
55 self.resultchecker_cfgs['verify_script'])
58 if "parameter" in self._config:
60 with open(self.verify_script, "r") as stdin_file:
61 exit_status, stdout, stderr = self.connection.execute(
65 exit_status, stdout = \
66 execute_shell_command(
67 "/bin/bash {0} {1}".format(
71 LOG.debug("action script of the operation is: %s",
73 LOG.debug("action parameter the of operation is: %s",
77 with open(self.verify_script, "r") as stdin_file:
78 exit_status, stdout, stderr = self.connection.execute(
82 exit_status, stdout = execute_shell_command(
83 "/bin/bash {0}".format(self.verify_script))
85 LOG.debug("action script of the operation is: %s",
88 LOG.debug("exit_status ,stdout : %s ,%s", exit_status, stdout)
89 if exit_status == 0 and stdout:
90 self.actualResult = stdout
91 LOG.debug("verifying resultchecker: %s", self.key)
92 LOG.debug("verifying resultchecker,expected: %s",
94 LOG.debug("verifying resultchecker,actual: %s", self.actualResult)
95 LOG.debug("verifying resultchecker,condition: %s", self.condition)
96 if (type(self.expectedResult) is int):
97 self.actualResult = int(self.actualResult)
98 if self.condition == Condition.EQUAL:
99 self.success = self.actualResult == self.expectedResult
100 elif self.condition == Condition.GREATERTHAN:
101 self.success = self.actualResult > self.expectedResult
102 elif self.condition == Condition.GREATERTHANEQUAL:
103 self.success = self.actualResult >= self.expectedResult
104 elif self.condition == Condition.LESSTHANEQUAL:
105 self.success = self.actualResult <= self.expectedResult
106 elif self.condition == Condition.LESSTHAN:
107 self.success = self.actualResult < self.expectedResult
108 elif self.condition == Condition.IN:
109 self.success = self.expectedResult in self.actualResult
113 "error happened when resultchecker: %s Invalid condition",
118 "error happened when resultchecker: %s verifying the result",
123 "verifying resultchecker: %s,the result is : %s", self.key,